PlatformIO Community

Code writhe method

When we open new sketch in arduino, there are two pre defined functions available.

void setup() {}
and 
void loop() {}

where setup runs only one time.
how can I write such function in C, with platform IO

Just do one call of setup() and then call loop() within in infinite loop?

Ok,
I have few more doubts, Pl. explain,

can I define boolian type variable?
How can I use GPIO as 8 bit port ?

How to load a variable with hex OR binery value?

It seems you have problems about many programming basics in C/C++.

Thus I can only suggest free courses like https://www.udemy.com/course/free-learn-c-tutorial-beginners/ and https://www.learn-cpp.org/de/ and https://www.youtube.com/watch?v=vLnPwxZdW4Y.

Instead of asking here and having to wait for an answer, please always google your questions first. The answer is pretty much always the first result.

C++ has the builtin type bool, so you can just do bool myVariable = false;. For C, you have to #include <stdbool.h> and then you get the same type and values.

Without knowing what exact microcontroller you’re talking about I have no idea how to answer that. Usually, there is some “output data register” for a GPIO pin bank (that can have 8 or 16 pins or whatever), but every MCU is different. For an ATMega328P and related, one would use PORTD = 0x..; to achieve that. That technical manual of your MCU is your friend here.

In C/C++, you just load it with a 0x prefix for hex or 0b for binary.

#include <stdint.h>

void some_func() {
   uint16_t myVar1 = 0xABCD;
   uint8_t myVar2 = 0b00110001;
}

note that there are forums / answer-question boards like stackoverflow.com/ that help in these cases – however, you should always look if your question wasn’t answered there before.

Thanks maxgerhardt,

I forgot the syntex, I wrote “boolian” instead of “bool” , thatswhy compiler shows error.

I have 15 yrs experience of AVR MEga MCU, mostly I am using mega32, and programming in assembly in AVR Studio. So I am aware of PORT, At present I want to know
How can I use port in ESP32?

Tell me one thing,
In the “led blink” example, how they get 1ms tick?
where is its code?

That’s an interesting question an the answer to that should lie in the implementation https://github.com/espressif/esp-idf/tree/master/components/freertos for the FreeRTOS timer (which isn’t necessarily 1ms, it’s configurable), and the GPIO driver is in https://github.com/espressif/esp-idf/blob/master/components/driver/gpio.c.

These all user timers of probably the XTensa CPU and the registers of the microcontroller itself, which are documented in https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf

Have you made progress here? I’m kind of interested in compiling a bare-metal project which just has a startup file, linker file and a small amount of code with direct register access for timer and GPIO access…

Just as a little side project I’ve started https://github.com/maxgerhardt/minimal-esp32-sdk as a bare-metal firmware project. No frameworks used, just header files and direct register access. It already runs a printf() loop and watchdog reset logic pretty nicely, and one can experiment with other peripherals (GPIO, timers, …) there too.

Can I debug in “single step” mode ? (only software, to check program flow)
how to protect code? is there any lock bit ? like avr controller ?

I know everything at chip level,(this is the reason I am working in assembly. each machine cycle is under my control). but problem is here, I dont know , how to write these stuff in C.
I also seen udemy video (as you suggested) but still there is some confusion. In that videos, they only discuss about software, not hardware.
I even dont know, what is the use of “cmake” file.

This is a video, I made this machine. its hardware is built with AVR mega32, it works within 25 micron accuracy. I run stepper motor in realtime ,without missing a single step