目录
一、使用DMA实现从存储器1发送数据到存储器2中
1.CUBE_MX配置
2.KEIL5配置
一、使用DMA实现从存储器1发送数据到存储器2中
1.CUBE_MX配置
1.在DMA选项中添加MEMORY TO MEMORY
选择数据宽度,并确保地址递增功能打开。
2.系统时钟72MHz
3.生成代码
2.KEIL5配置
1.打开文件dma.c
#include "dma.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure DMA */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
DMA_HandleTypeDef hdma_memtomem_dma1_channel1;
/**
* Enable DMA controller clock
* Configure DMA for memory to memory transfers
* hdma_memtomem_dma1_channel1
*/
void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
/* Configure DMA request hdma_memtomem_dma1_channel1 on DMA1_Channel1 */
hdma_memtomem_dma1_channel1.Instance = DMA1_Channel1;
hdma_memtomem_dma1_channel1.Init.Direction = DMA_MEMORY_TO_MEMORY;
hdma_memtomem_dma1_channel1.Init.PeriphInc = DMA_PINC_ENABLE;
hdma_memtomem_dma1_channel1.Init.MemInc = DMA_MINC_ENABLE;
hdma_memtomem_dma1_channel1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_memtomem_dma1_channel1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_memtomem_dma1_channel1.Init.Mode = DMA_NORMAL;
hdma_memtomem_dma1_channel1.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_memtomem_dma1_channel1) != HAL_OK)
{
Error_Handler();
}
}
2.在MX_DMA_Init()函数中加入完成初始化(不要忘记了)
HAL_DMA_Init(&hdma_memtomem_dma1_channel1);
3.打开main.c文件(已经默认调用好了头文件)
4.先定义存储器1
#define SENDBUFF_SIZE 10
const uint32_t aSRC_Const_Buffer[SENDBUFF_SIZE]=
{
0x61626364,0x65666768,0x696A6B6C,0x6D6E6F70,
0x71727374,0x75767778,0x797A7B7C,0x7D7E7F80
};
5.再定义储存器2
uint32_t aDST_Buffer[SENDBUFF_SIZE];
6.在main结构体中调用函数
HAL_StatusTypeDef DMA_status ;
//DMA_status 反应了传输的状态
DMA_status = HAL_DMA_Start(&hdma_memtomem_dma1_channel1,(uint32_t)aSRC_Const_Buffer,
(uint32_t)aDST_Buffer,SENDBUFF_SIZE);
//HAL_DMA_Start 开始传送
//四个参数 1.DMA通道 2.存储器1 3.存储器2 4.传输的数据大小
//返回参数 传输的状态
if(DMA_status == HAL_OK)
{
//当发送成功以后,执行相应的函数
}