Skip to content

Commit 4b64949

Browse files
committed
F4_HAL/mmc: Set the MMC relative address correctly.
This fix comes from the H7 HAL v1.9.0. Signed-off-by: Damien George <[email protected]>
1 parent 7988827 commit 4b64949

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_sdmmc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ uint32_t SDMMC_CmdSendSCR(SDIO_TypeDef *SDIOx);
10981098
uint32_t SDMMC_CmdSendCID(SDIO_TypeDef *SDIOx);
10991099
uint32_t SDMMC_CmdSendCSD(SDIO_TypeDef *SDIOx, uint32_t Argument);
11001100
uint32_t SDMMC_CmdSetRelAdd(SDIO_TypeDef *SDIOx, uint16_t *pRCA);
1101+
uint32_t SDMMC_CmdSetRelAddMmc(SDIO_TypeDef *SDIOx, uint16_t RCA);
11011102
uint32_t SDMMC_CmdSendStatus(SDIO_TypeDef *SDIOx, uint32_t Argument);
11021103
uint32_t SDMMC_CmdStatusRegister(SDIO_TypeDef *SDIOx);
11031104

STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_mmc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ static uint32_t MMC_InitCard(MMC_HandleTypeDef *hmmc)
23932393

23942394
/* Send CMD3 SET_REL_ADDR with argument 0 */
23952395
/* MMC Card publishes its RCA. */
2396-
errorstate = SDMMC_CmdSetRelAdd(hmmc->Instance, &mmc_rca);
2396+
errorstate = SDMMC_CmdSetRelAddMmc(hmmc->Instance, mmc_rca);
23972397
if(errorstate != HAL_MMC_ERROR_NONE)
23982398
{
23992399
return errorstate;

STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,31 @@ uint32_t SDMMC_CmdSetRelAdd(SDIO_TypeDef *SDIOx, uint16_t *pRCA)
10391039
return errorstate;
10401040
}
10411041

1042+
/**
1043+
* @brief Send the Set Relative Address command to MMC card (not SD card).
1044+
* @param SDMMCx Pointer to SDMMC register base
1045+
* @param RCA Card RCA
1046+
* @retval HAL status
1047+
*/
1048+
uint32_t SDMMC_CmdSetRelAddMmc(SDIO_TypeDef *SDIOx, uint16_t RCA)
1049+
{
1050+
SDIO_CmdInitTypeDef sdmmc_cmdinit;
1051+
uint32_t errorstate;
1052+
1053+
/* Send CMD3 SD_CMD_SET_REL_ADDR */
1054+
sdmmc_cmdinit.Argument = ((uint32_t)RCA << 16U);
1055+
sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SET_REL_ADDR;
1056+
sdmmc_cmdinit.Response = SDIO_RESPONSE_SHORT;
1057+
sdmmc_cmdinit.WaitForInterrupt = SDIO_WAIT_NO;
1058+
sdmmc_cmdinit.CPSM = SDIO_CPSM_ENABLE;
1059+
SDIO_SendCommand(SDIOx, &sdmmc_cmdinit);
1060+
1061+
/* Check for error conditions */
1062+
errorstate = SDMMC_GetCmdResp1(SDIOx, SDMMC_CMD_SET_REL_ADDR, SDIO_CMDTIMEOUT);
1063+
1064+
return errorstate;
1065+
}
1066+
10421067
/**
10431068
* @brief Send the Status command and check the response.
10441069
* @param SDIOx: Pointer to SDIO register base

0 commit comments

Comments
 (0)