Page 1 of 1

Macro to detect ESP32-xx architecture

Posted: Thu Jun 08, 2023 10:53 pm
by geedotk
Is there any defined macro that I can use to detect the ESP32-xx architecture at build time? I've got some code that I would like to be able to compile for different architectures like ARM or x86. For example, I can check for the existence of the "__ARM_ARCH" macro to see if it is being built for ARM. Is there some similar macro for ESP32-xx?

Thanks!

Re: Macro to detect ESP32-xx architecture

Posted: Fri Jun 09, 2023 8:31 am
by MicroController
As to the architecture, you can use

Code: Select all

#ifdef __XTENSA__
...
#endif
#ifdef __riscv
...
#endif
Then there is ESP_PLATFORM which "can be used to detect that build happens within ESP-IDF".

For the specific target SoC, sdkconfig.h defines the current target, i.e.

Code: Select all

#if CONFIG_IDF_TARGET_ESP32
...
#elif CONFIG_IDF_TARGET_ESP32S2
...
#elif CONFIG_IDF_TARGET_ESP32C3
...
#elif CONFIG_IDF_TARGET_ESP32S3
...
#elif CONFIG_IDF_TARGET_ESP32H4
...
#elif CONFIG_IDF_TARGET_ESP32C2
...
#elif CONFIG_IDF_TARGET_ESP32C6
...
#elif CONFIG_IDF_TARGET_ESP32H2
...
#endif