You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2023/07/14 08:38:09 UTC

[mynewt-core] 01/02: hw/drivers/mmc: Fix Multiple Block Read CMD18

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 126504c2042c3f5055865fdf11b51d2719ecab3c
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Mon Jul 10 14:36:59 2023 +0200

    hw/drivers/mmc: Fix Multiple Block Read CMD18
    
    For multiply block read control token and CRC is send
    for each block not just the first one.
    
    Signed-off-by: Jerzy Kasenberg <je...@codecoup.pl>
---
 hw/drivers/mmc/src/mmc.c | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/hw/drivers/mmc/src/mmc.c b/hw/drivers/mmc/src/mmc.c
index 9296f6c9c..0ea9918bf 100644
--- a/hw/drivers/mmc/src/mmc.c
+++ b/hw/drivers/mmc/src/mmc.c
@@ -400,27 +400,29 @@ mmc_read(uint8_t mmc_id, uint32_t addr, void *buf, uint32_t len)
         goto out;
     }
 
-    /**
-     * 7.3.3 Control tokens
-     *   Wait up to 200ms for control token.
-     */
-    timeout = os_time_get() + OS_TICKS_PER_SEC / 5;
-    do {
-        res = hal_spi_tx_val(mmc->spi_num, 0xff);
-        if (res != 0xFF) break;
-        os_time_delay(OS_TICKS_PER_SEC / 20);
-    } while (os_time_get() < timeout);
-
-    /**
-     * 7.3.3.2 Start Block Tokens and Stop Tran Token
-     */
-    if (res != START_BLOCK) {
-        rc = MMC_TIMEOUT;
-        goto out;
-    }
-
     index = 0;
     while (block_count--) {
+        /**
+         * 7.3.3 Control tokens
+         *   Wait up to 200ms for control token.
+         */
+        timeout = os_time_get() + OS_TICKS_PER_SEC / 5;
+        do {
+            res = hal_spi_tx_val(mmc->spi_num, 0xff);
+            if (res != 0xFF) {
+                break;
+            }
+            os_time_delay(OS_TICKS_PER_SEC / 20);
+        } while (os_time_get() < timeout);
+
+        /**
+         * 7.3.3.2 Start Block Tokens and Stop Tran Token
+         */
+        if (res != START_BLOCK) {
+            rc = MMC_TIMEOUT;
+            goto out;
+        }
+
         for (n = 0; n < BLOCK_LEN; n++) {
             g_block_buf[n] = hal_spi_tx_val(mmc->spi_num, 0xff);
         }