Esp32: best preprocessor define to distinguish between variants?

What is the best preprocessor define to distinguish between esp32 and esp32-c3 (and esp32-s2 and all the other variants)?

I’ve been using ARDUINO_ESP32C3_DEV but that feels like a hack that just happens to work because I’m using the arduino framework.

In another thread someone suggested __riscv but that also feels like a hack, because that works because of the different processor instruction set, and not because of the different feature set of the SoC.

Now, in 2022, the term esp32 really has two different meanings:

  • The family of espressif32 SoCs,
  • The first member of that family, the esp32.

But there seems to be no way to distinguish the different members of the family, such as the s2/s3/c2/c6/original…

(Actually I’m using SoC here where espressif use “series”, they use SoC to mean something slightly different again in https://www.espressif.com/en/products/socs)

No answers…

So for whoever wanders by here: what I did in the end was using <soc/soc_caps.h> even though the espressif documentation says it is not a stable API: SoC Capabilities - ESP32-S2 - — ESP-IDF Programming Guide latest documentation

2 Likes