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.