pico-sdk icon indicating copy to clipboard operation
pico-sdk copied to clipboard

Aborting multiple DMA transfers simultaneously

Open neuschaefer opened this issue 1 year ago • 0 comments

Background

Suppose we have two DMA channels, 0 and 1, streaming data to a peripheral. Each one chains to the other, to generate gapless streaming without CPU involvement.

Occasionally, the software wants to start a third DMA channel (2) to transmit other data. To avoid interference of channels 0/1, it first has to abort them:

dma_channel_abort(0);
dma_channel_abort(1);

dma_channel_set_read_addr(2, buffer, false);   // transmit a buffer full of data
dma_channel_set_trans_count(2, size, true);    // and go!

This would have the desired effect most of the time: Either channel 0 or 1 was running, and it's now stopped. But occasionally, this would not work:

  channel 0:        channel 1:           CPU:
   (stopped)         (running)            
                                         abort 0 (no effect)
                      finish
    start               
                                         abort 1 (no effect)

Request

To deal with such situations, it would be nice to have a function in pico-sdk that reliably aborts multiple DMA channels that may chain to each other.

See also

  • https://github.com/raspberrypi/pico-sdk/issues/923

neuschaefer avatar Feb 27 '24 13:02 neuschaefer