Macro to detect ESP32-xx architecture

geedotk
Posts: 8
Joined: Sat Feb 04, 2023 9:39 pm

Macro to detect ESP32-xx architecture

Postby geedotk » Thu Jun 08, 2023 10:53 pm

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!

MicroController
Posts: 1136
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Macro to detect ESP32-xx architecture

Postby MicroController » Fri Jun 09, 2023 8:31 am

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

Who is online

Users browsing this forum: No registered users and 109 guests