9. DMA controller (DMA)

9.1 DMA introduction

Direct memory access (DMA) is used in order to provide high-speed data transfer between peripherals and memory and between memory and memory. Data can be quickly moved by DMA without any CPU action. This keeps CPU resources free for other operations.

The DMA controller combines a powerful dual AHB master bus architecture with independent FIFO to optimize the bandwidth of the system, based on a complex bus matrix architecture.

The two DMA controllers have 16 streams in total (8 for each controller), each dedicated to managing memory access requests from one or more peripherals. Each stream can have up to 8 channels (requests) in total. And each has an arbiter for handling the priority between DMA requests.

9.2 DMA main features

The main DMA features are:

Each DMA request immediately initiates a transfer from/to the memory. When it is configured in direct mode (FIFO disabled), to transfer data in memory-to-peripheral mode, the DMA preloads only one data from the memory to the internal

FIFO to ensure an immediate data transfer as soon as a DMA request is triggered by a peripheral.

9.3 DMA functional description

9.3.1 General description

Figure 22 shows the block diagram of a DMA.

Figure 22. DMA block diagram

Figure 22. DMA block diagram. The diagram shows a DMA controller with multiple channels (REQ_STR0_CH0 to REQ_STR7_CH7) connected to a Channel selection block. The Channel selection block feeds into an Arbiter, which outputs REQ_STREAM0 to REQ_STREAM7. These streams pass through FIFOs and then to two AHB master blocks. The top AHB master is connected to a Memory port, and the bottom AHB master is connected to a Peripheral port. An AHB slave programming interface is also shown, connected to a Programming port. The diagram is labeled ai15945.
Figure 22. DMA block diagram. The diagram shows a DMA controller with multiple channels (REQ_STR0_CH0 to REQ_STR7_CH7) connected to a Channel selection block. The Channel selection block feeds into an Arbiter, which outputs REQ_STREAM0 to REQ_STREAM7. These streams pass through FIFOs and then to two AHB master blocks. The top AHB master is connected to a Memory port, and the bottom AHB master is connected to a Peripheral port. An AHB slave programming interface is also shown, connected to a Programming port. The diagram is labeled ai15945.

The DMA controller performs direct memory transfer: as an AHB master, it can take the control of the AHB bus matrix to initiate AHB transactions.

It can carry out the following transactions:

The DMA controller provides two AHB master ports: the AHB memory port , intended to be connected to memories and the AHB peripheral port , intended to be connected to peripherals. However, to allow memory-to-memory transfers, the AHB peripheral port must also have access to the memories.

The AHB slave port is used to program the DMA controller (it supports only 32-bit accesses).

See Figure 23 for the implementation of the system of two DMA controllers.

Figure 23. System implementation of the two DMA controllers (STM32F401xB/C and STM32F401xD/E)

Block diagram of the system implementation of two DMA controllers (DMA1 and DMA2) connected to a Bus Matrix (AHB multilayer). The diagram shows DMA2 connected to the Bus Matrix via its AHB slave port, which is connected to the DCODE and ICODE lines. DMA1 is connected to the Bus Matrix via its AHB slave port, which is connected to the SRAM line. Both DMA controllers have multiple DMA request lines connected to the Bus Matrix. The Bus Matrix is connected to Flash memory, SRAM, AHB1 peripherals, AHB-APB bridge2 (dual AHB) which connects to APB2 peripherals, AHB-APB bridge1 (dual AHB) which connects to APB1 peripherals, and AHB2 peripherals. The diagram also shows the internal structure of the DMA controllers, including the DMA request block, Arbiter, FIFO, and AHB memory port. The diagram is labeled MS31426V1.
Block diagram of the system implementation of two DMA controllers (DMA1 and DMA2) connected to a Bus Matrix (AHB multilayer). The diagram shows DMA2 connected to the Bus Matrix via its AHB slave port, which is connected to the DCODE and ICODE lines. DMA1 is connected to the Bus Matrix via its AHB slave port, which is connected to the SRAM line. Both DMA controllers have multiple DMA request lines connected to the Bus Matrix. The Bus Matrix is connected to Flash memory, SRAM, AHB1 peripherals, AHB-APB bridge2 (dual AHB) which connects to APB2 peripherals, AHB-APB bridge1 (dual AHB) which connects to APB1 peripherals, and AHB2 peripherals. The diagram also shows the internal structure of the DMA controllers, including the DMA request block, Arbiter, FIFO, and AHB memory port. The diagram is labeled MS31426V1.
  1. 1. The DMA1 controller AHB peripheral port is not connected to the bus matrix like DMA2 controller. As a result, only DMA2 streams are able to perform memory-to-memory transfers.

9.3.2 DMA transactions

A DMA transaction consists of a sequence of a given number of data transfers. The number of data items to be transferred and their width (8-bit, 16-bit or 32-bit) are software-programmable.

Each DMA transfer consists of three operations:

After an event, the peripheral sends a request signal to the DMA controller. The DMA controller serves the request depending on the channel priorities. As soon as the DMA controller accesses the peripheral, an Acknowledge signal is sent to the peripheral by the DMA controller. The peripheral releases its request as soon as it gets the Acknowledge signal from the DMA controller. Once the request has been deasserted by the peripheral, the DMA controller releases the Acknowledge signal. If there are more requests, the peripheral can initiate the next transaction.

9.3.3 Channel selection

Each stream is associated with a DMA request that can be selected out of 8 possible channel requests. The selection is controlled by the CHSEL[2:0] bits in the DMA_SxCR register.

Figure 24. Channel selection

Diagram illustrating channel selection for a DMA stream. Eight peripheral request lines (REQ_STRx_CH0 to REQ_STRx_CH7) are shown entering a multiplexer. The output of the multiplexer is labeled REQ_STREAMx. Below the multiplexer, a bit field diagram for the DMA_SxCR register shows the CHSEL[2:0] bits (bits 27 to 25) used for selection. The diagram is labeled ai15947b.
Diagram illustrating channel selection for a DMA stream. Eight peripheral request lines (REQ_STRx_CH0 to REQ_STRx_CH7) are shown entering a multiplexer. The output of the multiplexer is labeled REQ_STREAMx. Below the multiplexer, a bit field diagram for the DMA_SxCR register shows the CHSEL[2:0] bits (bits 27 to 25) used for selection. The diagram is labeled ai15947b.

The 8 requests from the peripherals (TIM, ADC, SPI, I2C, etc.) are independently connected to each channel and their connection depends on the product implementation.

See the following table(s) for examples of DMA request mappings.

Table 28. DMA1 request mapping (STM32F401xB/C and STM32F401xD/E)

Peripheral requestsStream 0Stream 1Stream 2Stream 3Stream 4Stream 5Stream 6Stream 7
Channel 0SPI3_RX-SPI3_RXSPI2_RXSPI2_TXSPI3_TX-SPI3_TX
Channel 1I2C1_RXI2C3_RX---I2C1_RXI2C1_TXI2C1_TX
Channel 2TIM4_CH1-I2S3_EXT_RXTIM4_CH2I2S2_EXT_TXI2S3_EXT_TXTIM4_UPTIM4_CH3
Channel 3I2S3_EXT_RXTIM2_UP
TIM2_CH3
I2C3_RXI2S2_EXT_RXI2C3_TXTIM2_CH1TIM2_CH2
TIM2_CH4
TIM2_UP
TIM2_CH4
Channel 4-----USART2_RXUSART2_TX-
Channel 5--TIM3_CH4
TIM3_UP
-TIM3_CH1
TIM3_TRIG
TIM3_CH2-TIM3_CH3

Table 28. DMA1 request mapping (STM32F401xB/C and STM32F401xD/E) (continued)

Peripheral requestsStream 0Stream 1Stream 2Stream 3Stream 4Stream 5Stream 6Stream 7
Channel 6TIM5_CH3
TIM5_UP
TIM5_CH4
TIM5_TRIG
TIM5_CH1TIM5_CH4
TIM5_TRIG
TIM5_CH2I2C3_TXTIM5_UP-
Channel 7--I2C2_RXI2C2_RX---I2C2_TX

Table 29. DMA2 request mapping (STM32F401xB/C and STM32F401xD/E)

