Repository navigation
arch/arm/src/common/stm32: Bound SDIO command response wait by time. - #19793
Merged
xiaoxiang781216 merged 1 commit intoAug 12, 2026
Merged
Conversation
stm32_waitresponse() polls SDIO_STA bounded only by an iteration counter, set to 0x7fffffff for all R1/R1B/R2/R4/R5/R6 commands. The hardware CTIMEOUT flag is the intended exit for a missing response, but it is only generated while the card clock is running and the CPSM has reached its Wait state. If the card clock stops or the peripheral fails, SDIO_STA never updates and the loop spins for INT32_MAX iterations while holding the FAT filesystem lock, at the caller's priority-inheritance boosted priority if higher priority tasks block on the filesystem. Since the mmcsd layer retries failed commands, the driver's recovery paths are never reached and the system never recovers. Bound the wait by time instead: 250 ms for response-bearing commands (the largest timeout the SD specification allows for any operation) and 10 ms for the no-response/R3/R7 cases. CTIMEOUT remains the normal error exit within microseconds; the software bound only fires when the peripheral itself is dead, converting an unbounded spin into -ETIMEDOUT so the existing mmcsd retry logic can run. Signed-off-by: Luka Filipović <[email protected]> Assisted-by: Claude Code:claude-fable-5
Luka-Filipovic
requested review from
antmerlino,
davids5 and
xiaoxiang781216
as code owners
August 11, 2026 12:34
acassis
approved these changes
Aug 11, 2026
xiaoxiang781216
approved these changes
Aug 12, 2026
Contributor
Author
|
Thanks for reviewing and merging, but have in mind that:
I can make a new PR that includes these as well if you see a need. |
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.
Summary
Potential fix for #19792.
stm32_waitresponse()inarch/arm/src/common/stm32/stm32_sdio_m3m4_v1.cpolls
SDIO_STAin a busy loop bounded only by an iteration count(
SDIO_LONGTIMEOUT=0x7ffffffffor response-bearing commands). Thehardware
CTIMEOUTflag normally ends the wait within microseconds, but itis only generated while the card clock is running and the command state
machine is in its Wait state. If the peripheral gets into a bad state,
SDIO_STAnever changes and the loop spins for minutes at 100% CPU whileholding the FAT semaphore. With
CONFIG_PRIORITY_INHERITANCE=ythespinning thread inherits the priority of the highest waiter blocked on the
filesystem, starving every task at or below that priority (details in
#19792).
Bound the wait by time instead: 250 ms for response-bearing commands (the
same value #3669 used for the F7/H7 data path timeout) and 10 ms for the
no-response/R3/R7 cases.
CTIMEOUTremains the normal exit; the softwarebound only fires when the peripheral is stuck, and returns
-ETIMEDOUTsothe existing mmcsd error handling can run.
The same pattern exists in
stm32f7/stm32_sdmmc.c,stm32h7/stm32_sdmmc.c,at32/at32_sdio.candgd32f4/gd32f4xx_sdio.c.Impact
CMDREND/CCRCFAIL/CTIMEOUTwithin microseconds.-ETIMEDOUTafter 250 ms instead of anunbounded spin (previously CPU-frequency dependent, ~2.5 minutes at
168 MHz).
SDIO_CMDTIMEOUT/SDIO_LONGTIMEOUThad no remaining users and are removed.
Testing
Host: Ubuntu 26.04 x86_64,
ghcr.io/apache/nuttx/apache-nuttx-ci-linux.Built
stm32f401rc-rs485:sdcard(CONFIG_STM32_SDIO=y) - clean:nxstyle clean on the changed file.
On STM32F427 hardware running the identical change:
sd_benchworks as expected, and no problems were found inregular usage (card init at 400 kHz, FAT mount, continuous logging at
the full transfer clock).