PlatformIO Community

How to use c Compiler for ESP8266

Hi there,
i have been working with platformio for a few weeks now and have been able to create quite a bit for my microcontroller (atmega328p). I have always tried to get away from the Arduino structure. So no “void setup” or “void loop” but simple C.
Now I got a ESP8266, which I would like to compile with a C environment.
When I create the project now (for the 12E) it asks which framework I should use. I have tried them all by replacing the Arduino setup and loop with the int main(){} function, however it always came up with errors. Does anyone know how I can use a pure C environment for the ESP8266?

Your best bet for a good, kind of updated C-only environment would be GitHub - espressif/ESP8266_RTOS_SDK: Latest ESP8266 SDK based on FreeRTOS, esp-idf style. (outdated in PIO) and GitHub - SuperHouse/esp-open-rtos: Open source FreeRTOS-based ESP8266 software framework, which is however not supported in PlatformIO.

What is supported and C-only but outdated is ESP8266-NonOS SDK and RTOS SDK (see e.g. this issue.

If you want to use the Arduino framework with C, you can still write setup() and loop() in a .cpp file but then with an appropriate extern "C" void setup_c(); declaration e.g. you can call into a setup_c() function that you can implement in a .c file. Not however that you will likely not be able to use much of the Arduino C++ API without creating such a C helper function in C++, such as

extern "C" void pinMode_c(int pin, int mode) {
  pinMode(pin, mode);

then C code can have a header with void pinMode_c(int pin, int mode); declaration and call into that function implemented in C++.