Configure DMA
- 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;
- Initialize the DMA resource configuration struct with the module's default values.
dma_get_config_defaults(&config);
config.peripheral_trigger = M2M_DMAC_TRIGGER_ID;
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings. - Allocate a DMA resource with the configurations.
dma_allocate(resource, &config);
- 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;
- 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. - Set the specific parameters for a DMA transfer with transfer size, source address, and destination address.
descriptor_config.block_transfer_count = TRANSFER_SIZE;
descriptor_config.source_address = (uint32_t)source_memory + TRANSFER_SIZE;
descriptor_config.destination_address =
(uint32_t)destination_memory + TRANSFER_SIZE;
- Create the DMA transfer descriptor.
dma_descriptor_create(descriptor, &descriptor_config);
- Add the DMA transfer descriptor to the allocated DMA resource.
dma_add_descriptor(&example_resource, &example_descriptor);
- Register a callback to indicate transfer status.
dma_register_callback(&example_resource, transfer_done,
DMA_CALLBACK_TRANSFER_DONE);
- The transfer done flag is set in the registered callback function.
void
transfer_done(
struct
dma_resource*
const
resource )
{
UNUSED(resource);
transfer_is_done =
true
;
}