Target Preprocessor Macro List -- needs to be found easily! (AVR, SAM, STM32...)

This topic has been raised before. I searched for this information. I found those for AVR. But found no easy general information. Many of them can be "seen" in libraries, but where to find all of them.

  • where are these preprocessor macros defined?

  • why is this information not directly available in Arduino IDE Help?

Maybe this is a stupid question, but most likely I am not the only one with this question.


The compiler may define architecture specific macros. For example AVR, etc.: These are not generated by the Arduino IDE and the Arduino IDE is made to work with any compiler the hardware packages so it wouldn't make sense to document those macros in the Arduino documentation, just as the Arduino language reference doesn't attempt to be a complete C++ reference. They should already well documented elsewhere.

It's standard practice to also define Arduino IDE specific architecture macros, as determined by the architecture folder of the hardware package of the currently selected board. ARDUINO_ARCH_{architecture name}. This is done in a recipe in platform.txt so it's not hard coded into the Arduino IDE and a 3rd party hardware package author could choose to not define it. This is documented at: I think it might be reasonable to also document that better in the hardware specification as I don't think the library specification is the obvious place to go looking for that information. It does show the recipe that defines the macro.

Thank you very much, the two links are very helpful.

But it remains a challenge for programmers targeting multiple platforms.

For quick reference, I add a copy from the second reference:

#if defined(ARDUINO_ARCH_AVR)
  // AVR-specific code
#elif defined(ARDUINO_ARCH_SAM)
  // SAM-specific code
  // generic, non-platform specific code

For AVR I have seen that:


are also available.

For STM32 it seems more complicated, because there are 2 versions, one for STM32-Nucleo using platform manager, and one for Marple and generic STM32 versions, on GitHub.

STM32-Nucleo has STM32 defined in variant.h, but the other version doesn't. For individual STM32 targets defines can be found in compiler options in boards.txt

I hope the STM32 versions get generalized and streamlined sometimes.

Jean-Marc Zingg

ZinggJM: For AVR I have seen that:


are also available.

From the first link in my previous reply:

the preprocessor will define the macros AVR and __AVR (to the value 1) when compiling for an AVR target. The macro AVR will be defined as well when using the standard levels gnu89 (default) and gnu99 but not with c89 and c99.

I'm not experienced with STM32. I'd research to see if there is a standard macro defined in the toolchain for both packages. If there isn't one you can use the ARDUINO_ARCH macros:

#if defined(ARDUINO_ARCH_STM32F0) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F3) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32L4)

that will cover any board in both the STM32 Nucleo and Arduino_STM32 hardware packages.

#if defined(ARDUINO_ARCH_AVR)
  // AVR-specific code
#elif defined(ARDUINO_ARCH_SAM)

These, as their names imply, ARE defined by the Arduino environment. They're from the platforms.txt and boards.txt installed by the board managers. platforms.txt has lines like:

recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mcpu={build.mcu} -mthumb -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} [color=red]-DARDUINO_ARCH_{build.arch} [/color]{compiler.cpp.extra_flags} {build.extra_flags} {compiler.libsam.c.flags} {includes} "{source_file}" -o "{object_file}"

And then boards.txt has lines like: Well crap; I can't find where build.arch is defined. As this points out, the various definitions and their files are difficult to find. and there is no guarantee that a third-party board (like STM32F0) will have similar rules in their "platform.txt." (OTOH, each vendor tends to independently define symbols for each of THEIR cpus...)

westfw: I can't find where build.arch is defined.

It's the name of the architecture folder of the hardware package.

westfw: there is no guarantee that a third-party board (like STM32F0) will have similar rules in their "platform.txt."

I did verify that the two STM32 packages do define the ARDUINO_ARCH macros but this may not be the case with every 3rd party hardware package out there. That would actually be a benefit of documenting this in the hardware specification, to make it more likely to be a standard thing across all packages. I would prefer to use a macro such as AVR since this is not dependent on the hardware package's architecture folder name.