Page 1 of 1

ifdef for selected board

Posted: Tue May 25, 2021 10:36 pm
by dudmuck
is preprocessor directive defined for board selected from arduino-IDE?
I have code for multiple boards, it needs to know which board is built for so correct source is built and stuff like pin definitions. Because the nucleo boards typically have arduino-uno form-factor, but others arent and need different pins. An #ifdef used for this in code.

Re: ifdef for selected board

Posted: Wed May 26, 2021 6:19 am
by mlundin
every variant have a specific define, to see them use verbose output from compilation and look at the command line sent to the compiler, all the defines can be seen there (its a looooong line of includes and defines).

Re: ifdef for selected board

Posted: Wed May 26, 2021 6:43 am
by ag123
check the usual places like boards.txt and platforms.txt

Re: ifdef for selected board

Posted: Wed May 26, 2021 7:51 am
by fpiSTM
https://github.com/stm32duino/Arduino_Core_STM32/blob/a7283739a4d8bafe95c9f9b9156e6f82a1ebbd75/platform.txt#L92-L93

Code: Select all

# Build information's
build.info.flags=-D{build.series} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DBOARD_NAME="{build.board}" -DVARIANT_H="{build.variant_h}"
Specifically: -DARDUINO_{build.board}

where build.board is defined in the boards.txt:
For example

Code: Select all

GenF1.menu.pnum.BLUEPILL_F103C8.build.board=BLUEPILL_F103C8
So for this board you can use:

Code: Select all

#ifdef ARDUINO_BLUEPILL_F103C8