STM32: Overwrite board variant in platformio.ini?


I’ve got a board using a STM32F030 which is specified in platform-ststm32/demo_f030f4.json at master · platformio/platform-ststm32 · GitHub. The file uses "variant": "DEMO_F030F4". The currently stable STM32Duino release 1.7.0 has two other board variants: DEMO_F030F4_16M and DEMO_F030F4_HSI. Is it possible to overwrite/change the variant from platformio.ini without creating a custom board json?

I tried board_build.variant = DEMO_F030F4_16M, however this fails somewhere inside the STM32 toolchain:
~/.platformio/packages/framework-arduinoststm32/system/STM32F0xx/stm32f0xx_hal_conf.h:4:10: fatal error: variant.h: No such file or directory

As you can see in the STM32Duino repo you referenced it says

So, they all use the same build.variant=DEMO_F030F4, but a different build.board value. This results in a different macro being created.

As you can then see in the variant.cpp file:

Depending on the set Macros (ARDUINO_DEMO_F030F4_HSI and ARDUINO_DEMO_F030F4_16M`), a different oscillator initialization is done.

Thus you can just adapt the macros in your custom board.json or add them via build_flags.


Thanks for the answer. For those searching along: This would be the corresponding platformio.ini:

platform = ststm32
board = demo_f030f4
framework = arduino
build_flags = -DARDUINO_DEMO_F030F4_16M