MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
DMA: Direct Memory Access Controller Driver

Overview

The MCUXpresso SDK provides a peripheral driver for the Direct Memory Access (DMA) of MCUXpresso SDK devices.

Typical use case

DMA Operation

dma_transfer_config_t transferConfig;
uint32_t transferDone = false;
DMA_Init(DMA0);
DMA_EnableChannel(DMA0, channel);
DMA_CreateHandle(&g_DMA_Handle, DMA0, channel);
DMA_SetCallback(&g_DMA_Handle, DMA_Callback, &transferDone);
DMA_PrepareTransfer(&transferConfig, srcAddr, destAddr, transferByteWidth, transferBytes,
DMA_SubmitTransfer(&g_DMA_Handle, &transferConfig);
DMA_StartTransfer(&g_DMA_Handle);
/* Wait for DMA transfer finish */
while (transferDone != true);

Files

file  fsl_dma.h
 

Data Structures

struct  dma_descriptor_t
 DMA descriptor structure. More...
 
struct  dma_xfercfg_t
 DMA transfer configuration. More...
 
struct  dma_channel_trigger_t
 DMA channel trigger. More...
 
struct  dma_transfer_config_t
 DMA transfer configuration. More...
 
struct  dma_handle_t
 DMA transfer handle structure. More...
 

Typedefs

typedef void(* dma_callback )(struct _dma_handle *handle, void *userData, bool transferDone, uint32_t intmode)
 Define Callback function for DMA. More...
 

Enumerations

enum  dma_priority_t {
  kDMA_ChannelPriority0 = 0,
  kDMA_ChannelPriority1,
  kDMA_ChannelPriority2,
  kDMA_ChannelPriority3,
  kDMA_ChannelPriority4,
  kDMA_ChannelPriority5,
  kDMA_ChannelPriority6,
  kDMA_ChannelPriority7
}
 DMA channel priority. More...
 
enum  dma_irq_t {
  kDMA_IntA,
  kDMA_IntB
}
 DMA interrupt flags. More...
 
enum  dma_trigger_type_t {
  kDMA_NoTrigger = 0,
  kDMA_LowLevelTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1) | DMA_CHANNEL_CFG_TRIGTYPE(1),
  kDMA_HighLevelTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1) | DMA_CHANNEL_CFG_TRIGTYPE(1) | DMA_CHANNEL_CFG_TRIGPOL(1),
  kDMA_FallingEdgeTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1),
  kDMA_RisingEdgeTrigger = DMA_CHANNEL_CFG_HWTRIGEN(1) | DMA_CHANNEL_CFG_TRIGPOL(1)
}
 DMA trigger type. More...
 
enum  dma_trigger_burst_t {
  kDMA_SingleTransfer = 0,
  kDMA_LevelBurstTransfer = DMA_CHANNEL_CFG_TRIGBURST(1),
  kDMA_EdgeBurstTransfer1 = DMA_CHANNEL_CFG_TRIGBURST(1),
  kDMA_EdgeBurstTransfer2 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(1),
  kDMA_EdgeBurstTransfer4 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(2),
  kDMA_EdgeBurstTransfer8 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(3),
  kDMA_EdgeBurstTransfer16 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(4),
  kDMA_EdgeBurstTransfer32 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(5),
  kDMA_EdgeBurstTransfer64 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(6),
  kDMA_EdgeBurstTransfer128 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(7),
  kDMA_EdgeBurstTransfer256 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(8),
  kDMA_EdgeBurstTransfer512 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(9),
  kDMA_EdgeBurstTransfer1024 = DMA_CHANNEL_CFG_TRIGBURST(1) | DMA_CHANNEL_CFG_BURSTPOWER(10)
}
 DMA trigger burst. More...
 
enum  dma_burst_wrap_t {
  kDMA_NoWrap = 0,
  kDMA_SrcWrap = DMA_CHANNEL_CFG_SRCBURSTWRAP(1),
  kDMA_DstWrap = DMA_CHANNEL_CFG_DSTBURSTWRAP(1),
  kDMA_SrcAndDstWrap = DMA_CHANNEL_CFG_SRCBURSTWRAP(1) | DMA_CHANNEL_CFG_DSTBURSTWRAP(1)
}
 DMA burst wrapping. More...
 
enum  dma_transfer_type_t {
  kDMA_MemoryToMemory = 0x0U,
  kDMA_PeripheralToMemory,
  kDMA_MemoryToPeripheral,
  kDMA_StaticToStatic
}
 DMA transfer type. More...
 
