Back to Riot

Doc Esp32.Doc

cpu/esp32/doc_esp32.doc.md

2026.07-devel12.3 KB
Original Source
<!-- SPDX-FileCopyrightText: 2025 Gunar Schorcht SPDX-License-Identifier: LGPL-2.1-only -->

@defgroup cpu_esp32_esp32 ESP32 family @ingroup cpu_esp32 @brief Specific properties of ESP32 variant (family) @author Gunar Schorcht [email protected]

\section esp32_riot_esp32 Specific properties of ESP32 variant (family)

GPIO pins {#esp32_gpio_pins_esp32}

ESP32 has 34 GPIO pins, where only a subset can be used as output, as ADC channel, as DAC channel and as GPIOs in deep-sleep mode, the so-called RTC GPIOs. Some of them are used by special SoC components, e.g., as touch sensors. The following table gives a short overview.

<center>
PinTypeADC / RTCPU / PDSpecial functionRemarks
GPIO0In/OutyesyesTouch sensorBootstrapping, pulled up
GPIO1In/Out-yesUART0 TxDConsole
GPIO2In/OutyesyesTouch sensorBootstrapping, pulled down
GPIO3In/Out-yesUART0 RxDConsole
GPIO4In/OutyesyesTouch sensor-
GPIO5In/Out-yes--
GPIO6In/Out-yesFlash SD_CLK-
GPIO7In/Out-yesFlash SD_DATA0-
GPIO8In/Out-yesFlash SD_DATA1-
GPIO9In/Out-yesFlash SD_DATA2only in qoutand qiomode, see section Flash Modes
GPIO10In/Out-yesFlash SD_DATA3only in qoutand qiomode, see section Flash Modes
GPIO11In/Out-yesFlash SD_CMD-
GPIO12In/OutyesyesMTDI / Touch sensorJTAG interface / Bootstrapping, pulled down
GPIO13In/OutyesyesMTCK / Touch sensorJTAG interface
GPIO14In/OutyesyesMTMS / Touch sensorJTAG interface
GPIO15In/OutyesyesMTDO / Touch sensorJTAG interface / Bootstrapping, pulled up
GPIO16In/Out-yes-usually not available when SPI RAM is used
GPIO17In/Out-yes-usually not available when SPI RAM is used
GPIO18In/Out-yes--
GPIO19In/Out-yes--
GPIO21In/Out-yes--
GPIO22In/Out-yes--
GPIO23In/Out-yes--
GPIO25In/OutyesyesDAC1-
GPIO26In/OutyesyesDAC2-
GPIO27In/OutyesyesTouch sensor-
GPIO32In/OutyesyesXTAL32_Pcan be used to connect an external 32 kHz crystal
GPIO33In/Outyes-XTAL32_Ncan be used to connect an external 32 kHz crystal
GPIO34Inyes-VDET-
GPIO35Inyes-VDET-
GPIO36Inyes-SENSOR_VP-
GPIO37Inyes-SENSOR_CAPPusually not broken out
GPIO38Inyes-SENSOR_CAPNusually not broken out
GPIO39Inyes-SENSOR_VN-
</center>

<b>ADC:</b> these pins can be used as ADC inputs

<b>RTC:</b> these pins are RTC GPIOs and can be used in deep-sleep mode

<b>PU/PD:</b> these pins have software configurable pull-up/pull-down functionality.

@note GPIOs that can be used as ADC channels are also available as low power digital inputs/outputs in deep sleep mode.

GPIO0, GPIO2 are bootstrapping pins which are used to boot ESP32 in different modes:

<center>
GPIO0GPIO2Mode
1Xboot in FLASH mode to boot the firmware from flash (default mode)
00boot in UART mode for flashing the firmware
</center>

@note GPIO2 becomes the SPI MISO signal for boards that use the HSPI interface as SD-Card interface in 4-bit SD mode. On these boards all signals of the SD-Card interface are pulled up. Because of the bootstrapping functionality of GPIO2, it can become necessary to either press the Boot button, remove the SD card or remove the peripheral hardware to flash RIOT.

ADC Channels {#esp32_adc_channels_esp32}

ESP32 integrates two 12-bit ADCs (ADC1 and ADC2) capable of measuring up to 18 analog signals in total. Most of these ADC channels are either connected to a number of integrated sensors like a Hall sensors, touch sensors and a temperature sensor or can be connected with certain GPIOs. Integrated sensors are disabled in RIOT's implementation and are not accessible. Thus, up to 18 GPIOs, can be used as ADC inputs:

  • ADC1 supports 8 channels: GPIOs 32-39
  • ADC2 supports 10 channels: GPIOs 0, 2, 4, 12-15, 25-27

These GPIOs are realized by the RTC unit and are therefore also called RTC GPIOs or RTCIO GPIOs.

The maximum number of ADC channels #ADC_NUMOF_MAX is 18

@note

  • GPIO37 and GPIO38 are usually not broken out on ESP32 boards and can not be used therefore.
  • ADC2 is also used by the WiFi module. The GPIOs connected to ADC2 are therefore not available as ADC channels if the modules esp_wifi or esp_now are used.

DAC Channels {#esp32_dac_channels_esp32}

ESP32 SoC supports 2 DAC lines at GPIO25 and GPIO26.

I2C Interfaces {#esp32_i2c_interfaces_esp32}

ESP32 has two built-in I2C interfaces.

The following table shows the default configuration of I2C interfaces used for a large number of ESP32 boards. It can be overridden by application-specific configurations.

<center>
DeviceSignalPinSymbolRemarks
I2C_DEV(0)#I2C0_SPEEDdefault is I2C_SPEED_FAST
I2C_DEV(0)SCLGPIO22#I2C0_SCL-
I2C_DEV(0)SDAGPIO21#I2C0_SDA-
</center>

PWM Channels {#esp32_pwm_channels_esp32}

The ESP32 LEDC module has 2 channel groups with 8 channels each. Each of these channels can be clocked by one of the 4 timers.

SDMMC Interfaces {#esp32_sdmmc_interfaces_esp32}

The ESP32 variant uses the direct I/O (i.e. SOC_SDMMC_USE_IOMUX is defined in the SoC capabilities file). The GPIOs used for SDMMC signals are therefore fixed for each slot. Since the GPIOs used for slot 0 are the same as those used for the Flash, slot 0 cannot be used. Therefore, only slot 1 can be used.

The GPIOs used by ESP32 for slot 1 are:

<center> | Signal | GPIO Slot 1 | |:------ |:------------| | CLK | GPIO14 | | CMD | GPIO15 | | DAT0 | GPIO2 | | DAT1 | GPIO4 | | DAT2 | GPIO12 | | DAT3 | GPIO13 | </center>

The board-specific configuration is realized by defining the @ref sdmmc_config array, for example:

{.c}
static const sdmmc_conf_t sdmmc_config[] = {
    {
        .slot = SDMMC_SLOT_1,
        .cd = GPIO21,
        .wp = GPIO_UNDEF,
        .bus_width = 1,
    },
};

#define SDMMC_NUMOF 1

Used data bus width has to be defined in sdmmc_conf_t::bus_width in addition to the slot, where 1 and 4 are valid values.

@note The slot must be @ref SDMMC_SLOT_1 for ESP32.

If the board supports a Card Detect pin or a Write Protect pin, the corresponding GPIOs have to be defined in @ref sdmmc_conf_t::cd and @ref sdmmc_conf_t::wp. Otherwise they have to be set to undefined (@ref GPIO_UNDEF).

SPI Interfaces {#esp32_spi_interfaces_esp32}

ESP32 has four SPI controllers where SPI0 and SPI1 share the same bus and are used as interface for external memory:

  • Controller SPI0 is reserved for caching external memory like Flash
  • Controller SPI1 is reserved for external memory like PSRAM
  • Controller SPI2 can be used as general purpose SPI (also called HSPI)
  • Controller SPI3 can be used as general purpose SPI (also called VSPI)

Thus, only SPI2 (HSPI) and SPI3 (VSPI) can be used as general purpose SPI in RIOT as SPI_DEV(0) and SPI_DEV(1) in arbitrary order.

The following table shows the pin configuration used for most boards, even though it can vary from board to board.

<center>
DeviceSignalPinSymbolRemarks
SPI0_HOST/SPI1_HOSTSCKGPIO6-reserved for flash and PSRAM
SPI0_HOST/SPI1_HOSTCMDGPIO11-reserved for flash and PSRAM
SPI0_HOST/SPI1_HOSTSD0GPIO7-reserved for flash and PSRAM
SPI0_HOST/SPI1_HOSTSD1GPIO8-reserved for flash and PSRAM
SPI0_HOST/SPI1_HOSTSD2GPIO9-reserved for flash and PSRAM (only in qio or qout mode)
SPI0_HOST/SPI1_HOSTSD3GPIO10-reserved for flash and PSRAM (only in qio or qout mode)
SPI2_HOST (HSPI)SCKGPIO14#SPI1_SCKcan be used
SPI2_HOST (HSPI)MISOGPIO12#SPI1_MISOcan be used
SPI2_HOST (HSPI)MOSIGPIO13#SPI1_MOSIcan be used
SPI2_HOST (HSPI)CS0GPIO15#SPI1_CS0can be used
SPI3_HOST (VSPI)SCKGPIO18#SPI0_SCKcan be used
SPI3_HOST (VSPI)MISOGPIO19#SPI0_MISOcan be used
SPI3_HOST (VSPI)MOSIGPIO23#SPI0_MOSIcan be used
SPI3_HOST (VSPI)CS0GPIO5#SPI0_CS0can be used
</center>

Some boards use the HSPI (SPI2_HOST) as SD-Card interface (SDIO) in 4-bit SD mode.

<center>
DevicePinSD 4-bit modeSPI mode
SPI2_HOST (HSPI)GPIO14CLKSCK
SPI2_HOST (HSPI)GPIO15CMDCS0
SPI2_HOST (HSPI)GPIO2DAT0MISO
SPI2_HOST (HSPI)GPIO4DAT1-
SPI2_HOST (HSPI)GPIO12DAT2-
SPI2_HOST (HSPI)GPIO13DAT3MOSI
</center>

@note On these boards, all these signals are pulled up. This may cause flashing problems due to the bootstrap function of the GPIO2 pin, see section GPIO pins. Therefore, it can be necessary to either press the Boot button, to remove the SD card or to remove the peripheral hardware to flash RIOT.

Timers {#esp32_timers_esp32}

ESP32 has two timer groups with two timers each, resulting in a total of four timers. Since one timer is used as system timer, up to three timers with one channel each can be used in RIOT as timer devices TIMER_DEV(0) ... TIMER_DEV(2).

Additionally ESP32 has three CCOMPARE registers which can be used alternatively as timer devices TIMER_DEV(0) ... TIMER_DEV(2) can be used in RIOT if the module esp_hw_counter is enabled.

UART Interfaces {#esp32_uart_interfaces_esp32}

ESP32 integrates three UART interfaces. The following default pin configuration of UART interfaces as used by a most boards can be overridden by the application, see section [Application-Specific Configurations] (#esp32_application_specific_configurations).

<center>
DeviceSignalPinSymbolRemarks
UART_DEV(0)TxDGPIO1#UART0_TXDcannot be changed
UART_DEV(0)RxDGPIO3#UART0_RXDcannot be changed
UART_DEV(1)TxDGPIO10#UART1_TXDoptional, can be overridden
UART_DEV(1)RxDGPIO9#UART1_RXDoptional, can be overridden
UART_DEV(2)TxDGPIO17UART2_TXDoptional, can be overridden
UART_DEV(2)RxDGPIO16UART2_RXDoptional, can be overridden
</center>

JTAG Interface {#esp32_jtag_interface_esp32}

The JTAG interface on ESP32 is connected to the following GPIOs:

<center>
JTAG SignalESP32 Pin
TRST_NCHIP_PU
TDOGPIO15 (MTDO)
TDIGPIO12 (MTDI)
TCKGPIO13 (MTCK)
TMSGPIO14 (MTMS)
GNDGND
</center>