Skip to content

Commit df02dd7

Browse files
committed
sd: wait longer for initialization
1 parent f8b652c commit df02dd7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Changelog
22

33
## [Unreleased]
4-
-
4+
- Attempt to fix flaky SD behavior
55

66
## 9.5.0 [released 2021-03-10]
77
- RestoreFrommnemonic: ported to Rust. Will now return UserAbortError on user abort instead of GenericError.

src/sd.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,17 @@ bool sd_card_inserted(void)
380380
#else
381381
sd_mmc_err_t err = sd_mmc_check(0);
382382
sd_mmc_pause_clock();
383-
return (err == SD_MMC_OK || err == SD_MMC_INIT_ONGOING);
383+
/* If initialization is ongoing, wait up to 1 second for it to initialize */
384+
if (err == SD_MMC_INIT_ONGOING) {
385+
for (int i = 0; i < 10; ++i) {
386+
delay_ms(100);
387+
err = sd_mmc_check(0);
388+
if (err != SD_MMC_INIT_ONGOING) {
389+
break;
390+
}
391+
}
392+
}
393+
return err == SD_MMC_OK;
384394
#endif
385395
}
386396

0 commit comments

Comments
 (0)