DMAC Demos

Single Block

  1. 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

  2. Configure the interrupt type

    PGDMA_InitTypeDef->GDMA_IsrType = (TransferType | ErrType);
    
  3. Configure interrupt handling function

    Clear the pending interrupt in the interrupt processing function.

    GDMA_ClearINT(0, PGDMA_InitTypeDef->GDMA_ChNum);
    
  4. 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
    
  5. 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;
    
  6. Configure the transfer address

    PGDMA_InitTypeDef->GDMA_SrcAddr = (u32)BDSrcTest;
    PGDMA_InitTypeDef->GDMA_DstAddr = (u32)BDDstTest;
    
  7. 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);
    
  8. Clean and invalidate Cache

    DCache_CleanInvalidate();
    
  9. 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.

  1. 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

  1. Configure the interrupt type

    PGDMA_InitTypeDef->GDMA_IsrType = (BlockType | TransferType | ErrType);
    
  2. Configure interrupt handling function

    1. Clear the interrupt.

      GDMA_ClearINT(0, PGDMA_InitTypeDef->GDMA_ChNum);
      
    2. Clear the auto reload mode before the last block starts.

      GDMA_ChCleanAutoReload(0, PGDMA_InitTypeDef->GDMA_ChNum, CLEAN_RELOAD_SRC);
      
  1. 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;
    
  2. 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;
    
  3. Configure the transfer address

    PGDMA_InitTypeDef->GDMA_SrcAddr = (u32)BDSrcTest;
    PGDMA_InitTypeDef->GDMA_DstAddr = (u32)BDDstTest;
    
  4. 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);
    
  5. Clean and invalidate Cache

    DCache_CleanInvalidate();
    
  6. Enable DMAC channel

    GDMA_Cmd(gdma.index, gdma.ch_num, ENABLE);