STM32 gotchas
240. Don't disable DMA request at source in dual-port DMA

In the dual-port DMA (as found in 'F2/'F4/'F7 and as general-purpose DMA in 'H7 1), when a request (trigger) arrives to some of its Streams from the peripheral to which it is configured (by setting its Channel number in DMA_SxCR.CHSEL), DMA performs a sequence of operations:

Experimental evidence suggests, that if the request is removed during this process 3 - for example, if in case of timer-triggered transfer, the relevant TIMx_DIER.xxDE bit is cleared - the results are unpredictible and sometimes fatal, such as a Stream which simply gets stuck and unresponsive. This is probably due to the fact, that the request is not latched inside the DMA for the whole duration of arbitration and transfer, and removing it before the transfer is finished simply leaves the Stream's logic in an unexpected state.

So, Streams in the dual-port DMA cannot be "suspended" by disabling the request source (unless there is some comprehensive software mechanism which ensures that under no circumstances such request is disabled amidst an already ongoing transfer, but that in most of the cases is simply unfeasible or straight impossible).

After disabling a Stream by clearing its respective DMA_SxCR.EN, a built-in hardware mechanism ensures that ongoing transfers are finished and in the peripheral-to-memory case FIFO is flushed before hardware signals back by clearing the read DMA_SxCR.EN bit (and also, somewhat surprisingly but documentedly, by setting the transfer-complete status flag). Only after that may the request source be disabled. However, transfers on such disabled Stream cannot be resumed, as the internal address pointers/indexes are not preserved and upon restarting transfers begin at the beginning of memory buffers.

Some of the reports of this problem here and here.


1. Dual-port DMA is described in AN4031.

2. In case of memory-to-peripheral transfer, the memory-to-buffer transfer occurs before the trigger from peripheral arrives, the first transfer occurring as soon as the given Stream is enabled. If a request arrives before the buffer is filled, a FIFO underrun occurs and FIFO error is generated (even in Direct mode, i.e. when FIFO is not used), but DMA continues to operate.

3. More precisely, presumably, only duration of the peripheral-side arbitration and transfer is critical, as the memory-side arbitration and transfer is triggered by FIFO content being above/below threshold, depending on direction.