Configure DMA

  1. Create a callback function of receiver done.
    static void transfer_done_rx(struct dma_resource* const resource )
    {
        dma_start_transfer_job(&usart_dma_resource_tx);
    }
    
  2. Create a callback function of transmission done.
    static void transfer_done_tx(struct dma_resource* const resource )
    {
        dma_start_transfer_job(&usart_dma_resource_rx);
    }
    
  3. Create a DMA resource configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
    struct dma_resource_config config;
    
  4. Initialize the DMA resource configuration struct with the module's default values.
    dma_get_config_defaults(&config);
    
    Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  5. Set extra configurations for the DMA resource. It is using peripheral trigger. SERCOM TX empty trigger causes a beat transfer in this example.
    config.peripheral_trigger = EDBG_CDC_SERCOM_DMAC_ID_RX;
    config.trigger_action = DMA_TRIGGER_ACTON_BEAT;
    
  6. Allocate a DMA resource with the configurations.
    dma_allocate(resource, &config);
    
  7. Create a DMA transfer descriptor configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
    struct dma_descriptor_config descriptor_config;
    
  8. Initialize the DMA transfer descriptor configuration struct with the module's default values.
    dma_descriptor_get_config_defaults(&descriptor_config);
    
    Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  9. Set the specific parameters for a DMA transfer with transfer size, source address, and destination address.
    descriptor_config.beat_size = DMA_BEAT_SIZE_HWORD;
    descriptor_config.src_increment_enable = false;
    descriptor_config.block_transfer_count = BUFFER_LEN;
    descriptor_config.destination_address =
            (uint32_t)string + sizeof(string);
    descriptor_config.source_address =
            (uint32_t)(&usart_instance.hw->USART.DATA.reg);
    
  10. Create the DMA transfer descriptor.
    dma_descriptor_create(descriptor, &descriptor_config);
    
  11. Create a DMA resource configuration structure for TX, which can be filled out to adjust the configuration of a single DMA transfer.
    struct dma_resource_config config;
    
  12. Initialize the DMA resource configuration struct with the module's default values.
    dma_get_config_defaults(&config);
    
    Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  13. Set extra configurations for the DMA resource. It is using peripheral trigger. SERCOM RX Ready trigger causes a beat transfer in this example.
    config.peripheral_trigger = EDBG_CDC_SERCOM_DMAC_ID_TX;
    config.trigger_action = DMA_TRIGGER_ACTON_BEAT;
    
  14. Allocate a DMA resource with the configurations.
    dma_allocate(resource, &config);
    
  15. Create a DMA transfer descriptor configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
    struct dma_descriptor_config descriptor_config;
    
  16. Initialize the DMA transfer descriptor configuration struct with the module's default values.
    dma_descriptor_get_config_defaults(&descriptor_config);
    
    Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  17. Set the specific parameters for a DMA transfer with transfer size, source address, and destination address.
    descriptor_config.beat_size = DMA_BEAT_SIZE_HWORD;
    descriptor_config.dst_increment_enable = false;
    descriptor_config.block_transfer_count = BUFFER_LEN;
    descriptor_config.source_address = (uint32_t)string + sizeof(string);
    descriptor_config.destination_address =
        (uint32_t)(&usart_instance.hw->USART.DATA.reg);
    
  18. Create the DMA transfer descriptor.
    dma_descriptor_create(descriptor, &descriptor_config);