Skip to content

Conversation

@TheSlowGrowth
Copy link
Contributor

@TheSlowGrowth TheSlowGrowth commented Oct 8, 2025

To prevent the while loops from being optimized into very long loops.

Without this change, loops such as this one in SD_read() (sd_diskio.c:154) get "optimized" into 30s loops, when the (ReadStatus == 0) check gets optimized out:

        while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) {}

This can be observed with arm-gcc-none-eabi 10 2021-q4-major using DaisyProject.cmake
This makes the SD unusable.

@TheSlowGrowth TheSlowGrowth changed the title Add missing volatile to status flags in sd_diskio.c Add missing volatile to status flags to prevent infinite loop after optimization Oct 8, 2025
@github-actions
Copy link

github-actions bot commented Oct 8, 2025

Test Results

150 tests  ±0   150 ✅ ±0   0s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit e8a01a3. ± Comparison against base commit ea7f924.

♻️ This comment has been updated with latest results.

To prevent the while loops from being optimized into
very long loops that always wait for the timeout.
@TheSlowGrowth TheSlowGrowth force-pushed the fix-sd-diskio-volatile branch from c53ee36 to e8a01a3 Compare October 9, 2025 00:07
@TheSlowGrowth TheSlowGrowth changed the title Add missing volatile to status flags to prevent infinite loop after optimization Add missing volatile to status flags to prevent "infinite" loop after optimization Oct 9, 2025
munshkr added a commit to nopia-suite/libDaisy that referenced this pull request Oct 11, 2025
@stephenhensley
Copy link
Collaborator

Woah, fascinating.

I've hit this loop a few times before, but never reliably.
I have almost entirely used the Make builds, so maybe some flag set there causes this to be more intermittent than with the CMake build.

In either case, nice catch. Thanks for the update!
I'll give this a quick test before the end of the week, and get it merged!

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.

2 participants