DMA (Direct Memory Access)

group group_dma

Configures a DMA channel and its descriptor(s).

The functions and other declarations used in this driver are in cy_dma.h. You can include cy_pdl.h to get access to all functions and declarations in the PDL.

The DMA channel can be used in any project to transfer data without CPU intervention basing on a hardware trigger signal from another component.

A device may support more than one DMA hardware block. Each block has a set of registers, a base hardware address, and supports multiple channels. Many API functions for the DMA driver require a base hardware address and channel number. Ensure that you use the correct hardware address for the DMA block in use.

Features:

  • Multiple DW blocks (device specific)

  • Multiple channels per each DW block (device specific)

  • Four priority levels for each channel

  • Byte, half-word (2-byte), and word (4-byte) transfers

  • Configurable source and destination addresses

  • CRC calculation support (only for CPUSS_ver2)

Configuration Considerations

To set up a DMA driver, initialize a descriptor, initialize and enable a channel, and enable the DMA block.

To set up a descriptor, provide the configuration parameters for the descriptor in the cy_stc_dma_descriptor_config_t structure. Then call the Cy_DMA_Descriptor_Init function to initialize the descriptor in SRAM. You can modify the source and destination addresses dynamically by calling Cy_DMA_Descriptor_SetSrcAddress and Cy_DMA_Descriptor_SetDstAddress.

To set up a DMA channel, provide a filled cy_stc_dma_channel_config_t structure. Call the Cy_DMA_Channel_Init function, specifying the channel number. Use Cy_DMA_Channel_Enable to enable the configured DMA channel.

Call Cy_DMA_Channel_Enable for each DMA channel in use.

When configured, another peripheral typically triggers the DMA. The trigger is connected to the DMA using the trigger multiplexer. The trigger multiplexer driver has a software trigger you can use in firmware to trigger the DMA. See the Trigger Multiplexer documentation.

The following is a simplified structure of the DMA driver API interdependencies in a typical user application: ../../../_images/dma.png

NOTE: Even if a DMA channel is enabled, it is not operational until the DMA block is enabled using function Cy_DMA_Enable.NOTE: If the DMA descriptor is configured to generate an interrupt, the interrupt must be enabled using the Cy_DMA_Channel_SetInterruptMask function for each DMA channel.

For example:

    
    /* Scenario: Initialize a 1D descriptor */
    #define DATACNT (8UL)
    cy_stc_dma_descriptor_t descriptor;
    cy_stc_dma_descriptor_t nextDescriptor;
    uint32_t src[DATACNT];
    uint32_t dst[DATACNT];
    
    cy_stc_dma_descriptor_config_t descriptor_cfg = 
    {
        .retrigger = CY_DMA_RETRIG_IM,
        .interruptType = CY_DMA_DESCR,
        .triggerOutType = CY_DMA_DESCR,
        .channelState = CY_DMA_CHANNEL_ENABLED,
        .triggerInType = CY_DMA_DESCR,
        .dataSize = CY_DMA_WORD,
        .srcTransferSize = CY_DMA_TRANSFER_SIZE_WORD,
        .dstTransferSize = CY_DMA_TRANSFER_SIZE_WORD,
        .descriptorType = CY_DMA_1D_TRANSFER,
        .srcAddress = &src,
        .dstAddress = &dst,
        .srcXincrement = 1U,
        .dstXincrement = 1U,
        .xCount = DATACNT,
        .srcYincrement = 0U,
        .dstYincrement = 0U,
        .yCount = 1UL,
        .nextDescriptor = &nextDescriptor,
    };
    
    if (CY_DMA_SUCCESS != Cy_DMA_Descriptor_Init(&descriptor, &descriptor_cfg))
    {
        /* Insert error handling */
    }
    
    /* Scenario: Setup and enable the DMA channel 0 of block DW0 */
    cy_stc_dma_channel_config_t channelConfig;
    channelConfig.preemptable = false;
    channelConfig.enable = false;
    channelConfig.bufferable = false;
    
    if (CY_DMA_SUCCESS != Cy_DMA_Channel_Init(DW0, 0UL, &channelConfig))
    {
        /* Insert error handling */
    }
    
    Cy_DMA_Channel_SetDescriptor(DW0, 0UL, &descriptor);
    Cy_DMA_Channel_SetPriority(DW0, 0UL, 3UL);
    Cy_DMA_Channel_Enable(DW0, 0UL);
    
    Cy_DMA_Enable(DW0);
    

More Information.

See: the DMA chapter of the device technical reference manual (TRM); the DMA Component datasheet; CE219940 - PSoC 6 MCU Multiple DMA Concatenation.

Changelog

Version

Changes

Reason for Change

2.40

Minor Bug fixes.

Check for valid parameters.

2.30

Fixed MISRA 2012 violations.

MISRA 2012 compliance.

2.20.1

Minor documentation updates.

Documentation enhancement.

2.20

The channel number validation method is updated.

New devices support.

2.10

Flattened the organization of the driver source code into the single source directory and the single include directory.

Driver library directory-structure simplification.

Added CRC mode and the CRC descriptor support.
Added the Cy_DMA_Crc_Init function.

New devices support.

Added register access layer. Use register access macros instead of direct register access using dereferenced pointers.

Makes register access device-independent, so that the PDL does not need to be recompiled for each supported part number.

2.0.1

Changed CY_DMA_BWC macro values from Boolean to numeric

Improvements made based on usability feedback

2.0

* All the API is refactored to be consistent within itself and with the rest of the PDL content.

  • The descriptor API is updated as follows: The Cy_DMA_Descriptor_Init function sets a full bunch of descriptor settings, and the rest of the descriptor API is a get/set interface to each of the descriptor settings.

  • There is a group of macros to support the backward compatibility with most of the driver version 1.0 API. But, you should use the new v2.0 interface in new designs (do not just copy-paste from old projects). To enable the backward compatibility support, the CY_DMA_BWC definition should be changed to "1".

1.0

Initial version