5.1. DMA - Data Transfer Between RAM
This demo is based on the memory to memory mode of DMA for data transfer.
5.1.1. Hardware Connection
None
5.1.2. Software Implementation
For the code see
examples/dma/dma_m2m
1#define BSP_USING_DMA0_CH0
2
3#if defined(BSP_USING_DMA0_CH0)
4#ifndef DMA0_CH0_CONFIG
5#define DMA0_CH0_CONFIG \
6{ \
7.id = 0, \
8.ch = 0,\
9.direction = DMA_MEMORY_TO_MEMORY,\
10.transfer_mode = DMA_LLI_ONCE_MODE, \
11.src_req = DMA_REQUEST_NONE, \
12.dst_req = DMA_REQUEST_NONE, \
13.src_width = DMA_TRANSFER_WIDTH_32BIT , \
14.dst_width = DMA_TRANSFER_WIDTH_32BIT , \
15}
16#endif
17#endif
Enable
BSP_USING_DMA0_CH0
and configure theDMA
device, seebsp/board/bl706_iot/peripheral_config.h
1dma_register(DMA0_CH0_INDEX, "DMA", DEVICE_OFLAG_RDWR);
2
3struct device *dma = device_find("DMA");
4
5if (dma)
6{
7 device_open(dma, 0);
8 device_set_callback(dma, dma_transfer_done);
9 device_control(dma, DEVICE_CTRL_SET_INT, NULL);
10}
First call the
dma_register
function to register a channel of theDMA
device, currently registerDMA_CH0
Then use the
find
function to find the handle corresponding to the device and save it in thedma
handleFinally use
device_open
to open thedma
device in the default mode, calldevice_set_callback
to register a dma channel 0 interrupt callback function, and calldevice_control
to open the dma transmission completion interrupt
1dma_reload(dma,(uint32_t)dma_src_buffer,(uint32_t)dma_dst_buffer,8000);
2dma_channel_start(dma);
Call the
dma_reload
function to supplement the configuration of dma channel 0. A part of the configuration has been supplemented inDMA0_CH0_CONFIG
. Here we mainly supplement the source data address, destination data address and total transmission lengthCall
dma_channel_start
to start dma transmission
1void dma_transfer_done(struct device *dev, void *args, uint32_t size, uint32_t state)
2{
3 uint32_t index=0;
4
5 if(!state)
6 {
7 MSG("dma transfer task done\r\n");
8
9 for(index=0;index<8000;index++){
10 if(dma_dst_buffer[index]!=0xff){
11 MSG("dma transfer error\r\n");
12 }
13 }
14
15 MSG("dma transfer success\r\n");
16 }
17
18}
Check whether the data transmission is correct in the interrupt function
5.1.3. Compile and Program
CDK compilation
Open project:dma_m2m.cdkproj
Refer to the steps of Guide to using CDK (like MDK Keil) under Windows to compile and download
Command compilation
1 $ cd <sdk_path>/bl_mcu_sdk
2 $ make BOARD=bl706_iot APP=dma_m2m
Program
5.1.4. Experimental Phenomena
The data in the dma_src_buffer
array is transferred to the dma_dst_buffer
array through DMA channel 0 with a source 32-bit width and a target 32-bit width. After the data transfer is completed, the serial port prints dma transfer success
.