Skip to content

Audio related DMA cleanup#7274

Open
SchrodiL wants to merge 1 commit intoEdgeTX:mainfrom
SchrodiL:audio-dma-cleanup
Open

Audio related DMA cleanup#7274
SchrodiL wants to merge 1 commit intoEdgeTX:mainfrom
SchrodiL:audio-dma-cleanup

Conversation

@SchrodiL
Copy link
Copy Markdown

@SchrodiL SchrodiL commented Apr 7, 2026

This pull request introduces improvements to the DMA (Direct Memory Access) handling for audio output on STM32 platforms, focusing on more robust detection of buffer underruns and safer stopping of the DMA stream. The main goal is to reduce unnecessary start/stop cycles (thrashing) when the audio producer briefly lags, and to ensure DMA flags are properly managed for reliable operation.

DMA underrun detection and handling:

  • Added a counter (_empty_dma_halves) and a threshold (DMA_EMPTY_HALVES_STOP_THRESHOLD) to require sustained silence (multiple empty DMA buffer halves) before stopping the DMA stream, preventing rapid start/stop cycles when the audio buffer briefly runs out of data. [1] [2]
  • The DMA interrupt handler now increments _empty_dma_halves only when buffer underruns are detected, and resets it when new data is available. DMA is only stopped when the threshold is reached. [1] [2]

DMA flag management and stream control:

  • Introduced dac_clear_dma_flags() to clear any stale DMA half/complete transfer flags before starting or after stopping a DMA transfer, ensuring the DMA state machine operates from a clean slate.
  • Modified dac_close_dma_xfer() to wait for the DMA enable bit to clear and then reset DMA flags, improving robustness when stopping the stream.
  • Updated dac_start_dma() to clear DMA flags before enabling the stream and interrupts, preventing spurious interrupts from previous transfers.

These changes should make audio playback more resilient to brief underruns and improve the reliability of DMA operations.

@raphaelcoeffic raphaelcoeffic self-requested a review April 7, 2026 17:10
@SchrodiL
Copy link
Copy Markdown
Author

SchrodiL commented Apr 8, 2026

Related to #7227
It completely fixes the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant