172 #if defined(HAL_SD_MODULE_ENABLED) || defined(HAL_MMC_MODULE_ENABLED)
180 static uint32_t SDMMC_GetCmdResp1(
SDMMC_TypeDef *SDMMCx, uint8_t SD_CMD, uint32_t Timeout);
184 static uint32_t SDMMC_GetCmdResp6(
SDMMC_TypeDef *SDMMCx, uint8_t SD_CMD, uint16_t *pRCA);
226 tmpreg |= (
Init.ClockEdge |\
228 Init.ClockPowerSave |\
230 Init.HardwareFlowControl |\
268 return (SDMMCx->
FIFO);
280 SDMMCx->
FIFO = *pWriteData;
329 SDMMCx->
POWER = (uint32_t)0x00000000;
370 tmpreg |= (uint32_t)(
Command->CmdIndex |\
388 return (uint8_t)(SDMMCx->
RESPCMD);
403 uint32_t SDMMC_GetResponse(
SDMMC_TypeDef *SDMMCx, uint32_t Response)
411 tmp = (uint32_t)(&(SDMMCx->
RESP1)) + Response;
413 return (*(
__IO uint32_t *) tmp);
432 assert_param(IS_SDMMC_TRANSFER_MODE(Data->TransferMode));
436 SDMMCx->
DTIMER = Data->DataTimeOut;
439 SDMMCx->
DLEN = Data->DataLength;
442 tmpreg |= (uint32_t)(Data->DataBlockSize |\
444 Data->TransferMode |\
471 return (SDMMCx->
FIFO);
486 assert_param(IS_SDMMC_READWAIT_MODE(SDMMC_ReadWaitMode));
518 uint32_t SDMMC_CmdBlockLength(
SDMMC_TypeDef *SDMMCx, uint32_t BlockSize)
520 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
524 sdmmc_cmdinit.Argument = (uint32_t)BlockSize;
525 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SET_BLOCKLEN;
526 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
527 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
528 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
529 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
532 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SET_BLOCKLEN, SDMMC_CMDTIMEOUT);
542 uint32_t SDMMC_CmdReadSingleBlock(
SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd)
544 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
548 sdmmc_cmdinit.Argument = (uint32_t)ReadAdd;
549 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_READ_SINGLE_BLOCK;
550 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
551 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
552 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
553 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
556 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_READ_SINGLE_BLOCK, SDMMC_CMDTIMEOUT);
566 uint32_t SDMMC_CmdReadMultiBlock(
SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd)
568 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
572 sdmmc_cmdinit.Argument = (uint32_t)ReadAdd;
573 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_READ_MULT_BLOCK;
574 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
575 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
576 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
577 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
580 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_READ_MULT_BLOCK, SDMMC_CMDTIMEOUT);
590 uint32_t SDMMC_CmdWriteSingleBlock(
SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd)
592 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
596 sdmmc_cmdinit.Argument = (uint32_t)WriteAdd;
597 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_WRITE_SINGLE_BLOCK;
598 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
599 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
600 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
601 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
604 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_WRITE_SINGLE_BLOCK, SDMMC_CMDTIMEOUT);
614 uint32_t SDMMC_CmdWriteMultiBlock(
SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd)
616 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
620 sdmmc_cmdinit.Argument = (uint32_t)WriteAdd;
621 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_WRITE_MULT_BLOCK;
622 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
623 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
624 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
625 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
628 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_WRITE_MULT_BLOCK, SDMMC_CMDTIMEOUT);
638 uint32_t SDMMC_CmdSDEraseStartAdd(
SDMMC_TypeDef *SDMMCx, uint32_t StartAdd)
640 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
644 sdmmc_cmdinit.Argument = (uint32_t)StartAdd;
645 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_ERASE_GRP_START;
646 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
647 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
648 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
649 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
652 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SD_ERASE_GRP_START, SDMMC_CMDTIMEOUT);
662 uint32_t SDMMC_CmdSDEraseEndAdd(
SDMMC_TypeDef *SDMMCx, uint32_t EndAdd)
664 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
668 sdmmc_cmdinit.Argument = (uint32_t)EndAdd;
669 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_ERASE_GRP_END;
670 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
671 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
672 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
673 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
676 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SD_ERASE_GRP_END, SDMMC_CMDTIMEOUT);
686 uint32_t SDMMC_CmdEraseStartAdd(
SDMMC_TypeDef *SDMMCx, uint32_t StartAdd)
688 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
692 sdmmc_cmdinit.Argument = (uint32_t)StartAdd;
693 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_ERASE_GRP_START;
694 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
695 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
696 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
697 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
700 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_ERASE_GRP_START, SDMMC_CMDTIMEOUT);
710 uint32_t SDMMC_CmdEraseEndAdd(
SDMMC_TypeDef *SDMMCx, uint32_t EndAdd)
712 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
716 sdmmc_cmdinit.Argument = (uint32_t)EndAdd;
717 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_ERASE_GRP_END;
718 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
719 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
720 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
721 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
724 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_ERASE_GRP_END, SDMMC_CMDTIMEOUT);
736 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
740 sdmmc_cmdinit.Argument = 0U;
741 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_ERASE;
742 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
743 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
744 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
745 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
748 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_ERASE, SDMMC_MAXERASETIMEOUT);
760 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
764 sdmmc_cmdinit.Argument = 0U;
765 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_STOP_TRANSMISSION;
766 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
767 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
768 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
769 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
772 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_STOP_TRANSMISSION, SDMMC_STOPTRANSFERTIMEOUT);
783 uint32_t SDMMC_CmdSelDesel(
SDMMC_TypeDef *SDMMCx, uint64_t Addr)
785 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
789 sdmmc_cmdinit.Argument = (uint32_t)Addr;
790 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEL_DESEL_CARD;
791 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
792 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
793 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
794 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
797 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SEL_DESEL_CARD, SDMMC_CMDTIMEOUT);
809 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
812 sdmmc_cmdinit.Argument = 0U;
813 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_GO_IDLE_STATE;
814 sdmmc_cmdinit.Response = SDMMC_RESPONSE_NO;
815 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
816 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
817 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
820 errorstate = SDMMC_GetCmdError(SDMMCx);
832 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
840 sdmmc_cmdinit.Argument = SDMMC_CHECK_PATTERN;
841 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_HS_SEND_EXT_CSD;
842 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
843 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
844 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
845 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
848 errorstate = SDMMC_GetCmdResp7(SDMMCx);
861 uint32_t SDMMC_CmdAppCommand(
SDMMC_TypeDef *SDMMCx, uint32_t Argument)
863 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
866 sdmmc_cmdinit.Argument = (uint32_t)Argument;
867 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_APP_CMD;
868 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
869 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
870 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
871 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
877 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_APP_CMD, SDMMC_CMDTIMEOUT);
889 uint32_t SDMMC_CmdAppOperCommand(
SDMMC_TypeDef *SDMMCx, uint32_t Argument)
891 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
894 sdmmc_cmdinit.Argument = SDMMC_VOLTAGE_WINDOW_SD | Argument;
895 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_APP_OP_COND;
896 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
897 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
898 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
899 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
902 errorstate = SDMMC_GetCmdResp3(SDMMCx);
913 uint32_t SDMMC_CmdBusWidth(
SDMMC_TypeDef *SDMMCx, uint32_t BusWidth)
915 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
918 sdmmc_cmdinit.Argument = (uint32_t)BusWidth;
919 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_APP_SD_SET_BUSWIDTH;
920 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
921 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
922 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
923 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
926 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_APP_SD_SET_BUSWIDTH, SDMMC_CMDTIMEOUT);
938 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
942 sdmmc_cmdinit.Argument = 0U;
943 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_APP_SEND_SCR;
944 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
945 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
946 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
947 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
950 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SD_APP_SEND_SCR, SDMMC_CMDTIMEOUT);
962 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
966 sdmmc_cmdinit.Argument = 0U;
967 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_ALL_SEND_CID;
968 sdmmc_cmdinit.Response = SDMMC_RESPONSE_LONG;
969 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
970 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
971 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
974 errorstate = SDMMC_GetCmdResp2(SDMMCx);
985 uint32_t SDMMC_CmdSendCSD(
SDMMC_TypeDef *SDMMCx, uint32_t Argument)
987 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
991 sdmmc_cmdinit.Argument = Argument;
992 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEND_CSD;
993 sdmmc_cmdinit.Response = SDMMC_RESPONSE_LONG;
994 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
995 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
996 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
999 errorstate = SDMMC_GetCmdResp2(SDMMCx);
1010 uint32_t SDMMC_CmdSetRelAdd(
SDMMC_TypeDef *SDMMCx, uint16_t *pRCA)
1012 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
1013 uint32_t errorstate;
1016 sdmmc_cmdinit.Argument = 0U;
1017 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SET_REL_ADDR;
1018 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
1019 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
1020 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
1021 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
1024 errorstate = SDMMC_GetCmdResp6(SDMMCx, SDMMC_CMD_SET_REL_ADDR, pRCA);
1035 uint32_t SDMMC_CmdSendStatus(
SDMMC_TypeDef *SDMMCx, uint32_t Argument)
1037 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
1038 uint32_t errorstate;
1040 sdmmc_cmdinit.Argument = Argument;
1041 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEND_STATUS;
1042 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
1043 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
1044 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
1045 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
1048 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SEND_STATUS, SDMMC_CMDTIMEOUT);
1060 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
1061 uint32_t errorstate;
1063 sdmmc_cmdinit.Argument = 0U;
1064 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SD_APP_STATUS;
1065 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
1066 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
1067 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
1068 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
1071 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_SD_APP_STATUS, SDMMC_CMDTIMEOUT);
1083 uint32_t SDMMC_CmdOpCondition(
SDMMC_TypeDef *SDMMCx, uint32_t Argument)
1085 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
1086 uint32_t errorstate;
1088 sdmmc_cmdinit.Argument = Argument;
1089 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_SEND_OP_COND;
1090 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
1091 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
1092 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
1093 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
1096 errorstate = SDMMC_GetCmdResp3(SDMMCx);
1107 uint32_t SDMMC_CmdSwitch(
SDMMC_TypeDef *SDMMCx, uint32_t Argument)
1109 SDMMC_CmdInitTypeDef sdmmc_cmdinit;
1110 uint32_t errorstate;
1114 sdmmc_cmdinit.Argument = Argument;
1115 sdmmc_cmdinit.CmdIndex = SDMMC_CMD_HS_SWITCH;
1116 sdmmc_cmdinit.Response = SDMMC_RESPONSE_SHORT;
1117 sdmmc_cmdinit.WaitForInterrupt = SDMMC_WAIT_NO;
1118 sdmmc_cmdinit.CPSM = SDMMC_CPSM_ENABLE;
1119 (void)SDMMC_SendCommand(SDMMCx, &sdmmc_cmdinit);
1122 errorstate = SDMMC_GetCmdResp1(SDMMCx, SDMMC_CMD_HS_SWITCH, SDMMC_CMDTIMEOUT);
1151 return SDMMC_ERROR_TIMEOUT;
1154 }
while(!__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CMDSENT));
1157 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
1159 return SDMMC_ERROR_NONE;
1168 static uint32_t SDMMC_GetCmdResp1(
SDMMC_TypeDef *SDMMCx, uint8_t SD_CMD, uint32_t Timeout)
1170 uint32_t response_r1;
1181 return SDMMC_ERROR_TIMEOUT;
1183 sta_reg = SDMMCx->
STA;
1184 }
while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT)) == 0U) ||
1185 ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
1187 if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
1189 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
1191 return SDMMC_ERROR_CMD_RSP_TIMEOUT;
1193 else if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL))
1195 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL);
1197 return SDMMC_ERROR_CMD_CRC_FAIL;
1205 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
1208 if(SDMMC_GetCommandResponse(SDMMCx) != SD_CMD)
1210 return SDMMC_ERROR_CMD_CRC_FAIL;
1214 response_r1 = SDMMC_GetResponse(SDMMCx, SDMMC_RESP1);
1216 if((response_r1 & SDMMC_OCR_ERRORBITS) == SDMMC_ALLZERO)
1218 return SDMMC_ERROR_NONE;
1220 else if((response_r1 & SDMMC_OCR_ADDR_OUT_OF_RANGE) == SDMMC_OCR_ADDR_OUT_OF_RANGE)
1222 return SDMMC_ERROR_ADDR_OUT_OF_RANGE;
1224 else if((response_r1 & SDMMC_OCR_ADDR_MISALIGNED) == SDMMC_OCR_ADDR_MISALIGNED)
1226 return SDMMC_ERROR_ADDR_MISALIGNED;
1228 else if((response_r1 & SDMMC_OCR_BLOCK_LEN_ERR) == SDMMC_OCR_BLOCK_LEN_ERR)
1230 return SDMMC_ERROR_BLOCK_LEN_ERR;
1232 else if((response_r1 & SDMMC_OCR_ERASE_SEQ_ERR) == SDMMC_OCR_ERASE_SEQ_ERR)
1234 return SDMMC_ERROR_ERASE_SEQ_ERR;
1236 else if((response_r1 & SDMMC_OCR_BAD_ERASE_PARAM) == SDMMC_OCR_BAD_ERASE_PARAM)
1238 return SDMMC_ERROR_BAD_ERASE_PARAM;
1240 else if((response_r1 & SDMMC_OCR_WRITE_PROT_VIOLATION) == SDMMC_OCR_WRITE_PROT_VIOLATION)
1242 return SDMMC_ERROR_WRITE_PROT_VIOLATION;
1244 else if((response_r1 & SDMMC_OCR_LOCK_UNLOCK_FAILED) == SDMMC_OCR_LOCK_UNLOCK_FAILED)
1246 return SDMMC_ERROR_LOCK_UNLOCK_FAILED;
1248 else if((response_r1 & SDMMC_OCR_COM_CRC_FAILED) == SDMMC_OCR_COM_CRC_FAILED)
1250 return SDMMC_ERROR_COM_CRC_FAILED;
1252 else if((response_r1 & SDMMC_OCR_ILLEGAL_CMD) == SDMMC_OCR_ILLEGAL_CMD)
1254 return SDMMC_ERROR_ILLEGAL_CMD;
1256 else if((response_r1 & SDMMC_OCR_CARD_ECC_FAILED) == SDMMC_OCR_CARD_ECC_FAILED)
1258 return SDMMC_ERROR_CARD_ECC_FAILED;
1260 else if((response_r1 & SDMMC_OCR_CC_ERROR) == SDMMC_OCR_CC_ERROR)
1262 return SDMMC_ERROR_CC_ERR;
1264 else if((response_r1 & SDMMC_OCR_STREAM_READ_UNDERRUN) == SDMMC_OCR_STREAM_READ_UNDERRUN)
1266 return SDMMC_ERROR_STREAM_READ_UNDERRUN;
1268 else if((response_r1 & SDMMC_OCR_STREAM_WRITE_OVERRUN) == SDMMC_OCR_STREAM_WRITE_OVERRUN)
1270 return SDMMC_ERROR_STREAM_WRITE_OVERRUN;
1272 else if((response_r1 & SDMMC_OCR_CID_CSD_OVERWRITE) == SDMMC_OCR_CID_CSD_OVERWRITE)
1274 return SDMMC_ERROR_CID_CSD_OVERWRITE;
1276 else if((response_r1 & SDMMC_OCR_WP_ERASE_SKIP) == SDMMC_OCR_WP_ERASE_SKIP)
1278 return SDMMC_ERROR_WP_ERASE_SKIP;
1280 else if((response_r1 & SDMMC_OCR_CARD_ECC_DISABLED) == SDMMC_OCR_CARD_ECC_DISABLED)
1282 return SDMMC_ERROR_CARD_ECC_DISABLED;
1284 else if((response_r1 & SDMMC_OCR_ERASE_RESET) == SDMMC_OCR_ERASE_RESET)
1286 return SDMMC_ERROR_ERASE_RESET;
1288 else if((response_r1 & SDMMC_OCR_AKE_SEQ_ERROR) == SDMMC_OCR_AKE_SEQ_ERROR)
1290 return SDMMC_ERROR_AKE_SEQ_ERR;
1294 return SDMMC_ERROR_GENERAL_UNKNOWN_ERR;
1314 return SDMMC_ERROR_TIMEOUT;
1316 sta_reg = SDMMCx->
STA;
1317 }
while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT)) == 0U) ||
1318 ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
1320 if (__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
1322 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
1324 return SDMMC_ERROR_CMD_RSP_TIMEOUT;
1326 else if (__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL))
1328 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL);
1330 return SDMMC_ERROR_CMD_CRC_FAIL;
1336 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
1339 return SDMMC_ERROR_NONE;
1358 return SDMMC_ERROR_TIMEOUT;
1360 sta_reg = SDMMCx->
STA;
1361 }
while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT)) == 0U) ||
1362 ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
1364 if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
1366 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
1368 return SDMMC_ERROR_CMD_RSP_TIMEOUT;
1373 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
1376 return SDMMC_ERROR_NONE;
1387 static uint32_t SDMMC_GetCmdResp6(
SDMMC_TypeDef *SDMMCx, uint8_t SD_CMD, uint16_t *pRCA)
1389 uint32_t response_r1;
1400 return SDMMC_ERROR_TIMEOUT;
1402 sta_reg = SDMMCx->
STA;
1403 }
while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT)) == 0U) ||
1404 ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
1406 if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
1408 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
1410 return SDMMC_ERROR_CMD_RSP_TIMEOUT;
1412 else if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL))
1414 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL);
1416 return SDMMC_ERROR_CMD_CRC_FAIL;
1424 if(SDMMC_GetCommandResponse(SDMMCx) != SD_CMD)
1426 return SDMMC_ERROR_CMD_CRC_FAIL;
1430 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_STATIC_CMD_FLAGS);
1433 response_r1 = SDMMC_GetResponse(SDMMCx, SDMMC_RESP1);
1435 if((response_r1 & (SDMMC_R6_GENERAL_UNKNOWN_ERROR | SDMMC_R6_ILLEGAL_CMD | SDMMC_R6_COM_CRC_FAILED)) == SDMMC_ALLZERO)
1437 *pRCA = (uint16_t) (response_r1 >> 16);
1439 return SDMMC_ERROR_NONE;
1441 else if((response_r1 & SDMMC_R6_ILLEGAL_CMD) == SDMMC_R6_ILLEGAL_CMD)
1443 return SDMMC_ERROR_ILLEGAL_CMD;
1445 else if((response_r1 & SDMMC_R6_COM_CRC_FAILED) == SDMMC_R6_COM_CRC_FAILED)
1447 return SDMMC_ERROR_COM_CRC_FAILED;
1451 return SDMMC_ERROR_GENERAL_UNKNOWN_ERR;
1471 return SDMMC_ERROR_TIMEOUT;
1473 sta_reg = SDMMCx->
STA;
1474 }
while(((sta_reg & (SDMMC_FLAG_CCRCFAIL | SDMMC_FLAG_CMDREND | SDMMC_FLAG_CTIMEOUT)) == 0U) ||
1475 ((sta_reg & SDMMC_FLAG_CMDACT) != 0U ));
1477 if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT))
1480 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CTIMEOUT);
1482 return SDMMC_ERROR_CMD_RSP_TIMEOUT;
1484 else if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL))
1487 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CCRCFAIL);
1489 return SDMMC_ERROR_CMD_CRC_FAIL;
1496 if(__SDMMC_GET_FLAG(SDMMCx, SDMMC_FLAG_CMDREND))
1499 __SDMMC_CLEAR_FLAG(SDMMCx, SDMMC_FLAG_CMDREND);
1502 return SDMMC_ERROR_NONE;