DMAC Demos
Single Block
Allocate a free channel
ch_num = GDMA_ChnlAlloc(gdma.index, (IRQ_FUN) Dma_memcpy_int, (u32)(&gdma), 3);
This function also includes the following operation:
Register IRQ handler if using interrupt mode
Enable NVIC interrupt
Register the DMAC channel to use
Configure the interrupt type
PGDMA_InitTypeDef->GDMA_IsrType = (TransferType | ErrType);
Configure interrupt handling function
Clear the pending interrupt in the interrupt processing function.
GDMA_ClearINT(0, PGDMA_InitTypeDef->GDMA_ChNum);
Configure transfer settings
PGDMA_InitTypeDef->GDMA_SrcMsize = MsizeEight; PGDMA_InitTypeDef->GDMA_SrcDataWidth = TrWidthFourBytes; PGDMA_InitTypeDef->GDMA_DstMsize = MsizeEight; PGDMA_InitTypeDef->GDMA_DstDataWidth = TrWidthFourBytes; PGDMA_InitTypeDef->GDMA_BlockSize = DMA_CPY_LEN >> 2; PGDMA_InitTypeDef->GDMA_DstInc = IncType; // if dst type is peripheral:no change PGDMA_InitTypeDef->GDMA_SrcInc = IncType; // if src type is peripheral:no change
Configure hardware handshake interface if slave is peripheral
PGDMA_InitTypeDef->GDMA_SrcHandshakeInterface= GDMA_HANDSHAKE_INTERFACE_AUDIO_RX;
or
PGDMA_InitTypeDef->GDMA_DstHandshakeInterface = GDMA_HANDSHAKE_INTERFACE_AUDIO_TX;
Configure the transfer address
PGDMA_InitTypeDef->GDMA_SrcAddr = (u32)BDSrcTest; PGDMA_InitTypeDef->GDMA_DstAddr = (u32)BDDstTest;
Program DMAC index, DMAC channel, data width, msize, transfer direction, address increment mode, hardware handshake interface, reload control, interrupt type, block size, multi-block configuration and the source and destination address using the
GDMA_Init()function.GDMA_Init(gdma.index, gdma.ch_num, PGDMA_InitTypeDef);
Clean and invalidate Cache
DCache_CleanInvalidate();
Enable DMAC channel
GDMA_Cmd(gdma.index, gdma.ch_num, ENABLE);
Multi-block
This example is SRC auto reload, compared with single block, multi-block is different in Step 2 to Step 4.
Allocate a free channel
ch_num = GDMA_ChnlAlloc(gdma.index, (IRQ_FUN) Dma_memcpy_int, (u32)(&gdma), 3);
This function also includes the following operation:
Register IRQ handler if use interrupt mode
Enable NVIC interrupt
Register the DMAC channel to use
Configure the interrupt type
PGDMA_InitTypeDef->GDMA_IsrType = (BlockType | TransferType | ErrType);
Configure interrupt handling function
Clear the interrupt.
GDMA_ClearINT(0, PGDMA_InitTypeDef->GDMA_ChNum);
Clear the auto reload mode before the last block starts.
GDMA_ChCleanAutoReload(0, PGDMA_InitTypeDef->GDMA_ChNum, CLEAN_RELOAD_SRC);
Configure transfer settings
PGDMA_InitTypeDef->GDMA_SrcMsize = MsizeEight; PGDMA_InitTypeDef->GDMA_SrcDataWidth = TrWidthFourBytes; PGDMA_InitTypeDef->GDMA_DstMsize = MsizeEight; PGDMA_InitTypeDef->GDMA_DstDataWidth = TrWidthFourBytes; PGDMA_InitTypeDef->GDMA_BlockSize = DMA_CPY_LEN >> 2; PGDMA_InitTypeDef->GDMA_DstInc = IncType; // If DST type is peripheral: no change PGDMA_InitTypeDef->GDMA_SrcInc = IncType; // If SRC type is peripheral: no change PGDMA_InitTypeDef->GDMA_ReloadSrc = 1; PGDMA_InitTypeDef->GDMA_ReloadDst = 0;
Configure hardware handshake interface if slave is peripheral.
PGDMA_InitTypeDef->GDMA_SrcHandshakeInterface= GDMA_HANDSHAKE_INTERFACE_AUDIO_RX;
or
PGDMA_InitTypeDef->GDMA_DstHandshakeInterface = GDMA_HANDSHAKE_INTERFACE_AUDIO_TX;
Configure the transfer address
PGDMA_InitTypeDef->GDMA_SrcAddr = (u32)BDSrcTest; PGDMA_InitTypeDef->GDMA_DstAddr = (u32)BDDstTest;
Program DMAC index, DMAC channel, data width, msize, transfer direction, address increment mode, hardware handshake interface, reload control, interrupt type, block size, multi-block configuration and the source and destination address using the
GDMA_Init()function.GDMA_Init(gdma.index, gdma.ch_num, PGDMA_InitTypeDef);
Clean and invalidate Cache
DCache_CleanInvalidate();
Enable DMAC channel
GDMA_Cmd(gdma.index, gdma.ch_num, ENABLE);