Peripheral requestsStream 0Stream 1Stream 2Stream 3Stream 4Stream 5Stream 6Stream 7
Channel 0ADC1---ADC1-TIM1_CH1
TIM1_CH2
TIM1_CH3
-
Channel 1--------
Channel 2--------
Channel 3SPI1_RX-SPI1_RXSPI1_TX-SPI1_TX--
Channel 4SPI4_RXSPI4_TXUSART1_RXSDIO-USART1_RXSDIOUSART1_TX
Channel 5-USART6_RXUSART6_RXSPI4_RXSPI4_TX-USART6_TXUSART6_TX
Channel 6TIM1_TRIGTIM1_CH1TIM1_CH2TIM1_CH1TIM1_CH4
TIM1_TRIG
TIM1_COM
TIM1_UPTIM1_CH3-
Channel 7--------

9.3.4 Arbiter

An arbiter manages the 8 DMA stream requests based on their priority for each of the two AHB master ports (memory and peripheral ports) and launches the peripheral/memory access sequences.

Priorities are managed in two stages:

9.3.5 DMA streams

Each of the 8 DMA controller streams provides a unidirectional transfer link between a source and a destination.

Each stream can be configured to perform:

The amount of data to be transferred (up to 65535) is programmable and related to the source width of the peripheral that requests the DMA transfer connected to the peripheral AHB port. The register that contains the amount of data items to be transferred is decremented after each transaction.

9.3.6 Source, destination and transfer modes

Both source and destination transfers can address peripherals and memories in the entire 4 GB area, at addresses comprised between 0x0000 0000 and 0xFFFF FFFF.

The direction is configured using the DIR[1:0] bits in the DMA_SxCR register and offers three possibilities: memory-to-peripheral, peripheral-to-memory or memory-to-memory transfers. Table 30 describes the corresponding source and destination addresses.

Table 30. Source and destination address

Bits DIR[1:0] of the DMA_SxCR registerDirectionSource addressDestination address
00Peripheral-to-memoryDMA_SxPARDMA_SxM0AR
01Memory-to-peripheralDMA_SxM0ARDMA_SxPAR
10Memory-to-memoryDMA_SxPARDMA_SxM0AR
11reserved--

When the data width (programmed in the PSIZE or MSIZE bits in the DMA_SxCR register) is a half-word or a word, respectively, the peripheral or memory address written into the DMA_SxPAR or DMA_SxM0AR/M1AR registers has to be aligned on a word or half-word address boundary, respectively.

Peripheral-to-memory mode

Figure 25 describes this mode.

When this mode is enabled (by setting the bit EN in the DMA_SxCR register), each time a peripheral request occurs, the stream initiates a transfer from the source to fill the FIFO.

When the threshold level of the FIFO is reached, the contents of the FIFO are drained and stored into the destination.

The transfer stops once the DMA_SxNDTR register reaches zero, when the peripheral requests the end of transfers (in case of a peripheral flow controller) or when the EN bit in the DMA_SxCR register is cleared by software.

In direct mode (when the DMDIS value in the DMA_SxFCR register is '0'), the threshold level of the FIFO is not used: after each single data transfer from the peripheral to the FIFO, the corresponding data are immediately drained and stored into the destination.

The stream has access to the AHB source or destination port only if the arbitration of the corresponding stream is won. This arbitration is performed using the priority defined for each stream using the PL[1:0] bits in the DMA_SxCR register.

Figure 25. Peripheral-to-memory mode

Figure 25: Peripheral-to-memory mode diagram. The diagram shows a DMA controller block containing an Arbiter, a FIFO level indicator, a FIFO buffer, and an AHB memory port. The Arbiter receives REQ_STREAMx signals and controls the FIFO level. The FIFO level feeds into the FIFO buffer. The FIFO buffer feeds into the AHB memory port. The AHB memory port is connected to a Memory bus, which leads to a Memory destination. The DMA controller also contains registers DMA_SxM0AR and DMA_SxM1AR(1) which feed into the AHB memory port. The AHB memory port is also connected to an AHB peripheral port. The AHB peripheral port is connected to a Peripheral bus, which leads to a Peripheral source. The DMA controller also contains a register DMA_SxPAR which feeds into the AHB peripheral port. A Peripheral DMA request signal is shown entering the DMA controller from the bottom. The diagram is labeled MS47543V1.
Figure 25: Peripheral-to-memory mode diagram. The diagram shows a DMA controller block containing an Arbiter, a FIFO level indicator, a FIFO buffer, and an AHB memory port. The Arbiter receives REQ_STREAMx signals and controls the FIFO level. The FIFO level feeds into the FIFO buffer. The FIFO buffer feeds into the AHB memory port. The AHB memory port is connected to a Memory bus, which leads to a Memory destination. The DMA controller also contains registers DMA_SxM0AR and DMA_SxM1AR(1) which feed into the AHB memory port. The AHB memory port is also connected to an AHB peripheral port. The AHB peripheral port is connected to a Peripheral bus, which leads to a Peripheral source. The DMA controller also contains a register DMA_SxPAR which feeds into the AHB peripheral port. A Peripheral DMA request signal is shown entering the DMA controller from the bottom. The diagram is labeled MS47543V1.

1. For double-buffer mode.

Memory-to-peripheral mode

Figure 26 describes this mode.

When this mode is enabled (by setting the EN bit in the DMA_SxCR register), the stream immediately initiates transfers from the source to entirely fill the FIFO.

Each time a peripheral request occurs, the contents of the FIFO are drained and stored into the destination. When the level of the FIFO is lower than or equal to the predefined threshold level, the FIFO is fully reloaded with data from the memory.

The transfer stops once the DMA_SxNDTR register reaches zero, when the peripheral requests the end of transfers (in case of a peripheral flow controller) or when the EN bit in the DMA_SxCR register is cleared by software.

In direct mode (when the DMDIS value in the DMA_SxFCR register is '0'), the threshold level of the FIFO is not used. Once the stream is enabled, the DMA preloads the first data to transfer into an internal FIFO. As soon as the peripheral requests a data transfer, the DMA transfers the preloaded value into the configured destination. It then reloads again the

empty internal FIFO with the next data to be transfer. The preloaded data size corresponds to the value of the PSIZE bitfield in the DMA_SxCR register.

The stream has access to the AHB source or destination port only if the arbitration of the corresponding stream is won. This arbitration is performed using the priority defined for each stream using the PL[1:0] bits in the DMA_SxCR register.

Figure 26. Memory-to-peripheral mode

Figure 26: Memory-to-peripheral mode diagram. The diagram shows a DMA controller block containing an Arbiter, a FIFO, and two AHB ports (memory and peripheral). The memory port is connected to a memory source via a memory bus. The peripheral port is connected to a peripheral destination via a peripheral bus. The FIFO is filled from the memory source and drained to the peripheral destination. The arbiter receives REQ_STREAMx signals and controls the FIFO level. The DMA controller also contains registers DMA_SxM0AR, DMA_SxM1AR(1), and DMA_SxPAR. A peripheral DMA request signal is shown entering the controller from the bottom.

The diagram illustrates the internal architecture of a DMA controller in memory-to-peripheral mode. Inside the controller, an 'Arbiter' block receives 'REQ_STREAMx' signals. It is connected to a 'FIFO' block which has a 'FIFO level' indicator. The FIFO is connected to an 'AHB memory port' and an 'AHB peripheral port'. The memory port connects to an external 'Memory source' via a 'Memory bus'. The peripheral port connects to an external 'Peripheral destination' via a 'Peripheral bus'. Control registers 'DMA_SxM0AR', 'DMA_SxM1AR(1)', and 'DMA_SxPAR' are shown within the controller, with arrows pointing to the AHB ports. A 'Peripheral DMA request' signal enters the controller from the bottom.

Figure 26: Memory-to-peripheral mode diagram. The diagram shows a DMA controller block containing an Arbiter, a FIFO, and two AHB ports (memory and peripheral). The memory port is connected to a memory source via a memory bus. The peripheral port is connected to a peripheral destination via a peripheral bus. The FIFO is filled from the memory source and drained to the peripheral destination. The arbiter receives REQ_STREAMx signals and controls the FIFO level. The DMA controller also contains registers DMA_SxM0AR, DMA_SxM1AR(1), and DMA_SxPAR. A peripheral DMA request signal is shown entering the controller from the bottom.

