UAC: take each packet in the USB interrupt, so a busy interpreter no longer costs packets (#39) - #47
Merged
Merged
Conversation
…y interpreter no longer costs packets (usbif#39)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #39 on the ESP32-P4. With the interpreter busy, the P4 sound card now gets the whole stream, and the steady tick under the music is gone.
Needs micropython-pydevices#21; merge that first. It gives TinyUSB 0.21 to the P4 only. The S2 and S3 stay on 0.18 for now (#48). There this change builds and behaves as before, so an S3 sound card still ticks under load. That remainder lives in #48.
What changed
tud_audio_rx_done_isr(), and TinyUSB has already re-armed the endpoint by the time it runs. On older TinyUSB it's stilltud_audio_rx_done_post_read_cb(). Either way it does only ISR-safe work: two counters, a FIFO level read and a task notification. No MicroPython, no FIFO reads, nothing that blocks.usbif_pump_notify()checks where it's called from. From the ISR it usesvTaskNotifyGiveFromISR+portYIELD_FROM_ISR; from a task (rate change, stop) it usesxTaskNotifyGive.uac_stats()still counts overflows (FIFO above three-quarters with no pump).TUD_AUDIO_EP_SIZEtook a speed argument in 0.20; a small wrapper keeps both versions building.Evidence
This was on the P4 panel, using
tests/hardware/uac_stream_check.pyplusuac_play_tone.pyfrom Windows WASAPI, with a 440 Hz sine, 10 s windows and at least 80 s per run. The board volume was 30 %.soundcard.pyThe checker failed on the old build (every window below the 99.5 % gate) and passes on the new one. At 44.1 kHz the pump still times out 7 or 8 times per 10 s, which is #40 (no feedback), unchanged.
Also on the 0.21 image:
Both TinyUSB versions, one source (2026-09-25)
Both boards ran images from this branch (b7ee671; the later commit only touches the README) on micropython-pydevices#21's per-target overlay, with a quiet 440 Hz tone over WASAPI, 48 kHz shared.
v0.21.0.1-micropython1)tud_audio_rx_done_isrtud_audio_rx_done_post_read_cbtud_audio_rx_done_post_read_cbv0.21.0.1-micropython1tud_audio_rx_done_isrThe version guards pick the right callback,
TUD_AUDIO_EP_SIZEform and high-speed interval on each: both builds compile, and the link maps name the hook shown. On the T-Embed the pitch at I2S read 440.0 in a mono run; the checker's tap only reads a mono sink. On 0.18 under load the T-Embed's CDC console also went silent to the host, so its busy runs logged to a file on the board.