How to select sdkconfig.defaults per environment

I have a project where I would like to have a different platform io “environment” for different build types (like developement vs production).

The production version would have no console uart configured.

I have run menuconfig and have two different resulting sdkconfig files (sdkconfig.defaults.dev and sdkconfig.defaults.prod).

My CMakeLists.txt contains:

list(APPEND SDKCONFIG_DEFAULTS "sdkconfig.defaults.dev")

and everything works in the dev case. How can get platformio to tell cmake to use the other file?

The reason I want this is because other devs on the team derive/inherit their configs from what I am trying to provide. IOW, I have

[env:device-dev]
...
build_flags =

[env:device-prod]
...
build_flags = -DPRODUCTION

[env:alice]
extends = env:device-dev
upload_port = ...

[env:alice-prod]
extends = env:device-prod
upload_port = ...

(of course, the reason each dev needs their own env is because each esp32 device gets a unique /dev filename on a Mac)

Perfectly willing to accept that I’ve painted myself into a corner and there’s another way. Hit me!

Thanks for any pointers.

Hm, seems weird. PlatformIO automatically uses sdkconfig files based on the environment name in the platformio.ini, since I reported it in Make used sdkconfig file user-selectible · Issue #539 · platformio/platform-espressif32 · GitHub and Regenerate sdkconfig.<board> if missing · Issue #588 · platformio/platform-espressif32 · GitHub.

Yes, that’s true. However, in the absence of the file, it just pulls out the default from the bowels of esp-idf (which was no good to me) – thus the hack in CMakeLists.txt (which took me entirely too long to google/figure out).

I (thought that I) needed to provide a pattern where new dev could just create a new env entry in platformio.ini for themselves that inherits from a main config. The new twist is that now I have two different main configs that I want to inherit from.

Of course, I could just tell folks to manually copy the correct sdkconfig.defaults for their case but that seems clunky and it feels like this is a good time to sanity check my methods.

The current platform code should definitely support it that config files (when they’re regenerated because they are deleted) are pulled from the sdkconfig.defaults of the project, not ESP-IDF, if present.

But I also see that Updated sdkconfig files should trigger CMake to regenerate project · platformio/platform-espressif32@6379928 · GitHub is not taking into account that you might have different sdkconfig.defaults for each sub-environment. Try opening an issue in the linked repository for that.

1 Like

For the curious, I created sdkconfig.defaults per environment · Issue #638 · platformio/platform-espressif32 · GitHub

And big thanks to Max

I just updated the github issue with a solution that hopefully also works for you. Not fully platform.io-integrated, but does it’s job.