enum  _dma_transfer_status { kStatus_DMA_Busy = MAKE_STATUS(kStatusGroup_DMA, 0) }
 DMA transfer status. More...
 

Driver version

#define FSL_DMA_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 DMA driver version. More...
 

DMA initialization and De-initialization

void DMA_Init (DMA_Type *base)
 Initializes DMA peripheral. More...
 
void DMA_Deinit (DMA_Type *base)
 Deinitializes DMA peripheral. More...
 

DMA Channel Operation

static bool DMA_ChannelIsActive (DMA_Type *base, uint32_t channel)
 Return whether DMA channel is processing transfer. More...
 
static void DMA_EnableChannelInterrupts (DMA_Type *base, uint32_t channel)
 Enables the interrupt source for the DMA transfer. More...
 
static void DMA_DisableChannelInterrupts (DMA_Type *base, uint32_t channel)
 Disables the interrupt source for the DMA transfer. More...
 
static void DMA_EnableChannel (DMA_Type *base, uint32_t channel)
 Enable DMA channel. More...
 
static void DMA_DisableChannel (DMA_Type *base, uint32_t channel)
 Disable DMA channel. More...
 
static void DMA_EnableChannelPeriphRq (DMA_Type *base, uint32_t channel)
 Set PERIPHREQEN of channel configuration register. More...
 
static void DMA_DisableChannelPeriphRq (DMA_Type *base, uint32_t channel)
 Get PERIPHREQEN value of channel configuration register. More...
 
void DMA_ConfigureChannelTrigger (DMA_Type *base, uint32_t channel, dma_channel_trigger_t *trigger)
 Set trigger settings of DMA channel. More...
 
uint32_t DMA_GetRemainingBytes (DMA_Type *base, uint32_t channel)
 Gets the remaining bytes of the current DMA descriptor transfer. More...
 
static void DMA_SetChannelPriority (DMA_Type *base, uint32_t channel, dma_priority_t priority)
 Set priority of channel configuration register. More...
 
static dma_priority_t DMA_GetChannelPriority (DMA_Type *base, uint32_t channel)
 Get priority of channel configuration register. More...
 
void DMA_CreateDescriptor (dma_descriptor_t *desc, dma_xfercfg_t *xfercfg, void *srcAddr, void *dstAddr, void *nextDesc)
 Create application specific DMA descriptor to be used in a chain in transfer. More...
 

DMA Transactional Operation

void DMA_AbortTransfer (dma_handle_t *handle)
 Abort running transfer by handle. More...
 
void DMA_CreateHandle (dma_handle_t *handle, DMA_Type *base, uint32_t channel)
 Creates the DMA handle. More...
 
void DMA_SetCallback (dma_handle_t *handle, dma_callback callback, void *userData)
 Installs a callback function for the DMA transfer. More...
 
void DMA_PrepareTransfer (dma_transfer_config_t *config, void *srcAddr, void *dstAddr, uint32_t byteWidth, uint32_t transferBytes, dma_transfer_type_t type, void *nextDesc)
 Prepares the DMA transfer structure. More...
 
status_t DMA_SubmitTransfer (dma_handle_t *handle, dma_transfer_config_t *config)
 Submits the DMA transfer request. More...
 
void DMA_StartTransfer (dma_handle_t *handle)
 DMA start transfer. More...
 
void DMA_HandleIRQ (void)
 DMA IRQ handler for descriptor transfer complete. More...
 

Data Structure Documentation

struct dma_descriptor_t

Data Fields

uint32_t xfercfg
 Transfer configuration.
 
void * srcEndAddr
 Last source address of DMA transfer.
 
void * dstEndAddr
 Last destination address of DMA transfer.
 
void * linkToNextDesc
 Address of next DMA descriptor in chain.
 
struct dma_xfercfg_t

Data Fields

bool valid
 Descriptor is ready to transfer.
 
bool reload
 Reload channel configuration register after current descriptor is exhausted.
 
bool swtrig
 Perform software trigger. More...
 
bool clrtrig
 Clear trigger.
 
bool intA
 Raises IRQ when transfer is done and set IRQA status register flag.
 
bool intB
 Raises IRQ when transfer is done and set IRQB status register flag.
 
uint8_t byteWidth
 Byte width of data to transfer.
 
uint8_t srcInc
 Increment source address by 'srcInc' x 'byteWidth'.
 
uint8_t dstInc
 Increment destination address by 'dstInc' x 'byteWidth'.
 
uint16_t transferCount
 Number of transfers.
 

Field Documentation

bool dma_xfercfg_t::swtrig

