From c9321c2561ce8e07c1b6ff496da8416241daadf7 Mon Sep 17 00:00:00 2001 From: Star Date: Fri, 16 Jan 2026 15:26:52 +0800 Subject: [PATCH 1/6] Fixbug: Fix the bug where the cmd6 command is sent but the status of the card is not queried, which can cause failure in switching to the high-speed mode in DDR mode. --- components/drivers/sdio/dev_mmc.c | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/components/drivers/sdio/dev_mmc.c b/components/drivers/sdio/dev_mmc.c index 2012d9e5297..e03c035c3c4 100644 --- a/components/drivers/sdio/dev_mmc.c +++ b/components/drivers/sdio/dev_mmc.c @@ -270,6 +270,68 @@ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) return 0; } +/* + * Send Status. + */ +static int mmc_send_status(struct rt_mmcsd_card *card, rt_uint32_t *status, unsigned retries) +{ + int err; + struct rt_mmcsd_cmd cmd; + + cmd.busy_timeout = 0; + cmd.cmd_code = SEND_STATUS; + cmd.arg = card->rca << 16; + cmd.flags = RESP_R1 | CMD_AC; + err = mmcsd_send_cmd(card->host, &cmd, retries); + if (err) + return err; + + if (status) + *status = cmd.resp[0]; + + return 0; +} + +/* + * Poll Busy. + */ +static int mmc_poll_for_busy(struct rt_mmcsd_card *card, unsigned int timeout_ms, int retries) +{ + int timeout = rt_tick_from_millisecond(timeout_ms); + int err = 0; + rt_uint32_t status; + rt_tick_t start; + + start = rt_tick_get(); + do + { + rt_bool_t out = (int)(rt_tick_get() - start) > timeout; + + err = mmc_send_status(card, &status, retries); + if (err) + { + LOG_E("error %d requesting status", err); + return err; + } + + if (out) + { + LOG_E("wait card busy timeout"); + return -RT_ETIMEOUT; + } + + rt_thread_mdelay(1); + /* + * Some cards mishandle the status bits, + * so make sure to check both the busy + * indication and the card state. + */ + } + while (!(status & R1_READY_FOR_DATA)); + + return err; +} + /** * mmc_switch - modify EXT_CSD register * @card: the MMC card associated with the data transfer @@ -295,6 +357,13 @@ static int mmc_switch(struct rt_mmcsd_card *card, rt_uint8_t set, if (err) return err; + /* + * Poll the status of the cmd13 card with a timeout of 500ms and a polling interval of 1ms. + */ + err = mmc_poll_for_busy(card, 500, 3); + if (err) + return err; + return 0; } From a3c0c860e6fba63b49e37d376e4fa628aac5d054 Mon Sep 17 00:00:00 2001 From: Star Date: Fri, 16 Jan 2026 15:26:52 +0800 Subject: [PATCH 2/6] Fixbug: Fix the bug where the cmd6 command is sent but the status of the card is not queried, which can cause failure in switching to the high-speed mode in DDR mode. --- components/drivers/sdio/dev_mmc.c | 33 ++++++++++++++----------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/components/drivers/sdio/dev_mmc.c b/components/drivers/sdio/dev_mmc.c index e03c035c3c4..65f79354894 100644 --- a/components/drivers/sdio/dev_mmc.c +++ b/components/drivers/sdio/dev_mmc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006-2024, RT-Thread Development Team + * Copyright (c) 2006-2026, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * @@ -276,7 +276,7 @@ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) static int mmc_send_status(struct rt_mmcsd_card *card, rt_uint32_t *status, unsigned retries) { int err; - struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_cmd cmd = (struct rt_mmcsd_cmd){ 0 }; cmd.busy_timeout = 0; cmd.cmd_code = SEND_STATUS; @@ -295,7 +295,7 @@ static int mmc_send_status(struct rt_mmcsd_card *card, rt_uint32_t *status, unsi /* * Poll Busy. */ -static int mmc_poll_for_busy(struct rt_mmcsd_card *card, unsigned int timeout_ms, int retries) +static int mmc_poll_for_busy(struct rt_mmcsd_card *card, rt_uint32_t timeout_ms, unsigned retries) { int timeout = rt_tick_from_millisecond(timeout_ms); int err = 0; @@ -303,16 +303,10 @@ static int mmc_poll_for_busy(struct rt_mmcsd_card *card, unsigned int timeout_ms rt_tick_t start; start = rt_tick_get(); + do { - rt_bool_t out = (int)(rt_tick_get() - start) > timeout; - - err = mmc_send_status(card, &status, retries); - if (err) - { - LOG_E("error %d requesting status", err); - return err; - } + rt_bool_t out = (int)(rt_tick_get() - start) >= timeout; if (out) { @@ -321,11 +315,13 @@ static int mmc_poll_for_busy(struct rt_mmcsd_card *card, unsigned int timeout_ms } rt_thread_mdelay(1); - /* - * Some cards mishandle the status bits, - * so make sure to check both the busy - * indication and the card state. - */ + + err = mmc_send_status(card, &status, retries); + if (R1_STATUS(err)) + { + LOG_E("error %d requesting status", err); + return err; + } } while (!(status & R1_READY_FOR_DATA)); @@ -358,7 +354,7 @@ static int mmc_switch(struct rt_mmcsd_card *card, rt_uint8_t set, return err; /* - * Poll the status of the cmd13 card with a timeout of 500ms and a polling interval of 1ms. + * Poll the card status using CMD13 with a timeout of 500ms and a polling interval of 1ms. */ err = mmc_poll_for_busy(card, 500, 3); if (err) @@ -559,7 +555,7 @@ rt_err_t mmc_send_op_cond(struct rt_mmcsd_host *host, err = -RT_ETIMEOUT; - rt_thread_mdelay(10); //delay 10ms + rt_thread_mdelay(10); /* delay 10ms */ } if (rocr && !controller_is_spi(host)) @@ -884,3 +880,4 @@ rt_int32_t init_mmc(struct rt_mmcsd_host *host, rt_uint32_t ocr) return err; } + From a7e939fed670018696ade229b8b889964a576411 Mon Sep 17 00:00:00 2001 From: Star Date: Fri, 16 Jan 2026 15:26:52 +0800 Subject: [PATCH 3/6] Fixbug: Fix the bug where the cmd6 command is sent but the status of the card is not queried, which can cause failure in switching to the high-speed mode in DDR mode. --- components/drivers/sdio/dev_mmc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/drivers/sdio/dev_mmc.c b/components/drivers/sdio/dev_mmc.c index 65f79354894..307e8235479 100644 --- a/components/drivers/sdio/dev_mmc.c +++ b/components/drivers/sdio/dev_mmc.c @@ -323,7 +323,8 @@ static int mmc_poll_for_busy(struct rt_mmcsd_card *card, rt_uint32_t timeout_ms, return err; } } - while (!(status & R1_READY_FOR_DATA)); + while (!(status & R1_READY_FOR_DATA) || + (R1_CURRENT_STATE(status) == R1_STATE_PRG)); return err; } From cb37ee7c7b91c2218e4e4f6522e03b8889e99b9c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jan 2026 14:08:27 +0800 Subject: [PATCH 4/6] chore: trigger CLA check From eeb42b40dd036588709581b3a16ec730d3f11f46 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jan 2026 14:18:24 +0800 Subject: [PATCH 5/6] chore: refresh CLA status From c433ad4f8a96902ba90b400173681dd08e08585d Mon Sep 17 00:00:00 2001 From: Star Date: Mon, 19 Jan 2026 14:18:24 +0800 Subject: [PATCH 6/6] chore: refresh CLA status --- components/drivers/sdio/dev_mmc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/components/drivers/sdio/dev_mmc.c b/components/drivers/sdio/dev_mmc.c index 307e8235479..8a09aa937df 100644 --- a/components/drivers/sdio/dev_mmc.c +++ b/components/drivers/sdio/dev_mmc.c @@ -303,7 +303,6 @@ static int mmc_poll_for_busy(struct rt_mmcsd_card *card, rt_uint32_t timeout_ms, rt_tick_t start; start = rt_tick_get(); - do { rt_bool_t out = (int)(rt_tick_get() - start) >= timeout;