eMMC初始化命令发送流程
通过stm32单片机驱动eMMC芯片,在完成项目的过程中,命令发送和响应很令人头疼,所以整理出一篇文档供各位开发者参考。
初始化命令发送流程
1、第一步发送CMD0,让芯片进入IDLE状态。
/* CMD0: GO_IDLE_STATE */
errorstate = SDMMC_CmdGoIdleState(hmmc->Instance);
if(errorstate != HAL_MMC_ERROR_NONE)
{
return errorstate;
}
2、发送CMD1,发送主机容量信息,激活卡的初始化过程。
/* SEND CMD1 APP_CMD with MMC_HIGH_VOLTAGE_RANGE(0xC0FF8000) as argument */
errorstate = SDMMC_CmdOpCondition(hmmc->Instance, eMMC_HIGH_VOLTAGE_RANGE);
if(errorstate != HAL_MMC_ERROR_NONE)
{
return HAL_MMC_ERROR_UNSUPPORTED_FEATURE;
}
3、发送CMD2,获取卡的CID信息。
/* Send CMD2 ALL_SEND_CID */
errorstate = SDMMC_CmdSendCID(hmmc->Instance);
if(errorstate != HAL_MMC_ERROR_NONE)
{
return errorstate;
}
4、发送CMD3,获取卡的相对地址(RCA)
/* Send CMD3 SET_REL_ADDR with argument 0 */
/* MMC Card publishes its RCA. */
errorstate = SDMMC_CmdSetRelAdd(hmmc->Instance, &mmc_rca);
if(errorstate != HAL_MMC_ERROR_NONE)
{
return errorstate;
}
5、发送CMD9,寻址的设备在 CMD 线上发送其设备专有数据(CSD)
/* Send CMD9 SEND_CSD with argument as card's RCA */
errorstate = SDMMC_CmdSendCSD(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U));
if(errorstate != HAL_MMC_ERROR_NONE)
{
return errorstate;
}
else
{
/* Get Card Specific Data */
hmmc->CSD[0U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP1);
hmmc->CSD[1U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP2);
hmmc->CSD[2U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP3);
hmmc->CSD[3U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP4);
}
/* Get the Card Class */
hmmc->MmcCard.Class = (SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP2) >> 20);
/* Select the Card */
errorstate = SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16));
if(errorstate != HAL_MMC_ERROR_NONE)
{
return errorstate;
}
/* Get CSD parameters */
HAL_MMC_GetCardCSD(hmmc, &CSD);
6、寻址的设备发送其状态寄存器CMD13
/* While card is not ready for data and trial number for sending CMD13 is not exceeded */
errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16));
if(errorstate != HAL_MMC_ERROR_NONE)
{
hmmc->ErrorCode |= errorstate;
}
初始化完成。

本文档详细介绍了通过stm32单片机驱动eMMC芯片的初始化命令发送流程,包括CMD0进入IDLE状态,CMD1激活初始化,CMD2获取CID,CMD3获取RCA,CMD9获取CSD以及CMD13获取状态寄存器的过程,旨在为开发者提供参考。
1万+

被折叠的 条评论
为什么被折叠?