Transfer if fired when 'valid' is set

struct dma_channel_trigger_t
struct dma_transfer_config_t

Data Fields

uint8_t * srcAddr
 Source data address.
 
uint8_t * dstAddr
 Destination data address.
 
uint8_t * nextDesc
 Chain custom descriptor.
 
dma_xfercfg_t xfercfg
 Transfer options.
 
bool isPeriph
 DMA transfer is driven by peripheral.
 
struct dma_handle_t

Data Fields

dma_callback callback
 Callback function. More...
 
void * userData
 Callback function parameter.
 
DMA_Type * base
 DMA peripheral base address.
 
uint8_t channel
 DMA channel number.
 

Field Documentation

dma_callback dma_handle_t::callback

Invoked when transfer of descriptor with interrupt flag finishes

Macro Definition Documentation

#define FSL_DMA_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))

Version 2.0.0.

Typedef Documentation

typedef void(* dma_callback)(struct _dma_handle *handle, void *userData, bool transferDone, uint32_t intmode)

Enumeration Type Documentation

Enumerator
kDMA_ChannelPriority0 

Highest channel priority - priority 0.

kDMA_ChannelPriority1 

Channel priority 1.

kDMA_ChannelPriority2 

Channel priority 2.

kDMA_ChannelPriority3 

Channel priority 3.

kDMA_ChannelPriority4 

Channel priority 4.

kDMA_ChannelPriority5 

Channel priority 5.

kDMA_ChannelPriority6 

Channel priority 6.

kDMA_ChannelPriority7 

Lowest channel priority - priority 7.

enum dma_irq_t
Enumerator
kDMA_IntA 

DMA interrupt flag A.

kDMA_IntB 

DMA interrupt flag B.

Enumerator
kDMA_NoTrigger 

Trigger is disabled.

kDMA_LowLevelTrigger 

Low level active trigger.

kDMA_HighLevelTrigger 

High level active trigger.

kDMA_FallingEdgeTrigger 

Falling edge active trigger.

kDMA_RisingEdgeTrigger 

Rising edge active trigger.

Enumerator
kDMA_SingleTransfer 

Single transfer.

kDMA_LevelBurstTransfer 

Burst transfer driven by level trigger.

kDMA_EdgeBurstTransfer1 

Perform 1 transfer by edge trigger.

kDMA_EdgeBurstTransfer2 

Perform 2 transfers by edge trigger.

kDMA_EdgeBurstTransfer4 

Perform 4 transfers by edge trigger.

kDMA_EdgeBurstTransfer8 

Perform 8 transfers by edge trigger.

kDMA_EdgeBurstTransfer16 

Perform 16 transfers by edge trigger.

kDMA_EdgeBurstTransfer32 

Perform 32 transfers by edge trigger.

kDMA_EdgeBurstTransfer64 

Perform 64 transfers by edge trigger.

kDMA_EdgeBurstTransfer128 

Perform 128 transfers by edge trigger.

kDMA_EdgeBurstTransfer256 

Perform 256 transfers by edge trigger.

kDMA_EdgeBurstTransfer512 

Perform 512 transfers by edge trigger.

kDMA_EdgeBurstTransfer1024 

Perform 1024 transfers by edge trigger.

Enumerator
kDMA_NoWrap 

Wrapping is disabled.

kDMA_SrcWrap 

Wrapping is enabled for source.

kDMA_DstWrap 

Wrapping is enabled for destination.

kDMA_SrcAndDstWrap 

Wrapping is enabled for source and destination.

Enumerator
kDMA_MemoryToMemory 

Transfer from memory to memory (increment source and destination)

kDMA_PeripheralToMemory 

Transfer from peripheral to memory (increment only destination)

kDMA_MemoryToPeripheral 

Transfer from memory to peripheral (increment only source)

kDMA_StaticToStatic 

Peripheral to static memory (do not increment source or destination)

Enumerator
kStatus_DMA_Busy 

Channel is busy and can't handle the transfer request.

Function Documentation

void DMA_Init ( DMA_Type *  base)

This function enable the DMA clock, set descriptor table and enable DMA peripheral.

Parameters
baseDMA peripheral base address.
void DMA_Deinit ( DMA_Type *  base)

This function gates the DMA clock.

