Section [env]

Each project may have multiple configuration environments defining the available project tasks for building, programming, debugging, unit testing, device monitoring, library dependencies, etc. The configuration environments are declared using [env] sections in “platformio.ini” (Project Configuration File).

The allowed options are listed under Options.

Common [env]

An optional configuration environment with common options that will be shared between all [env:NAME] environments in the platformio.ini file. It is very useful if the configuration file has a lot of environments [env:NAME] and they share common settings.

For example:

[env]
platform = ststm32
framework = stm32cube
board = nucleo_l152re
lib_deps = Dep1, Dep2

[env:release]
build_flags = -D RELEASE
lib_deps =
    ${env.lib_deps}
    Dep3

[env:debug]
build_type = debug
build_flags = -D DEBUG
lib_deps = DepCustom

In this example we have two configuration environments release and debug. This is equivalent to duplicating all options as shown below:

[env:release]
platform = ststm32
framework = stm32cube
board = nucleo_l152re
build_flags = -D RELEASE
lib_deps = Dep1, Dep2, Dep3

[env:debug]
platform = ststm32
framework = stm32cube
board = nucleo_l152re
build_type = debug
build_flags = -D DEBUG
lib_deps = DepCustom

Working [env:NAME]

A working environment in PlatformIO is defined using the [env:NAME] syntax. This environment is used by various PlatformIO commands such as pio run, pio test, pio check, pio debug, and others. Every project must define at least one working environment.

You can define multiple working environments in your project by using different names for the [env:NAME] section. It’s important to note that each environment must have a unique name. The name should only include lowercase letters a-z, numbers 0-9, and special characters _ (underscore) and - (hyphen). For example, [env:hello_world] is a valid name.

If you have defined multiple working environments and you only want to process a subset of them, you can use the -e or --environment option with the PlatformIO commands mentioned above. You can specify the name of the environment you want to process using this option.

In addition to using the -e option, you can define a default set of working environments for the PlatformIO commands to process by using the [platformio] default_envs option. This can be useful if you frequently work with a specific set of environments and don’t want to specify them every time you run a command.

Options