当前位置:网站首页>DMA use of stm32
DMA use of stm32
2022-07-06 04:35:00 【Struggling little Yin】
STM32 And DMA Use
The following are memory to memory and memory to peripherals ( A serial port ) Demonstrate the use of
Learn From Who said that?Jiangjiang STM32
One 、DMA brief introduction
Direct memory access (DMA) Used to provide high-speed data transfer between peripheral and memory or between memory and memory . need not CPU intervention , Data can be obtained by DMA Moving fast , This saves CPU To do other operations .
Two DMA The controller has 12 Channels (DMA1 Yes 7 Channels ,DMA2 Yes 5 Channels ), Each channel is dedicated to managing requests for memory access from one or more peripherals . There is also an arbiter to coordinate the various DMA The priority of the claim .
Two 、DMA The main features
12 A separate configurable channel ( request ):DMA1 Yes 7 Channels ,DMA2 Yes 5 Channels
● Each channel is directly connected to dedicated hardware DMA request , Each channel also supports software triggering . These functions are configured by software .
● In the same DMA On module , The priority between multiple requests can be set by software programming ( There are four levels : Very high 、 high 、 Medium and low ), When the priority settings are equal, it is determined by the hardware ( request 0 Priority over request 1, And so on ) .
● Transmission width of independent data source and target data area ( byte 、 Half word 、 Whole word ), Simulate the process of packing and unpacking . The source and destination addresses must be aligned according to the data transmission width .
● Buffer management supporting loops
● Every channel has 3 Event markers (DMA Semi transmission 、DMA The transmission is complete and DMA Transmission error ), this 3 An event flag logic or a separate interrupt request .
● Memory and memory to memory transfer
● Peripherals and memory 、 Transfer between memory and peripherals
● Flash memory 、SRAM、 Peripheral SRAM、APB1、APB2 and AHB Peripherals can be used as the source and target of access .
● The number of programmable data transfers : The maximum is 65535
3、 ... and 、 Functional block diagram
Four 、DMA passageway
Each channel can be executed between a peripheral register with a fixed address and a memory address DMA transmission .
DMA The amount of data transmitted is programmable , Up to 65535.
A register containing the number of data items to be transferred , Decrements after each transmission .
4.1 Programmable amount of data
The amount of data transmitted by peripherals and memory can be through DMA_CCRx In register PSIZE and MSIZE Bit programming .
4.24.2 Pointer increment
4.34.3 The configuration process
Here is the configuration DMA passageway x The process of (x Represents the channel number ):
- stay DMA_CPARx Register sets the address of the peripheral register . When a peripheral data transmission request occurs , This address will be the source or destination of data transmission .2. stay DMA_CMARx Register sets the address of the data memory . When a peripheral data transmission request occurs , The transmitted data will be read from or written to this address .3. stay DMA_CNDTRx Set the amount of data to be transmitted in the register . After each data transmission , This number decreases .4. stay DMA_CCRx The register of PL[1:0] Bit to set the priority of the channel .5. stay DMA_CCRx Set the direction of data transmission in the register 、 Circulation patterns 、 Incremental mode of peripherals and memory 、 Data width of peripherals and memory 、 An interrupt occurs when half of the transmission is completed or when the transmission is completed .6. Set up DMA_CCRx The register of ENABLE position , Start the channel .
Once it's started DMA passageway , It can respond to the of peripherals connected to the channel DMA request .
When half the data is transmitted , Half transmission flag (HTIF) Be placed 1, When it is set to allow half transmission break (HTIE) when , An interrupt request will be generated . At the end of data transmission , Transmission completion flag (TCIF) Be placed 1, When the interrupt bit is set to allow the transmission to complete (TCIE) when , An interrupt request will be generated .
4.4 Circulation patterns
4.5 Memory to memory mode
5、 ... and 、DMA Handle
After an event , Peripherals to DMA The controller sends a request signal .DMA The controller processes the request according to the priority of the channel . When DMA When the controller starts accessing the requested peripheral ,DMA The controller immediately sends it a reply signal . When from DMA When the controller gets the reply signal , The peripheral immediately releases its request . Once the peripheral releases the request ,DMA The controller cancels the reply signal at the same time . If there are more requests , The peripheral can start the next cycle .
All in all , Every time DMA Transmitted by 3 It consists of two operations :
● From the peripheral data register or from the current peripheral / The memory address indicated by the memory address register takes data , The start address for the first transmission is DMA_CPARx or DMA_CMARx Register specifies the peripheral base address or memory unit .
● Save data to the peripheral data register or the current peripheral / The memory address indicated by the memory address register , The start address for the first transmission is DMA_CPARx or DMA_CMARx Register specifies the peripheral base address or memory unit .
● Do it once DMA_CNDTRx Decrement of registers , This register contains the number of outstanding operations
6、 ... and 、DMA interrupt
7、 ... and 、DMA Request image
8、 ... and 、DMA register
Code demonstration
dma.h
#ifndef _DMA_H_
#define _DMA_H_
#include "stm32f10x.h"
void DMA_MTM_Init(void);
uint8_t Buffercmp(const uint32_t * pBuffer1,uint32_t *pBuffer2,uint32_t BufferLength);
void DMA_USART_Init(void);
#define USART_DR_ADDR (USART1_BASE + 0x04)
#define BUFFER_SIZE 4
#define Send_SIZE 50
#endif
dma.c
#include "dma.h"
const uint32_t SRC_Buffer[BUFFER_SIZE] = {
0x00000001,0x10101010,0x00111010,0x00111101};
uint32_t DES_Buffer[BUFFER_SIZE];
uint8_t Send_Buffer[Send_SIZE];
void DMA_MTM_Init(void)
{
DMA_InitTypeDef DMA_InitStructure;
// Clock configuration
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
//DMA Structure configuration
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) SRC_Buffer; // Peripheral address
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) DES_Buffer; // Memory address
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // Transmission direction
DMA_InitStructure.DMA_BufferSize = BUFFER_SIZE; // Number of transmissions
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;// Peripheral address increment mode
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // Memory address increment mode
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; // Memory data width
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;// Peripheral data width
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; // Mode selection
DMA_InitStructure.DMA_Priority = DMA_Priority_High; // Channel priority
DMA_InitStructure.DMA_M2M = DMA_M2M_Enable; // Memory to memory mode
DMA_Init(DMA1_Channel6,&DMA_InitStructure);
DMA_ClearFlag(DMA1_FLAG_TC6);
DMA_Cmd(DMA1_Channel6,ENABLE);
}
uint8_t Buffercmp(const uint32_t * pBuffer1,uint32_t *pBuffer2,uint32_t BufferLength)
{
while(BufferLength--) // The data length decreases
{
if(*pBuffer1 != *pBuffer2) // Determine whether the two data sources are equal
{
return 0; // It's not equal return 0
}
pBuffer1++; // Increment two source address pointers
pBuffer2++;
}
return 1; // complete And equal
}
void DMA_USART_Init(void)
{
DMA_InitTypeDef DMA_InitStructure;
// Clock configuration
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
// Structure configuration
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Send_Buffer;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)USART_DR_ADDR;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = Send_SIZE;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel4,&DMA_InitStructure);
DMA_ClearFlag(DMA1_FLAG_TC4);
DMA_Cmd(DMA1_Channel4,ENABLE);
}
main.c
#include "stm32f10x.h"
#include "led.h"
#include "dma.h"
#include "SysTick.h"
#include "usart.h"
extern const uint32_t SRC_Buffer[BUFFER_SIZE] ;
extern uint32_t DES_Buffer[BUFFER_SIZE];
extern uint8_t Send_Buffer[Send_SIZE];
void Delay(unsigned int t)
{
while(t--);
}
int main(void)
{
uint16_t i = 0;
Usart_Init();
DMA_USART_Init();
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);
// Open the serial port assistant to observe the data
for(i = 0; i< Send_SIZE;i++)
{
Send_Buffer[i] = '0';
}
/* uint8_t status = 0; DMA_MTM_Init(); Led_Init(); status = Buffercmp(SRC_Buffer,DES_Buffer,BUFFER_SIZE); if(status == 0) { GPIO_SetBits(GPIOC,GPIO_Pin_13); } else { GPIO_ResetBits(GPIOC,GPIO_Pin_13); } */
while(1)
{
}
}
边栏推荐
- CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
- POI add border
- Overturn your cognition? The nature of get and post requests
- Sqlserver query results are not displayed in tabular form. How to modify them
- 捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
- coreldraw2022新版本新功能介绍cdr2022
- ue5 小知识点 开启lumen的设置
- Ue5 small knowledge freezerendering view rendered objects in the cone
- Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
- Figure application details
猜你喜欢
Database - MySQL storage engine (deadlock)
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
Mlapi series - 04 - network variables and network serialization [network synchronization]
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
Practical development of member management applet 06 introduction to life cycle function and user-defined method
coreldraw2022新版本新功能介绍cdr2022
Figure application details
Execution order of scripts bound to game objects
Comprehensive ability evaluation system
随机推荐
Basic use of MySQL (it is recommended to read and recite the content)
[HBZ share] reasons for slow addition and deletion of ArrayList and fast query
[Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
【HBZ分享】云数据库如何定位慢查询
E. Best Pair
Query the number and size of records in each table in MySQL database
颠覆你的认知?get和post请求的本质
P3500 [POI2010]TES-Intelligence Test(二分&离线)
Microservice resource address
Mysql database storage engine
[try to hack] John hash cracking tool
Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码
How does computer nail adjust sound
C. The Third Problem(找规律)
动态规划(树形dp)
Is the mode of education together - on campus + off campus reliable
Execution order of scripts bound to game objects
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
Overturn your cognition? The nature of get and post requests