Nested sections in PlatformIO.ini

I am trying set up a multiple board INI file with each board having a release and debug build configuration, possibly adding a test configuration later. What I am trying to do follows this structure:


    flags etc for debug

    flags etc for release (if any)

   board one settings

   board_one settings

    board_one settings

   board two settings

    board_two settings

    board_two settings

Is this possible?

1 Like

Yes, you can use extends = ... as needed.

Thank you @maxgerhardt

I tried the following but PIO reports an error when I save it:

default_envs = nucleo_l452re_monitor

build_flags = -mfloat-abi=softfp -mfpu=fpv4-sp-d16
    -I src/freeRTOS/include -I src/freeRTOS/portable/GCC/ARM_CM4F -I src/tinyusb/src
    -I src/tinyusb/src/device
framework = stm32cube
board_build.stm32cube.custom_config_header = yes
platform = ststm32
platform_packages = toolchain-gccarmnoneeabi@~1.100301.0

board = nucleo_l452re
build_flags = -D STM32L4 -D CFG_TUSB_DEBUG=3 ${env.build_flags}
build_type = debug

extends = env:nucleo_l452re
build_flags = -D __DEBUG__ ${env:nucleo_l452re.build_flags}

Which is?

The only thing that looks weird to me is the build_flags in env, since every environment inherits from env, it may be that some build_flags are overwritten. You could call it default_build_flags in env and then reference ${env.default_build_flags} in env:nucleo_l452re.

Sorry I did not see the full error, it says:

Unknown environment names 'nucleo_l452re_monitor'. Valid names are 'nucleo_l452re'

Every selectible environment must start with env:.

(You can still arbitarily use environmemt names that don’t start with env: or are not [env] to store build settings and reference them).

Yes, I just discovered that. The next issue is that I am not getting the build I expected and tried to use the verbose build. However, it seems that command does not build the default build named in the INI file. I have:

default_envs = nucleo_l452re_monitor

However, the verbose build command executes:

Executing task: C:\Users\sidpr\.platformio\penv\Scripts\platformio.exe run --verbose --environment nucleo_l452re

Is it possible to get the verbose command to use the default env?

Are you sure you’ve selected the “Default” environment in the project tasks? It could have explicitly selected the other [env:] by now.

@maxgerhardt The issue was not the build task, it was the debugging task. I was not building the correct configuration for my special debug build. I needed to create a new debug launch task in VSCode that used the required build configuration.
Many thanks for you help.

@maxgerhardt It seems each step reveals a new challenge.

This is my launch task for the new build:

            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug monitor",
            "executable": "D:/DataRoot/Projects/PIO_STM32_Cube/.pio/build/nucleo_l452re/firmware.elf",
            "projectEnvName": "nucleo_l452re_monitor",
            "toolchainBinDir": "C:/Users/sidpr/.platformio/packages/toolchain-gccarmnoneeabi@1.100301.220327/bin",
            "internalConsoleOptions": "openOnSessionStart",
            "svdPath": "C:/Users/sidpr/.platformio/platforms/ststm32/misc/svd/STM32L4x2.svd",
            "preLaunchTask": {
                "type": "PlatformIO",
                "task": "Pre-Debug (nucleo_l452re_monitor)"

However the pre-launch task is not found:

No, you should not have to modify any file in .vscode since everything in there is autogenerated, especially the intellisense config and the launch tasks.

  1. For which environment do you want to start the debugger?
  2. Full screenshot of VSCode window?
  3. Have you tried re-selecting the correct environment in the project environment switcher?
  4. Have you tried deleting the .vscode folder in the project and restarting VSCode? (Ctrl+Shift+P → Reload Window)

Again, thank you @maxgerhardt

Using the project switcher worked for me.

This seems like a bug since the PIO INI file had a default environment set as I wanted it. Surely, this should also set the project environment switcher?

I found an example of using configuration very well, you can refer to it