当前位置:网站首页>STM32 - DMA
STM32 - DMA
2022-07-31 04:55:00 【Mountain,】
DMA(Direct Memory Access)That is, direct storage access.
简单理解,DMA就是不占用CPUThe data transfer mode of the resource.DMA 传输将数据从AThe address space is copied toB地址空间,这个过程由 DMA 控制器来完成,CPU只需要把DMAJust do the initial setup,在数据传输时不需要CPU参与.
使用DMA可以大大减轻CPU工作量,尤其是数据量非常大的时候.
比如从ADCOr the serial port is coming3000个数据,CPUCopying data is required3000次操作:
for(int i = 0;i < 3000;i++)
{
buf[i] = data;
}
虽然目前的CPU主频很高,3000data can be transferred immediately,But in some cases this doesn't work.during this period of data transmission,CPU只负责传输数据,十分浪费CPU资源.So for large-capacity data transmission this situation is not actually neededCPU一直参与,只需在A、B之间创建个通道,让它们自己传输即可.这就是DMA,Generally used for large data transfersDMA进行数据传输.
使用DMA,Only need to provide two addresses and a data length on it,Destination address and data source address,启动DMA后,DMAAutomatically move data from the data source address to the destination address.This is liberatingCPU,使得CPUcan do other more important things.
DMAThere are the following three data transfer modes:
1、内存到外设
2、外设到内存
3、内存到内存
DMA控制器:
从上图可以看到,DMAThere are eight data streams,Each data stream has 8个通道.
流:数据传输的链路,One maximum transfer256KB数据.
通道:Every data stream has it8个通道选择,每个通道对应不同的DMA请求,比如ADC、DAC、串口等.
DMA请求映射:
DMA_SxCR设置DMA通道、数据流、优先级等设置
当多个DMAWhen the request comes at the same time,DMA会通过DMAThe arbiter decides who to deal with first.
软件:DMA_SxCR的PL位决定.
硬件:Data stream numbers with smaller numbers have higher priority.
同一个数据流只能使用一个通道,同一个DMA控制器可以使用多个数据流.
DMA控制器中的FIFOIt can be simply thought of as a buffer,Provide a data transfer space between the data source and the target.
DMAThere is a direct mode for data movement、FIFO模式等.
Direct mode is where the data arrivesFIFOSend out directly.
FIFOIt can be set to pass in a few bytes before passing out,if it comes in4、8、12、16start out after bytes
FIFO突发模式:Look at your data and send it several times,一次发送、Send twice and so on.
DMARelated structures and initialization functions(基于标准库):
DMA初始化结构体DMA_ InitTypeDef
:
typedef struct
{
uint32_t
uint32_t DMA_PeripheralBaseAddr; // 外设地址
uint32_t DMA_MemoryBaseAddr; // 存储器地址
uint32_t DMA_DIR; // 传输方向:内存到外设、外设到内存、内存到内存
uint32_t DMA_BufferSize; // 传输数目:传输数据的个数
uint32_t DMA_PeripheralInc; // 外设地址是否递增
uint32_t DMA_MemoryInc; // 存储器地址是否递增
uint32_t DMA_PeripheralDataSize; // 外设数据宽度
uint32_t DMA_MemoryDataSize; // 存储器数据宽度
uint32_t DMA_Mode; // 模式选择
uint32_t DMA_Priority; // 通道优先级
uint32_t DMA_M2M; // 存储器到存储器模式
} DMA_InitTypeDef;
The data width of the source and destination is the same,数据不会丢失
The source is smaller than the destination width,数据不会丢失,But it will waste target memory
The source is larger than the destination width,数据会丢失,Receive data only at the target width
库函数:
初始化DMA的寄存器到复位状态:
DMA_DeInit(DMA_Stream_TypeDef* DMAy_Streamx);
DMA初始化:
void DMA_Init(DMA_Stream_TypeDef* DMAy_Streamx,DMA_InitTypeDef* DMA_InitStruct);
DMA使能函数:
MDA_Cmd(DMA_Stream_TypeDef* DMAy_Streamx,FunctionalState NewState);
边栏推荐
- [Cloud Native] DevOps (5): Integrating Harbor
- STM32HAL library modifies Hal_Delay to us-level delay
- C language confession code?
- ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
- 剑指offer专项突击版第15天
- Open Source Smart Future | 2022 OpenAtom Global Open Source Summit OpenAtom openEuler sub-forum was successfully held
- WPF WPF 】 【 the depth resolution of the template
- [debug highlights] Expected input batch_size (1) to match target batch_size (0)
- The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
- unity2d小游戏
猜你喜欢
ENSP, VLAN division, static routing, comprehensive configuration of Layer 3 switches
矩池云快速安装torch-sparse、torch-geometric等包
Minesweeper game - C language
mysql使用on duplicate key update批量更新数据
CentOS7 安装MySQL 图文详细教程
Hand in hand to realize the picture preview plug-in (3)
The input input box displays the precision of two decimal places
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
MySQL数据库安装配置保姆级教程(以8.0.29为例)有手就行
随机推荐
EasyExcel的简单读取操作
矩池云快速安装torch-sparse、torch-geometric等包
Understanding of the presence of a large number of close_wait states
[py script] batch binarization processing images
ERP Production Operation Control Kingdee
MySQL数据库备份
MySQL优化:从十几秒优化到三百毫秒
The 15th day of the special assault version of the sword offer
微信小程序使用云函数更新和添加云数据库嵌套数组元素
信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作
View source and switch mirrors in two ways: npm and nrm
STM32——DMA
The input input box displays the precision of two decimal places
MySQL to revise the root password
[R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters
【线性神经网络】softmax回归
Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
From scratch, a mirror to the end, a pure system builds a grasscutter (Grasscutter)
三道leetcode上的oj题
1. 获取数据-requests.get()