Repository navigation
arch/arm: Bound SDMMC/SDIO command response wait by time - #20908
Merged
xiaoxiang781216 merged 1 commit intoOct 26, 2026
Merged
Conversation
Swatantra-66
requested review from
antmerlino,
davids5,
jerpelea,
simbit18 and
xiaoxiang781216
as code owners
October 22, 2026 21:29
xiaoxiang781216
previously approved these changes
Oct 23, 2026
|
Swatantra-66
force-pushed
the
fix/stm32-sdio-timeout-hang
branch
from
October 23, 2026 05:36
83524f7 to
6e38f1f
Compare
xiaoxiang781216
previously approved these changes
Oct 23, 2026
Contributor
|
@Swatantra-66 please fix the conflict. |
Contributor
|
@Swatantra-66 ping again. |
Contributor
Author
|
@xiaoxiang781216 will fix it soon, maybe before 12 pm IST |
Follow up on commit 62b41ad to fix the same SDMMC/SDIO polling timeout starvation issue across the remaining STM32 families and clone architectures (stm32f7, stm32h5, stm32h7, stm32l4, at32, gd32f4). The command waitresponse functions previously polled the status register bounded only by an iteration counter (up to 0x7fffffff iterations). If the card clock stops or the peripheral freezes, the hardware CTIMEOUT flag is never generated and the loop spins for INT32_MAX iterations while holding the filesystem lock, causing high CPU load and starving lower-priority threads. Bound the wait by time using clock_systime_ticks(): 250 ms for response-bearing commands (the maximum timeout allowed by the SD physical layer specification) and 10 ms for no-response/R3/R7 commands. Fixes apache#19792 Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
force-pushed
the
fix/stm32-sdio-timeout-hang
branch
from
October 24, 2026 06:30
6e38f1f to
79706e5
Compare
Contributor
Author
|
Rebased onto latest |
Contributor
|
let's ignore ci error which is fixed by #20949 instead wasting ci resource by retrigger. |
xiaoxiang781216
approved these changes
Oct 24, 2026
GUIDINGLI
approved these changes
Oct 26, 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.
Summary
Follow up on #19793 (commit
62b41ad9b40d5a513486a3b7f9be86ed8cdfe0e5) to address and completely close #19792.Background & Problem
In the STM32 SDMMC/SDIO drivers,
stm32_waitresponse()(orgd32_wait_response/at32_waitresponse) polls the status register (STA/STAT) waiting for command completion flags (CMDDONEorRESPDONE).Previously, the timeout mechanism was bounded solely by an iteration counter:
SDMMC_CMDTIMEOUT=100000SDMMC_LONGTIMEOUT=0x7fffffff(~2.14 billion iterations)The hardware
CTIMEOUTflag in the status register is intended to signal a missing response, but it relies on the Command Path State Machine (CPSM) and card clock running. If the SD card is abruptly removed, the card clock stops, or the peripheral freezes/fails:STA/STATnever updates withCTIMEOUTorRESPDONE.INT32_MAX(2.14 billion) iterations, consuming 100% CPU time for seconds or even minutes.mmcsdretries, the system remains unresponsive indefinitely.While PR #19793 fixed this in
arch/arm/src/common/stm32/stm32_sdio_m3m4_v1.c, issue #19792 remained open because all other STM32 family variants and clone architectures shared the exact same iteration-counter loop.What This PR Does
This patch replaces the loop-count timeouts with deterministic, tick-based timeouts (
clock_systime_ticks()) across all remaining affected drivers:arch/arm/src/stm32f7/stm32_sdmmc.carch/arm/src/stm32h5/stm32_sdmmc.carch/arm/src/stm32h7/stm32_sdmmc.carch/arm/src/stm32l4/stm32l4_sdmmc.carch/arm/src/at32/at32_sdio.carch/arm/src/gd32f4/gd32f4xx_sdio.cTimeout Values & Design
SDMMC_LONGTIMEOUT_MS(250 ms): Configured usingMSEC2TICK(250)for response-bearing commands (R1,R1B,R2,R4,R5,R6). 250 ms is the maximum response timeout defined by the SD Physical Layer Specification for busy operations.SDMMC_CMDTIMEOUT_MS(10 ms): Configured usingMSEC2TICK(10)for commands with no response,R3, orR7.CTIMEOUTflag still detects missing card responses within microseconds. The software tick timeout acts strictly as a safety backstop when the hardware peripheral or card clock is unresponsive, gracefully returning-ETIMEDOUTso the higher-levelmmcsderror recovery and retry logic can execute.Fixes #19792
Impact
Testing
./tools/checkpatch.sh -m -g HEADon the commit; all style and commit message checks pass without warnings or errors.62b41ad9b40d5a513486a3b7f9be86ed8cdfe0e5(arch/arm/src/common/stm32/stm32_sdio_m3m4_v1.c).