Right way for custom SDKCONFIG per environment

Hi,

im rather new to platformio and ESP32 and now I ran into a problem where even after an extensive research I dont realy understand how to best solve it.

Problem: I need to change some values in the sdkconfig for my project. Ideally I would like to have seperate config per environment.

Proposed solution in the documentation: In the documentation it is recommended to change it via menuconfig (pio run -t menuconfig).

Issue: Unfortunately this commands returns an error. After a lot of googling I realized that it is because I use Arduiono as SDK and it comes with a precompiled ESP-IDF. In this case it is recommended to directly change the sdkconfig, but I’m not quite understanding how to do this, as:

Questions:

  • What are the differences between SDKConfig, SDKConfig.h, SDKConfig.default. And in what directories are they located? I found one in \Users"username".platformio\packages\framework-arduinoespressif32\tools\sdk\esp32 but I assume this is the general config and I would not like to change the generic one as the changes are project specific.
  • Apparently there is a way to link seperate sdkconfig via cmake file. But I havent really understood how this is done.
  • There seems to be another possibility via sdkconfig.h and build flags in platformio.ini. But not sure if this is the best solution.
  • In the documenation it states that the sdkconfig.default is in the project root folder. Mine is nevertheless empty. Can I just copy the one from (path above) to my root folder and do my changes inline? This would fix per project configuration but not per environment. Any suggestions?

Can anybody shed some light on how this is best done. I cant imagine that I’m the first person having those issues.

Thank you very much in advance!

Please read through Using esp-idf library within the Arduino Framework (ESP32) - #2 by maxgerhardt, it might solve a lot of your questions.

If you are using Arduino-ESP32, the best way (currently) is to use GitHub - espressif/esp32-arduino-lib-builder to recompile the needed libraries undere a new configuration.

If you want to have different libraries per environment in the same project (I’m really not sure why you would want to do that though) you need to use Advanced Scripting — PlatformIO latest documentation to dynamically redirect the lib folder to where your custom ones are. But I highly recommend starting off with just one recompilation of the libraries for one environment first.

1 Like

Hi Max, thanks a ton for your quick response. I will read carefully and try to understand your proposed solution.

Note: Per environment has the following background. I have environments for release and debug via serial or wifi. For a special debugging case I would like to write the core dump to flash but not for the regular operation. Hope that explains it.

Ok, I had a look on the post and the wifi example.

Figured that I dont need to be in arduino, as I could switch to espidf and still use arduino libraries if i have arduino as a component. By this, espidf would cleanly recompile the idf which results in using cmake build process and allowing menuconfig.

Unfortunately i dont get anything to work:

I did setup a new project with espidf as sdk. Copied my files into the new folder and change the plaformio.ini to this:

[env:lolin32]
platform = espressif32
board = lolin32
framework = espidf, arduino
lib_deps = 
	milesburton/DallasTemperature@^3.9.1
	lbernstone/Tone32@^1.0.0
	thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays @ ^4.3.0
check_tool=clangtidy
check_flags =
  clangtidy: --checks=-*,cert-*,clang-analyzer-* --fix
platform_packages =
  ; use a special branch
  framework-arduinoespressif32 @ https://github.com/marcovannoord/arduino-esp32.git#idf-release/v4.0

But if I try to compile I get cmake errors. See below:

Reading CMake configuration...
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Configuring incomplete, errors occurred!
See also "C:/Users/David/Documents/PlatformIO/Projects/Sprudelcontrol_final/.pio/build/lolin32-COM-debug-crash-dump/CMakeFiles/CMakeOutput.log".
See also "C:/Users/David/Documents/PlatformIO/Projects/Sprudelcontrol_final/.pio/build/lolin32-COM-debug-crash-dump/CMakeFiles/CMakeError.log". 

CMake Error at CMakeLists.txt:2 (include):
  include could not find load file:

    C:\Users\David\.platformio\packages\framework-espidf@3.40001.200521/tools/cmake/project.cmake


CMake Error at CMakeLists.txt:3 (project):
  No CMAKE_C_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:3 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

If I remove arduino from the platformio.ini then the cmake errors disappear but I see errors that it cannot find some of the libraries dependencies. I assume those are the arduino libraries not specifically listed in the libdeps of platformio.ini.

Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Compiling .pio\build\lolin32-COM-debug-crash-dump\src\main.o
Generating LD script .pio\build\lolin32-COM-debug-crash-dump\esp32_out.ld
Generating partitions .pio\build\lolin32-COM-debug-crash-dump\partitions.bin
src/main.c:2:10: fatal error: Wire.h: No such file or directory

**************************************************************
* Looking for Wire.h dependency? Check our library registry!  
*
* CLI  > platformio lib search "header:Wire.h"
* Web  > https://registry.platformio.org/search?q=header:Wire.h
*
**************************************************************

 #include <Wire.h>
          ^~~~~~~~
compilation terminated.
Compiling .pio\build\lolin32-COM-debug-crash-dump\app_trace\app_trace.o
Compiling .pio\build\lolin32-COM-debug-crash-dump\app_trace\app_trace_util.o
Compiling .pio\build\lolin32-COM-debug-crash-dump\app_trace\host_file_io.o
Compiling .pio\build\lolin32-COM-debug-crash-dump\app_trace\gcov\gcov_rtio.o
Compiling .pio\build\lolin32-COM-debug-crash-dump\app_update\esp_ota_ops.o
*** [.pio\build\lolin32-COM-debug-crash-dump\src\main.o] Error 1
==================================================================================================================================== [FAILED] Took 10.44 seconds ====================================================================================================================================
Environment                   Status    Duration
----------------------------  --------  ------------
lolin32-COM-debug-crash-dump  FAILED    00:00:10.439

Any ideas what I do wrong?

Sadly this is not working for the latest Arduino-ESP32 2.0.2 core because ESP-IDF lags behind (they need a special v4.4 version, PIO has v.4.3.x). Only a much older version can be compiled succesfully that way (Latest (Arduino v2.0.1) ESP32 Arduino and IDF Build - #3 by valeros). The developers need to fix this.

(If this were working with the latest version, then yes, this would have been 100% the best way to do this. Seems I subconously evaded this because I know it was not working in the latest version ;))