ESP32-IDF examples, can't find example projects

Not sure what details I need to include…
Visual Studio Code, platformIO, Linux

Let me start by saying I have searched and read, and searched and read in VSCode, PlatformIO, etc. in various places around the web. This served to make my head spin with total confusion on who, what, when, where…

I have never been able to figure out the correct way to access and use examples included in a platform after adding it.

The example files are there but, I can’t find them in the platformio import examples.

I can see the files in:


But, the contents don’t show up in platformio import examples.

That being the case I want to experiment with the MCPWM in the ESP32-IDF. So, I created a project with PIO and copied the .c source to the src directory of the project.

When I attempt to compile that code I get the following errors:

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/home/mac/SharedData/Projects/DMX_Dimmer/MCPWM_basic_config/ESP-PWM/src/mcpwm_basic_config_example.c).

cannot open source file "soc/mcpwm_periph.h"

I get that the include isn’t set correctly…but, again, I can’t find clear (at least to my addled brain) documentation of how to go about setting it correctly for a given platform or project.

What am I missing? What don’t I know yet?


Are you sure you have framework = espidf in your platformio.ini and not Arduino? Documentation is by the way Espressif IoT Development Framework — PlatformIO latest documentation and Espressif 32 — PlatformIO latest documentation.

Example PlatformIO + ESP-IDF projects are located at platform-espressif32/examples at develop · platformio/platform-espressif32 · GitHub.

Do you have the file /home/mac/.platformio/packages/framework-espidf/components/soc/include/soc/mcpwm_periph.h?

No I don’t have that file.

I changed the include to:

#include "soc/mcpwm_reg.h"
#include "soc/mcpwm_struct.h"

And it works.

Yes, I know where the docs are. The problem is, to me at least, understanding what they say/mean/imply in the context of what I’m doing or trying to fix. :woozy_face:

Oh yeah actually that makes perfect sense, I don’t have the file either.

Latest master does have the code, but PlatformIO uses only stable release versions. As can be seen here, that is currently 3.2.2.

Therefore, you must not take the latest master version of the example, but the version associated with the tag. Which is here. And that codes reads as

#include <stdio.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_attr.h"

#include "driver/mcpwm.h"
#include "soc/mcpwm_reg.h"
#include "soc/mcpwm_struct.h"

#define GPIO_PWM0A_OUT 15   //Set GPIO 15 as PWM0A
#define GPIO_PWM0B_OUT 16   //Set GPIO 16 as PWM0B

static void mcpwm_example_gpio_initialize()
    printf("initializing mcpwm gpio...\n");
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, GPIO_PWM0A_OUT);
    mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, GPIO_PWM0B_OUT);

So no soc/mcpwm_periph.h includes, this restructure only happens in the next versions.

Baseline: Don’t use latest master examples on the esp-idf repo but always use the ones with the correct version tag from the platform-espressif32 release.