1. For double-buffer mode.

Memory-to-memory mode

The DMA channels can also work without being triggered by a request from a peripheral. This is the memory-to-memory mode, described in Figure 27 .

When the stream is enabled by setting the Enable bit (EN) in the DMA_SxCR register, the stream immediately starts to fill the FIFO up to the threshold level. When the threshold level is reached, the FIFO contents are drained and stored into the destination.

The transfer stops once the DMA_SxNDTR register reaches zero or when the EN bit in the DMA_SxCR register is cleared by software.

The stream has access to the AHB source or destination port only if the arbitration of the corresponding stream is won. This arbitration is performed using the priority defined for each stream using the PL[1:0] bits in the DMA_SxCR register.

Note: When memory-to-memory mode is used, the Circular and direct modes are not allowed. Only the DMA2 controller is able to perform memory-to-memory transfers.

Figure 27. Memory-to-memory mode

Figure 27: Memory-to-memory mode diagram. The diagram shows the internal structure of a DMA controller. Inside the controller, an 'Arbiter' receives a 'Stream enable' signal. The Arbiter is connected to a 'FIFO' block (with 'FIFO level' indicator) and an 'AHB memory port'. The FIFO block is also connected to an 'AHB peripheral port'. The 'AHB memory port' is controlled by registers 'DMA_SxM0AR' and 'DMA_SxM1AR(1)'. It connects via a 'Memory bus' to 'Memory 2 destination'. The 'AHB peripheral port' is controlled by the 'DMA_SxPAR' register and connects via a 'Peripheral bus' to 'Memory 1 source'. Arrows indicate data flow from Memory 1 source through the peripheral port, into the FIFO, and out through the memory port to Memory 2 destination.
Figure 27: Memory-to-memory mode diagram. The diagram shows the internal structure of a DMA controller. Inside the controller, an 'Arbiter' receives a 'Stream enable' signal. The Arbiter is connected to a 'FIFO' block (with 'FIFO level' indicator) and an 'AHB memory port'. The FIFO block is also connected to an 'AHB peripheral port'. The 'AHB memory port' is controlled by registers 'DMA_SxM0AR' and 'DMA_SxM1AR(1)'. It connects via a 'Memory bus' to 'Memory 2 destination'. The 'AHB peripheral port' is controlled by the 'DMA_SxPAR' register and connects via a 'Peripheral bus' to 'Memory 1 source'. Arrows indicate data flow from Memory 1 source through the peripheral port, into the FIFO, and out through the memory port to Memory 2 destination.

1. For double-buffer mode.

9.3.7 Pointer incrementation

Peripheral and memory pointers can optionally be automatically post-incremented or kept constant after each transfer depending on the PINC and MINC bits in the DMA_SxCR register.

Disabling the Increment mode is useful when the peripheral source or destination data are accessed through a single register.

If the Increment mode is enabled, the address of the next transfer is the address of the previous one incremented by 1 (for bytes), 2 (for half-words) or 4 (for words) depending on the data width programmed in the PSIZE or MSIZE bits in the DMA_SxCR register.

In order to optimize the packing operation, it is possible to fix the increment offset size for the peripheral address whatever the size of the data transferred on the AHB peripheral port. The PINCOS bit in the DMA_SxCR register is used to align the increment offset size with the data size on the peripheral AHB port, or on a 32-bit address (the address is then incremented by 4). The PINCOS bit has an impact on the AHB peripheral port only.

If PINCOS bit is set, the address of the next transfer is the address of the previous one incremented by 4 (automatically aligned on a 32-bit address) whatever the PSIZE value. The AHB memory port, however, is not impacted by this operation.

9.3.8 Circular mode

The Circular mode is available to handle circular buffers and continuous data flows (e.g. ADC scan mode). This feature can be enabled using the CIRC bit in the DMA_SxCR register.

When the circular mode is activated, the number of data items to be transferred is automatically reloaded with the initial value programmed during the stream configuration phase, and the DMA requests continue to be served.

Note: In the circular mode, it is mandatory to respect the following rule in case of a burst mode configured for memory:

\( DMA\_SxNDTR = \text{Multiple of } ((Mburst\ beat) \times (Msize)/(Psize)) \) , where:

For example: \( Mburst\ beat = 8 \) (INCR8), \( MSIZE = '00' \) (byte) and \( PSIZE = '01' \) (half-word), in this case: \( DMA\_SxNDTR \) must be a multiple of \( (8 \times 1/2 = 4) \) .

If this formula is not respected, the DMA behavior and data integrity are not guaranteed.

NDTR must also be a multiple of the Peripheral burst size multiplied by the peripheral data size, otherwise this could result in a bad DMA behavior.

9.3.9 Double buffer mode

This mode is available for all the DMA1 and DMA2 streams.

The Double buffer mode is enabled by setting the DBM bit in the DMA_SxCR register.

