Professional Documents
Culture Documents
6 DMA Controller (DMA) : 6.1 Overview
6 DMA Controller (DMA) : 6.1 Overview
6 DMA Controller (DMA) : 6.1 Overview
6.1 Overview
Direct Memory Access (DMA) is used for high-speed data transfer between peripherals and memory, as well as
from memory to memory. Data can be quickly moved with DMA without any CPU intervention, thus allowing for
more efficient use of the cores when processing data.
In the ESP32, 13 peripherals are capable of using DMA for data transfer, namely, UART0, UART1, UART2, SPI1,
SPI2, SPI3, I2S0, I2S1, SDIO slave, SD/MMC host, EMAC, BT, and Wi-Fi.
6.2 Features
The DMA controllers in the ESP32 feature:
Each DMA controller features different functions. However, the architecture of the DMA engine (DMA_ENGINE) is
the same in all DMA controllers.
The DMA Engine accesses SRAM over the AHB BUS. In Figure 12, the RAM represents the internal SRAM banks
available on ESP32. Further details on the SRAM addressing range can be found in Chapter System and Memory.
Software can use a DMA Engine by assigning a linked list to define the DMA operational parameters.
The DMA Engine transmits the data from the RAM to a peripheral, according to the contents of the out_link de-
scriptor. Also, the DMA Engine stores the data received from a peripheral into a specified RAM location, according
to the contents of the in_link descriptor.
The DMA descriptor’s linked lists (out_link and in_link) have the same structure. As shown in Figure 13, a linked-list
descriptor consists of three words. The meaning of each field is as follows:
• owner (DW0) [31]: The allowed operator of the buffer corresponding to the current linked list.
1’b0: the allowed operator is the CPU;
1’b1: the allowed operator is the DMA controller.
• length (DW0) [23:12]: The number of valid bytes in the buffer corresponding to the current linked list. The
field value indicates the number of bytes to be transferred to/from the buffer denoted by word DW1.
• size (DW0) [11:0]: The size of the buffer corresponding to the current linked list.
NOTE: The size must be word-aligned.
• buffer address pointer (DW1): Buffer address pointer. This is the address of the data buffer.
NOTE: The buffer address must be word-aligned.
• next descriptor address (DW2): The address pointer of the next linked-list item. The value is 0, if the current
linked-list item is the last on the list (eof=1).
When receiving data, if the data transfer length is smaller than the specified buffer size, DMA will not use the
remaining space. This enables the DMA engine to be used for transferring an arbitrary number of data bytes.
Figure 14 shows the data transfer in UDMA mode. Before the DMA Engine receives data, software must initialize
the receive-linked-list. UHCI_INLINK_ADDR is used to point to the first in_link descriptor. The register must be
programmed with the lower 20 bits of the address of the initial linked-list item. After UHCI_INLINK_START is set,
the Universal Host Controller Interface (UHCI) will transmit the data received by UART to the Decoder. After being
parsed, the data will be stored in the RAM as specified by the receive-linked-list descriptor.
Before DMA transmits data, software must initialize the transmit-linked-list and the data to be transferred. UHCI_
OUTLINK_ADDR is used to point to the first out_link descriptor. The register must be programmed with the lower
20 bits of the address of the initial transmit-linked-list item. After UHCI_OUTLINK_START is set, the DMA Engine
will read data from the RAM location specified by the linked-list descriptor and then transfer the data through the
Encoder. The DMA Engine will then shift the data out serially through the UART transmitter.
The UART DMA follows a format of (separator + data + separator). The Encoder is used for adding separa-
tors before and after data, as well as using special-character sequences to replace data that are the same
as separators. The Decoder is used for removing separators before and after data, as well as replacing the
special-character sequences with separators. There can be multiple consecutive separators marking the be-
ginning or end of data. These separators can be configured through UHCI_SEPER_CH, with the default val-
ues being 0xC0. Data that are the same as separators can be replaced with UHCI_ESC_SEQ0_CHAR0 (0xDB
by default) and UHCI_ESC_SEQ0_CHAR1 (0xDD by default). After the transmission process is complete, a
UHCI_OUT_TOTAL_EOF_INT interrupt will be generated. After the reception procedure is complete, a UHCI_IN_
SUC_EOF_INT interrupt will be generated.
ESP32 SPI modules can use DMA as well as the CPU for data exchange with peripherals. As can be seen from
Figure 15, two DMA channels are shared by SPI1, SPI2 and SPI3 controllers. Each DMA channel can be used by
any one SPI controller at any given time.
The ESP32 SPI DMA Engine also uses a linked list to receive/transmit data. Burst transmission is supported. The
minimum data length for a single transfer is one byte. Consecutive data transfer is also supported.