7.8.1.1.3 Workflow

  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. 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. Allocate a DMA resource with the configurations.
    dma_allocate(resource, &config);
    
  4. Declare 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;
    
  5. 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.
  6. Set the specific parameters for a DMA transfer with transfer size, source address, and destination address. In this example, we have enabled the source and destination address increment. The source and destination addresses to be stored into descriptor_config must correspond to the end of the transfer.

    descriptor_config.block_transfer_count = sizeof(source_memory);
    descriptor_config.source_address = (uint32_t)source_memory +
        sizeof(source_memory);
    descriptor_config.destination_address = (uint32_t)destination_memory +
        sizeof(source_memory);
    
  7. Create the DMA transfer descriptor.
    dma_descriptor_create(descriptor, &descriptor_config);
    
  8. Add the DMA transfer descriptor to the allocated DMA resource.
    dma_add_descriptor(&example_resource, &example_descriptor);
    
  9. Register a callback to indicate transfer status.
    dma_register_callback(&example_resource, transfer_done,
            DMA_CALLBACK_TRANSFER_DONE);
    
  10. Set the transfer done flag in the registered callback function.
    static void transfer_done(struct dma_resource* const resource )
    {
        transfer_is_done = true;
    }
    
  11. Enable the registered callbacks.
    dma_enable_callback(&example_resource, DMA_CALLBACK_TRANSFER_DONE);