Skip to content

Fix garbled I2S audio on the ESP32-P4 - #11875

Open
mikeysklar wants to merge 1 commit into
adafruit:mainfrom
mikeysklar:espressif-p4-i2s-cache-sync
Open

mikeysklar wants to merge 1 commit into
adafruit:mainfrom
mikeysklar:espressif-p4-i2s-cache-sync

Conversation

@mikeysklar

Copy link
Copy Markdown
Collaborator

What

Fix garbled I2S audio on ESP32-P4 boards.

Why

The P4 caches internal RAM, so the DMA sometimes played old samples.

Fixes #11873

Tested

Board Metro ESP32-P4 (chip rev v0.1), MAX98357 on A0, A1, A2
Code the tone, MP3 and WAV examples from #11873
By ear clean with this branch
Also built Metro ESP32-S3, where the change compiles out

Pin loopback

I2S1 RX reading the TX pins while playing slow.mp3, on a debug build with the write-back switchable.

Run Write-back Stale blocks
1 on 0
2 off 392
3 on 0

Not tested: other P4 boards.

AI assistance: Claude helped find and write this. I checked the fix by ear and with the loopback captures.

🤖 Generated with Claude Code

On the ESP32-P4 internal RAM is reached through the L1 cache. IDF writes
the DMA buffer back right after the on_sent callback, but audiobusio
fills the buffer later from a background callback, so the new samples
can sit in the cache while the DMA plays the buffer's old contents.
MP3 playback through I2SOut came out garbled.

Write the buffer back after each fill. Only chips that cache internal
RAM (SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE) compile it in.

Measured on a Metro ESP32-P4 with an on-chip loopback (I2S1 RX reading
the TX pins), slow.mp3, three runs: 0, 392, 0 stale blocks with the
write-back on, off, on.

Fixes adafruit#11873

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

I2S audio playback is garbled for tone and mp3 playback on Metro ESP32-P4

2 participants