Skip to content

Fix synthio crashing ESP32-S2 and S3 boards when playing through I2S - #11967

Open
mikeysklar wants to merge 1 commit into
adafruit:mainfrom
mikeysklar:synthio-task-safe-blocks
Open

mikeysklar wants to merge 1 commit into
adafruit:mainfrom
mikeysklar:synthio-task-safe-blocks

Conversation

@mikeysklar

@mikeysklar mikeysklar commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

Synthio no longer crashes when I2S audio refills on its own task.

Why

Since #11923, a synthesizer playing through I2SOut hard faults right after play().

mp_iternext() checks the main task's stack, so on the fill task it raises.

Testing

Board 11.0.0-beta.0 this PR
Metro ESP32-S3 hard fault, 3 of 3 OK, 10 of 10
Metro ESP32-S2 hard fault, 3 of 3 OK, 10 of 10

Each run is a power-on, then a read of supervisor.runtime.safe_mode_reason. Five of the ten add synth.blocks.append(synthio.LFO(rate=2)).

import array, math, time
import board, audiobusio, audiomixer, synthio
SAMPLE_RATE = 88200
sine = array.array("h", [int(math.sin(2 * math.pi * i / 64) * 32767) for i in range(64)])
audio = audiobusio.I2SOut(bit_clock=board.D9, word_select=board.D10, data=board.D11)
mixer = audiomixer.Mixer(voice_count=1, channel_count=1, bits_per_sample=16,
                         samples_signed=True, sample_rate=SAMPLE_RATE, buffer_size=2048)
synth = synthio.Synthesizer(sample_rate=SAMPLE_RATE, waveform=sine)
audio.play(mixer)
mixer.voice[0].play(synth)
while True:
    time.sleep(0.1)

Listened on a Metro ESP32-P4 with a MAX98357 amp at 20% volume, 44100 Hz: a clean synthio tone, no fault.

🤖 Generated with Claude Code

adafruit#11923 moved Espressif I2S refill to its own task. A Synthesizer refill
steps its blocks with mp_iternext(), which starts with mp_cstack_check().
That check measures against the main task stack, so on the fill task it
raises RecursionError, and the jump back onto the main task's stack
faults. Reading the list directly has no stack check.

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.

1 participant