Introduction to DMA
The role of the DMA controller is not only to enhance system performance and reduce processor interrupt generation, but it is also specifically designed to be optimized for 32-bit MCU applications. The DMA controller provides 7 channels for memory-to-memory, memory-to-peripheral, and peripheral-to-memory transfers. Each channel supports the mapping of DMA requests for peripherals to any channel. Figure 1DMA controller architecture
Introduction to DMAMUX
DMAMUX is used to map DMA requests for peripherals to arbitrary traffic channels. DMAMUX has a unique ID number for each peripheral, and users only need to write this ID number to the corresponding register and turn on the DMAMUX function. The introduction of DMAMUX makes DMA more flexible than traditional DMA controllers, and users can allocate the usage of 7 channels at will, and no longer have to worry about DMA requests with a certain IP that can only be used on one or several channels. The corresponding ID numbers of each IP address are as follows: Table 1A list of the ID numbers corresponding to each IP address
Note: "DMAMUX Request" in ** is the ID number;"* DMA requests for each IP.
DMA function analysis
Programmable data width
The DMA controller's channel can support the transmission of different data widths, bytes and halfword words. The data width of the source data and the target data can be programmed through the pwidth and mwidth bits in DMA CXCTRL, and the pwidth and mwidth bits need to be set to be equal in normal cases, and when the pwidth is not equal to the mwidth, the data will be aligned according to the pwidth mwidth setting. Figure 2 pwidth:byte, mwidth: half-word
Figure 3 pwidth: half-word, mwidth: word
Configure DMAMUX
In M2P and P2M modes, DMAMux must be configured, otherwise DMA will not respond to peripheral DMA requests. The role of DMAMUX is to multiplex the DMA request for the peripheral, that is, the DMA request of any peripheral can be mapped to any channel of DMA1 and DMA2, which greatly increases the flexibility of DMA channel allocation. Configuring DMAMUX is as simple as calling two specially provided interface functions
Configure the Request Generator module
When DMAMUX is configured, you can optionally configure the DMA request generator module, which has a total of 4 request generator channels. This module does not require any traditional peripherals (such as timer, SPI, etc.) to provide DMA requests, and can be used as DMA request source input through external EXINT inputs. Configuring the Request Generator module is as simple as calling a specially provided interface function:
Configure the request synchronization module
When DMAMUX is configured, you can optionally configure the DMA synchronization module, which has a total of 7 synchronization channels. After this function is enabled, when the peripheral generates a DMA request, DMA will not respond immediately and transmit data, but will wait for the arrival of the synchronization signal, and when the synchronization signal is received, the DMA will transmit data according to the configuration. The synchronization signal can be provided by an external exint input, and configuring the synchronization module is as simple as calling a specially provided interface function
DMA configuration parsing
The following describes the DMA configuration interface and process.
Functional interfaces
Table 2A list of channel configuration functions
Dataflow configuration
Set the peripheral address (CXPADDR register).The initial peripheral address of the data transmission cannot be changed during the transmission process. Set the memory address (CXMADDR register).The initial memory address of data transmission cannot be changed during transmission. Configure the amount of data transferred (cxdtcnt registers).The maximum length of the programmable transmitted data is 65535. During the transfer process, the value of the amount of data transferred decreases gradually. Data flow configuration (cxctrl register).
It includes channel priority, direction and width of data transmission, address increment mode, round-robin mode, and interrupt mode.
Priority (CHPL).
There are 4 levels, highest priority, high priority, medium priority, and low priority.
If two streams have the same priority, the lower numbered stream has a higher priority. For example, stream 1 takes precedence over stream 2.
Data Transfer Direction (DTD).It is divided into memory-to-peripherals (M2P), peripheral-to-memory (P2M), or memory-to-memory (M2M) transfers. Cyclic mode, double-buffered mode, and direct mode are not allowed in memory-to-memory transfer mode. The width of the data transfer (pwidth mwidth).Based on the actual usage scenario, you can configure the width to byte, halfword, or word. Address increment mode (pincm mincm).When the channel configuration is set to incremental mode, the address of the next transfer will be the address of the previous transfer plus the transmission width (pwidth mwidth). Cyclic mode (LM).When the stream configuration is set to cyclic mode, the contents of the CXDTCNT register will revert to their initial values after the last transmission. Enable DMAMUX (TBL SEL bit of the MUXsel register).In non-memory-to-memory (M2M) mode, DMAMUX needs to be enabled to initiate data flow in response to DMA requests from peripherals. Write the peripheral ID number (reqsel of the muxcxctrl register).In non-memory-to-memory (M2M) mode, the DMA request ID number of the peripheral needs to be written in order to initiate a data flow in response to the DMA request for the peripheral. Open the data stream (chen bit of the cxctrl register).
Configure the process
Turn on the DMA clock;Invoke the channel reset function to reset the data stream;Call the struct initialization function to initialize the channel configuration struct;Call the initialization function to initialize the channel;Call the dmamux enable function and write the id number function to configure dmamux-related contentCall the channel enable function to open the channel. If you need data sheets, sample testing, procurement, BOM matching and other needs, **Customer Service WeChat: 13310830171.