hal_sdc misuses SET_RELATIVE_ADDR cmd for eMMC Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Mbroek635
Posts: 3
Joined: Thu Oct 06, 2022 10:21 am
Been thanked: 3 times

hal_sdc misuses SET_RELATIVE_ADDR cmd for eMMC  Topic is solved

Postby Mbroek635 » Thu Nov 24, 2022 5:02 pm

In sdc_hal.c the relative address is requested from an sd card:
https://github.com/ChibiOS/ChibiOS/blob ... sdc.c#L674
MMCSD_CMD_SEND_RELATIVE_ADDR tranalates to CMD3.

This is correct according to the SD SDIO specification.
However this is not correct for eMMC devices.
eMMC devices use CMD3 as SET_RELATIVE_ADDR.
source:
https://linux.codingbelief.com/zh/stora ... mands.html

I'd suggest the following patch:

Code: Select all

diff --git a/os/hal/include/hal_mmcsd.h b/os/hal/include/hal_mmcsd.h
index ab4977557..1294ded49 100644
--- a/os/hal/include/hal_mmcsd.h
+++ b/os/hal/include/hal_mmcsd.h
@@ -71,6 +71,7 @@
 #define MMCSD_CMD_INIT                  1U
 #define MMCSD_CMD_ALL_SEND_CID          2U
 #define MMCSD_CMD_SEND_RELATIVE_ADDR    3U
+#define MMCSD_CMD_SET_RELATIVE_ADDR     MMCSD_CMD_SEND_RELATIVE_ADDR
 #define MMCSD_CMD_SET_BUS_WIDTH         6U
 #define MMCSD_CMD_SWITCH                MMCSD_CMD_SET_BUS_WIDTH
 #define MMCSD_CMD_SEL_DESEL_CARD        7U
diff --git a/os/hal/src/hal_sdc.c b/os/hal/src/hal_sdc.c
index d10010389..acfb8af3a 100644
--- a/os/hal/src/hal_sdc.c
+++ b/os/hal/src/hal_sdc.c
@@ -654,7 +654,7 @@ bool sdcConnect(SDCDriver *sdcp) {
   }
 
   /* Perform specific initialization procedure.*/
-  if ((sdcp->cardmode &  SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) {
+  if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) {
     if (HAL_FAILED == mmc_init(sdcp)) {
       goto failed;
     }
@@ -670,10 +670,19 @@ bool sdcConnect(SDCDriver *sdcp) {
     goto failed;
   }
 
-  /* Asks for the RCA.*/
-  if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_RELATIVE_ADDR,
-                                 0, &sdcp->rca)) {
-    goto failed;
+  if ((sdcp->cardmode & SDC_MODE_CARDTYPE_MASK) == SDC_MODE_CARDTYPE_MMC) {
+    /* Set the RCA.*/
+    sdcp->rca = 0;
+    if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SET_RELATIVE_ADDR,
+                                  sdcp->rca, resp)) {
+      goto failed;
+    }
+  } else {
+    /* Asks for the RCA.*/
+    if (sdc_lld_send_cmd_short_crc(sdcp, MMCSD_CMD_SEND_RELATIVE_ADDR,
+                                  0, &sdcp->rca)) {
+      goto failed;
+    }
   }
 
   /* Reads CSD.*/


Make of this what you will. This does not fully support relative addresses.
I'm on ChibiOS stable 21.11.x.
Using an stm32l496.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: hal_sdc misuses SET_RELATIVE_ADDR cmd for eMMC

Postby Giovanni » Fri Dec 09, 2022 11:14 am

Hi,

I added that definition, thanks.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 10 guests