DMA - Direct Memory Access#
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.
Memoryscatter-gather, used for transferring a number of buffers between memory locations.
Peripheralscatter-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.
Modules#
Enumerations#
Amount source/destination address should be incremented for each data transfer.
Data sizes (in number of bytes) to be read/written by DMA transfer.
Types of DMA transfer.
Number of transfers before controller does new arbitration.
Typedefs#
DMA interrupt callback function pointer.
Functions#
Interrupt handler for the DMA cycle completion handling.
Activate the DMA auto-request cycle (used for memory-memory transfers).
Activate the DMA basic cycle (used for memory-peripheral transfers).
Activate a DMA ping-pong cycle (used for memory-peripheral transfers).
Activate the DMA scatter-gather cycle (used for either memory-peripheral or memory-memory transfers).
Configure a DMA channel.
Configure the DMA descriptor for auto-request, basic, or ping-pong DMA cycles.
Configure an alternate DMA descriptor for use with scatter-gather DMA cycles.
Enable or disable a DMA channel.
Check if the DMA channel is enabled.
Enable or disable a DMA channel request.
Initialize the DMA controller.
Refresh a descriptor used in a DMA ping-pong cycle.
Reset the DMA controller.
Clear one or more pending DMA interrupts.
Disable one or more DMA interrupts.
Enable one or more DMA interrupts.
Get pending DMA interrupt flags.
Get enabled and pending DMA interrupt flags.
Set one or more pending DMA interrupts.
Enumeration Documentation#
DMA_DataInc_TypeDef#
DMA_DataInc_TypeDef
Amount source/destination address should be incremented for each data transfer.
Enumerator | |
---|---|
dmaDataInc1 | Increment address 1 byte. |
dmaDataInc2 | Increment address 2 bytes. |
dmaDataInc4 | Increment address 4 bytes. |
dmaDataIncNone | Do not increment address. |
57
of file platform/emlib/inc/em_dma.h
DMA_DataSize_TypeDef#
DMA_DataSize_TypeDef
Data sizes (in number of bytes) to be read/written by DMA transfer.
Enumerator | |
---|---|
dmaDataSize1 | 1 byte DMA transfer size. |
dmaDataSize2 | 2 byte DMA transfer size. |
dmaDataSize4 | 4 byte DMA transfer size. |
65
of file platform/emlib/inc/em_dma.h
DMA_CycleCtrl_TypeDef#
DMA_CycleCtrl_TypeDef
Types of DMA transfer.
Enumerator | |
---|---|
dmaCycleCtrlBasic | Basic DMA cycle. |
dmaCycleCtrlAuto | Auto-request DMA cycle. |
dmaCycleCtrlPingPong | Ping-pong DMA cycle. |
dmaCycleCtrlMemScatterGather | Memory scatter-gather DMA cycle. |
dmaCycleCtrlPerScatterGather | Peripheral scatter-gather DMA cycle. |
72
of file platform/emlib/inc/em_dma.h
DMA_ArbiterConfig_TypeDef#
DMA_ArbiterConfig_TypeDef
Number of transfers before controller does new arbitration.
Enumerator | |
---|---|
dmaArbitrate1 | Arbitrate after 1 DMA transfer. |
dmaArbitrate2 | Arbitrate after 2 DMA transfers. |
dmaArbitrate4 | Arbitrate after 4 DMA transfers. |
dmaArbitrate8 | Arbitrate after 8 DMA transfers. |
dmaArbitrate16 | Arbitrate after 16 DMA transfers. |
dmaArbitrate32 | Arbitrate after 32 DMA transfers. |
dmaArbitrate64 | Arbitrate after 64 DMA transfers. |
dmaArbitrate128 | Arbitrate after 128 DMA transfers. |
dmaArbitrate256 | Arbitrate after 256 DMA transfers. |
dmaArbitrate512 | Arbitrate after 512 DMA transfers. |
dmaArbitrate1024 | Arbitrate after 1024 DMA transfers. |
86
of file platform/emlib/inc/em_dma.h
Typedef Documentation#
DMA_FuncPtr_TypeDef#
typedef void(* DMA_FuncPtr_TypeDef) (unsigned int channel, bool primary, void *user) )(unsigned int channel, bool primary, void *user)
DMA interrupt callback function pointer.
Parameters:
channel - DMA channel the callback function is invoked for.
primary - Indicates if callback is invoked for completion of primary (true) or alternate (false) descriptor. Mainly useful for ping-pong DMA cycles, to know which descriptor to refresh.
user - User definable reference that may be used to pass information to be used by the callback handler. If used, referenced data must be valid at the point when the interrupt handler invokes callback. If callback changes any data in the provided user structure, remember that those changes are done in interrupt context and proper protection of data may be required.
120
of file platform/emlib/inc/em_dma.h
Function Documentation#
DMA_IRQHandler#
void DMA_IRQHandler (void )
Interrupt handler for the DMA cycle completion handling.
N/A |
Clears any pending flags and calls registered callback (if any).
If using the default interrupt vector table setup provided, this function is automatically placed in the IRQ table due to weak linking. If taking control over the interrupt vector table in some other way, this interrupt handler must be installed to support callback actions.
For the user to implement a custom IRQ handler or run without a DMA IRQ handler, define EXCLUDE_DEFAULT_DMA_IRQ_HANDLER with a #define statement or with the compiler option -D.
259
of file platform/emlib/src/em_dma.c
DMA_ActivateAuto#
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).
[in] | channel | The DMA channel to activate the DMA cycle for. |
[in] | primary |
|
[in] | dst | An ddress to a start location to transfer data to. If NULL, leave setting in descriptor as is from a previous activation. |
[in] | src | An address to a start location to transfer data from. If NULL, leave setting in descriptor as is from a previous activation. |
[in] | nMinus1 | A number of DMA transfer elements (minus 1) to transfer (<= 1023). The size of the DMA transfer element (1, 2 or 4 bytes) is configured with DMA_CfgDescr(). |
Prior to activating the DMA cycle, the channel and descriptor to be used must have been properly configured.
Note
If using this function on a channel already activated and in use by the DMA controller, the behavior is undefined.
355
of file platform/emlib/src/em_dma.c
DMA_ActivateBasic#
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).
[in] | channel | The DMA channel to activate the DMA cycle for. |
[in] | primary |
|
[in] | useBurst | The burst feature is only used on peripherals supporting DMA bursts. Bursts must not be used if the total length (as given by nMinus1) is less than the arbitration rate configured for the descriptor. See the reference manual for more details on burst usage. |
[in] | dst | An address to a start location to transfer data to. If NULL, leave setting in descriptor as is from a previous activation. |
[in] | src | An address to a start location to transfer data from. If NULL, leave setting in descriptor as is from a previous activation. |
[in] | nMinus1 | A number of DMA transfer elements (minus 1) to transfer (<= 1023). The size of the DMA transfer element (1, 2 or 4 bytes) is configured with DMA_CfgDescr(). |
Prior to activating the DMA cycle, the channel and descriptor to be used must have been properly configured.
Note
If using this function on a channel already activated and in use by the DMA controller, the behavior is undefined.
417
of file platform/emlib/src/em_dma.c
DMA_ActivatePingPong#
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).
[in] | channel | The DMA channel to activate DMA cycle for. |
[in] | useBurst | The burst feature is only used on peripherals supporting DMA bursts. Bursts must not be used if the total length (as given by nMinus1) is less than the arbitration rate configured for the descriptors. See the reference manual for more details on burst usage. Notice that this setting is used for both the primary and alternate descriptors. |
[in] | primDst | An address to a start location to transfer data to, for the primary descriptor. If NULL, leave setting in descriptor as is from a previous activation. |
[in] | primSrc | An address to a start location to transfer data from, for the primary descriptor. If NULL, leave setting in the descriptor as is from a previous activation. |
[in] | primNMinus1 | A number of DMA transfer elements (minus 1) to transfer (<= 1023), for primary descriptor. The size of the DMA transfer element (1, 2 or 4 bytes) is configured with DMA_CfgDescr(). |
[in] | altDst | An address to a start location to transfer data to, for an alternate descriptor. If NULL, leave setting in descriptor as is from a previous activation. |
[in] | altSrc | An address to a start location to transfer data from, for an alternate descriptor. If NULL, leave setting in descriptor as is from a previous activation. |
[in] | altNMinus1 | A number of DMA transfer elements (minus 1) to transfer (<= 1023), for an alternate descriptor. The size of the DMA transfer element (1, 2 or 4 bytes) is configured with DMA_CfgDescr(). |
Prior to activating the DMA cycle, the channel and both descriptors must have been properly configured. The primary descriptor is always the first descriptor to be used by the DMA controller.
Note
If using this function on a channel already activated and in use by the DMA controller, the behavior is undefined.
488
of file platform/emlib/src/em_dma.c
DMA_ActivateScatterGather#
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).
[in] | channel | The DMA channel to activate DMA cycle for. |
[in] | useBurst | The burst feature is only used on peripherals supporting DMA bursts (this parameter is ignored for memory scatter-gather cycles). This parameter determines if bursts should be enabled during DMA transfers using the alternate descriptors. Bursts must not be used if the total length (as given by nMinus1 for the alternate descriptor) is less than the arbitration rate configured for the descriptor. See the reference manual for more details on burst usage. |
[inout] | altDescr | A pointer to a start of an array with prepared alternate descriptors. The last descriptor will have its cycle control type reprogrammed to a basic type. |
[in] | count | A number of alternate descriptors in |
Prior to activating the DMA cycle, the array with alternate descriptors must have been properly configured. This function can be reused without reconfiguring the alternate descriptors, as long as count
is the same.
Note
If using this function on a channel already activated and in use by the DMA controller, the behavior is undefined.
557
of file platform/emlib/src/em_dma.c
DMA_CfgChannel#
void DMA_CfgChannel (unsigned int channel, DMA_CfgChannel_TypeDef * cfg)
Configure a DMA channel.
[in] | channel | The DMA channel to configure. |
[in] | cfg | The configuration to use. |
Configure miscellaneous issues for a DMA channel. This function is typically used once to set up a channel for a certain type of use.
Note
If using this function on a channel already in use by the DMA controller, the behavior is undefined.
661
of file platform/emlib/src/em_dma.c
DMA_CfgDescr#
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.
[in] | channel | The DMA channel to configure for. |
[in] | primary |
|
[in] | cfg | The configuration to use. |
This function is used to configure a descriptor for the following DMA cycle types:
auto-request - used for a memory/memory transfer
basic - used for a peripheral/memory transfer
ping-pong - used for a ping-pong-based peripheral/memory transfer style providing time to refresh one descriptor while the other is in use.
The DMA cycle is not activated. See DMA_ActivateAuto(), DMA_ActivateBasic(), or DMA_ActivatePingPong() to activate the DMA cycle. In many cases, the configuration only has to be done once, and all subsequent cycles may be activated with the activate function.
For ping-pong DMA cycles, this function must be used both on the primary and the alternate descriptor prior to activating the DMA cycle.
Notice that the DMA channel must also be configured. See DMA_CfgChannel().
Note
If using this function on a descriptor already activated and in use by the DMA controller, the behavior is undefined.
729
of file platform/emlib/src/em_dma.c
DMA_CfgDescrScatterGather#
void DMA_CfgDescrScatterGather (DMA_DESCRIPTOR_TypeDef * descr, unsigned int indx, DMA_CfgDescrSGAlt_TypeDef * cfg)
Configure an alternate DMA descriptor for use with scatter-gather DMA cycles.
[in] | descr | Points to the start of a memory area holding the alternate descriptors. |
[in] | indx | An alternate descriptor index number to configure (numbered from 0). |
[in] | cfg | The configuration to use. |
In scatter-gather mode, the alternate descriptors are located in one contiguous memory area. Each of the alternate descriptors must be fully configured prior to starting the scatter-gather DMA cycle.
The DMA cycle is not activated by this function. See DMA_ActivateScatterGather() to activate the DMA cycle. In some cases, the alternate configuration only has to be done once and all subsequent transfers may be activated with the activate function.
Notice that the DMA channel must also be configured, see DMA_CfgChannel().
844
of file platform/emlib/src/em_dma.c
DMA_ChannelEnable#
void DMA_ChannelEnable (unsigned int channel, bool enable)
Enable or disable a DMA channel.
[in] | channel | The DMA channel to enable or disable. |
[in] | enable | If 'true', the channel will be enabled. If 'false', the channel will be disabled. |
Use this function to explicitly enable or disable a DMA channel. A DMA channel is automatically disabled when the DMA controller has finished a transaction.
910
of file platform/emlib/src/em_dma.c
DMA_ChannelEnabled#
bool DMA_ChannelEnabled (unsigned int channel)
Check if the DMA channel is enabled.
[in] | channel | The DMA channel to check. |
The DMA channel is disabled when the DMA controller has finished a DMA cycle.
Returns
True if the channel is enabled, false if not.
935
of file platform/emlib/src/em_dma.c
DMA_ChannelRequestEnable#
void DMA_ChannelRequestEnable (unsigned int channel, bool enable)
Enable or disable a DMA channel request.
[in] | channel | The DMA channel to enable or disable the request on. |
[in] | enable | If 'true', the request will be enabled. If 'false', the request will be disabled. |
Use this function to enable or disable a DMA channel request. This will prevent the DMA from proceeding after its current transaction if disabled.
956
of file platform/emlib/src/em_dma.c
DMA_Init#
void DMA_Init (DMA_Init_TypeDef * init)
Initialize the DMA controller.
[in] | init | A pointer to a structure containing the DMA initialization information. |
This function resets and prepares the DMA controller for use. Although it may be used several times, it is normally only used during system initialization. If reused during a normal operation, any ongoing DMA transfers will be aborted. When complete, the DMA controller is in an enabled state.
Note
Must be invoked before using the DMA controller.
984
of file platform/emlib/src/em_dma.c
DMA_RefreshPingPong#
void DMA_RefreshPingPong (unsigned int channel, bool primary, bool useBurst, void * dst, const void * src, unsigned int nMinus1, bool stop)
Refresh a descriptor used in a DMA ping-pong cycle.
[in] | channel | The DMA channel to refresh the ping-pong descriptor for. |
[in] | primary |
|
[in] | useBurst | The burst feature is only used on peripherals supporting DMA bursts. Bursts must not be used if the total length (as given by nMinus1) is less than the arbitration rate configured for the descriptor. See the reference manual for more details on burst usage. |
[in] | dst | An address to a start location to transfer data to. If NULL, leave setting in descriptor as is. |
[in] | src | An address to a start location to transfer data from. If NULL, leave setting in descriptor as is. |
[in] | nMinus1 | A number of DMA transfer elements (minus 1) to transfer (<= 1023). The size of the DMA transfer element (1, 2 or 4 bytes) is configured with DMA_CfgDescr(). |
[in] | stop | Indicate that the DMA ping-pong cycle stops when done using this descriptor. |
During a ping-pong DMA cycle, the DMA controller automatically alternates between the primary and alternate descriptors, when completing use of a descriptor. While the other descriptor is in use by the DMA controller, the software should refresh the completed descriptor. This is typically done from the callback defined for the ping-pong cycle.
1061
of file platform/emlib/src/em_dma.c
DMA_Reset#
void DMA_Reset (void )
Reset the DMA controller.
N/A |
This functions will disable the DMA controller and set it to a reset state.
Note
Note that any ongoing transfers will be aborted.
1135
of file platform/emlib/src/em_dma.c
DMA_IntClear#
void DMA_IntClear (uint32_t flags)
Clear one or more pending DMA interrupts.
[in] | flags | Pending DMA interrupt sources to clear. Use one or more valid interrupt flags for the DMA module (DMA_IFC_nnn). |
430
of file platform/emlib/inc/em_dma.h
DMA_IntDisable#
void DMA_IntDisable (uint32_t flags)
Disable one or more DMA interrupts.
[in] | flags | DMA interrupt sources to disable. Use one or more valid interrupt flags for the DMA module (DMA_IEN_nnn). |
443
of file platform/emlib/inc/em_dma.h
DMA_IntEnable#
void DMA_IntEnable (uint32_t flags)
Enable one or more DMA interrupts.
[in] | flags | DMA interrupt sources to enable. Use one or more valid interrupt flags for the DMA module (DMA_IEN_nnn). |
Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using DMA_IntClear() prior to enabling the interrupt.
461
of file platform/emlib/inc/em_dma.h
DMA_IntGet#
uint32_t DMA_IntGet (void )
Get pending DMA interrupt flags.
N/A |
Note
Event bits are not cleared by the use of this function.
Returns
DMA interrupt sources pending. Returns one or more valid interrupt flags for the DMA module (DMA_IF_nnn).
477
of file platform/emlib/inc/em_dma.h
DMA_IntGetEnabled#
uint32_t DMA_IntGetEnabled (void )
Get enabled and pending DMA interrupt flags.
N/A |
Useful for handling more interrupt sources in the same interrupt handler.
Note
Interrupt flags are not cleared by the use of this function.
Returns
Pending and enabled DMA interrupt sources Return value is the bitwise AND of
the enabled interrupt sources in DMA_IEN and
the pending interrupt flags DMA_IF.
496
of file platform/emlib/inc/em_dma.h
DMA_IntSet#
void DMA_IntSet (uint32_t flags)
Set one or more pending DMA interrupts.
[in] | flags | DMA interrupt sources to set to pending. Use one or more valid interrupt flags for the DMA module (DMA_IFS_nnn). |
512
of file platform/emlib/inc/em_dma.h