当前位置:网站首页>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);
边栏推荐
- MySQL优化:从十几秒优化到三百毫秒
- MySQL forgot password
- unity2d game
- Minesweeper game - C language
- 30 Years of Open Source Community | 2022 Open Atom Global Open Source Summit 30 Years of Open Source Community Special Event Held Successfully
- Unity URP渲染管线摄像机核心机制剖析
- Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
- npm、nrm两种方式查看源和切换镜像
- Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法
- SQL语句中对时间字段进行区间查询
猜你喜欢

PWN ROP

MySQL database must add, delete, search and modify operations (CRUD)

ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your

专访 | 阿里巴巴首席技术官程立:云+开源共同形成数字世界的可信基础

Create componentized development based on ILRuntime hot update

重磅 | 基金会为白金、黄金、白银捐赠人授牌

VScode+ESP32快速安装ESP-IDF插件

Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions

Centos7 install mysql5.7 steps (graphical version)

View source and switch mirrors in two ways: npm and nrm
随机推荐
信息系统项目管理师核心考点(五十五)配置管理员(CMO)的工作
110道 MySQL面试题及答案 (持续更新)
View source and switch mirrors in two ways: npm and nrm
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
【ORACLE Explain 详解】
MySQL数据库增删改查(基础操作命令详解)
Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
SQL行列转换
mysql使用on duplicate key update批量更新数据
open failed: EACCES (Permission denied)
【wpf】wpf中的那些模板之深度解析
Sql解析转换之JSqlParse完整介绍
益智类游戏关卡设计:逆推法--巧解益智类游戏关卡设计
高斯分布及其极大似然估计
Doris学习笔记之监控
[py script] batch binarization processing images
1. 获取数据-requests.get()
PWN ROP
重磅 | 基金会为白金、黄金、白银捐赠人授牌
MySQL优化:从十几秒优化到三百毫秒