How to determine from a library which platform / frameworks it compiles for?
Earlier (in ArduinoIDE) I used the following construction:
#if defined(ESP32)
#include “bla-bla-bla-esp32.h”
…
#endif
#if defined(ESP8266)
#include “bla-bla-bla-esp8266.h”
…
#endif
This does not work in the PlatformIO!
Specifically, I need to define the frameworks “espidf”, “esp8266-rtos-sdk”
kotyara12:
Earlier (in ArduinoIDE) I used the following construction:
#if defined(ESP32)
#include “bla-bla-bla-esp32.h”
…
#endif
#if defined(ESP8266)
#include “bla-bla-bla-esp8266.h”
…
#endif
This does not work in the PlatformIO!
This does work in PlatformIO + Arduino.
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
any compiler invocation has the flags (which you can also check by simply executing the “Verbose Build” task)
-DPLATFORMIO=50004 -DARDUINO_ESP32_DEV -DESP32 -DESP_PLATFORM -DF_CPU=240000000L -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DARDUINO=10805 -DARDUINO_ARCH_ESP32 -DARDUINO_VARIANT="esp32" “-DARDUINO_BOARD="Espressif ESP32 Dev Module"”
As you can see ESP32
is also in there.
However in ESP-IDF flags are different.
xtensa-esp32-elf-gcc -o .pio\build\esp32dev\esp-idf\app_update\esp_ota_ops.c.o -c -std=gnu99 -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Werror=all
-Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -Wno-old-style-declaration -DPLATFORMIO=50004 -DARDUINO_ESP32_DEV -DCONFIG_BLINK_GPIO=2 -D_GNU_SOURCE -DIDF_VER="3.40100.200827" -DESP_PLATFORM …
So you can e.g. use ESP_PLATFORM
or #ifdef IDF_VER
.
For
[env:esp8266]
platform = espressif8266
board = nodemcuv2
framework = esp8266-rtos-sdk
the Verbose Build shows that flags
-DPLATFORMIO=50004 -DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_NODEMCU -DF_CPU=80000000L -D__ets__ -DICACHE_FLASH
Are used so this works still with #ifdef ESP8266
.
Also note that libraries which have different library dependencies for each platform might need to set their libLDFMode
value in the library.json
to either chain+
or deep+
.
What you need! THANKS !!!
kotyara12:
THANKS !!!
No problem, marking as solved then.
Alas, but for some reason it didn’t work for me again
Perhaps my PlatformIO was installed crookedly???
I installed it on three computers, and everywhere there were some problems during installation. Different everywhere.
If you could upload the whole project with the library that doesn’t work, we can take a look.
Good. Here is a library and a demo for it. They work great on ESP 32.
https://kotyara12.ru/wp-content/uploads/iot/07_led32/bug/led32demo.zip
Now I want to adapt it for esp8266 (for FreeRtos, of course)
Thanks for your help and support. Checked build verbose. Result in the picture:
For some reason, there is an ARDUINO_ESP32_DEV define (although the project is only for ESPIDF), but not just ESP32. It remains to be seen why.
My demo above showed ESP32 with the Arduino platform. In the text above I explained that for ESP-IDF, other macros must be used, e.g. IDF_VER
. Changing #ifdef ESP32
to #ifdef IDF_VER
, and deleting an errornous #else
in rLed32.h
line 120 makes the project compile.
Now I understand, thank you very much
Replaced with
#if defined(IDF_VER) || defined(ESP32)
It works. Thanks again