DMA involves the following concepts:
①: DMA stands for Direct Memory Access, which is a peripheral unique to STM32. Large-capacity STM32 products integrate two DMAs, namely DMA1 and DMA2. DMA1 has 7 channels and DMA2 has 5 channels. For the specific peripherals connected to each channel, please refer to the data manual of the STM32 chip.
②: DMA can be used to transfer data between two different addresses, such as memory to peripheral registers, peripheral registers to memory, or from memory to memory.
③: When two data are transferred between different addresses, it is necessary to determine the number of bytes transmitted each time in the program configuration, and determine whether it is a byte, half word or word.
④: The priority of each DMA channel is variable. Take DMA1 as an example. It has 7 channels. Each channel can be configured with one of the following four priority levels: very high, high, medium, or low. If two channels have the same priority, when both channels have DMA requests at the same time, the channel with the smaller number has a higher priority.
⑤: The amount of data transferred by DMA each time is variable. There is a special register in DMA to store this data value. This register is 32 bits, but the upper 16 bits are all reserved as 0. In fact, the lower 16 bits are effective, so the maximum amount of data transferred each time is 65536.
⑥: As shown in ⑤, for example, if the data volume value is set to 100, if the DMA transmission is set to cyclic mode, the next round of transmission will be automatically carried out after 100 data transmissions are completed. If it is set to non-cyclic mode, you need to turn off DMA first, then set the data volume value, and then turn on DMA before the next round of transmission can be carried out.
⑦: During the DMA transmission process, there are three common flags: half of the transmission is completed, the transmission is completed, and an error occurs during the transmission process. You can set the interrupt corresponding to the flag in the program. When the flag arrives, the interrupt service program will be executed. You can also not enable the interrupt of the corresponding flag.
⑧: After determining the peripheral and memory address to be transferred, you need to set the transfer direction in the program, that is, whether the transfer direction is from the peripheral to the register, or from the register to the peripheral.
⑨: DMA is generally used to transfer data between peripherals and memory, so it is also necessary to set whether the peripheral address and memory address are incremented. For example, if an array is defined, char data[100], and the peripheral address is &UART->TX, if the 100 data in the array are transferred to UART->TX, the memory address needs to be incremented each time, but the peripheral address does not need to be incremented.
DMA configuration process:
①: Determine the peripheral and register address of the transmitted data
②: Determine the transmission direction
③: Determine the amount of data transferred each time
④: Determine the number of bytes of transmitted data
⑤: Configure channel priority
⑥: Determine whether the transmission is in cyclic mode or non-cyclic mode
⑦: If you need to enable interrupt, enable the response bit interrupt
Note: DMA can also be from memory to memory, but the memory to memory process can only be non-circular mode.
Program explanation:
Example: The function implemented by the program is to transfer the data in the memory to the transmit register TX of the serial port. The amount of data transmitted each time is 100, and the transmission is in non-cyclic mode.
void MYDMA_Config(DMA_Channel_TypeDef* DMA_CHx, u32 cpar, u32 cmar, u16 cndtr)
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //Start the clock
DMA_DeInit(DMA_CHx); //Initialize the channel and set it to default configuration
DMA1_MEM_LEN=cndtr;
DMA_InitStructure.DMA_PeripheralBaseAddr = cpar; //Peripheral address
DMA_InitStructure.DMA_MemoryBaseAddr = cmar; //Memory address
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //Transmission direction, from memory to peripherals
DMA_InitStructure.DMA_BufferSize = cndtr; //The amount of data transferred in each cycle
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //Peripheral address remains unchanged
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //The memory address increases by 1 each time
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //Byte transfer
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //Byte transfer
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //Non-cyclic mode
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; //Set priority - Medium
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //Not memory to memory
DMA_Init(DMA_CHx, &DMA_InitStructure); //Initialize DMA configuration process
}
//Start a transmission
void MYDMA_Enable(DMA_Channel_TypeDef*DMA_CHx)
{
DMA_Cmd(DMA_CHx, DISABLE ); //关闭DMA
DMA_SetCurrDataCounter(DMA_CHx,DMA1_MEM_LEN); //Redetermine the amount of data to be transferred in each cycle
DMA_Cmd(DMA_CHx, ENABLE); //Enable DMA again
}
int main()
{
u8 SendBuff[100]; //Memory data
MYDMA_Config(DMA1_Channel4, (u32)&USART1->DR, (u32)SendBuff, 100); //Call function
MYDMA_Enable(DMA1_Channel4); //Start a transmission
}
Previous article:STM32 interrupt control process
Next article:STM32 basic design (5) --- ADC conversion (interrupt mode)
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- The problem of repeated declaration of global variables in embedded C programming
- 3G license issuance timetable is not determined, Ministry of Information Industry has little say
- AD some operation problems
- UWB can use the frequency band in China,,,,
- What should I do if I have a colleague who is nagging and incompetent?
- The reason why a pair of ground capacitors are connected on both sides of the MCU crystal
- Hiring embedded software engineer
- Definition and function of the middle segment in DSP program
- Detailed explanation of microcontroller principles and applications
- How to use hex 80 in MSP430 bootloader (BSL) communication