7.8.1.1.2 Code

Copy-paste the following setup code to your user application:
#define DATA_LENGTH (512)

static uint8_t source_memory[DATA_LENGTH];

static uint8_t destination_memory[DATA_LENGTH];

static volatile bool transfer_is_done = false;

COMPILER_ALIGNED(16)
DmacDescriptor example_descriptor SECTION_DMAC_DESCRIPTOR;

static void transfer_done(struct dma_resource* const resource )
{
    transfer_is_done = true;
}

static void configure_dma_resource(struct dma_resource *resource)
{
    struct dma_resource_config config;

    dma_get_config_defaults(&config);

    dma_allocate(resource, &config);
}

static void setup_transfer_descriptor(DmacDescriptor *descriptor )
{
    struct dma_descriptor_config descriptor_config;

    dma_descriptor_get_config_defaults(&descriptor_config);

    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);

    dma_descriptor_create(descriptor, &descriptor_config);
}

Add the below section to user application initialization (typically the start of main()):
configure_dma_resource(&example_resource);

setup_transfer_descriptor(&example_descriptor);

dma_add_descriptor(&example_resource, &example_descriptor);

dma_register_callback(&example_resource, transfer_done,
        DMA_CALLBACK_TRANSFER_DONE);

dma_enable_callback(&example_resource, DMA_CALLBACK_TRANSFER_DONE);

for (uint32_t i = 0; i < DATA_LENGTH; i++) {
    source_memory[i] = i;
}