Jump to main content
Configure DMA
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);
}
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);
}
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);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
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;
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.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);
Create the DMA transfer descriptor.
dma_descriptor_create(descriptor, &descriptor_config);
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;
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.
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;
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.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);
Create the DMA transfer descriptor.
dma_descriptor_create(descriptor, &descriptor_config);
The online versions of the documents are provided as a courtesy. Verify all content and data in the device’s PDF documentation found on the device product page.