A double-buffer stream works as a regular (single buffer) stream with the difference that it has two memory pointers. When the Double buffer mode is enabled, the Circular mode is automatically enabled (CIRC bit in DMA_SxCR is don't care) and at each end of transaction, the memory pointers are swapped.

In this mode, the DMA controller swaps from one memory target to another at each end of transaction. This allows the software to process one memory area while the second memory area is being filled/used by the DMA transfer. The double-buffer stream can work in both directions (the memory can be either the source or the destination) as described in Table 31: Source and destination address registers in Double buffer mode (DBM=1) .

Note: In Double buffer mode, it is possible to update the base address for the AHB memory port on-the-fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled, by respecting the following conditions:

To avoid any error condition, it is advised to change the base address as soon as the TCIF flag is asserted because, at this point, the targeted memory must have changed from

memory 0 to 1 (or from 1 to 0) depending on the value of CT in the DMA_SxCR register in accordance with one of the two above conditions.

For all the other modes (except the Double buffer mode), the memory address registers are write-protected as soon as the stream is enabled.

Table 31. Source and destination address registers in Double buffer mode (DBM=1)

Bits DIR[1:0] of the DMA_SxCR registerDirectionSource addressDestination address
00Peripheral-to-memoryDMA_SxPARDMA_SxM0AR / DMA_SxM1AR
01Memory-to-peripheralDMA_SxM0AR / DMA_SxM1ARDMA_SxPAR
10Not allowed (1)
11Reserved--
  1. 1. When the Double buffer mode is enabled, the Circular mode is automatically enabled. Since the memory-to-memory mode is not compatible with the Circular mode, when the Double buffer mode is enabled, it is not allowed to configure the memory-to-memory mode.

9.3.10 Programmable data width, packing/unpacking, endianness

The number of data items to be transferred has to be programmed into DMA_SxNDTR (number of data items to transfer bit, NDT) before enabling the stream (except when the flow controller is the peripheral, PFCTRL bit in DMA_SxCR is set).

When using the internal FIFO, the data widths of the source and destination data are programmable through the PSIZE and MSIZE bits in the DMA_SxCR register (can be 8-, 16- or 32-bit).

When PSIZE and MSIZE are not equal:

This packing/unpacking procedure may present a risk of data corruption when the operation is interrupted before the data are completely packed/unpacked. So, to ensure data coherence, the stream may be configured to generate burst transfers: in this case, each group of transfers belonging to a burst are indivisible (refer to Section 9.3.11: Single and burst transfers ).

In direct mode (DMDIS = 0 in the DMA_SxFCR register), the packing/unpacking of data is not possible. In this case, it is not allowed to have different source and destination transfer data widths: both are equal and defined by the PSIZE bits in the DMA_SxCR MSIZE bits are don't care).

Table 32. Packing/unpacking & endian behavior (bit PINC = MINC = 1)

AHB memory port widthAHB peripheral port widthNumber of data items to transfer (NDT)Memory transfer numberMemory port address / byte lanePeripheral transfer numberPeripheral port address / byte lane
PINCOS = 1PINCOS = 0
88410x0 / B0[7:0]10x0 / B0[7:0]0x0 / B0[7:0]
20x1 / B1[7:0]20x4 / B1[7:0]0x1 / B1[7:0]
30x2 / B2[7:0]30x8 / B2[7:0]0x2 / B2[7:0]
40x3 / B3[7:0]40xC / B3[7:0]0x3 / B3[7:0]
816210x0 / B0[7:0]10x0 / B1|B0[15:0]0x0 / B1|B0[15:0]
20x1 / B1[7:0]20x4 / B3|B2[15:0]0x2 / B3|B2[15:0]
30x2 / B2[7:0]
40x3 / B3[7:0]
832110x0 / B0[7:0]10x0 / B3|B2|B1|B0[31:0]0x0 / B3|B2|B1|B0[31:0]
20x1 / B1[7:0]
30x2 / B2[7:0]
40x3 / B3[7:0]
168410x0 / B1|B0[15:0]10x0 / B0[7:0]0x0 / B0[7:0]
20x2 / B3|B2[15:0]20x4 / B1[7:0]0x1 / B1[7:0]
330x8 / B2[7:0]0x2 / B2[7:0]
440xC / B3[7:0]0x3 / B3[7:0]
1616210x0 / B1|B0[15:0]10x0 / B1|B0[15:0]0x0 / B1|B0[15:0]
20x2 / B1|B0[15:0]20x4 / B3|B2[15:0]0x2 / B3|B2[15:0]
1632110x0 / B1|B0[15:0]10x0 / B3|B2|B1|B0[31:0]0x0 / B3|B2|B1|B0[31:0]
20x2 / B3|B2[15:0]
328410x0 / B3|B2|B1|B0[31:0]10x0 / B0[7:0]0x0 / B0[7:0]
220x4 / B1[7:0]0x1 / B1[7:0]
330x8 / B2[7:0]0x2 / B2[7:0]
440xC / B3[7:0]0x3 / B3[7:0]
3216210x0 / B3|B2|B1|B0[31:0]10x0 / B1|B0[15:0]0x0 / B1|B0[15:0]
220x4 / B3|B2[15:0]0x2 / B3|B2[15:0]
3232110x0 / B3|B2|B1|B0[31:0]10x0 / B3|B2|B1|B0[31:0]0x0 / B3|B2|B1|B0[31:0]

Note: Peripheral port may be the source or the destination (it could also be the memory source in the case of memory-to-memory transfer).

PSIZE, MSIZE and NDT[15:0] have to be configured so as to ensure that the last transfer is not incomplete. This can occur when the data width of the peripheral port (PSIZE bits) is lower than the data width of the memory port (MSIZE bits). This constraint is summarized in Table 33 .

Table 33. Restriction on NDT versus PSIZE and MSIZE
PSIZE[1:0] of DMA_SxCRMSIZE[1:0] of DMA_SxCRNDT[15:0] of DMA_SxNDTR
00 (8-bit)01 (16-bit)must be a multiple of 2
00 (8-bit)10 (32-bit)must be a multiple of 4
01 (16-bit)10 (32-bit)must be a multiple of 2

9.3.11 Single and burst transfers

The DMA controller can generate single transfers or incremental burst transfers of 4, 8 or 16 beats.

The size of the burst is configured by software independently for the two AHB ports by using the MBURST[1:0] and PBURST[1:0] bits in the DMA_SxCR register.

The burst size indicates the number of beats in the burst, not the number of bytes transferred.

To ensure data coherence, each group of transfers that form a burst are indivisible: AHB transfers are locked and the arbiter of the AHB bus matrix does not degrant the DMA master during the sequence of the burst transfer.

Depending on the single or burst configuration, each DMA request initiates a different number of transfers on the AHB peripheral port:

The same as above has to be considered for the AHB memory port considering the MBURST and MSIZE bits.

In direct mode, the stream can only generate single transfers and the MBURST[1:0] and PBURST[1:0] bits are forced by hardware.

The address pointers (DMA_SxPAR or DMA_SxM0AR registers) must be chosen so as to ensure that all transfers within a burst block are aligned on the address boundary equal to the size of the transfer.

The burst configuration has to be selected in order to respect the AHB protocol, where bursts must not cross the 1 KB address boundary because the minimum address space that can be allocated to a single slave is 1 KB. This means that the 1 KB address boundary should not be crossed by a burst block transfer, otherwise an AHB error would be generated, that is not reported by the DMA registers.

9.3.12 FIFO

FIFO structure

The FIFO is used to temporarily store data coming from the source before transmitting them to the destination.

Each stream has an independent 4-word FIFO and the threshold level is software-configurable between 1/4, 1/2, 3/4 or full.

To enable the use of the FIFO threshold level, the direct mode must be disabled by setting the DMDIS bit in the DMA_SxFCR register.

The structure of the FIFO differs depending on the source and destination data widths, and is described in Figure 28: FIFO structure .

Figure 28. FIFO structure

Figure 28. FIFO structure. Four diagrams showing FIFO organization for different source and destination data widths: byte-to-word, byte-to-half-word, half-word-to-word, and half-word-to-byte. Each diagram shows a 4-word FIFO with 4 byte lanes and threshold levels (Empty, 1/4, 1/2, 3/4, Full).

The figure illustrates four FIFO structures based on source and destination data widths. Each structure shows a 4-word FIFO with 4 byte lanes (byte lane 0 to 3). The FIFO levels are marked as Empty, 1/4, 1/2, 3/4, and Full.

Figure 28. FIFO structure. Four diagrams showing FIFO organization for different source and destination data widths: byte-to-word, byte-to-half-word, half-word-to-word, and half-word-to-byte. Each diagram shows a 4-word FIFO with 4 byte lanes and threshold levels (Empty, 1/4, 1/2, 3/4, Full).

ai15951

FIFO threshold and burst configuration

Caution is required when choosing the FIFO threshold (bits FTH[1:0] of the DMA_SxFCR register) and the size of the memory burst (MBURST[1:0] of the DMA_SxCR register): The content pointed by the FIFO threshold must exactly match to an integer number of memory burst transfers. If this is not in the case, a FIFO error (flag FEIFx of the DMA_HISR or DMA_LISR register) is generated when the stream is enabled, then the stream is automatically disabled. The allowed and forbidden configurations are described in the Table 34: FIFO threshold configurations .

Table 34. FIFO threshold configurations

MSIZEFIFO levelMBURST = INCR4MBURST = INCR8MBURST = INCR16
Byte1/41 burst of 4 beatsforbiddenforbidden
1/22 bursts of 4 beats1 burst of 8 beats
3/43 bursts of 4 beatsforbidden
Full4 bursts of 4 beats2 bursts of 8 beats1 burst of 16 beats
Half-word1/4forbiddenforbiddenforbidden
1/21 burst of 4 beats
3/4forbidden
Full2 bursts of 4 beats1 burst of 8 beats
Word1/4forbiddenforbiddenforbidden
1/2
3/4
Full1 burst of 4 beats

In all cases, the burst size multiplied by the data size must not exceed the FIFO size (data size can be: 1 (byte), 2 (half-word) or 4 (word)).

Incomplete Burst transfer at the end of a DMA transfer may happen if one of the following conditions occurs:

In such cases, the remaining data to be transferred is managed in single mode by the DMA, even if a burst transaction was requested during the DMA stream configuration.

Note: When burst transfers are requested on the peripheral AHB port and the FIFO is used (DMDIS = 1 in the DMA_SxCR register), it is mandatory to respect the following rule to avoid permanent underrun or overrun conditions, depending on the DMA stream direction:
If \( (PBURST \times PSIZE) = FIFO\_SIZE \) (4 words), \( FIFO\_Threshold = 3/4 \) is forbidden with \( PSIZE = 1, 2 \) or \( 4 \) and \( PBURST = 4, 8 \) or \( 16 \) .

This rule ensures that enough FIFO space at a time is free to serve the request from the peripheral.

FIFO flush

The FIFO can be flushed when the stream is disabled by resetting the EN bit in the DMA_SxCR register and when the stream is configured to manage peripheral-to-memory or memory-to-memory transfers: If some data are still present in the FIFO when the stream is disabled, the DMA controller continues transferring the remaining data to the destination (even though stream is effectively disabled). When this flush is completed, the transfer complete status bit (TCIFx) in the DMA_LISR or DMA_HISR register is set.

The remaining data counter DMA_SxNDTR keeps the value in this case to indicate how many data items are currently available in the destination memory.

Note that during the FIFO flush operation, if the number of remaining data items in the FIFO to be transferred to memory (in bytes) is less than the memory data width (for example 2 bytes in FIFO while MSIZE is configured to word), data is sent with the data width set in the MSIZE bit in the DMA_SxCR register. This means that memory is written with an undesired value. The software may read the DMA_SxNDTR register to determine the memory area that contains the good data (start address and last address).

If the number of remaining data items in the FIFO is lower than a burst size (if the MBURST bits in DMA_SxCR register are set to configure the stream to manage burst on the AHB memory port), single transactions are generated to complete the FIFO flush.

Direct mode

By default, the FIFO operates in direct mode (DMDIS bit in the DMA_SxFCR is reset) and the FIFO threshold level is not used. This mode is useful when the system requires an immediate and single transfer to or from the memory after each DMA request.

When the DMA is configured in direct mode (FIFO disabled), to transfer data in memory-to-peripheral mode, the DMA preloads one data from the memory to the internal FIFO to ensure an immediate data transfer as soon as a DMA request is triggered by a peripheral.

To avoid saturating the FIFO, it is recommended to configure the corresponding stream with a high priority.

This mode is restricted to transfers where:

Direct mode must not be used when implementing memory-to-memory transfers.

9.3.13 DMA transfer completion

Different events can generate an end of transfer by setting the TCIFx bit in the DMA_LISR or DMA_HISR status register:

to-memory) all the remaining data have been flushed from the FIFO into the memory

