How to access low-level features on ESP32?

I started to tackle the ESP32S3 DevKit. The toolchain installs smoothly :slight_smile:

One limitation of RIOT is that the PWM module uses the PWM LED Controller of the MCU, whose maximum frequency, according to my tests, is limited to about 19kHz.

However, I need a PWM frequency in the 100s kHz range (Peltier driver). The Motor Control PWM can reach this higher frequencies. So, I’d like to use it, along with RIOT’s PWM module to drive some other slower hardware (brushless pump motor).

Therefore, I need some lower level library.

  1. Is the ESP-IDF SDK the way to go ?
  2. The documentation says it installs automatically, but I can’t find it…

Hey, not that I am an expert on ESP32 things but I made a PR that uses the ESP-IDF SDK, everything must go through that.

  1. The documentation says it installs automatically, but I can’t find it…

Are you using docker?

If it is installed as a package it would be in ${RIOTBASE}/build/pkg/esp32_* and is gitignored so some tools may not automatically search there.

Thanks. I did look at your PR, but still, I can’t link against the SDK. I’m not using Docker.

Searching through $(RIOTBASE)/build/pkg/esp32_pkg, I found the header I need. So, I added:

#include "driver/mcpwm.h"

to my source code.

A added:

USEPKG += esp32_sdk
USEMODULE += esp32_sdk

to my Makefile. The header is found, but ld returns an undefined reference error on the function from mcpwm.h I’m trying to call.

Any clue ?

I found a real dirty way to pass the link step by editing $(RIOTBASE)/cpu/esp32/esp-idf/common/Makefile and adding:

ESP32_SDK_SRC += components/soc/esp32s3/mcpwm_periph.c
ESP32_SDK_SRC += components/driver/mcpwm.c
ESP32_SDK_SRC += components/hal/mcpwm_hal.c

Obviously, it lacks a ifneq (,$(filter periph_mcpwm%,$(USEMODULE))) guard, but periph_mcpwm doesn’t exist.

I probably shouldn’t even have edited that file. How can I do it the clean way?

Maybe @gschorcht can help?

In the initial ESP32 port of RIOT, we actually used the MCPWM for the PWM peripheral driver in RIOT. But since the ESP32 is the only ESP32x SoC that has this MCPWM, while all other ESP32x SoCs only have the LED PWM controller, we now use the LED PWM controller to support all ESP32x SoCs by one peripheral implementation.

In RIOT we only use some low-level drivers that are really necessary to avoid programming on bare metal for a poorly documented SoC. It is not intended nor possible to use libraries from the ESP-IDF SDK by the application. The application should only use what is provided by RIOT.

From my point of view, the right way would be to define a new pseudomodule, e.g. esp32_mcpwm, and to extend the PWM peripheral driver implementation to use MCPWM instead of LED PWM if this module is enabled.