Repository navigation
max3421e: don't run tuh_task() while the shared SPI bus is held - #11695
Merged
Merged
Conversation
tuh_max3421_spi_cs_api() can't wait for a bus that other code holds, so it skips the transfer. TinyUSB then acts on register values it never read; a dropped transfer start leaves busy_lock set with no transfer-done interrupt to clear it, and the host stalls until reset. usb_background() now checks max3421e_spi_busy() first and reschedules itself when the bus is held, so tuh_task() only runs when its transfers can go through. Fixes adafruit#11692 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
|
I moved some hardware around to free up a Feather doubler and I'm running some tests just to be safe. Will get back to you this afternoon. |
mikeysklar
approved these changes
Oct 30, 2026
mikeysklar
left a comment
Collaborator
There was a problem hiding this comment.
Tested this PR and its parent on a Feather RP2350 with real SD reads.
| Build | Test | Stuck until reset |
|---|---|---|
| Parent | Host alone | 0/2 |
| Parent | Real SD | 10/10 |
| Parent | SPI load | 2/5 |
| PR | Host alone | 0/2 |
| PR | Real SD | 0/10 |
| PR | SPI load | 0/5 |
No hard fault. Not tested with SD-over-USB on, or on other ports.
This was referenced Oct 30, 2026
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 #11692.
tuh_max3421_spi_cs_api()can't wait for an SPI bus that other code holds, so it skips the transfer silently. TinyUSB then acts on register values it never read. When the dropped write is the one that starts a transfer,busy_lockstays set with no transfer-done interrupt to clear it, and the host stalls until reset. Python code, a display refresh or an SD card read can all run background tasks while holding the bus, sotuh_task()can run at any of those times.This adds
max3421e_spi_busy(), which try-locks the MAX3421E's bus and releases it again.usb_background()checks it beforetuh_task(), and when the bus is held it reschedules itself instead, so the host task only runs when its transfers can go through. Boards withoutCIRCUITPY_MAX3421Eare unchanged.Testing:
board.SPI()with an HX8357 TFT and an SD card, enumerating and flashing a USB MIDI device over many runs.🤖 Generated with Claude Code