Arduino board preprocessor #defines for STM32Fxx boards

Please post bugs and enhancements for the STM core here
Post Reply
dackley
Posts: 14
Joined: Mon Jul 17, 2017 9:43 pm

Arduino board preprocessor #defines for STM32Fxx boards

Post by dackley » Fri Oct 27, 2017 7:39 pm

I appears that Arduino type boards have predefined preprocessor #defines for allowing conditionally compiling Arduino board specific code.

Example: when compiling code for an AVR ATmega168 board, one can conditionally compile code by using:

Code: Select all

#if defined(__AVR_ATmega168__)
 ... 
#endif
preprocessor statements.

It would be nice to have corresponding predefined preprocessor #defines for allowing STM32Fxx board specific conditional code compiling.

Example: when compiling code for a Nucleo-f411re board, one could conditionally compile code by using something like:

Code: Select all

#if defined(__Nucleo_F411RE__)
 ... 
#endif
preprocessor statements.

Example: when compiling code for a STM32F407G-DISC1 board, one could conditionally compile code by using something like:

Code: Select all

#if defined(__STM32F407G-DISC1__)
 ... 
#endif
preprocessor statements.

Example: when compiling code for a BluePill STM32F103C8 board, one could conditionally compile by using something like:

Code: Select all

if defined(__BluePill_F103C8__)
 ... 
#endif
preprocessor statements.

stevestrong
Posts: 1829
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Arduino board preprocessor #defines for STM32Fxx boards

Post by stevestrong » Sat Oct 28, 2017 8:27 am

There is already such a define implemented, look for "build.variant" in platform.txt and boards.txt.
Example:

Code: Select all

#ifdef BOARD_nucleo_f103rb
...
#endif

dackley
Posts: 14
Joined: Mon Jul 17, 2017 9:43 pm

Re: Arduino board preprocessor #defines for STM32Fxx boards

Post by dackley » Tue Oct 31, 2017 12:32 am

Thank you very much stevestrong for pointing out the platform.txt and boards.txt files that contain the Arduino board preprocessor #defines. This is exactly the information I was looking for. There are so many files in the Arduino IDE I never would have found these file without your help. So I really appreciate your help.

fpiSTM
Posts: 250
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Arduino board preprocessor #defines for STM32Fxx boards

Post by fpiSTM » Sat Nov 04, 2017 10:40 am

Hi @dackley,

There are several defined created during the build which are useful.
You see them in the platform.txt mentioned by Steve:

Code: Select all

-DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} 
One is based on the core name:
ARDUINO_ARCH_xxxxx where xxxxx is the name of the core.
ex for the Arduino_Core_STM32: ARDUINO_ARCH_STM32
One is the board built:
ARDUINO_xxxxx where xxxxx is the board name:
ex for the NUCLEO_L476RG: ARDUINO_NUCLEO_L476RG

In Roger's core, a variant could be used to build several board, that's why it is also defined, I think:

Code: Select all

-DBOARD_{build.variant

Post Reply