DMA - Direct Memory Access

Description

Direct Memory Access (DMA) Peripheral API.

DMA access functions provide basic support for the following types of DMA cycles:

  • Basic , used for transferring data between memory and peripherals.
  • Auto-request , used for transferring data between memory locations.
  • Ping-pong , used for for continuous transfer of data between memory and peripherals, automatically toggling between primary and alternate descriptors.
  • Memory scatter-gather , used for transferring a number of buffers between memory locations.
  • Peripheral scatter-gather , used for transferring a number of buffers between memory and peripherals.

A basic understanding of the DMA controller is assumed. See the reference manual for more details.

The term 'descriptor' is synonymous to the 'channel control data structure' term.

To use the DMA controller, the initialization function must have been executed once (normally during the system initialization):

* DMA_Init();
* 

Normally, a DMA channel is configured:

* DMA_CfgChannel();
* 

The channel configuration only has to be done once if reusing the channel for the same purpose later.

To set up a DMA cycle, the primary and/or alternate descriptor has to be set up as indicated below.

For basic or auto-request cycles, use once on either primary or alternate descriptor:

* DMA_CfgDescr();
* 

For ping-pong cycles, configure both primary or alternate descriptors:

* DMA_CfgDescr(); // Primary descriptor config
* DMA_CfgDescr(); // Alternate descriptor config
* 

For scatter-gather cycles, program the alternate descriptor array:

* // 'n' is the number of scattered buffers
* // 'descr' points to the start of the alternate descriptor array
*
* // Fill in 'cfg'
* DMA_CfgDescrScatterGather(descr, 0, cfg);
* // Fill in 'cfg'
* DMA_CfgDescrScatterGather(descr, 1, cfg);
* :
* // Fill in 'cfg'
* DMA_CfgDescrScatterGather(descr, n - 1, cfg);
* 

In many cases, the descriptor configuration only has to be done once if re-using the channel for the same type of DMA cycles later.

To activate the DMA cycle, use the respective DMA_Activate...() function.

For ping-pong DMA cycles, use DMA_RefreshPingPong() from the callback to prepare the completed descriptor for reuse. Notice that the refresh must be done prior to the other active descriptor completes, otherwise the ping-pong DMA cycle will halt.

Data Structures

struct DMA_CB_TypeDef
Callback structure that can be used to define DMA complete actions.
struct DMA_CfgChannel_TypeDef
Configuration structure for a channel.
struct DMA_CfgDescr_TypeDef
Configuration structure for primary or alternate descriptor (not used for scatter-gather DMA cycles).
struct DMA_CfgLoop_TypeDef
Configuration structure for loop mode.
struct DMA_CfgRect_TypeDef
Configuration structure for rectangular copy.
struct DMA_CfgDescrSGAlt_TypeDef
Configuration structure for alternate scatter-gather descriptor.
struct DMA_Init_TypeDef
DMA initialization structure.

Functions

void DMA_ActivateAuto (unsigned int channel, bool primary, void *dst, const void *src, unsigned int nMinus1)
Activate the DMA auto-request cycle (used for memory-memory transfers).
void DMA_ActivateBasic (unsigned int channel, bool primary, bool useBurst, void *dst, const void *src, unsigned int nMinus1)
Activate the DMA basic cycle (used for memory-peripheral transfers).
void DMA_ActivatePingPong (unsigned int channel, bool useBurst, void *primDst, const void *primSrc, unsigned int primNMinus1, void *altDst, const void *altSrc, unsigned int altNMinus1)
Activate a DMA ping-pong cycle (used for memory-peripheral transfers).
void DMA_ActivateScatterGather (unsigned int channel, bool useBurst, DMA_DESCRIPTOR_TypeDef *altDescr, unsigned int count)
Activate the DMA scatter-gather cycle (used for either memory-peripheral or memory-memory transfers).
void DMA_CfgChannel (unsigned int channel, DMA_CfgChannel_TypeDef *cfg)
Configure a DMA channel.
void DMA_CfgDescr (unsigned int channel, bool primary, DMA_CfgDescr_TypeDef *cfg)
Configure the DMA descriptor for auto-request, basic, or ping-pong DMA cycles.
void DMA_CfgLoop (unsigned int channel, DMA_CfgLoop_TypeDef *cfg)
Configure the DMA channel for Loop mode or 2D transfer.
void DMA_CfgRect (unsigned int channel, DMA_CfgRect_TypeDef *cfg)
Configure the DMA channel 2D transfer properties.
void DMA_ResetLoop (unsigned int channel)
Clear Loop configuration for channel.
void DMA_ResetRect (unsigned int channel)
Clear Rect/2D DMA configuration for channel.
void DMA_CfgDescrScatterGather (DMA_DESCRIPTOR_TypeDef *descr, unsigned int indx, DMA_CfgDescrSGAlt_TypeDef *cfg)