I would like to build and test a “single source” code on multiple platforms. I’m want to use the same code on a ST Nucleo 32 board and on a LGT8F328P board. But I’m running into problems with pin assignments. So I would like to assign my pins during compilation.
Is there a way I can access the board as specified in the .ini-file from my source code. Be it by a variable or by an IFDEF block?
Yes, every board implicitly has one or more macros that are given in the build process. When e.g. compiling for your board = nucleo_l432kc environment, you will see with the project task “Advanced → Verbose Build” that it has the compile flags
Hello,
I was looking to create a topic but my issue is close to what was written here before.
I need a name for my board to use it as a macro in my main.cpp.
When I do the same action as @maxgerhardt did, with my project environnement set on arduino uno. I get no name for my board. Is there other way to get the name and used it as macro ?
build verbose result
> Executing task in folder ds18b20: C:\Users\xxx\.platformio\penv\Scripts\platformio.exe run --verbose --environment uno <
Processing uno (platform: atmelavr; board: uno; framework: arduino; lib_deps: OneWire@2.3.5, DallasTemperature@3.9.1; src_filter: +<*> -<.git/> -<.svn/> -<test_ds18b20.cpp> +<bus_ds18b20.cpp>) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR (3.3.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
- framework-arduino-avr 5.1.0
- toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 18 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <OneWire> 2.3.5 (C:\Users\xxx\Documents\Code\platform\ds18b20\.pio\libdeps\uno\OneWire)
|-- <DallasTemperature> 3.9.1 (C:\Users\xxx\Documents\Code\platform\ds18b20\.pio\libdeps\uno\DallasTemperature)
| |-- <OneWire> 2.3.5 (C:\Users\xxx\Documents\Code\platform\ds18b20\.pio\libdeps\uno\OneWire)
|-- <BoardDefinitionV3_1> (C:\Users\xxx\Documents\Code\platform\ds18b20\lib\BoardDefinitionV3_1)
Building in release mode
MethodWrapper(["checkprogsize"], [".pio\build\uno\firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
I need to use a macro for two customs boards like this :
ifdef board_custom_1
pinMode(VDD,OUTPUT); //board_custom_1 need this
digitalWrite(VDD,HIGH);
endif
ifdef board_custom_2
pinMode(VDD,OUTPUT); //board_custom_2 need this
digitalWrite(VDD,LOW);
endif
You didn’t post your platformio.ini, without that I can’t tell you what’s wrong.
However, you seem to be going in the wrong direction anyways. If you just have seperate board environments and need different global macros being visible for them, just add build_flags expression to them.
As e.g.
[env:board1]
platform = atmelavr
; both envs use uno board
board = uno
framework = arduino
build_flags = -D BOARD_CUSTOM_1
[env:board2]
platform = atmelavr
board = uno
framework = arduino
build_flags = -D BOARD_CUSTOM_2
That means what exactly, “Getting no name”? The board definition for uno.json clearly shows
the macro ARDUINO_AVR_UNO being defined.
Thus you can tell if you selected board = uno in the platformio.ini. If multiple environments use the same board value, differentiate them with the build_flags options and arbitrary macros above.
Ah, I see. Due to the wrong formatting above the verbose log was cut off early.
The commands are only visible when a source file is built. Here you executed a verbose build even though the firmware was already previously built. Execute a “Clean” and then again a verbose build.