Configure the DMA

  1. 1.
    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;
    
  2. 2.
    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.
  3. 3.
    Set extra configurations for the DMA resource. ADC_DMAC_ID_RESRDY trigger causes a beat transfer in this example.
    #if (SAMC21)
        config.peripheral_trigger = ADC1_DMAC_ID_RESRDY;
    #else
        config.peripheral_trigger = ADC_DMAC_ID_RESRDY;
    #endif
        config.trigger_action = DMA_TRIGGER_ACTON_BEAT;
    
  4. 4.
    Allocate a DMA resource with the configurations.
    dma_allocate(resource, &config);
    
  5. 5.
    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;
    
  6. 6.
    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.
  7. 7.
    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.src_increment_enable = false;
    descriptor_config.block_transfer_count = 1000;
    descriptor_config.source_address = (uint32_t)(&adc_instance.hw->RESULT.reg);
    #if (SAML21)
        descriptor_config.destination_address = (uint32_t)(&dac_instance.hw->DATA[DAC_CHANNEL_0].reg);
    #else
        descriptor_config.destination_address = (uint32_t)(&dac_instance.hw->DATA.reg);
    #endif
        descriptor_config.next_descriptor_address = (uint32_t)descriptor;
    
  8. 8.
    Create the DMA transfer descriptor.
    dma_descriptor_create(descriptor, &descriptor_config);
    
  9. 9.
    Add DMA descriptor to DMA resource.
    dma_add_descriptor(&example_resource, &example_descriptor);