Parameters
baseDMA peripheral base address.
static bool DMA_ChannelIsActive ( DMA_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseDMA peripheral base address.
channelDMA channel number.
Returns
True for active state, false otherwise.
static void DMA_EnableChannelInterrupts ( DMA_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseDMA peripheral base address.
channelDMA channel number.
static void DMA_DisableChannelInterrupts ( DMA_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseDMA peripheral base address.
channelDMA channel number.
static void DMA_EnableChannel ( DMA_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseDMA peripheral base address.
channelDMA channel number.
static void DMA_DisableChannel ( DMA_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseDMA peripheral base address.
channelDMA channel number.
static void DMA_EnableChannelPeriphRq ( DMA_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseDMA peripheral base address.
channelDMA channel number.
static void DMA_DisableChannelPeriphRq ( DMA_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseDMA peripheral base address.
channelDMA channel number.
Returns
True for enabled PeriphRq, false for disabled.
void DMA_ConfigureChannelTrigger ( DMA_Type *  base,
uint32_t  channel,
dma_channel_trigger_t trigger 
)
Parameters
baseDMA peripheral base address.
channelDMA channel number.
triggertrigger configuration.
uint32_t DMA_GetRemainingBytes ( DMA_Type *  base,
uint32_t  channel 
)
Parameters
baseDMA peripheral base address.
channelDMA channel number.
Returns
The number of bytes which have not been transferred yet.
static void DMA_SetChannelPriority ( DMA_Type *  base,
uint32_t  channel,
dma_priority_t  priority 
)
inlinestatic
Parameters
baseDMA peripheral base address.
channelDMA channel number.
priorityChannel priority value.
static dma_priority_t DMA_GetChannelPriority ( DMA_Type *  base,
uint32_t  channel 
)
inlinestatic
Parameters
baseDMA peripheral base address.
channelDMA channel number.
Returns
Channel priority value.
void DMA_CreateDescriptor ( dma_descriptor_t desc,
dma_xfercfg_t xfercfg,
void *  srcAddr,
void *  dstAddr,
void *  nextDesc 
)
Parameters
descDMA descriptor address.
xfercfgTransfer configuration for DMA descriptor.
srcAddrAddress of last item to transmit
dstAddrAddress of last item to receive.
nextDescAddress of next descriptor in chain.
void DMA_AbortTransfer ( dma_handle_t handle)

This function aborts DMA transfer specified by handle.

Parameters
handleDMA handle pointer.
void DMA_CreateHandle ( dma_handle_t handle,
DMA_Type *  base,
uint32_t  channel 
)

This function is called if using transaction API for DMA. This function initializes the internal state of DMA handle.

Parameters
handleDMA handle pointer. The DMA handle stores callback function and parameters.
baseDMA peripheral base address.
channelDMA channel number.
void DMA_SetCallback ( dma_handle_t handle,
dma_callback  callback,
void *  userData 
)

This callback is called in DMA IRQ handler. Use the callback to do something after the current major loop transfer completes.

Parameters
handleDMA handle pointer.
callbackDMA callback function pointer.
userDataParameter for callback function.
void DMA_PrepareTransfer ( dma_transfer_config_t config,
void *  srcAddr,
void *  dstAddr,
uint32_t  byteWidth,
uint32_t  transferBytes,
dma_transfer_type_t  type,
void *  nextDesc 
)

This function prepares the transfer configuration structure according to the user input.

Parameters
configThe user configuration structure of type dma_transfer_t.
srcAddrDMA transfer source address.
dstAddrDMA transfer destination address.
byteWidthDMA transfer destination address width(bytes).
transferBytesDMA transfer bytes to be transferred.
typeDMA transfer type.
nextDescChain custom descriptor to transfer.
Note
The data address and the data width must be consistent. For example, if the SRC is 4 bytes, so the source address must be 4 bytes aligned, or it shall result in source address error(SAE).
status_t DMA_SubmitTransfer ( dma_handle_t handle,
dma_transfer_config_t config 
)

This function submits the DMA transfer request according to the transfer configuration structure. If the user submits the transfer request repeatedly, this function packs an unprocessed request as a TCD and enables scatter/gather feature to process it in the next time.

Parameters
handleDMA handle pointer.
configPointer to DMA transfer configuration structure.
Return values
kStatus_DMA_SuccessIt means submit transfer request succeed.
kStatus_DMA_QueueFullIt means TCD queue is full. Submit transfer request is not allowed.
kStatus_DMA_BusyIt means the given channel is busy, need to submit request later.
void DMA_StartTransfer ( dma_handle_t handle)

This function enables the channel request. User can call this function after submitting the transfer request or before submitting the transfer request.

Parameters
handleDMA handle pointer.
void DMA_HandleIRQ ( void  )

This function clears the channel major interrupt flag and call the callback function if it is not NULL.