Note: The transfer completion is dependent on the remaining data in FIFO to be transferred into memory only in the case of peripheral-to-memory mode. This condition is not applicable in memory-to-peripheral mode.

If the stream is configured in noncircular mode, after the end of the transfer (that is when the number of data to be transferred reaches zero), the DMA is stopped (EN bit in DMA_SxCR register is cleared by Hardware) and no DMA request is served unless the software reprograms the stream and re-enables it (by setting the EN bit in the DMA_SxCR register).

9.3.14 DMA transfer suspension

At any time, a DMA transfer can be suspended to be restarted later on or to be definitively disabled before the end of the DMA transfer.

There are two cases:

Note: Note that a Transfer complete interrupt flag (TCIF in DMA_LISR or DMA_HISR) is set to indicate the end of transfer due to the stream interruption.

9.3.15 Flow controller

The entity that controls the number of data to be transferred is known as the flow controller. This flow controller is configured independently for each stream using the PFCTRL bit in the DMA_SxCR register.

The flow controller can be:

When the peripheral flow controller is used for a given stream, the value written into the DMA_SxNDTR has no effect on the DMA transfer. Actually, whatever the value written, it is forced by hardware to 0xFFFF as soon as the stream is enabled, to respect the following schemes:

Note: When configured in memory-to-memory mode, the DMA is always the flow controller and the PFCTRL bit is forced to 0 by hardware.

The Circular mode is forbidden in the peripheral flow controller mode.

9.3.16 Summary of the possible DMA configurations

Table 35 summarizes the different possible DMA configurations.

Table 35. Possible DMA configurations

DMA transfer modeSourceDestinationFlow controllerCircular modeTransfer typeDirect modeDouble buffer mode
Peripheral-to-memoryAHB peripheral portAHB memory portDMApossiblesinglepossiblepossible
burstforbidden
Peripheralforbiddensinglepossibleforbidden
burstforbidden
Memory-to-peripheralAHB memory portAHB peripheral portDMApossiblesinglepossiblepossible
burstforbidden
Peripheralforbiddensinglepossibleforbidden
burstforbidden
Memory-to-memoryAHB peripheral portAHB memory portDMA onlyforbiddensingleforbiddenforbidden
burst

9.3.17 Stream configuration procedure

The following sequence should be followed to configure a DMA stream x (where x is the stream number):

  1. 1. If the stream is enabled, disable it by resetting the EN bit in the DMA_SxCR register, then read this bit in order to confirm that there is no ongoing stream operation. Writing this bit to 0 is not immediately effective since it is actually written to 0 once all the current transfers have finished. When the EN bit is read as 0, this means that the stream is ready to be configured. It is therefore necessary to wait for the EN bit to be cleared before starting any stream configuration. All the stream dedicated bits set in the status register (DMA_LISR and DMA_HISR) from the previous data block DMA transfer should be cleared before the stream can be re-enabled.
  2. 2. Set the peripheral port register address in the DMA_SxPAR register. The data are moved from/ to this address to/ from the peripheral port after the peripheral event.
  3. 3. Set the memory address in the DMA_SxMA0R register (and in the DMA_SxMA1R register in the case of a double buffer mode). The data are written to or read from this memory after the peripheral event.
  4. 4. Configure the total number of data items to be transferred in the DMA_SxNDTR register. After each peripheral event or each beat of the burst, this value is decremented.
  5. 5. Select the DMA channel (request) using CHSEL[2:0] in the DMA_SxCR register.
  6. 6. If the peripheral is intended to be the flow controller and if it supports this feature, set the PFCTRL bit in the DMA_SxCR register.
  7. 7. Configure the stream priority using the PL[1:0] bits in the DMA_SxCR register.
  8. 8. Configure the FIFO usage (enable or disable, threshold in transmission and reception)
  9. 9. Configure the data transfer direction, peripheral and memory incremented/fixed mode, single or burst transactions, peripheral and memory data widths, Circular mode,

Double buffer mode and interrupts after half and/or full transfer, and/or errors in the DMA_SxCR register.

  1. 10. Activate the stream by setting the EN bit in the DMA_SxCR register.

As soon as the stream is enabled, it can serve any DMA request from the peripheral connected to the stream.

Once half the data have been transferred on the AHB destination port, the half-transfer flag (HTIF) is set and an interrupt is generated if the half-transfer interrupt enable bit (HTIE) is set. At the end of the transfer, the transfer complete flag (TCIF) is set and an interrupt is generated if the transfer complete interrupt enable bit (TCIE) is set.


Warning: To switch off a peripheral connected to a DMA stream request, it is mandatory to, first, switch off the DMA stream to which the peripheral is connected, then to wait for EN bit = 0. Only then can the peripheral be safely disabled.


9.3.18 Error management

The DMA controller can detect the following errors:

In direct mode, the FIFO error flag can also be set under the following conditions:

If the TEIFx or the FEIFx flag is set due to incompatibility between burst size and FIFO threshold level, the faulty stream is automatically disabled through a hardware clear of its EN bit in the corresponding stream configuration register (DMA_SxCR).

If the DMEIFx or the FEIFx flag is set due to an overrun or underrun condition, the faulty stream is not automatically disabled and it is up to the software to disable or not the stream by resetting the EN bit in the DMA_SxCR register. This is because there is no data loss when this kind of errors occur.

When the stream's error interrupt flag (TEIF, FEIF, DMEIF) in the DMA_LISR or DMA_HISR register is set, an interrupt is generated if the corresponding interrupt enable bit (TEIE, FEIF, DMIE) in the DMA_SxCR or DMA_SxFCR register is set.

Note: When a FIFO overrun or underrun condition occurs, the data are not lost because the peripheral request is not acknowledged by the stream until the overrun or underrun condition is cleared. If this acknowledge takes too much time, the peripheral itself may detect an overrun or underrun condition of its internal buffer and data might be lost.

9.4 DMA interrupts

For each DMA stream, an interrupt can be produced on the following events:

Separate interrupt enable control bits are available for flexibility as shown in Table 36 .

Table 36. DMA interrupt requests

Interrupt eventEvent flagEnable control bit
Half-transferHTIFHTIE
Transfer completeTCIFTCIE
Transfer errorTEIFTEIE
FIFO overrun/underrunFEIFFEIE
Direct mode errorDMEIFDMEIE

Note: Before setting an Enable control bit to '1', the corresponding event flag should be cleared, otherwise an interrupt is immediately generated.

9.5 DMA registers

The DMA registers have to be accessed by words (32 bits).

9.5.1 DMA low interrupt status register (DMA_LISR)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedTCIF3HTIF3TEIF3DMEIF3ReservedFEIF3TCIF2HTIF2TEIF2DMEIF2ReservedFEIF2
rrrrrrrrrrrrrr
1514131211109876543210
ReservedTCIF1HTIF1TEIF1DMEIF1ReservedFEIF1TCIF0HTIF0TEIF0DMEIF0ReservedFEIF0
rrrrrrrrrrrrrr

