Skip to content

STM32 SAI DMA: copy whole runs of frames, larger halves and queue - #9

Merged
JohnAmadis merged 1 commit into
mainfrom
perf/bulk-copy
Oct 11, 2026
Merged

JohnAmadis merged 1 commit into
mainfrom
perf/bulk-copy

Conversation

@JaxCalder

Copy link
Copy Markdown
Contributor

Summary

In the STM32 SAI DMA, the writer and the interrupt worked one frame at a time, with atomics on every frame:

  • Writer: copies as many frames as fit and moves tx_head once.
  • Interrupt: refills a half buffer with one or two memcpy() calls from the queue (two when the queue wraps) and moves tx_tail once. Underruns are counted as before.
  • Half buffer: 64 → 128 frames, so at 48 kHz there is an interrupt every 2.7 ms instead of every 1.3 ms. The DMA buffer comes from the small dma heap: 4 KB for 4 TDM slots.
  • Queue: 256 → 1024 frames (21 ms, from the ordinary heap). A mixer's 10 ms period (480 frames) now fits, so its writer is woken a few times per period instead of on every half.

Part of bringing dmaudio on the STM32F746G-DISCO from ~45 % to ~10 % of the CPU (see choco-technologies/dmaudio, choco-technologies/dmwm8994, choco-technologies/dmdevfs).

Test plan

  • Builds for stm32f7
  • STM32F746G-DISCO: MP3 playback through dmaudio → dmwm8994 → dmsai

🤖 Generated with Claude Code

The writer copies as many frames as there is room for and moves the head
once; the interrupt refills a half with one or two memcpy() of the queue
and moves the tail once - instead of a pass with atomics per frame. A half
is 128 frames (an interrupt every 2.7 ms at 48 kHz, not 1.3 ms), the queue
1024 (21 ms): a mixer's 10 ms period fits, so its writer is woken a few
times per period instead of every half.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JohnAmadis
JohnAmadis merged commit ee3213b into main Oct 11, 2026
3 checks passed
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.

2 participants