EasyDMA

EasyDMA is a module implemented by some peripherals to gain direct access to Data RAM.

EasyDMA is an AHB bus master similar to CPU and is connected to the AHB multilayer interconnect for direct access to Data RAM. EasyDMA is not able to access flash.

A peripheral can implement multiple EasyDMA instances to provide dedicated channels. For example, for reading and writing of data between the peripheral and RAM. This concept is illustrated in EasyDMA example.

Figure 1. EasyDMA example
EasyDMA example

An EasyDMA channel is implemented in the following way, but some variations may occur:


  
  READERBUFFER_SIZE 5
  WRITERBUFFER_SIZE 6

  uint8_t readerBuffer[READERBUFFER_SIZE]  __at__ 0x20000000;
  uint8_t writerBuffer[WRITERBUFFER_SIZE]  __at__ 0x20000005;

  // Configuring the READER channel
  MYPERIPHERAL->READER.MAXCNT = READERBUFFER_SIZE;  
  MYPERIPHERAL->READER.PTR = &readerBuffer;

  // Configure the WRITER channel
  MYPERIPHERAL->WRITER.MAXCNT = WRITEERBUFFER_SIZE;
  MYPERIPHERAL->WRITER.PTR = &writerBuffer;
  

This example shows a peripheral called MYPERIPHERAL that implements two EasyDMA channels - one for reading called READER, and one for writing called WRITER. When the peripheral is started, it is assumed that the peripheral will perform the following tasks:

The memory layout of these buffers is illustrated in EasyDMA memory layout.

Figure 2. EasyDMA memory layout
EasyDMA memory layout

The WRITER.MAXCNT register should not be specified larger than the actual size of the buffer (writerBuffer). Otherwise, the channel would overflow the writerBuffer.

Once an EasyDMA transfer is completed, the AMOUNT register can be read by the CPU to see how many bytes were transferred. For example, CPU can read MYPERIPHERAL->WRITER.AMOUNT register to see how many bytes WRITER wrote to RAM.

Note: The PTR register of a READER or WRITER must point to a valid memory region before use. The reset value of a PTR register is not guaranteed to point to valid memory. See Memory for more information about the different memory regions and EasyDMA connectivity.

EasyDMA error handling

Some errors may occur during DMA handling.

If READER.PTR or WRITER.PTR is not pointing to a valid memory region, an EasyDMA transfer may result in a HardFault or RAM corruption. See Memory for more information about the different memory regions.

If several AHB bus masters try to access the same AHB slave at the same time, AHB bus congestion might occur. An EasyDMA channel is an AHB master. Depending on the peripheral, the peripheral may either stall and wait for access to be granted, or lose data.

EasyDMA array list

EasyDMA is able to operate in Array List mode.

The Array List mode is implemented in channels where the LIST register is available.

The array list does not provide a mechanism to explicitly specify where the next item in the list is located. Instead, it assumes that the list is organized as a linear array where items are located one after the other in RAM.

The EasyDMA Array List can be implemented by using the data structure ArrayList_type as illustrated in the code example below using a READER EasyDMA channel as an example:


  
  #define BUFFER_SIZE  4
  
  typedef struct ArrayList
  {
    uint8_t buffer[BUFFER_SIZE];
  } ArrayList_type;
  
  ArrayList_type ReaderList[3]  __at__ 0x20000000;

  MYPERIPHERAL->READER.MAXCNT = BUFFER_SIZE;
  MYPERIPHERAL->READER.PTR = &ReaderList;
  MYPERIPHERAL->READER.LIST = MYPERIPHERAL_READER_LIST_ArrayList;
  

The data structure only includes a buffer with size equal to the size of READER.MAXCNT register. EasyDMA uses the READER.MAXCNT register to determine when the buffer is full.

Figure 3. EasyDMA array list
EasyDMA array list