ifdef for selected board

Post here first, or if you can't find a relevant section!
Post Reply
dudmuck
Posts: 3
Joined: Tue May 25, 2021 10:31 pm

ifdef for selected board

Post 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.
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

Re: ifdef for selected board

Post 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).
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: ifdef for selected board

Post by ag123 »

check the usual places like boards.txt and platforms.txt
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: ifdef for selected board

Post 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
Post Reply

Return to “General discussion”