Bits 31:28, 15:12 Reserved, must be kept at reset value.

Bits 27, 21, 11, 5 TCIFx : Stream x transfer complete interrupt flag (x = 3..0)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_LIFCR register.

0: No transfer complete event on stream x

1: A transfer complete event occurred on stream x

Bits 26, 20, 10, 4 HTIFx : Stream x half transfer interrupt flag (x=3..0)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_LIFCR register.

0: No half transfer event on stream x

1: A half transfer event occurred on stream x

Bits 25, 19, 9, 3 TEIFx : Stream x transfer error interrupt flag (x=3..0)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_LIFCR register.

0: No transfer error on stream x

1: A transfer error occurred on stream x

Bits 24, 18, 8, 2 DMEIFx : Stream x direct mode error interrupt flag (x=3..0)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_LIFCR register.

0: No Direct Mode Error on stream x

1: A Direct Mode Error occurred on stream x

Bits 23, 17, 7, 1 Reserved, must be kept at reset value.

Bits 22, 16, 6, 0 FEIFx : Stream x FIFO error interrupt flag (x=3..0)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_LIFCR register.

0: No FIFO Error event on stream x

1: A FIFO Error event occurred on stream x

9.5.2 DMA high interrupt status register (DMA_HISR)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedTCIF7HTIF7TEIF7DMEIF7ReservedFEIF7TCIF6HTIF6TEIF6DMEIF6ReservedFEIF6
rrrrrrrrrr
1514131211109876543210
ReservedTCIF5HTIF5TEIF5DMEIF5ReservedFEIF5TCIF4HTIF4TEIF4DMEIF4ReservedFEIF4
rrrrrrrrrr

Bits 31:28, 15:12 Reserved, must be kept at reset value.

Bits 27, 21, 11, 5 TCIFx : Stream x transfer complete interrupt flag (x=7..4)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_HIFCR register.

0: No transfer complete event on stream x

1: A transfer complete event occurred on stream x

Bits 26, 20, 10, 4 HTIFx : Stream x half transfer interrupt flag (x=7..4)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_HIFCR register.

0: No half transfer event on stream x

1: A half transfer event occurred on stream x

Bits 25, 19, 9, 3 TEIFx : Stream x transfer error interrupt flag (x=7..4)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_HIFCR register.

0: No transfer error on stream x

1: A transfer error occurred on stream x

Bits 24, 18, 8, 2 DMEIFx : Stream x direct mode error interrupt flag (x=7..4)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_HIFCR register.

0: No Direct mode error on stream x

1: A Direct mode error occurred on stream x

Bits 23, 17, 7, 1 Reserved, must be kept at reset value.

Bits 22, 16, 6, 0 FEIFx : Stream x FIFO error interrupt flag (x=7..4)

This bit is set by hardware. It is cleared by software writing 1 to the corresponding bit in the DMA_HIFCR register.

0: No FIFO error event on stream x

1: A FIFO error event occurred on stream x

9.5.3 DMA low interrupt flag clear register (DMA_LIFCR)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedCTCIF3CHTIF3CTEIF3CDMEIF3ReservedCFEIF3CTCIF2CHTIF2CTEIF2CDMEIF2ReservedCFEIF2
wwwwwwwwww
1514131211109876543210
ReservedCTCIF1CHTIF1CTEIF1CDMEIF1ReservedCFEIF1CTCIF0CHTIF0CTEIF0CDMEIF0ReservedCFEIF0
wwwwwwwwww

Bits 31:28, 15:12 Reserved, must be kept at reset value.

Bits 27, 21, 11, 5 CTCIFx : Stream x clear transfer complete interrupt flag (x = 3..0)

Writing 1 to this bit clears the corresponding TCIFx flag in the DMA_LISR register

Bits 26, 20, 10, 4 CHTIFx : Stream x clear half transfer interrupt flag (x = 3..0)

Writing 1 to this bit clears the corresponding HTIFx flag in the DMA_LISR register

Bits 25, 19, 9, 3 CTEIFx : Stream x clear transfer error interrupt flag (x = 3..0)

Writing 1 to this bit clears the corresponding TEIFx flag in the DMA_LISR register

Bits 24, 18, 8, 2 CDMEIFx : Stream x clear direct mode error interrupt flag (x = 3..0)

Writing 1 to this bit clears the corresponding DMEIFx flag in the DMA_LISR register

Bits 23, 17, 7, 1 Reserved, must be kept at reset value.

Bits 22, 16, 6, 0 CFEIFx : Stream x clear FIFO error interrupt flag (x = 3..0)

Writing 1 to this bit clears the corresponding CFEIFx flag in the DMA_LISR register

9.5.4 DMA high interrupt flag clear register (DMA_HIFCR)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedCTCIF7CHTIF7CTEIF7CDMEIF7ReservedCFEIF7CTCIF6CHTIF6CTEIF6CDMEIF6ReservedCFEIF6
wwwwwwwwww
1514131211109876543210
ReservedCTCIF5CHTIF5CTEIF5CDMEIF5ReservedCFEIF5CTCIF4CHTIF4CTEIF4CDMEIF4ReservedCFEIF4
wwwwwwwwww

Bits 31:28, 15:12 Reserved, must be kept at reset value.

Bits 27, 21, 11, 5 CTCIFx : Stream x clear transfer complete interrupt flag (x = 7..4)

Writing 1 to this bit clears the corresponding TCIFx flag in the DMA_HISR register

Bits 26, 20, 10, 4 CHTIFx : Stream x clear half transfer interrupt flag (x = 7..4)

Writing 1 to this bit clears the corresponding HTIFx flag in the DMA_HISR register

Bits 25, 19, 9, 3 CTEIFx : Stream x clear transfer error interrupt flag (x = 7..4)

Writing 1 to this bit clears the corresponding TEIFx flag in the DMA_HISR register

Bits 24, 18, 8, 2 CDMEIFx : Stream x clear direct mode error interrupt flag (x = 7..4)

Writing 1 to this bit clears the corresponding DMEIFx flag in the DMA_HISR register

Bits 23, 17, 7, 1 Reserved, must be kept at reset value.

Bits 22, 16, 6, 0 CFEIFx : Stream x clear FIFO error interrupt flag (x = 7..4)

Writing 1 to this bit clears the corresponding CFEIFx flag in the DMA_HISR register

9.5.5 DMA stream x configuration register (DMA_SxCR) (x = 0..7)

This register is used to configure the concerned stream.

Address offset: 0x10 + 0x18 × stream number

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedCHSEL[2:0]MBURST [1:0]PBURST[1:0]Reser-
ved
CTDBMPL[1:0]
rwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
PINCOSMSIZE[1:0]PSIZE[1:0]MINCPINCCIRCDIR[1:0]PFCTRLTCIEHTIETEIEDMEIEEN
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:28 Reserved, must be kept at reset value.

Bits 27:25 CHSEL[2:0] : Channel selection

These bits are set and cleared by software.

000: channel 0 selected

001: channel 1 selected

010: channel 2 selected

011: channel 3 selected

100: channel 4 selected

101: channel 5 selected

110: channel 6 selected

111: channel 7 selected

These bits are protected and can be written only if EN is '0'

Bits 24:23 MBURST : Memory burst transfer configuration

These bits are set and cleared by software.

00: single transfer

01: INCR4 (incremental burst of 4 beats)

10: INCR8 (incremental burst of 8 beats)

11: INCR16 (incremental burst of 16 beats)

These bits are protected and can be written only if EN is '0'

In direct mode, these bits are forced to 0x0 by hardware as soon as bit EN='1'.

Bits 22:21 PBURST[1:0] : Peripheral burst transfer configuration

These bits are set and cleared by software.

00: single transfer

01: INCR4 (incremental burst of 4 beats)

10: INCR8 (incremental burst of 8 beats)

11: INCR16 (incremental burst of 16 beats)

These bits are protected and can be written only if EN is '0'

In direct mode, these bits are forced to 0x0 by hardware.

Bit 20 Reserved, must be kept at reset value.

Bit 19 CT : Current target (only in double buffer mode)

This bit is set and cleared by hardware. It can also be written by software.

0: The current target memory is Memory 0 (addressed by the DMA_SxM0AR pointer)

1: The current target memory is Memory 1 (addressed by the DMA_SxM1AR pointer)

