Skip to content

Commit 5f53bdb

Browse files
committed
sd: Retries on NO_CARD and faster retries
During testing it was shown that sd_mmc_check often returns NO_CARD on the first call.
1 parent 50094b2 commit 5f53bdb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/sd.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,11 @@ bool sd_card_inserted(void)
315315
return true;
316316
#else
317317
sd_mmc_err_t err = sd_mmc_check(0);
318-
/* If initialization is ongoing, wait up to 1 second for it to initialize */
319-
if (err == SD_MMC_INIT_ONGOING) {
320-
for (int i = 0; i < 10; ++i) {
321-
delay_ms(100);
318+
/* If initialization is ongoing, wait up to 1 second for it to initialize. */
319+
/* The first time sd_mmc_check is called it may return SD_MMC_ERR_NO_CARD. */
320+
if (err == SD_MMC_ERR_NO_CARD || err == SD_MMC_INIT_ONGOING) {
321+
for (int i = 0; i < 100; ++i) {
322+
delay_ms(10);
322323
err = sd_mmc_check(0);
323324
if (err != SD_MMC_INIT_ONGOING) {
324325
break;
@@ -334,7 +335,7 @@ bool sd_card_inserted(void)
334335
util_log("sd_mmc_check returned \"SD_MMC_ERR_UNUSABLE\"");
335336
break;
336337
case SD_MMC_INIT_ONGOING:
337-
util_log("sd_mmc_check returned \"SD_MMC_INIT_ONGOING\" after 10 retries");
338+
util_log("sd_mmc_check returned \"SD_MMC_INIT_ONGOING\" after 1s");
338339
break;
339340
default:
340341
util_log("sd_mmc_check returned %d", err);

0 commit comments

Comments
 (0)