My board is an esp32-s3 board, let the generic_gpio for example:.
platformio\packages\framework-espidf\examples\peripherals\gpio\generic_gpio\
If you using platformio compile the example rountine in you esp32-idf project directly, there are always some errors occured which caused by undefined macro definitions, as the picture shows above.
By many test, I find there are two solutions below to solve the errors, share them for the people who needed.
One solution: using the Kconfig.projbuild file to generate the macro definitions into sdkconfig.h automatically
step1: Create a new esp32s3 idf project using vscode-platformio, but do not compile.
step2: Copy gpio_example_main.c
file and Kconfig.projbuild file in
platformio\packages\framework-espidf\examples\peripherals\gpio\generic_gpio\
folder to your project path of src folder, such as
Documents\PlatformIO\Projects\esp32s3_idf_test\src
step3: Delete main.c, and rename gpio_example_main.c to main.c.
step4: Copy Kconfig.projbuild file to your project path of config folder, such as
Documents\PlatformIO\Projects\esp32s3_idf_test8\.pio\build\board_esp32s3\config
step5: Compile the project, then the errors occured by the undefined macro definitions of
CONFIG_GPIO_OUTPUT_0, CONFIG_GPIO_OUTPUT_1, CONFIG_GPIO_INPUT_0, CONFIG_GPIO_INPUT_1
disappeared.
After compiling, if you open the sdkconfig.h file in
Documents\PlatformIO\Projects\esp32s3_idf_test8\.pio\build\board_esp32s3\config
you can find that the macro definitions which needed has been created in sdkconfig.h automatically :
NOTE:
- I don’t know why must copy the Kconfig.projbuild file into the src folder and the config folder before first compiling, but if I do not do this, the errors shows in the top picture occured.
- If I compile the project first, then copy the Kconfig.projbuild file into the src folder and the config folder, and compile the project again, the errors can not solve.
- So, the operate order can not change, you must copy first, compile second, don’t reverse.
Another solution: using build_flags in platformio.ini file
Refer to this post: ESP32: blink - won't compile under pio
Add the defines in platformio.ini:
The values are refered to Kconfig.projbuild: