Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use stm32 DMA

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to talk to you about how to use stm32 DMA, many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.

Brief introduction of stm32 DMA peripherals:

DMA (Direct Memory Access), direct memory access, is a data access method that can greatly reduce the workload of CPU, so it is widely used. In the hardware system, it is mainly composed of CPU (kernel), peripherals, memory (SRAM), bus and other structures. Data is often transferred between memory and peripherals, or from peripheral A to peripheral B. DMA can transfer data from peripherals to memory or from memory to peripherals directly through CPU. In fact, the concrete performance is to establish a channel between the peripheral registers and memory variables, so that their data updates are synchronized, just like the same variable.

Stm32 DMA peripherals also have corresponding transmission interruptions.

Let's take the establishment of an one-way DMA channel from the data register of USART1 to memory variables as an example to illustrate the use of DMA. USART1- > to variables.

USART1 configuration is a general configuration, only one thing to note: be sure to enable the DMA function of USART1 peripherals.

USART_DMACmd (USART1, USART_DMAReq_Rx, ENABLE); / / be sure to remember to enable the DMA function of the peripheral, because this has been entangled for a long time.

DMA configuration:

Define USART1_DR_Base 0x40013804uint8_t TxBuff;void DMA_Config (void) {DMA_InitTypeDef DMA_InitStructure; RCC_AHBPeriphClockCmd (RCC_AHBPeriph_DMA1, ENABLE); / / turn on DMA clock / * set DMA source: memory address & serial port data register address * / DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_DR_Base / * memory address (pointer to the variable to be transferred) * / DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) (& TxBuff); / * Direction: from peripheral to memory * / DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; / * transfer size DMA_BufferSize=SENDBUFF_SIZE*/ DMA_InitStructure.DMA_BufferSize = 1 / * Peripheral address does not increase * / DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; / * memory address does not increase * / DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; / * Peripheral data unit * / DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte / * memory data unit 8bit*/ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; / * DMA mode, loop * / DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; / * priority: medium * / DMA_InitStructure.DMA_Priority = DMA_Priority_Medium / * disable memory-to-memory transfer * / DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; / * configure DMA1's 5-channel * / DMA_Init (DMA1_Channel5, & DMA_InitStructure); DMA_Cmd (DMA1_Channel5,ENABLE) / / enable DMA USART_DMACmd (USART1, USART_DMAReq_Rx, ENABLE); / / remember to enable the DMA function of the peripheral, because this has been going on for a long time. }

The configuration of DMA is relatively simple, so how to find the peripheral register address, that is, the macro in the code. Look for it in the data manual.

You can find the offset address of the register here. Then look for the base address, search for memory map in PDF, or find the corresponding chapter.

This is the base address of the register, and then the register address is 0x40013800+0x04=0x40013804

Stm32 has two dma, a total of 12 access dma1 has 7, dma2 has 5.

The following is a partial channel diagram of dma1

It can be seen from this figure that even the corresponding DMA channels of the same peripheral may be different, so it should be noted that each channel is dedicated, and only the corresponding peripherals can use the corresponding channel.

After reading the above, do you have any further understanding of how to use stm32 DMA? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report