From 6d2226119149e741ba81ee20fee0135624de3f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Wo=C5=82och?= Date: Sun, 18 Aug 2024 02:29:27 +0200 Subject: [PATCH] Improve support for eMMC cards This change fixes init for cards supporting High-speed mode, by waiting for the card to exit from busy state after switching the mode before issuing any further commands. --- os/hal/src/hal_sdc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/os/hal/src/hal_sdc.c b/os/hal/src/hal_sdc.c index f998b4393d..a8a544a29f 100644 --- a/os/hal/src/hal_sdc.c +++ b/os/hal/src/hal_sdc.c @@ -503,9 +503,9 @@ bool _sdc_wait_for_transfer_state(SDCDriver *sdcp) { uint32_t resp[1]; while (true) { - if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_STATUS, - sdcp->rca, resp) || - MMCSD_R1_ERROR(resp[0])) { + /* Not checking CRC here according to JEDEC Standard No. 84-B51 6.6.2 + so that this function can be used after High-speed mode selection */ + if (sdc_lld_send_cmd_short(sdcp, MMCSD_CMD_SEND_STATUS, sdcp->rca, resp) || MMCSD_R1_ERROR(resp[0])) { return HAL_FAILED; } @@ -723,6 +723,10 @@ bool sdcConnect(SDCDriver *sdcp) { } sdc_lld_set_data_clk(sdcp, clk); + if (HAL_SUCCESS != _sdc_wait_for_transfer_state(sdcp)) { + goto failed; + } + /* Block length fixed at 512 bytes.*/ if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SET_BLOCKLEN, MMCSD_BLOCK_SIZE, resp) ||