From 7dd67db95ca715cc25f66001b1a78180ecd5288f Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Mon, 7 Nov 2022 23:41:44 +0100 Subject: [PATCH] Intermediate update of uSD support for Scialys App --- v10/uSD.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/v10/uSD.c b/v10/uSD.c index fe90705..bf40f97 100644 --- a/v10/uSD.c +++ b/v10/uSD.c @@ -67,7 +67,17 @@ int scialys_uSD_write(uint32_t block_num) return -1; } ret = sdmmc_write_block(µ_sd, block_num, mmc_data); - /* FIXME : check return value */ + /* Check return value */ + if (ret == -EBUSY) { + uint8_t cnt = 10; + do { + ret = sdmmc_wait_for_ready(mmc, 0xFF); + while ((ret != 0xFF) && (cnt-- > 0)); + } else if (ret == -ENODEV) { + /* uSD stalled ??? */ + /* FIXME : Try reset ? */ + got_uSD = 0; + } return ret; } @@ -196,7 +206,6 @@ int scialys_uSD_detect(int uart) /* Let some time for uSD card to power up */ do { i = 0; - msleep(250); ret = sdmmc_init(µ_sd); if (ret == 0) { #ifdef DEBUG @@ -206,7 +215,7 @@ int scialys_uSD_detect(int uart) i++; msleep(10); ret = sdmmc_init_wait_card_ready(µ_sd); - } while ((ret == 0 ) && (i < 10)); + } while ((ret != 0 ) && (i < 10)); if (ret <= 1) { #ifdef DEBUG step = 2; @@ -224,7 +233,8 @@ int scialys_uSD_detect(int uart) if (loop++ > 10) { break; } - } while ((loop < 2) || (((ret < 0) || (ret > 1)) && (micro_sd.card_type == MMC_CARDTYPE_UNKNOWN))); + msleep(50); + } while (ret != 0); /* Got uSD ? */ if (loop >= 10) { -- 2.43.0