This bit can be written only if EN is '0' to indicate the target memory area of the first transfer.

Once the stream is enabled, this bit operates as a status flag indicating which memory area is the current target.

Bit 18 DBM : Double buffer mode

This bit is set and cleared by software.

0: No buffer switching at the end of transfer

1: Memory target switched at the end of the DMA transfer

This bit is protected and can be written only if EN is '0'.

Bits 17:16 PL[1:0] : Priority level

These bits are set and cleared by software.

00: Low

01: Medium

10: High

11: Very high

These bits are protected and can be written only if EN is '0'.

Bit 15 PINCOS : Peripheral increment offset size

This bit is set and cleared by software

0: The offset size for the peripheral address calculation is linked to the PSIZE

1: The offset size for the peripheral address calculation is fixed to 4 (32-bit alignment).

This bit has no meaning if bit PINC = '0'.

This bit is protected and can be written only if EN = '0'.

This bit is forced low by hardware when the stream is enabled (bit EN = '1') if the direct mode is selected or if PBURST are different from "00".

Bits 14:13 MSIZE[1:0] : Memory data size

These bits are set and cleared by software.

00: byte (8-bit)

01: half-word (16-bit)

10: word (32-bit)

11: reserved

These bits are protected and can be written only if EN is '0'.

In direct mode, MSIZE is forced by hardware to the same value as PSIZE as soon as bit EN = '1'.

Bits 12:11 PSIZE[1:0] : Peripheral data size

These bits are set and cleared by software.

00: Byte (8-bit)

01: Half-word (16-bit)

10: Word (32-bit)

11: reserved

These bits are protected and can be written only if EN is '0'

Bit 10 MINC : Memory increment mode

This bit is set and cleared by software.

0: Memory address pointer is fixed

1: Memory address pointer is incremented after each data transfer (increment is done according to MSIZE)

This bit is protected and can be written only if EN is '0'.

Bit 9 PINC: Peripheral increment mode

This bit is set and cleared by software.

0: Peripheral address pointer is fixed

1: Peripheral address pointer is incremented after each data transfer (increment is done according to PSIZE)

This bit is protected and can be written only if EN is '0'.

Bit 8 CIRC: Circular mode

This bit is set and cleared by software and can be cleared by hardware.

0: Circular mode disabled

1: Circular mode enabled

When the peripheral is the flow controller (bit PFCTRL=1) and the stream is enabled (bit EN=1), then this bit is automatically forced by hardware to 0.

It is automatically forced by hardware to 1 if the DBM bit is set, as soon as the stream is enabled (bit EN ='1').

Bits 7:6 DIR[1:0]: Data transfer direction

These bits are set and cleared by software.

00: Peripheral-to-memory

01: Memory-to-peripheral

10: Memory-to-memory

11: reserved

These bits are protected and can be written only if EN is '0'.

Bit 5 PFCTRL: Peripheral flow controller

This bit is set and cleared by software.

0: The DMA is the flow controller

1: The peripheral is the flow controller

This bit is protected and can be written only if EN is '0'.

When the memory-to-memory mode is selected (bits DIR[1:0]=10), then this bit is automatically forced to 0 by hardware.

Bit 4 TCIE: Transfer complete interrupt enable

This bit is set and cleared by software.

0: TC interrupt disabled

1: TC interrupt enabled

Bit 3 HTIE: Half transfer interrupt enable

This bit is set and cleared by software.

0: HT interrupt disabled

1: HT interrupt enabled

Bit 2 TEIE: Transfer error interrupt enable

This bit is set and cleared by software.

0: TE interrupt disabled

1: TE interrupt enabled

Bit 1 DMEIE: Direct mode error interrupt enable

This bit is set and cleared by software.

0: DME interrupt disabled

1: DME interrupt enabled

Bit 0 EN : Stream enable / flag stream ready when read low

This bit is set and cleared by software.

0: Stream disabled

1: Stream enabled

This bit may be cleared by hardware:

When this bit is read as 0, the software is allowed to program the Configuration and FIFO bits registers. It is forbidden to write these registers when the EN bit is read as 1.

Note: Before setting EN bit to '1' to start a new transfer, the event flags corresponding to the stream in DMA_LISR or DMA_HISR register must be cleared.

9.5.6 DMA stream x number of data register (DMA_SxNDTR) (x = 0..7)

