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.
These are not generated by Arduino IDE and 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 with the format ARDUINO_ARCH_<architecture name>, where <architecture name> is determined by the architecture folder of the platform of the currently selected board. 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.
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.
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:
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:
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...)
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_ARCHmacros 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.