A question about build_flags

I am working on a new SSTM32 project and initially because of a dev board being available I am going to write the code for Nucleo-L452. Later, the project will switch to Nucleo-G431. I am using the plarformio-freertos library, and I need different settings for the compiler for the two builds.

I have two “env” sections for the two boards and each has a similar, but not identical set of “build_flags”. I would like to avoid repeating the flags that are common to the two builds, however, it does not seem possible to have a “common” section with the shared build-flags and then have each env add the env specific flags to those build_flags.

This is the current contents of my PlatformIO.ini file:

[platformio]
default_envs = nucleo_l452re

[env:nucleo_l452re]
platform = ststm32
board = nucleo_l452re
framework = stm32cube
build_flags = -D STM32L4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
build_type = debug
lib_deps = bojit/PlatformIO-FreeRTOS@^2.1.3

[env:nucleo_g431rb]
platform = ststm32
board = nucleo_g431rb
framework = stm32cube
build_flags = -D G431RB -mfloat-abi=softfp -mfpu=fpv4-sp-d16
lib_deps = bojit/PlatformIO-FreeRTOS@^2.1.3

Is this possible with Platform IO please?

Yes, see documentation.

1 Like

Excellent, I read about “extend” but totally missed this.
Thank you :slight_smile:

No, not extend. The critical part for build flags is the interpolation of values and accessing them from different environments.

[common]
build_flags = -mfloat-abi=softfp -mfpu=fpv4-sp-d16

[env:nucleo_l452re]
platform = ststm32
board = nucleo_l452re
framework = stm32cube
build_flags = ${common.build_flags} -D STM32L4
build_type = debug
lib_deps = bojit/PlatformIO-FreeRTOS@^2.1.3

[env:nucleo_g431rb]
platform = ststm32
board = nucleo_g431rb
framework = stm32cube
build_flags = ${common.build_flags} -D G431RB
lib_deps = bojit/PlatformIO-FreeRTOS@^2.1.3

And in the step you can take advantage of the [env] environment which every other environment inherits from.

[common]
build_flags = -mfloat-abi=softfp -mfpu=fpv4-sp-d16

[env]
platform = ststm32
framework = stm32cube
build_type = debug
lib_deps = bojit/PlatformIO-FreeRTOS@^2.1.3

[env:nucleo_l452re]
board = nucleo_l452re
build_flags = ${common.build_flags} -D STM32L4

[env:nucleo_g431rb]
board = nucleo_g431rb
build_flags = ${common.build_flags} -D G431RB
1 Like

I said that I saw “extend” but missed “interpolate,” good answer and resolved my issue.