Address offset: \( 0x14 + 0x18 \times \text{stream number} \)

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
NDT[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 NDT[15:0] : Number of data items to transfer

Number of data items to be transferred (0 up to 65535). This register can be written only when the stream is disabled. When the stream is enabled, this register is read-only, indicating the remaining data items to be transmitted. This register decrements after each DMA transfer.

Once the transfer has completed, this register can either stay at zero (when the stream is in normal mode) or be reloaded automatically with the previously programmed value in the following cases:

If the value of this register is zero, no transaction can be served even if the stream is enabled.

9.5.7 DMA stream x peripheral address register (DMA_SxPAR) (x = 0..7)

Address offset: \( 0x18 + 0x18 \times \text{stream number} \)

Reset value: 0x0000 0000

31302928272625242322212019181716
PAR[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
PAR[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 PAR[31:0] : Peripheral address

Base address of the peripheral data register from/to which the data are read/written.

These bits are write-protected and can be written only when bit EN = '0' in the DMA_SxCR register.

9.5.8 DMA stream x memory 0 address register (DMA_SxM0AR) (x = 0..7)

Address offset: \( 0x1C + 0x18 \times \text{stream number} \)

Reset value: 0x0000 0000

31302928272625242322212019181716
M0A[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
M0A[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 M0A[31:0] : Memory 0 address

Base address of Memory area 0 from/to which the data are read/written.

These bits are write-protected. They can be written only if:

9.5.9 DMA stream x memory 1 address register (DMA_SxM1AR) (x = 0..7)

Address offset: \( 0x20 + 0x18 \times \text{stream number} \)

Reset value: 0x0000 0000

31302928272625242322212019181716
M1A[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
M1A[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 M1A[31:0] : Memory 1 address (used in case of Double buffer mode)

Base address of Memory area 1 from/to which the data are read/written.

This register is used only for the Double buffer mode.

These bits are write-protected. They can be written only if:

9.5.10 DMA stream x FIFO control register (DMA_SxFCR) (x = 0..7)

Address offset: 0x24 + 0x18 × stream number

Reset value: 0x0000 0021

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedFEIEReser
ved
FS[2:0]DMDISFTH[1:0]
rwrrrrwrwrw

Bits 31:8 Reserved, must be kept at reset value.

Bit 7 FEIE : FIFO error interrupt enable

This bit is set and cleared by software.

0: FE interrupt disabled

1: FE interrupt enabled

Bit 6 Reserved, must be kept at reset value.

Bits 5:3 FS[2:0]: FIFO status

These bits are read-only.

000: \( 0 < \text{fifo\_level} < 1/4 \)

001: \( 1/4 \leq \text{fifo\_level} < 1/2 \)

010: \( 1/2 \leq \text{fifo\_level} < 3/4 \)

011: \( 3/4 \leq \text{fifo\_level} < \text{full} \)

100: FIFO is empty

101: FIFO is full

others: no meaning

These bits are not relevant in the direct mode (DMDIS bit is zero).

Bit 2 DMDIS: Direct mode disable

This bit is set and cleared by software. It can be set by hardware.

0: Direct mode enabled

1: Direct mode disabled

This bit is protected and can be written only if EN is '0'.

This bit is set by hardware if the memory-to-memory mode is selected (DIR bit in DMA_SxCR are "10") and the EN bit in the DMA_SxCR register is '1' because the direct mode is not allowed in the memory-to-memory configuration.

Bits 1:0 FTH[1:0]: FIFO threshold selection

These bits are set and cleared by software.

00: 1/4 full FIFO

01: 1/2 full FIFO

10: 3/4 full FIFO

11: full FIFO

These bits are not used in the direct mode when the DMIS value is zero.

These bits are protected and can be written only if EN is '0'.

9.5.11 DMA register map

Table 37 summarizes the DMA registers.

Table 37. DMA register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x0000DMA_LISRReservedTCIF3HTIF3TEIF3DMEIF3ReservedFEIF3TCIF2HTIF2TEIF2DMEIF2ReservedReservedTCIF1HTIF1TEIF1DMEIF1ReservedFEIF1TCIF0HTIF0TEIF0DMEIF0ReservedFEIF0
Reset value0000000000000000000
0x0004DMA_HISRReservedTCIF7HTIF7TEIF7DMEIF7ReservedFEIF7TCIF6HTIF6TEIF6DMEIF6ReservedReservedTCIF5HTIF5TEIF5DMEIF5ReservedFEIF5TCIF4HTIF4TEIF4DMEIF4ReservedFEIF4
Reset value0000000000000000000
0x0008DMA_LIFCRReservedCTCIF3CHTF3TEIF3CDMEIF3ReservedCFEIF3CTCIF2CHTF2CTEIF2CDMEIF2ReservedReservedCTCIF1CHTF1CTEIF1CDMEIF1ReservedCFEIF1CTCIF0CHTF0CTEIF0CDMEIF0ReservedCFEIF0
Reset value0000000000000000000
0x000CDMA_HIFCRReservedCTCIF7CHTF7CTEIF7CDMEIF7ReservedCFEIF7CTCIF6CHTF6CTEIF6CDMEIF6ReservedReservedCTCIF5CHTF5CTEIF5CDMEIF5ReservedCFEIF5CTCIF4CHTF4CTEIF4CDMEIF4ReservedCFEIF4
Reset value0000000000000000000
0x0010DMA_S0CRReservedCHSEL[2:0]MBURST[1:0]PBURST[1:0]ReservedCTDBMPL[1:0]PINCOSMSIZE[1:0]PSIZE[1:0]MINCPINCCIRCDIR[1:0]PFCTRLTCIEHTIETEIEDMEIEEN
Reset value0000000000000000000000000
0x0014DMA_S0NDTRReservedNDT[15:]
Reset value0
0x0018DMA_S0PARPA[31:0]
Reset value
0x001CDMA_S0M0ARM0A[31:0]
Reset value
0x0020DMA_S0M1ARM1A[31:0]
Reset value
0x0024DMA_S0FCRReservedFEIEReservedFS[2:0]DMDISFTH[1:0]
Reset value010001
0x0028DMA_S1CRReservedCHSEL[2:0]MBURST[1:0]PBURST[1:0]ReservedCTDBMPL[1:0]PINCOSMSIZE[1:0]PSIZE[1:0]MINCPINCCIRCDIR[1:0]PFCTRLTCIEHTIETEIEDMEIEEN
Reset value0000000000000000000000000
0x002CDMA_S1NDTRReservedNDT[15:]
Reset value0
Table 37. DMA register map and reset values (continued)
OffsetRegister313029282726252423222120191817161514131211109876543210
0x0030DMA_S1PARPA[31:0]
Reset value00000000000000000000000000000000
0x0034DMA_S1M0ARM0A[31:0]
Reset value00000000000000000000000000000000
0x0038DMA_S1M1ARM1A[31:0]
Reset value00000000000000000000000000000000
0x003CDMA_S1FCRReservedFEIEReservedFS[2:0]DMDISFTH [1:0]
Reset value0100001
0x0040DMA_S2CRReservedCHSEL [2:0]MBURST[1:0]PBURST[1:0]ReservedCTDBMPL[1:0]PINCOSMSIZE[1:0]PSIZE[1:0]MINCPINCCIRCDIR [1:0]PFCTRLTCIEHTIETEIEDMEIEEN
Reset value000000000000000000000000000
0x0044DMA_S2NDTRReservedNDT[15:0]
Reset value0000000000000000
0x0048DMA_S2PARPA[31:0]
Reset value00000000000000000000000000000000
0x004CDMA_S2M0ARM0A[31:0]
Reset value00000000000000000000000000000000
0x0050DMA_S2M1ARM1A[31:0]
Reset value00000000000000000000000000000000
0x0054DMA_S2FCRReservedFEIEReservedFS[2:0]DMDISFTH [1:0]
Reset value0100001
0x0058DMA_S3CRReservedCHSEL[2:0]MBURST[1:0]PBURST[1:0]ReservedCTDBMPL[1:0]PINCOSMSIZE[1:0]PSIZE[1:0]MINCPINCCIRCDIR[1:0]PFCTRLTCIEHTIETEIEDMEIEEN
Reset value000000000000000000000000000
0x005CDMA_S3NDTRReservedNDT[15:0]
Reset value0000000000000000
0x0060DMA_S3PARPA[31:0]
Reset value00000000000000000000000000000000
0x0064DMA_S3M0ARM0A[31:0]
Reset value00000000000000000000000000000000

Table 37. DMA register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0x0068DMA_S3M1ARM1A[31:0]
Reset value00000000000000000000000000000000
0x006CDMA_S3FCRReservedFEIEReservedFS[2:0]DMDISFTH [1:0]
Reset value0100001
0x0070DMA_S4CRReservedCHSEL[2:0]MBURST[1:0]PBURST[1:0]ReservedCTDBMPL[1:0]PINCOSMSIZE[1:0]PSIZE[1:0]MINCPINCCIRCDIR[1:0]PFCTRLTCIEHTIETEIEDMEIEEN
Reset value000000000000000000000000000
0x0074DMA_S4NDTRReservedNDT[15:0]
Reset value0000000000000000
0x0078DMA_S4PARPA[31:0]
Reset value00000000000000000000000000000000
0x007CDMA_S4M0ARM0A[31:0]
Reset value00000000000000000000000000000000
0x0080DMA_S4M1ARM1A[31:0]
Reset value00000000000000000000000000000000
0x0084DMA_S4FCRReservedFEIEReservedFS[2:0]DMDISFTH [1:0]
Reset value0100001
0x0088DMA_S5CRReservedCHSEL[2:0]MBURST[1:0]PBURST[1:0]ReservedCTDBMPL[1:0]PINCOSMSIZE[1:0]PSIZE[1:0]MINCPINCCIRCDIR[1:0]PFCTRLTCIEHTIETEIEDMEIEEN
Reset value000000000000000000000000000
0x008CDMA_S5NDTRReservedNDT[15:0]
Reset value0000000000000000
0x0090DMA_S5PARPA[31:0]
Reset value00000000000000000000000000000000
0x0094DMA_S5M0ARM0A[31:0]
Reset value00000000000000000000000000000000
0x0098DMA_S5M1ARM1A[31:0]
Reset value00000000000000000000000000000000
0x009CDMA_S5FCRReservedFEIEReservedFS[2:0]DMDISFTH [1:0]
Reset value0100001
0x00A0DMA_S6CRReservedCHSEL[2:0]MBURST[1:0]PBURST[1:0]ReservedCTDBMPL[1:0]PINCOSMSIZE[1:0]PSIZE[1:0]MINCPINCCIRCDIR[1:0]PFCTRLTCIEHTIETEIEDMEIEEN
Reset value000000000000000000000000000
0x00A4DMA_S6NDTRReservedNDT[15:0]
Reset value0000000000000000
0x00A8DMA_S6PARPA[31:0]
Reset value00000000000000000000000000000000

Table 37. DMA register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00ACDMA_S6M0ARM0A[31:0]
Reset value00000000000000000000000000000000
0x00B0DMA_S6M1ARM1A[31:0]
Reset value00000000000000000000000000000000
0x00B4DMA_S6FCRReservedFEIEReservedFS[2:0]DMDISFTH [1:0]
Reset value0
0x00B8DMA_S7CRReservedCHSEL[2:0]MBURST[1:0]PBURST[1:0]ReservedCTDBMPL[1:0]PINCOSMSIZE[1:0]PSIZE[1:0]MNCPINCCIRCDIR[1:0]PFCTRLTCIEHTIETEIEDMEIEEN
Reset value
0x00BCDMA_S7NDTRReserved
Reset value
0x00C0DMA_S7PARPA[31:0]
Reset value00000000000000000000000000000000
0x00C4DMA_S7M0ARM0A[31:0]
Reset value00000000000000000000000000000000
0x00C8DMA_S7M1ARM1A[31:0]
Reset value00000000000000000000000000000000
0x00CCDMA_S7FCRReservedFEIEReservedFS[2:0]DMDISFTH [1:0]
Reset value0
Refer to Section 2.3: Memory map for the register boundary addresses.