Peripheral configuration that is common for all ESP32x SoCs. More...
Peripheral configuration that is common for all ESP32x SoCs.
Definition in file periph_cpu.h.
#include <stdbool.h>
#include <stdint.h>
#include "sdkconfig.h"
#include "hal/ledc_types.h"
#include "hal/spi_types.h"
#include "soc/ledc_struct.h"
#include "soc/periph_defs.h"
#include "soc/soc_caps.h"
#include "usbdev_synopsys_dwc2.h"
Go to the source code of this file.
Data Structures | |
union | gpio_conf_esp32 |
GPIO pin configuration for ESP32/ESP32Cx/ESP32Sx MCUs. More... | |
struct | i2c_conf_t |
I2C configuration structure. More... | |
struct | pwm_config_t |
PWM configuration structure type. More... | |
struct | rmt_channel_config_t |
RMT channel configuration. More... | |
struct | sdmmc_conf_t |
SDMMC slot configuration. More... | |
struct | spi_conf_t |
SPI device configuration. More... | |
struct | uart_conf_t |
UART device configuration. More... | |
Macros | |
#define | CPUID_LEN (6U) |
Length of the CPU_ID in octets. | |
#define | PERIPH_TIMER_PROVIDES_SET |
Prevent shared timer functions from being used. | |
#define | STDIO_UART_DEV CONFIG_ESP_CONSOLE_UART_NUM |
UART device used for STDIO. | |
Power management configuration | |
#define | PROVIDES_PM_SET_LOWEST |
#define | PROVIDES_PM_RESTART |
#define | PROVIDES_PM_OFF |
#define | PROVIDES_PM_LAYERED_OFF |
#define | PM_NUM_MODES (3U) |
Number of usable low power modes. | |
Power modes | |
#define | ESP_PM_MODEM_SLEEP (2U) |
#define | ESP_PM_LIGHT_SLEEP (1U) |
#define | ESP_PM_DEEP_SLEEP (0U) |
GPIO configuration | |
#define | HAVE_GPIO_T |
Override the default gpio_t type definition. | |
typedef unsigned int | gpio_t |
#define | GPIO_UNDEF (0xffffffff) |
Definition of a fitting UNDEF value. | |
#define | GPIO_PIN(x, y) ((x << 5) | y) |
Define a CPU specific GPIO pin generator macro. | |
#define | PORT_GPIO (0) |
Available GPIO ports on ESP32. | |
#define | GPIO_PIN_NUMOF (SOC_GPIO_PIN_COUNT) |
Define CPU specific number of GPIO pins. | |
ADC configuration | ||||||||||||||||
ESP32x SoCs integrate two SAR ADCs (ADC1 and ADC2). The bit width of the ADC devices, the number of channels per device and the GPIOs that can be used as ADC channels depend on the respective ESP32x SoC family. For details, see: ADC_GPIOS in the board-specific peripheral configuration defines the list of GPIOs that can be used as ADC channels on the board, for example: #define ADC_GPIOS { GPIO0, GPIO2, GPIO4 }
Thereby the order of the listed GPIOs determines the mapping between the ADC lines of the RIOT and the GPIOs. The maximum number of GPIOs in the list is ADC_NUMOF_MAX. The board specific configuration of ADC_GPIOS can be overridden by [Application specific configurations] (#esp32_application_specific_configurations). The number of defined ADC channels ADC_NUMOF is determined automatically from the ADC_GPIOS definition.
With the function adc_set_attenuation an attenuation of the input signal can be defined separately for each ADC channel. int adc_set_attenuation(adc_t line, adc_atten_t atten) Set the attenuation for the ADC line. This leads to different measurable maximum values for the voltage at the input. The higher the attenuation is, the higher the voltage measured at the input can be. The attenuation can be set to 4 fixed values 0 dB, 2.5/3 dB, 6 dB and 11/12 dB, where 11 dB respectively 12 dB is the default attenuation.
The Vref of a device can be read at a predefined GPIO with the function adc_line_vref_to_gpio. The results of the ADC input can then be adjusted accordingly. int adc_line_vref_to_gpio(adc_t line, gpio_t gpio) Output reference voltage of a ADC line to GPIO n. For the GPIO that can be used with this function, see: | ||||||||||||||||
#define | ADC_NUMOF_MAX (SOC_ADC_CHANNEL_NUM(0) + SOC_ADC_CHANNEL_NUM(1)) | |||||||||||||||
Number of ADC channels that could be used at maximum. | ||||||||||||||||
DAC configuration | |
Some ESP32x SoCs support 2 DAC lines at predefined GPIOs, depending on the respective ESP32x SoC family. These DACs have a width of 8 bits and produce voltages in the range from 0 V to 3.3 V (VDD_A). The 16 bit DAC values given as parameter of function dac_set are down-scaled to 8 bit. The GPIOs that can be used as DAC channels for a given board are defined by the #define DAC_GPIOS { GPIO25, GPIO26 }
This configuration can be changed by [application-specific configurations] (#esp32_application_specific_configurations). The order of the listed GPIOs determines the mapping between the RIOT's DAC lines and the GPIOs. The maximum number of GPIOs in the list is DAC_NUMOF_MAX. DAC_NUMOF is determined automatically from the DAC_GPIOS definition.
DACs are currently only supported for the ESP32 SoC variant. | |
#define | DAC_NUMOF_MAX (SOC_DAC_PERIPH_NUM) |
Number of DAC channels that could be used at maximum. | |
I2C configuration | |
ESP32x SoCs integrate up to two I2C hardware interfaces. The board-specific configuration of the I2C interface I2C_DEV(n) requires the definition of
where #define I2C0_SPEED I2C_SPEED_FAST
#define I2C0_SCL GPIO22
#define I2C0_SDA GPIO21
#define I2C1_SPEED I2C_SPEED_NORMAL
#define I2C1_SCL GPIO13
#define I2C1_SDA GPIO16
The board-specific pin configuration of I2C interfaces can be changed by application specific configurations by overriding the according
The number of used I2C interfaces I2C_NUMOF is determined automatically from board-specific peripheral definitions of I2C_DEV(n). | |
#define | I2C_NUMOF_MAX (SOC_I2C_NUM) |
Maximum number of I2C interfaces that can be used by board definitions. | |
#define | PERIPH_I2C_NEED_READ_REG |
Implementation requires i2c_read_reg. | |
#define | PERIPH_I2C_NEED_READ_REGS |
Implementation requires i2c_read_regs. | |
#define | PERIPH_I2C_NEED_WRITE_REG |
Implementation requires i2c_write_reg. | |
#define | PERIPH_I2C_NEED_WRITE_REGS |
Implementation requires i2c_write_regs. | |
PWM configuration | |||||||||||||||||||||
The PWM peripheral driver for ESP32x SoCs uses the LED PWM Controller (LEDC) module for implementation. The LEDC module has either 1 or 2 channel groups with 6 or 8 channels each, where the first channel group comprises the low-speed channels and the second channel group comprises the high-speed channels. The difference is that changes in the configuration of the high-speed channels take effect with the next PWM cycle, while the changes in the configuration of the low-speed channels must be explicitly updated by a trigger. The low-speed channel group always exists while the existence of the high-speed channel group depends on respective ESP32x SoC family. Each channel group has 4 timers which can be used as clock source by the channels of the respective channel group. Thus it would be possible to define a maximum of 4 virtual PWM devices in RIOT per channel group with different frequencies and resolutions. However, regardless of whether the LEDC module of the ESP32x SoC has one or two channel groups, the PWM driver implementation only allows the available channels to be organized into up to 4 virtual PWM devices. The assignment of the available channels to the virtual PWM devices is done in the board-specific peripheral configuration by defining the macros #define PWM0_GPIOS { GPIO0, GPIO2, GPIO4, GPIO16, GPIO17 }
#define PWM1_GPIOS { GPIO27, GPIO32, GPIO33 }
This configuration can be changed by [application-specific configurations] (#esp32_application_specific_configurations). The mapping of the GPIOs as channels of the available channel groups and channel group timers is organized by the driver automatically as follows:
For example, if the LEDC module of the ESP32x SoC has two channel groups, two virtual PWM devices with 2 x 6 (or 8) channels could be used by defining 'PWM0_GPIOS' and 'PWM1_GPIOS' with 6 (or 8) GPIOs each. The number of used PWM devices PWM_NUMOF is determined automatically from the definition of
| |||||||||||||||||||||
#define | PWM_NUMOF_MAX (4) | ||||||||||||||||||||
Maximum number of PWM devices. | |||||||||||||||||||||
#define | PWM_CH_NUMOF_MAX (SOC_LEDC_CHANNEL_NUM) | ||||||||||||||||||||
Maximum number of channels per PWM device. | |||||||||||||||||||||
RMT configuration | |
ESP32x SoCs have a Remote Control Peripheral (RMT) that can be used to generate digital waveforms, such as NEC remote control signals or WS2812B RGB LED signals. Each RMT peripheral has either 4 or 8 channels. Some ESP32x SoCs support configuring the clock sources used for each channel separately, while other ESP32x SoCs can only use a single clock source for all channels. | |
#define | RMT_CH_NUMOF_MAX (SOC_RMT_CHANNELS_PER_GROUP) |
Maximum number of RMT channels. | |
RNG configuration | |
#define | RNG_DATA_REG_ADDR (WDEV_RND_REG) |
The address of the register for accessing the hardware RNG. | |
RTT and RTC configuration | |
#define | RTT_FREQUENCY (32768UL) |
RTT frequency definition. | |
#define | RTT_MAX_VALUE (0xFFFFFFFFUL) |
RTT is a 32-bit counter. | |
SDMMC configuration | |
ESP32x SoC with SDMMC peripheral provide two SDMMC interfaces called slots. How many slots can be used depends on the ESP32x SoC, see sdmmc_slot_t. | |
#define | SDMMC_CPU_DMA_REQUIREMENTS __attribute__((aligned(SDMMC_CPU_DMA_ALIGNMENT))) |
SDIO/SDMMC buffer instantiation requirement for SDHC. | |
#define | SDMMC_CPU_DMA_ALIGNMENT 4 |
SDIO/SDMMC buffer alignment for SDHC because of DMA/FIFO buffer restrictions. | |
enum | sdmmc_slot_t { SDMMC_SLOT_0 = 0 , SDMMC_SLOT_1 = 1 } |
SDIO/SDMMC slots. More... | |
SPI configuration | |
ESP32x SoCs have up to four SPI controllers dependent on the specific ESP32x SoC variant (family):
The controllers SPI0 and SPI1 share the same bus signals and can only operate in memory mode on most ESP32x SoC variants. Therefore, depending on the specific ESP32x SoC family, a maximum of two SPI controllers can be used as peripheral interfaces:
In former ESP-IDF versions, SPI interfaces were identified by the alias names SPI interfaces could be used in quad SPI mode, but RIOT's low level device driver doesn't support it. The board-specific configuration of the SPI interface SPI_DEV(n) requires the definition of
where #define SPI0_CTRL SPI3_HOST // VSPI could also be used on ESP32 variant
#define SPI0_SCK GPIO18 // SCK signal
#define SPI0_MISO GPIO19 // MISO signal
#define SPI0_MOSI GPIO23 // MOSI signal
#define SPI0_CS0 GPIO5 // CS0 signal
#define SPI1_CTRL SPI2_HOST // HSPI could also be used here on ESP32 variant
#define SPI1_SCK GPIO14 // SCK Camera
#define SPI1_MISO GPIO12 // MISO Camera
#define SPI1_MOSI GPIO13 // MOSI Camera
#define SPI1_CS0 GPIO15 // CS0 Camera
The pin configuration of SPI interfaces can be changed by application specific configurations by overriding the according
SPI_NUMOF is determined automatically from the board-specific peripheral configuration for SPI_DEV(n). | |
#define | FSPI SPI2_HOST |
Alias name for SPI2_HOST as used in former ESP-IDF versions. | |
#define | SPI_NUMOF_MAX (SOC_SPI_PERIPH_NUM - 1) |
Maximum number of SPI interfaces that can be used by board definitions. | |
#define | PERIPH_SPI_NEEDS_TRANSFER_BYTE |
requires function spi_transfer_byte | |
#define | PERIPH_SPI_NEEDS_TRANSFER_REG |
requires function spi_transfer_reg | |
#define | PERIPH_SPI_NEEDS_TRANSFER_REGS |
requires function spi_transfer_regs | |
typedef spi_host_device_t | spi_ctrl_t |
Mapping of SPI controller type for source code compatibility. | |
Timer configuration depending on which implementation is used | |
There are two different implementations for hardware timers.
By default, the timer module is used. To use the counter implementation, add USEMODULE += esp_hw_counter
to application's makefile. Timers are MCU built-in features and not board-specific. There is nothing to be configured. | |
#define | TIMER_NUMOF (SOC_TIMER_GROUP_TOTAL_TIMERS - 1) |
Hardware timer modules are used for timer implementation (default) | |
#define | TIMER_CHANNEL_NUMOF (1) |
#define | TIMER_SYSTEM_GROUP TIMER_GROUP_0 |
Timer group used for system time. | |
#define | TIMER_SYSTEM_INDEX TIMER_0 |
Index of the timer in the timer timer group used for system time. | |
#define | TIMER_SYSTEM_INT_SRC ETS_TG0_T0_LEVEL_INTR_SOURCE |
System time interrupt source. | |
UART configuration | |
ESP32x SoCs integrate up to three UART devices, depending on the specific ESP32x SoC variant (family). The pin configuration of the UART device UART_DEV(n) is defined in the board-specific peripheral configuration by
where #define UART1_TX GPIO10 // TxD signal of UART_DEV(1)
#define UART1_RX GPIO9 // RxD signal of UART_DEV(1)
The pin configuration of UART interfaces can be changed by application specific configurations by overriding the according
UART_NUMOF is determined automatically from the board-specific peripheral configuration for UART_DEV(n). UART_DEV(0) has usually a fixed pin configuration that is used by all ESP32x boards as standard configuration for the console. The GPIOs used for UART_DEV(0) depend on the ESP32x SoC family. | |
#define | UART_NUMOF_MAX (SOC_UART_NUM) |
Maximum number of UART interfaces. | |
USB device configuration | |
ESP32x SoCs integrate depending on the specific ESP32x SoC variant (family) an USB OTG FS controller based on the Synopsys DWC2 IP core. | |
#define | USBDEV_NUMOF_MAX (SOC_USB_PERIPH_NUM) |
Maximum number of USB OTG FS interfaces. | |
#define ADC_NUMOF_MAX (SOC_ADC_CHANNEL_NUM(0) + SOC_ADC_CHANNEL_NUM(1)) |
Number of ADC channels that could be used at maximum.
Definition at line 351 of file periph_cpu.h.
#define CPUID_LEN (6U) |
Length of the CPU_ID in octets.
Definition at line 68 of file periph_cpu.h.
#define DAC_NUMOF_MAX (SOC_DAC_PERIPH_NUM) |
Number of DAC channels that could be used at maximum.
Definition at line 395 of file periph_cpu.h.
#define ESP_PM_DEEP_SLEEP (0U) |
Definition at line 60 of file periph_cpu.h.
#define ESP_PM_LIGHT_SLEEP (1U) |
Definition at line 59 of file periph_cpu.h.
#define ESP_PM_MODEM_SLEEP (2U) |
Definition at line 58 of file periph_cpu.h.
#define FSPI SPI2_HOST |
Alias name for SPI2_HOST as used in former ESP-IDF versions.
Definition at line 857 of file periph_cpu.h.
#define GPIO_PIN | ( | x, | |
y | |||
) | ((x << 5) | y) |
Define a CPU specific GPIO pin generator macro.
Definition at line 96 of file periph_cpu.h.
#define GPIO_PIN_NUMOF (SOC_GPIO_PIN_COUNT) |
Define CPU specific number of GPIO pins.
Definition at line 110 of file periph_cpu.h.
#define GPIO_UNDEF (0xffffffff) |
Definition of a fitting UNDEF value.
Definition at line 89 of file periph_cpu.h.
#define HAVE_GPIO_T |
Override the default gpio_t type definition.
This is required here to have gpio_t defined in this file.
Definition at line 81 of file periph_cpu.h.
#define I2C_NUMOF_MAX (SOC_I2C_NUM) |
Maximum number of I2C interfaces that can be used by board definitions.
Definition at line 479 of file periph_cpu.h.
#define PERIPH_I2C_NEED_READ_REG |
Implementation requires i2c_read_reg.
Definition at line 481 of file periph_cpu.h.
#define PERIPH_I2C_NEED_READ_REGS |
Implementation requires i2c_read_regs.
Definition at line 482 of file periph_cpu.h.
#define PERIPH_I2C_NEED_WRITE_REG |
Implementation requires i2c_write_reg.
Definition at line 483 of file periph_cpu.h.
#define PERIPH_I2C_NEED_WRITE_REGS |
Implementation requires i2c_write_regs.
Definition at line 484 of file periph_cpu.h.
#define PERIPH_SPI_NEEDS_TRANSFER_BYTE |
requires function spi_transfer_byte
Definition at line 876 of file periph_cpu.h.
#define PERIPH_SPI_NEEDS_TRANSFER_REG |
requires function spi_transfer_reg
Definition at line 877 of file periph_cpu.h.
#define PERIPH_SPI_NEEDS_TRANSFER_REGS |
requires function spi_transfer_regs
Definition at line 878 of file periph_cpu.h.
#define PERIPH_TIMER_PROVIDES_SET |
Prevent shared timer functions from being used.
Definition at line 929 of file periph_cpu.h.
#define PM_NUM_MODES (3U) |
Number of usable low power modes.
Definition at line 52 of file periph_cpu.h.
#define PORT_GPIO (0) |
Available GPIO ports on ESP32.
Definition at line 103 of file periph_cpu.h.
#define PROVIDES_PM_LAYERED_OFF |
Definition at line 47 of file periph_cpu.h.
#define PROVIDES_PM_OFF |
Definition at line 46 of file periph_cpu.h.
#define PROVIDES_PM_RESTART |
Definition at line 45 of file periph_cpu.h.
#define PROVIDES_PM_SET_LOWEST |
Definition at line 44 of file periph_cpu.h.
#define PWM_CH_NUMOF_MAX (SOC_LEDC_CHANNEL_NUM) |
Maximum number of channels per PWM device.
Definition at line 592 of file periph_cpu.h.
#define PWM_NUMOF_MAX (4) |
Maximum number of PWM devices.
Definition at line 587 of file periph_cpu.h.
#define RMT_CH_NUMOF_MAX (SOC_RMT_CHANNELS_PER_GROUP) |
Maximum number of RMT channels.
The number of configured channels must be less or equal.
Definition at line 626 of file periph_cpu.h.
#define RNG_DATA_REG_ADDR (WDEV_RND_REG) |
The address of the register for accessing the hardware RNG.
Definition at line 638 of file periph_cpu.h.
#define RTT_FREQUENCY (32768UL) |
RTT frequency definition.
The RTT frequency is always 32.768 kHz even if no external crystal is connected. In this case the RTT value counted with the internal 150 kHz RC oscillator is converted to a value for an RTT with 32.768 kHz.
Definition at line 653 of file periph_cpu.h.
#define RTT_MAX_VALUE (0xFFFFFFFFUL) |
RTT is a 32-bit counter.
Definition at line 658 of file periph_cpu.h.
#define SDMMC_CPU_DMA_ALIGNMENT 4 |
SDIO/SDMMC buffer alignment for SDHC because of DMA/FIFO buffer restrictions.
Definition at line 734 of file periph_cpu.h.
#define SDMMC_CPU_DMA_REQUIREMENTS __attribute__((aligned(SDMMC_CPU_DMA_ALIGNMENT))) |
SDIO/SDMMC buffer instantiation requirement for SDHC.
Definition at line 729 of file periph_cpu.h.
#define SPI_NUMOF_MAX (SOC_SPI_PERIPH_NUM - 1) |
Maximum number of SPI interfaces that can be used by board definitions.
Definition at line 874 of file periph_cpu.h.
#define STDIO_UART_DEV CONFIG_ESP_CONSOLE_UART_NUM |
UART device used for STDIO.
Definition at line 38 of file periph_cpu.h.
#define TIMER_CHANNEL_NUMOF (1) |
Definition at line 914 of file periph_cpu.h.
#define TIMER_NUMOF (SOC_TIMER_GROUP_TOTAL_TIMERS - 1) |
Hardware timer modules are used for timer implementation (default)
Since one timer is used for the system time, there is one timer less than the total number of timers.
Definition at line 913 of file periph_cpu.h.
#define TIMER_SYSTEM_GROUP TIMER_GROUP_0 |
Timer group used for system time.
Definition at line 918 of file periph_cpu.h.
#define TIMER_SYSTEM_INDEX TIMER_0 |
Index of the timer in the timer timer group used for system time.
Definition at line 920 of file periph_cpu.h.
#define TIMER_SYSTEM_INT_SRC ETS_TG0_T0_LEVEL_INTR_SOURCE |
System time interrupt source.
Definition at line 922 of file periph_cpu.h.
#define UART_NUMOF_MAX (SOC_UART_NUM) |
Maximum number of UART interfaces.
Definition at line 984 of file periph_cpu.h.
#define USBDEV_NUMOF_MAX (SOC_USB_PERIPH_NUM) |
Maximum number of USB OTG FS interfaces.
Definition at line 999 of file periph_cpu.h.
typedef unsigned int gpio_t |
Definition at line 82 of file periph_cpu.h.
typedef spi_host_device_t spi_ctrl_t |
Mapping of SPI controller type for source code compatibility.
Definition at line 842 of file periph_cpu.h.
enum sdmmc_slot_t |
SDIO/SDMMC slots.
ESP32x SoCs that have a SDMMC peripheral provide two SDMMC interfaces called slots.
SOC_SDMMC_USE_IOMUX
is defined in SoC capabilities), the GPIOs used for the SDMMC slots are fixed. In this case, slot 0 can't be used because the GPIOs are defined for Slot 0 are the same as those used for the Flash. If the ESP32x variant uses the GPIO matrix to route the SDMMC signals to arbitrary pins (i.e. SOC_SDMMC_USE_GPIO_MATRIX
is defined in SoC capabilities), slot 0 can be used but the GPIOs used for the slot have to be different from those used for the Flash. Enumerator | |
---|---|
SDMMC_SLOT_0 | SD/MMC host controller slot 0 (not usable on ESP32 variant) |
SDMMC_SLOT_1 | SD/MMC host controller slot 1. |
Definition at line 686 of file periph_cpu.h.