263 #ifdef HAL_MMC_MODULE_ENABLED 298 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 347 assert_param(IS_SDMMC_CLOCK_EDGE(hmmc->Init.ClockEdge));
348 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 349 assert_param(IS_SDMMC_CLOCK_BYPASS(hmmc->Init.ClockBypass));
351 assert_param(IS_SDMMC_CLOCK_POWER_SAVE(hmmc->Init.ClockPowerSave));
353 assert_param(IS_SDMMC_HARDWARE_FLOW_CONTROL(hmmc->Init.HardwareFlowControl));
356 if(hmmc->State == HAL_MMC_STATE_RESET)
360 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 366 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 373 if(hmmc->MspInitCallback == NULL)
379 hmmc->MspInitCallback(hmmc);
386 hmmc->State = HAL_MMC_STATE_BUSY;
395 hmmc->ErrorCode = HAL_DMA_ERROR_NONE;
398 hmmc->Context = MMC_CONTEXT_NONE;
401 hmmc->State = HAL_MMC_STATE_READY;
416 MMC_InitTypeDef
Init;
417 HAL_StatusTypeDef status;
420 Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
421 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 422 Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE;
424 Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
425 Init.BusWide = SDMMC_BUS_WIDE_1B;
426 Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
427 Init.ClockDiv = SDMMC_INIT_CLK_DIV;
431 if(status == HAL_ERROR)
436 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 438 __HAL_MMC_DISABLE(hmmc);
443 if(status == HAL_ERROR)
448 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 450 __HAL_MMC_ENABLE(hmmc);
455 if(errorstate != HAL_MMC_ERROR_NONE)
457 hmmc->State = HAL_MMC_STATE_READY;
458 hmmc->ErrorCode |= errorstate;
464 if(errorstate != HAL_MMC_ERROR_NONE)
466 hmmc->State = HAL_MMC_STATE_READY;
467 hmmc->ErrorCode |= errorstate;
490 hmmc->State = HAL_MMC_STATE_BUSY;
495 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 496 if(hmmc->MspDeInitCallback == NULL)
502 hmmc->MspDeInitCallback(hmmc);
508 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
509 hmmc->State = HAL_MMC_STATE_RESET;
581 uint32_t count, data, dataremaining;
582 uint32_t add = BlockAdd;
583 uint8_t *tempbuff = pData;
587 hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
591 if(hmmc->State == HAL_MMC_STATE_READY)
593 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
595 if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
597 hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
601 hmmc->State = HAL_MMC_STATE_BUSY;
604 hmmc->Instance->DCTRL = 0U;
606 if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
613 if(errorstate != HAL_MMC_ERROR_NONE)
616 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
617 hmmc->ErrorCode |= errorstate;
618 hmmc->State = HAL_MMC_STATE_READY;
624 config.
DataLength = NumberOfBlocks * MMC_BLOCKSIZE;
628 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 629 config.
DPSM = SDMMC_DPSM_ENABLE;
631 config.
DPSM = SDMMC_DPSM_DISABLE;
634 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 635 __SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
639 if(NumberOfBlocks > 1U)
641 hmmc->Context = MMC_CONTEXT_READ_MULTIPLE_BLOCK;
648 hmmc->Context = MMC_CONTEXT_READ_SINGLE_BLOCK;
653 if(errorstate != HAL_MMC_ERROR_NONE)
656 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
657 hmmc->ErrorCode |= errorstate;
658 hmmc->State = HAL_MMC_STATE_READY;
664 while(!__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DATAEND))
666 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_RXFIFOHF) && (dataremaining > 0U))
669 for(count = 0U; count < 8U; count++)
672 *tempbuff = (uint8_t)(data & 0xFFU);
675 *tempbuff = (uint8_t)((data >> 8U) & 0xFFU);
678 *tempbuff = (uint8_t)((data >> 16U) & 0xFFU);
681 *tempbuff = (uint8_t)((data >> 24U) & 0xFFU);
687 if(((
HAL_GetTick()-tickstart) >= Timeout) || (Timeout == 0U))
690 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
691 hmmc->ErrorCode |= HAL_MMC_ERROR_TIMEOUT;
692 hmmc->State= HAL_MMC_STATE_READY;
696 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 697 __SDMMC_CMDTRANS_DISABLE( hmmc->Instance);
701 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_DATAEND) && (NumberOfBlocks > 1U))
705 if(errorstate != HAL_MMC_ERROR_NONE)
708 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
709 hmmc->ErrorCode |= errorstate;
710 hmmc->State = HAL_MMC_STATE_READY;
716 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_DTIMEOUT))
719 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
720 hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT;
721 hmmc->State = HAL_MMC_STATE_READY;
724 else if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_DCRCFAIL))
727 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
728 hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL;
729 hmmc->State = HAL_MMC_STATE_READY;
732 else if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_RXOVERR))
735 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
736 hmmc->ErrorCode |= HAL_MMC_ERROR_RX_OVERRUN;
737 hmmc->State = HAL_MMC_STATE_READY;
745 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 747 while ((__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_RXDAVL)) && (dataremaining > 0U))
750 *tempbuff = (uint8_t)(data & 0xFFU);
753 *tempbuff = (uint8_t)((data >> 8U) & 0xFFU);
756 *tempbuff = (uint8_t)((data >> 16U) & 0xFFU);
759 *tempbuff = (uint8_t)((data >> 24U) & 0xFFU);
763 if(((
HAL_GetTick()-tickstart) >= Timeout) || (Timeout == 0U))
766 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
767 hmmc->ErrorCode |= HAL_MMC_ERROR_TIMEOUT;
768 hmmc->State= HAL_MMC_STATE_READY;
775 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
777 hmmc->State = HAL_MMC_STATE_READY;
783 hmmc->ErrorCode |= HAL_MMC_ERROR_BUSY;
805 uint32_t count, data, dataremaining;
806 uint32_t add = BlockAdd;
807 uint8_t *tempbuff = pData;
811 hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
815 if(hmmc->State == HAL_MMC_STATE_READY)
817 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
819 if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
821 hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
825 hmmc->State = HAL_MMC_STATE_BUSY;
828 hmmc->Instance->DCTRL = 0U;
830 if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
837 if(errorstate != HAL_MMC_ERROR_NONE)
840 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
841 hmmc->ErrorCode |= errorstate;
842 hmmc->State = HAL_MMC_STATE_READY;
845 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 848 config.
DataLength = NumberOfBlocks * MMC_BLOCKSIZE;
852 config.
DPSM = SDMMC_DPSM_DISABLE;
854 __SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
858 if(NumberOfBlocks > 1U)
860 hmmc->Context = MMC_CONTEXT_WRITE_MULTIPLE_BLOCK;
867 hmmc->Context = MMC_CONTEXT_WRITE_SINGLE_BLOCK;
872 if(errorstate != HAL_MMC_ERROR_NONE)
875 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
876 hmmc->ErrorCode |= errorstate;
877 hmmc->State = HAL_MMC_STATE_READY;
881 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 884 config.
DataLength = NumberOfBlocks * MMC_BLOCKSIZE;
888 config.
DPSM = SDMMC_DPSM_ENABLE;
894 while(!__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_TXUNDERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DATAEND))
896 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_TXFIFOHE) && (dataremaining > 0U))
899 for(count = 0U; count < 8U; count++)
901 data = (uint32_t)(*tempbuff);
904 data |= ((uint32_t)(*tempbuff) << 8U);
907 data |= ((uint32_t)(*tempbuff) << 16U);
910 data |= ((uint32_t)(*tempbuff) << 24U);
917 if(((
HAL_GetTick()-tickstart) >= Timeout) || (Timeout == 0U))
920 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
921 hmmc->ErrorCode |= errorstate;
922 hmmc->State = HAL_MMC_STATE_READY;
926 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 927 __SDMMC_CMDTRANS_DISABLE( hmmc->Instance);
931 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_DATAEND) && (NumberOfBlocks > 1U))
935 if(errorstate != HAL_MMC_ERROR_NONE)
938 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
939 hmmc->ErrorCode |= errorstate;
940 hmmc->State = HAL_MMC_STATE_READY;
946 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_DTIMEOUT))
949 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
950 hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT;
951 hmmc->State = HAL_MMC_STATE_READY;
954 else if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_DCRCFAIL))
957 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
958 hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL;
959 hmmc->State = HAL_MMC_STATE_READY;
962 else if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_TXUNDERR))
965 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
966 hmmc->ErrorCode |= HAL_MMC_ERROR_TX_UNDERRUN;
967 hmmc->State = HAL_MMC_STATE_READY;
976 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
978 hmmc->State = HAL_MMC_STATE_READY;
984 hmmc->ErrorCode |= HAL_MMC_ERROR_BUSY;
1005 uint32_t errorstate;
1006 uint32_t add = BlockAdd;
1010 hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
1014 if(hmmc->State == HAL_MMC_STATE_READY)
1016 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
1018 if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
1020 hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
1024 hmmc->State = HAL_MMC_STATE_BUSY;
1027 hmmc->Instance->DCTRL = 0U;
1029 hmmc->pRxBuffPtr = pData;
1030 hmmc->RxXferSize = MMC_BLOCKSIZE * NumberOfBlocks;
1032 __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND | SDMMC_FLAG_RXFIFOHF));
1034 if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
1041 if(errorstate != HAL_MMC_ERROR_NONE)
1044 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1045 hmmc->ErrorCode |= errorstate;
1046 hmmc->State = HAL_MMC_STATE_READY;
1052 config.
DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
1056 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 1057 config.
DPSM = SDMMC_DPSM_ENABLE;
1059 config.
DPSM = SDMMC_DPSM_DISABLE;
1062 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 1063 __SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
1066 if(NumberOfBlocks > 1U)
1068 hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_IT);
1075 hmmc->Context = (MMC_CONTEXT_READ_SINGLE_BLOCK | MMC_CONTEXT_IT);
1081 if(errorstate != HAL_MMC_ERROR_NONE)
1084 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1085 hmmc->ErrorCode |= errorstate;
1086 hmmc->State = HAL_MMC_STATE_READY;
1114 uint32_t errorstate;
1115 uint32_t add = BlockAdd;
1119 hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
1123 if(hmmc->State == HAL_MMC_STATE_READY)
1125 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
1127 if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
1129 hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
1133 hmmc->State = HAL_MMC_STATE_BUSY;
1136 hmmc->Instance->DCTRL = 0U;
1138 hmmc->pTxBuffPtr = pData;
1139 hmmc->TxXferSize = MMC_BLOCKSIZE * NumberOfBlocks;
1142 __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND | SDMMC_FLAG_TXFIFOHE));
1144 if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
1151 if(errorstate != HAL_MMC_ERROR_NONE)
1154 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1155 hmmc->ErrorCode |= errorstate;
1156 hmmc->State = HAL_MMC_STATE_READY;
1160 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 1163 config.
DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
1167 config.
DPSM = SDMMC_DPSM_DISABLE;
1170 __SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
1174 if(NumberOfBlocks > 1U)
1176 hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK| MMC_CONTEXT_IT);
1183 hmmc->Context = (MMC_CONTEXT_WRITE_SINGLE_BLOCK | MMC_CONTEXT_IT);
1188 if(errorstate != HAL_MMC_ERROR_NONE)
1191 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1192 hmmc->ErrorCode |= errorstate;
1193 hmmc->State = HAL_MMC_STATE_READY;
1197 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 1200 config.
DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
1204 config.
DPSM = SDMMC_DPSM_ENABLE;
1232 uint32_t errorstate;
1233 uint32_t add = BlockAdd;
1237 hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
1241 if(hmmc->State == HAL_MMC_STATE_READY)
1243 hmmc->ErrorCode = HAL_DMA_ERROR_NONE;
1245 if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
1247 hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
1251 hmmc->State = HAL_MMC_STATE_BUSY;
1254 hmmc->Instance->DCTRL = 0U;
1256 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 1257 __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND));
1266 hmmc->hdmarx->XferAbortCallback = NULL;
1269 hmmc->pRxBuffPtr = pData;
1270 hmmc->RxXferSize = MMC_BLOCKSIZE * NumberOfBlocks;
1273 if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
1280 if(errorstate != HAL_MMC_ERROR_NONE)
1283 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1284 hmmc->ErrorCode = errorstate;
1285 hmmc->State = HAL_MMC_STATE_READY;
1289 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 1292 config.
DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
1296 config.
DPSM = SDMMC_DPSM_DISABLE;
1300 __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND));
1302 __SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
1303 hmmc->Instance->IDMABASE0 = (uint32_t) pData ;
1304 hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_SINGLE_BUFF;
1307 if(
HAL_DMA_Start_IT(hmmc->hdmarx, (uint32_t)&hmmc->Instance->FIFO, (uint32_t)pData, (uint32_t)(MMC_BLOCKSIZE * NumberOfBlocks)/4) !=
HAL_OK)
1309 __HAL_MMC_DISABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND));
1310 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1311 hmmc->ErrorCode = HAL_MMC_ERROR_DMA;
1312 hmmc->State = HAL_MMC_STATE_READY;
1318 __HAL_MMC_DMA_ENABLE(hmmc);
1322 config.
DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
1326 config.
DPSM = SDMMC_DPSM_ENABLE;
1331 if(NumberOfBlocks > 1U)
1333 hmmc->Context = (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
1340 hmmc->Context = (MMC_CONTEXT_READ_SINGLE_BLOCK | MMC_CONTEXT_DMA);
1345 if(errorstate != HAL_MMC_ERROR_NONE)
1348 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1349 __HAL_MMC_DISABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_RXOVERR | SDMMC_IT_DATAEND));
1350 hmmc->ErrorCode = errorstate;
1351 hmmc->State = HAL_MMC_STATE_READY;
1356 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 1382 uint32_t errorstate;
1383 uint32_t add = BlockAdd;
1387 hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
1391 if(hmmc->State == HAL_MMC_STATE_READY)
1393 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
1395 if((BlockAdd + NumberOfBlocks) > (hmmc->MmcCard.LogBlockNbr))
1397 hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
1401 hmmc->State = HAL_MMC_STATE_BUSY;
1404 hmmc->Instance->DCTRL = 0U;
1406 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 1408 __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR));
1417 hmmc->hdmatx->XferAbortCallback = NULL;
1419 hmmc->pTxBuffPtr = pData;
1420 hmmc->TxXferSize = MMC_BLOCKSIZE * NumberOfBlocks;
1423 if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
1430 if(errorstate != HAL_MMC_ERROR_NONE)
1433 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1434 hmmc->ErrorCode |= errorstate;
1435 hmmc->State = HAL_MMC_STATE_READY;
1439 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 1442 config.
DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
1446 config.
DPSM = SDMMC_DPSM_DISABLE;
1450 __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND));
1452 __SDMMC_CMDTRANS_ENABLE( hmmc->Instance);
1454 hmmc->Instance->IDMABASE0 = (uint32_t) pData ;
1455 hmmc->Instance->IDMACTRL = SDMMC_ENABLE_IDMA_SINGLE_BUFF;
1459 if(NumberOfBlocks > 1U)
1461 hmmc->Context = (MMC_CONTEXT_WRITE_MULTIPLE_BLOCK | MMC_CONTEXT_DMA);
1468 hmmc->Context = (MMC_CONTEXT_WRITE_SINGLE_BLOCK | MMC_CONTEXT_DMA);
1473 if(errorstate != HAL_MMC_ERROR_NONE)
1476 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1477 __HAL_MMC_DISABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND));
1478 hmmc->ErrorCode |= errorstate;
1479 hmmc->State = HAL_MMC_STATE_READY;
1483 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 1485 __HAL_MMC_DMA_ENABLE(hmmc);
1488 if(
HAL_DMA_Start_IT(hmmc->hdmatx, (uint32_t)pData, (uint32_t)&hmmc->Instance->FIFO, (uint32_t)(MMC_BLOCKSIZE * NumberOfBlocks)/4) !=
HAL_OK)
1490 __HAL_MMC_DISABLE_IT(hmmc, (SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT | SDMMC_IT_TXUNDERR | SDMMC_IT_DATAEND));
1491 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1492 hmmc->ErrorCode |= HAL_MMC_ERROR_DMA;
1493 hmmc->State = HAL_MMC_STATE_READY;
1500 config.
DataLength = MMC_BLOCKSIZE * NumberOfBlocks;
1504 config.
DPSM = SDMMC_DPSM_ENABLE;
1530 uint32_t errorstate;
1531 uint32_t start_add = BlockStartAdd;
1532 uint32_t end_add = BlockEndAdd;
1534 if(hmmc->State == HAL_MMC_STATE_READY)
1536 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
1538 if(end_add < start_add)
1540 hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
1544 if(end_add > (hmmc->MmcCard.LogBlockNbr))
1546 hmmc->ErrorCode |= HAL_MMC_ERROR_ADDR_OUT_OF_RANGE;
1550 hmmc->State = HAL_MMC_STATE_BUSY;
1553 if(((hmmc->MmcCard.Class) & SDMMC_CCCC_ERASE) == 0U)
1556 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1557 hmmc->ErrorCode |= HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE;
1558 hmmc->State = HAL_MMC_STATE_READY;
1562 if((
SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP1) & SDMMC_CARD_LOCKED) == SDMMC_CARD_LOCKED)
1565 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1566 hmmc->ErrorCode |= HAL_MMC_ERROR_LOCK_UNLOCK_FAILED;
1567 hmmc->State = HAL_MMC_STATE_READY;
1571 if ((hmmc->MmcCard.CardType) != MMC_HIGH_CAPACITY_CARD)
1579 if(errorstate != HAL_MMC_ERROR_NONE)
1582 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1583 hmmc->ErrorCode |= errorstate;
1584 hmmc->State = HAL_MMC_STATE_READY;
1590 if(errorstate != HAL_MMC_ERROR_NONE)
1593 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1594 hmmc->ErrorCode |= errorstate;
1595 hmmc->State = HAL_MMC_STATE_READY;
1601 if(errorstate != HAL_MMC_ERROR_NONE)
1604 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
1605 hmmc->ErrorCode |= errorstate;
1606 hmmc->State = HAL_MMC_STATE_READY;
1610 hmmc->State = HAL_MMC_STATE_READY;
1627 uint32_t errorstate;
1628 uint32_t context = hmmc->Context;
1631 if((__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_RXFIFOHF) != RESET) && ((context & MMC_CONTEXT_IT) != 0U))
1636 else if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_DATAEND) != RESET)
1638 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_FLAG_DATAEND);
1640 __HAL_MMC_DISABLE_IT(hmmc, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT |\
1641 SDMMC_IT_TXUNDERR | SDMMC_IT_RXOVERR | SDMMC_IT_TXFIFOHE |\
1644 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 1645 hmmc->Instance->DCTRL &= ~(SDMMC_DCTRL_DTEN);
1647 __HAL_MMC_DISABLE_IT(hmmc, SDMMC_IT_IDMABTC);
1648 __SDMMC_CMDTRANS_DISABLE( hmmc->Instance);
1651 if((context & MMC_CONTEXT_DMA) != 0U)
1653 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 1654 hmmc->Instance->DLEN = 0;
1655 hmmc->Instance->DCTRL = 0;
1656 hmmc->Instance->IDMACTRL = SDMMC_DISABLE_IDMA ;
1659 if(((context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) != 0U) || ((context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U))
1662 if(errorstate != HAL_MMC_ERROR_NONE)
1664 hmmc->ErrorCode |= errorstate;
1665 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1666 hmmc->ErrorCallback(hmmc);
1674 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
1676 hmmc->State = HAL_MMC_STATE_READY;
1677 if(((context & MMC_CONTEXT_WRITE_SINGLE_BLOCK) != 0U) || ((context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U))
1679 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1680 hmmc->TxCpltCallback(hmmc);
1685 if(((context & MMC_CONTEXT_READ_SINGLE_BLOCK) != 0U) || ((context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) != 0U))
1687 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1688 hmmc->RxCpltCallback(hmmc);
1694 if((context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U)
1697 if(errorstate != HAL_MMC_ERROR_NONE)
1699 hmmc->ErrorCode |= errorstate;
1700 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1701 hmmc->ErrorCallback(hmmc);
1707 if(((context & MMC_CONTEXT_READ_SINGLE_BLOCK) == 0U) && ((context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) == 0U))
1711 hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDMMC_DCTRL_DMAEN);
1713 hmmc->State = HAL_MMC_STATE_READY;
1715 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1716 hmmc->TxCpltCallback(hmmc);
1723 else if((context & MMC_CONTEXT_IT) != 0U)
1726 if(((context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) != 0U) || ((context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U))
1729 if(errorstate != HAL_MMC_ERROR_NONE)
1731 hmmc->ErrorCode |= errorstate;
1732 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1733 hmmc->ErrorCallback(hmmc);
1741 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
1743 hmmc->State = HAL_MMC_STATE_READY;
1744 if(((context & MMC_CONTEXT_READ_SINGLE_BLOCK) != 0U) || ((context & MMC_CONTEXT_READ_MULTIPLE_BLOCK) != 0U))
1746 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1747 hmmc->RxCpltCallback(hmmc);
1754 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1755 hmmc->TxCpltCallback(hmmc);
1767 else if((__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_TXFIFOHE) != RESET) && ((context & MMC_CONTEXT_IT) != 0U))
1772 else if (__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_DCRCFAIL| SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_RXOVERR | SDMMC_FLAG_TXUNDERR) != RESET)
1775 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_IT_DCRCFAIL) != RESET)
1777 hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL;
1779 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_IT_DTIMEOUT) != RESET)
1781 hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT;
1783 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_IT_RXOVERR) != RESET)
1785 hmmc->ErrorCode |= HAL_MMC_ERROR_RX_OVERRUN;
1787 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_IT_TXUNDERR) != RESET)
1789 hmmc->ErrorCode |= HAL_MMC_ERROR_TX_UNDERRUN;
1793 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
1796 __HAL_MMC_DISABLE_IT(hmmc, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT|\
1797 SDMMC_IT_TXUNDERR| SDMMC_IT_RXOVERR);
1799 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 1800 __SDMMC_CMDTRANS_DISABLE( hmmc->Instance);
1801 hmmc->Instance->DCTRL |= SDMMC_DCTRL_FIFORST;
1802 hmmc->Instance->CMD |= SDMMC_CMD_CMDSTOP;
1805 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 1806 hmmc->Instance->CMD &= ~(SDMMC_CMD_CMDSTOP);
1807 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_FLAG_DABORT);
1810 if((context & MMC_CONTEXT_IT) != 0U)
1813 hmmc->State = HAL_MMC_STATE_READY;
1814 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1815 hmmc->ErrorCallback(hmmc);
1820 else if((context & MMC_CONTEXT_DMA) != 0U)
1822 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 1823 if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE)
1826 __HAL_MMC_DISABLE_IT(hmmc, SDMMC_IT_IDMABTC);
1827 hmmc->Instance->IDMACTRL = SDMMC_DISABLE_IDMA;
1830 hmmc->State = HAL_MMC_STATE_READY;
1831 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1832 hmmc->ErrorCallback(hmmc);
1839 if(hmmc->hdmatx != NULL)
1849 else if(hmmc->hdmarx != NULL)
1861 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
1862 hmmc->State = HAL_MMC_STATE_READY;
1863 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1864 hmmc->AbortCpltCallback(hmmc);
1877 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 1878 else if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_IDMABTC) != RESET)
1880 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_IT_IDMABTC);
1881 if(READ_BIT(hmmc->Instance->IDMACTRL, SDMMC_IDMA_IDMABACT) == 0U)
1884 if((context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U)
1886 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1887 hmmc->Write_DMADblBuf1CpltCallback(hmmc);
1894 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1895 hmmc->Read_DMADblBuf1CpltCallback(hmmc);
1904 if((context & MMC_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U)
1906 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1907 hmmc->Write_DMADblBuf0CpltCallback(hmmc);
1914 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 1915 hmmc->Read_DMADblBuf0CpltCallback(hmmc);
1948 return hmmc->ErrorCode;
2011 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 2033 HAL_StatusTypeDef status =
HAL_OK;
2035 if(pCallback == NULL)
2038 hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK;
2045 if(hmmc->State == HAL_MMC_STATE_READY)
2050 hmmc->TxCpltCallback = pCallback;
2053 hmmc->RxCpltCallback = pCallback;
2056 hmmc->ErrorCallback = pCallback;
2059 hmmc->AbortCpltCallback = pCallback;
2061 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 2063 hmmc->Read_DMADblBuf0CpltCallback = pCallback;
2066 hmmc->Read_DMADblBuf1CpltCallback = pCallback;
2069 hmmc->Write_DMADblBuf0CpltCallback = pCallback;
2072 hmmc->Write_DMADblBuf1CpltCallback = pCallback;
2076 hmmc->MspInitCallback = pCallback;
2079 hmmc->MspDeInitCallback = pCallback;
2083 hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK;
2089 else if (hmmc->State == HAL_MMC_STATE_RESET)
2094 hmmc->MspInitCallback = pCallback;
2097 hmmc->MspDeInitCallback = pCallback;
2101 hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK;
2110 hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK;
2140 HAL_StatusTypeDef status =
HAL_OK;
2145 if(hmmc->State == HAL_MMC_STATE_READY)
2161 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 2183 hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK;
2189 else if (hmmc->State == HAL_MMC_STATE_RESET)
2201 hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK;
2210 hmmc->ErrorCode |= HAL_MMC_ERROR_INVALID_CALLBACK;
2250 pCID->
ManufacturerID = (uint8_t)((hmmc->CID[0] & 0xFF000000U) >> 24U);
2252 pCID->
OEM_AppliID = (uint16_t)((hmmc->CID[0] & 0x00FFFF00U) >> 8U);
2254 pCID->
ProdName1 = (((hmmc->CID[0] & 0x000000FFU) << 24U) | ((hmmc->CID[1] & 0xFFFFFF00U) >> 8U));
2256 pCID->
ProdName2 = (uint8_t)(hmmc->CID[1] & 0x000000FFU);
2258 pCID->
ProdRev = (uint8_t)((hmmc->CID[2] & 0xFF000000U) >> 24U);
2260 pCID->
ProdSN = (((hmmc->CID[2] & 0x00FFFFFFU) << 8U) | ((hmmc->CID[3] & 0xFF000000U) >> 24U));
2262 pCID->
Reserved1 = (uint8_t)((hmmc->CID[3] & 0x00F00000U) >> 20U);
2264 pCID->
ManufactDate = (uint16_t)((hmmc->CID[3] & 0x000FFF00U) >> 8U);
2266 pCID->
CID_CRC = (uint8_t)((hmmc->CID[3] & 0x000000FEU) >> 1U);
2283 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 2284 uint32_t block_nbr = 0;
2287 pCSD->
CSDStruct = (uint8_t)((hmmc->CSD[0] & 0xC0000000U) >> 30U);
2289 pCSD->
SysSpecVersion = (uint8_t)((hmmc->CSD[0] & 0x3C000000U) >> 26U);
2291 pCSD->
Reserved1 = (uint8_t)((hmmc->CSD[0] & 0x03000000U) >> 24U);
2293 pCSD->
TAAC = (uint8_t)((hmmc->CSD[0] & 0x00FF0000U) >> 16U);
2295 pCSD->
NSAC = (uint8_t)((hmmc->CSD[0] & 0x0000FF00U) >> 8U);
2297 pCSD->
MaxBusClkFrec = (uint8_t)(hmmc->CSD[0] & 0x000000FFU);
2299 pCSD->
CardComdClasses = (uint16_t)((hmmc->CSD[1] & 0xFFF00000U) >> 20U);
2301 pCSD->
RdBlockLen = (uint8_t)((hmmc->CSD[1] & 0x000F0000U) >> 16U);
2303 pCSD->
PartBlockRead = (uint8_t)((hmmc->CSD[1] & 0x00008000U) >> 15U);
2305 pCSD->
WrBlockMisalign = (uint8_t)((hmmc->CSD[1] & 0x00004000U) >> 14U);
2307 pCSD->
RdBlockMisalign = (uint8_t)((hmmc->CSD[1] & 0x00002000U) >> 13U);
2309 pCSD->
DSRImpl = (uint8_t)((hmmc->CSD[1] & 0x00001000U) >> 12U);
2313 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 2319 if(hmmc->MmcCard.CardType == MMC_LOW_CAPACITY_CARD)
2322 pCSD->
DeviceSize = (((hmmc->CSD[1] & 0x000003FFU) << 2U) | ((hmmc->CSD[2] & 0xC0000000U) >> 30U));
2332 pCSD->
DeviceSizeMul = (uint8_t)((hmmc->CSD[2] & 0x00038000U) >> 15U);
2334 hmmc->MmcCard.BlockNbr = (pCSD->
DeviceSize + 1U) ;
2335 hmmc->MmcCard.BlockNbr *= (1UL << ((pCSD->
DeviceSizeMul & 0x07U) + 2U));
2336 hmmc->MmcCard.BlockSize = (1UL << (pCSD->
RdBlockLen & 0x0FU));
2338 hmmc->MmcCard.LogBlockNbr = (hmmc->MmcCard.BlockNbr) * ((hmmc->MmcCard.BlockSize) / 512U);
2339 hmmc->MmcCard.LogBlockSize = 512U;
2340 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 2342 else if(hmmc->MmcCard.CardType == MMC_HIGH_CAPACITY_CARD)
2344 hmmc->MmcCard.BlockNbr = block_nbr;
2345 hmmc->MmcCard.LogBlockNbr = hmmc->MmcCard.BlockNbr;
2346 hmmc->MmcCard.BlockSize = 512U;
2347 hmmc->MmcCard.LogBlockSize = hmmc->MmcCard.BlockSize;
2352 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
2353 hmmc->ErrorCode |= HAL_MMC_ERROR_UNSUPPORTED_FEATURE;
2354 hmmc->State = HAL_MMC_STATE_READY;
2359 pCSD->
EraseGrSize = (uint8_t)((hmmc->CSD[2] & 0x00004000U) >> 14U);
2361 pCSD->
EraseGrMul = (uint8_t)((hmmc->CSD[2] & 0x00003F80U) >> 7U);
2367 pCSD->
ManDeflECC = (uint8_t)((hmmc->CSD[3] & 0x60000000U) >> 29U);
2369 pCSD->
WrSpeedFact = (uint8_t)((hmmc->CSD[3] & 0x1C000000U) >> 26U);
2371 pCSD->
MaxWrBlockLen= (uint8_t)((hmmc->CSD[3] & 0x03C00000U) >> 22U);
2379 pCSD->
FileFormatGroup = (uint8_t)((hmmc->CSD[3] & 0x00008000U) >> 15U);
2381 pCSD->
CopyFlag = (uint8_t)((hmmc->CSD[3] & 0x00004000U) >> 14U);
2383 pCSD->
PermWrProtect = (uint8_t)((hmmc->CSD[3] & 0x00002000U) >> 13U);
2385 pCSD->
TempWrProtect = (uint8_t)((hmmc->CSD[3] & 0x00001000U) >> 12U);
2387 pCSD->
FileFormat = (uint8_t)((hmmc->CSD[3] & 0x00000C00U) >> 10U);
2389 pCSD->
ECC= (uint8_t)((hmmc->CSD[3] & 0x00000300U) >> 8U);
2391 pCSD->
CSD_CRC = (uint8_t)((hmmc->CSD[3] & 0x000000FEU) >> 1U);
2407 pCardInfo->
CardType = (uint32_t)(hmmc->MmcCard.CardType);
2408 pCardInfo->
Class = (uint32_t)(hmmc->MmcCard.Class);
2409 pCardInfo->
RelCardAdd = (uint32_t)(hmmc->MmcCard.RelCardAdd);
2410 pCardInfo->
BlockNbr = (uint32_t)(hmmc->MmcCard.BlockNbr);
2411 pCardInfo->
BlockSize = (uint32_t)(hmmc->MmcCard.BlockSize);
2412 pCardInfo->
LogBlockNbr = (uint32_t)(hmmc->MmcCard.LogBlockNbr);
2413 pCardInfo->
LogBlockSize = (uint32_t)(hmmc->MmcCard.LogBlockSize);
2431 __IO uint32_t count = 0U;
2432 SDMMC_InitTypeDef
Init;
2433 uint32_t errorstate;
2434 uint32_t response = 0U, busy = 0U;
2440 hmmc->State = HAL_MMC_STATE_BUSY;
2442 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 2444 Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
2445 Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE;
2446 Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
2447 Init.BusWide = WideMode;
2448 Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
2449 Init.ClockDiv = SDMMC_INIT_CLK_DIV;
2454 if(WideMode == SDMMC_BUS_WIDE_8B)
2457 if(errorstate != HAL_MMC_ERROR_NONE)
2459 hmmc->ErrorCode |= errorstate;
2462 else if(WideMode == SDMMC_BUS_WIDE_4B)
2465 if(errorstate != HAL_MMC_ERROR_NONE)
2467 hmmc->ErrorCode |= errorstate;
2470 else if(WideMode == SDMMC_BUS_WIDE_1B)
2473 if(errorstate != HAL_MMC_ERROR_NONE)
2475 hmmc->ErrorCode |= errorstate;
2481 hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
2487 if(count == SDMMC_MAX_TRIAL)
2489 hmmc->State = HAL_MMC_STATE_READY;
2490 hmmc->ErrorCode |= HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE;
2496 errorstate =
SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
2497 if(errorstate != HAL_MMC_ERROR_NONE)
2499 hmmc->ErrorCode |= errorstate;
2506 busy = (((response >> 7U) == 1U) ? 0U : 1U);
2510 count = SDMMC_DATATIMEOUT;
2511 while((response & 0x00000100U) == 0U)
2515 hmmc->State = HAL_MMC_STATE_READY;
2516 hmmc->ErrorCode |= HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE;
2522 errorstate =
SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
2523 if(errorstate != HAL_MMC_ERROR_NONE)
2525 hmmc->ErrorCode |= errorstate;
2532 if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE)
2535 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
2536 hmmc->State = HAL_MMC_STATE_READY;
2542 Init.ClockEdge = hmmc->Init.ClockEdge;
2543 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 2544 Init.ClockBypass = hmmc->Init.ClockBypass;
2546 Init.ClockPowerSave = hmmc->Init.ClockPowerSave;
2547 Init.BusWide = WideMode;
2548 Init.HardwareFlowControl = hmmc->Init.HardwareFlowControl;
2549 Init.ClockDiv = hmmc->Init.ClockDiv;
2554 hmmc->State = HAL_MMC_STATE_READY;
2567 uint32_t errorstate;
2568 uint32_t resp1 = 0U;
2571 if(errorstate != HAL_MMC_ERROR_NONE)
2573 hmmc->ErrorCode |= errorstate;
2576 cardstate = ((resp1 >> 9U) & 0x0FU);
2592 __HAL_MMC_DISABLE_IT(hmmc, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT|\
2593 SDMMC_IT_TXUNDERR| SDMMC_IT_RXOVERR);
2596 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
2598 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 2599 if((hmmc->hdmatx != NULL) || (hmmc->hdmarx != NULL))
2602 hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDMMC_DCTRL_DMAEN);
2605 if(hmmc->hdmatx != NULL)
2609 hmmc->ErrorCode |= HAL_MMC_ERROR_DMA;
2613 if(hmmc->hdmarx != NULL)
2617 hmmc->ErrorCode |= HAL_MMC_ERROR_DMA;
2623 hmmc->Instance->IDMACTRL = SDMMC_DISABLE_IDMA;
2626 hmmc->State = HAL_MMC_STATE_READY;
2629 hmmc->Context = MMC_CONTEXT_NONE;
2632 if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING))
2636 if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE)
2654 __HAL_MMC_DISABLE_IT(hmmc, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT|\
2655 SDMMC_IT_TXUNDERR| SDMMC_IT_RXOVERR);
2657 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 2659 hmmc->Instance->IDMACTRL = SDMMC_DISABLE_IDMA;
2663 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
2665 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 2666 if((hmmc->hdmatx != NULL) || (hmmc->hdmarx != NULL))
2669 hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDMMC_DCTRL_DMAEN);
2672 if(hmmc->hdmatx != NULL)
2677 hmmc->hdmatx = NULL;
2681 if(hmmc->hdmarx != NULL)
2686 hmmc->hdmarx = NULL;
2692 if((hmmc->hdmatx == NULL) && (hmmc->hdmarx == NULL))
2696 hmmc->State = HAL_MMC_STATE_READY;
2698 if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING))
2702 if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE)
2708 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 2709 hmmc->AbortCpltCallback(hmmc);
2713 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 2734 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 2745 __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DATAEND));
2756 uint32_t errorstate;
2759 if(hmmc->Context == (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA))
2762 if(errorstate != HAL_MMC_ERROR_NONE)
2764 hmmc->ErrorCode |= errorstate;
2765 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 2766 hmmc->ErrorCallback(hmmc);
2775 hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDMMC_DCTRL_DMAEN);
2778 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
2780 hmmc->State = HAL_MMC_STATE_READY;
2782 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 2783 hmmc->RxCpltCallback(hmmc);
2798 uint32_t RxErrorCode, TxErrorCode;
2800 RxErrorCode = hmmc->hdmarx->ErrorCode;
2801 TxErrorCode = hmmc->hdmatx->ErrorCode;
2802 if((RxErrorCode == HAL_DMA_ERROR_TE) || (TxErrorCode == HAL_DMA_ERROR_TE))
2805 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
2808 __HAL_MMC_DISABLE_IT(hmmc, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT|\
2809 SDMMC_IT_TXUNDERR| SDMMC_IT_RXOVERR);
2811 hmmc->ErrorCode |= HAL_MMC_ERROR_DMA;
2813 if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING))
2818 hmmc->State= HAL_MMC_STATE_READY;
2821 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 2822 hmmc->ErrorCallback(hmmc);
2838 if(hmmc->hdmatx != NULL)
2840 hmmc->hdmatx = NULL;
2844 if(hmmc->hdmarx == NULL)
2847 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
2848 hmmc->State = HAL_MMC_STATE_READY;
2849 if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING))
2853 if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE)
2855 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 2856 hmmc->AbortCpltCallback(hmmc);
2863 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 2864 hmmc->ErrorCallback(hmmc);
2883 if(hmmc->hdmarx != NULL)
2885 hmmc->hdmarx = NULL;
2889 if(hmmc->hdmatx == NULL)
2892 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
2893 hmmc->State = HAL_MMC_STATE_READY;
2894 if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING))
2898 if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE)
2900 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 2901 hmmc->AbortCpltCallback(hmmc);
2908 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U) 2909 hmmc->ErrorCallback(hmmc);
2927 uint32_t errorstate;
2928 uint16_t mmc_rca = 1U;
2929 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 2930 MMC_InitTypeDef
Init;
2937 return HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE;
2942 if(errorstate != HAL_MMC_ERROR_NONE)
2958 if(errorstate != HAL_MMC_ERROR_NONE)
2964 hmmc->MmcCard.RelCardAdd = mmc_rca;
2967 errorstate =
SDMMC_CmdSendCSD(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U));
2968 if(errorstate != HAL_MMC_ERROR_NONE)
2984 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx) 2988 return hmmc->ErrorCode;
2992 errorstate =
SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
2993 if(errorstate != HAL_MMC_ERROR_NONE)
2999 (void)
SDMMC_Init(hmmc->Instance, hmmc->Init);
3002 errorstate =
SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
3003 if(errorstate != HAL_MMC_ERROR_NONE)
3011 return hmmc->ErrorCode;
3015 errorstate =
SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
3016 if(errorstate != HAL_MMC_ERROR_NONE)
3018 hmmc->ErrorCode |= errorstate;
3022 Init.ClockEdge = hmmc->Init.ClockEdge;
3023 Init.ClockPowerSave = hmmc->Init.ClockPowerSave;
3024 Init.BusWide = SDMMC_BUS_WIDE_1B;
3025 Init.HardwareFlowControl = hmmc->Init.HardwareFlowControl;
3026 Init.ClockDiv = hmmc->Init.ClockDiv;
3031 return HAL_MMC_ERROR_NONE;
3043 __IO uint32_t count = 0U;
3044 uint32_t response = 0U, validvoltage = 0U;
3045 uint32_t errorstate;
3049 if(errorstate != HAL_MMC_ERROR_NONE)
3054 while(validvoltage == 0U)
3056 if(count++ == SDMMC_MAX_VOLT_TRIAL)
3058 return HAL_MMC_ERROR_INVALID_VOLTRANGE;
3063 if(errorstate != HAL_MMC_ERROR_NONE)
3065 return HAL_MMC_ERROR_UNSUPPORTED_FEATURE;
3072 validvoltage = (((response >> 31U) == 1U) ? 1U : 0U);
3076 if (((response & (0xFF000000U)) >> 24) == 0xC0U)
3078 hmmc->MmcCard.CardType = MMC_HIGH_CAPACITY_CARD;
3082 hmmc->MmcCard.CardType = MMC_LOW_CAPACITY_CARD;
3085 return HAL_MMC_ERROR_NONE;
3108 uint32_t errorstate;
3110 if(pCardStatus == NULL)
3112 return HAL_MMC_ERROR_PARAM;
3116 errorstate =
SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U));
3117 if(errorstate != HAL_MMC_ERROR_NONE)
3125 return HAL_MMC_ERROR_NONE;
3128 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 3139 uint32_t errorstate;
3145 hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
3148 hmmc->Instance->DCTRL = 0;
3156 config.
DPSM = SDMMC_DPSM_DISABLE;
3161 if(errorstate != HAL_MMC_ERROR_NONE)
3164 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
3165 hmmc->ErrorCode |= errorstate;
3166 hmmc->State = HAL_MMC_STATE_READY;
3176 config.
DPSM = SDMMC_DPSM_ENABLE;
3181 if(errorstate != HAL_MMC_ERROR_NONE)
3184 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
3185 hmmc->ErrorCode |= errorstate;
3186 hmmc->State = HAL_MMC_STATE_READY;
3191 while(!__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DATAEND))
3193 if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_RXFIFOHF))
3196 for(count = 0U; count < 8U; count++)
3199 if ((i == 48U) && (count == 5U))
3201 *pBlockNbr = tmp_data;
3207 if(((
HAL_GetTick()-tickstart) >= Timeout) || (Timeout == 0U))
3210 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
3211 hmmc->ErrorCode |= HAL_MMC_ERROR_TIMEOUT;
3212 hmmc->State= HAL_MMC_STATE_READY;
3218 errorstate =
SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16));
3219 if(errorstate != HAL_MMC_ERROR_NONE)
3221 hmmc->ErrorCode |= errorstate;
3225 __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
3227 hmmc->State = HAL_MMC_STATE_READY;
3241 uint32_t count, data, dataremaining;
3244 tmp = hmmc->pRxBuffPtr;
3245 dataremaining = hmmc->RxXferSize;
3247 if (dataremaining > 0U)
3250 for(count = 0U; count < 8U; count++)
3253 *tmp = (uint8_t)(data & 0xFFU);
3256 *tmp = (uint8_t)((data >> 8U) & 0xFFU);
3259 *tmp = (uint8_t)((data >> 16U) & 0xFFU);
3262 *tmp = (uint8_t)((data >> 24U) & 0xFFU);
3267 hmmc->pRxBuffPtr = tmp;
3268 hmmc->RxXferSize = dataremaining;
3280 uint32_t count, data, dataremaining;
3283 tmp = hmmc->pTxBuffPtr;
3284 dataremaining = hmmc->TxXferSize;
3286 if (dataremaining > 0U)
3289 for(count = 0U; count < 8U; count++)
3291 data = (uint32_t)(*tmp);
3294 data |= ((uint32_t)(*tmp) << 8U);
3297 data |= ((uint32_t)(*tmp) << 16U);
3300 data |= ((uint32_t)(*tmp) << 24U);
3306 hmmc->pTxBuffPtr = tmp;
3307 hmmc->TxXferSize = dataremaining;
void HAL_MMC_AbortCallback(MMC_HandleTypeDef *hmmc)
MMC Abort callbacks.
uint32_t SDMMC_CmdBlockLength(SDMMC_TypeDef *SDMMCx, uint32_t BlockSize)
Send the Data Block Lenght command and check the response.
HAL_StatusTypeDef HAL_MMC_ConfigWideBusOperation(MMC_HandleTypeDef *hmmc, uint32_t WideMode)
Enables wide bus operation for the requested card if supported by card.
__IO uint8_t WrProtectGrSize
uint32_t SDMMC_CmdSendEXTCSD(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Send the Send EXT_CSD command and check the response.
HAL_StatusTypeDef HAL_MMC_DeInit(MMC_HandleTypeDef *hmmc)
De-Initializes the MMC card.
__IO uint16_t ManufactDate
HAL_StatusTypeDef HAL_MMC_UnRegisterCallback(MMC_HandleTypeDef *hmmc, HAL_MMC_CallbackIDTypeDef CallbackId)
Unregister a User MMC Callback MMC Callback is redirected to the weak (surcharged) predefined callbac...
__IO uint8_t TempWrProtect
uint32_t SDMMC_CmdSelDesel(SDMMC_TypeDef *SDMMCx, uint64_t Addr)
Send the Select Deselect command and check the response.
HAL_StatusTypeDef HAL_MMC_RegisterCallback(MMC_HandleTypeDef *hmmc, HAL_MMC_CallbackIDTypeDef CallbackId, pMMC_CallbackTypeDef pCallback)
Register a User MMC Callback To be used instead of the weak (surcharged) predefined callback...
DMA handle Structure definition.
struct __MMC_HandleTypeDef else typedef struct endif MMC_HandleTypeDef
MMC handle Structure definition.
static uint32_t MMC_PowerON(MMC_HandleTypeDef *hmmc)
Enquires cards about their operating voltage and configures clock controls and stores MMC information...
uint32_t SDMMC_CmdReadSingleBlock(SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd)
Send the Read Single Block command and check the response.
void HAL_MMCEx_Read_DMADoubleBuffer0CpltCallback(MMC_HandleTypeDef *hmmc)
Read DMA Buffer 0 Transfer completed callbacks.
__IO uint8_t MaxWrCurrentVDDMax
HAL_StatusTypeDef HAL_MMC_Abort(MMC_HandleTypeDef *hmmc)
Abort the current transfer and disable the MMC.
uint32_t SDMMC_CmdWriteMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd)
Send the Write Multi Block command and check the response.
This file contains all the functions prototypes for the HAL module driver.
void HAL_MMC_MspInit(MMC_HandleTypeDef *hmmc)
Initializes the MMC MSP.
uint32_t SDMMC_CmdOpCondition(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Sends host capacity support information and activates the card's initialization process. Send SDMMC_CMD_SEND_OP_COND command.
__IO uint8_t WrBlockMisalign
SDMMC Data Control structure.
uint32_t SDMMC_CmdErase(SDMMC_TypeDef *SDMMCx)
Send the Erase command and check the response.
uint32_t SDMMC_CmdSendStatus(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Send the Status command and check the response.
uint32_t SDMMC_CmdSwitch(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Checks switchable function and switch card function. SDMMC_CMD_HS_SWITCH comand.
HAL_StatusTypeDef HAL_MMC_ReadBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
Reads block(s) from a specified address in a card. The Data transfer is managed in interrupt mode...
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__IO uint8_t ContentProtectAppli
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
__IO uint8_t PartBlockRead
HAL_StatusTypeDef HAL_MMC_InitCard(MMC_HandleTypeDef *hmmc)
Initializes the MMC Card.
static void MMC_Write_IT(MMC_HandleTypeDef *hmmc)
Wrap up writing in non-blocking mode.
static void MMC_DMAError(DMA_HandleTypeDef *hdma)
DMA MMC communication error callback.
__IO uint16_t OEM_AppliID
uint32_t SDMMC_GetPowerState(SDMMC_TypeDef *SDMMCx)
Get SDMMC Power state.
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
uint32_t SDMMC_CmdSendCSD(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Send the Send CSD command and check the response.
HAL_StatusTypeDef HAL_MMC_Erase(MMC_HandleTypeDef *hmmc, uint32_t BlockStartAdd, uint32_t BlockEndAdd)
Erases the specified memory area of the given MMC card.
__IO uint8_t RdBlockMisalign
void HAL_MMC_ErrorCallback(MMC_HandleTypeDef *hmmc)
MMC error callbacks.
void HAL_MMC_TxCpltCallback(MMC_HandleTypeDef *hmmc)
Tx Transfer completed callbacks.
HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState(MMC_HandleTypeDef *hmmc)
Gets the current mmc card data state.
HAL_StatusTypeDef HAL_MMC_WriteBlocks(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout)
Allows to write block(s) to a specified address in a card. The Data transfer is managed by polling mo...
void HAL_MMCEx_Write_DMADoubleBuffer0CpltCallback(MMC_HandleTypeDef *hmmc)
Write DMA Buffer 0 Transfer completed callbacks.
HAL_StatusTypeDef HAL_MMC_ReadBlocks(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout)
Reads block(s) from a specified address in a card. The Data transfer is managed by polling mode...
void(* pMMC_CallbackTypeDef)(MMC_HandleTypeDef *hmmc)
HAL_MMC_CallbackIDTypeDef
static HAL_StatusTypeDef MMC_ReadExtCSD(MMC_HandleTypeDef *hmmc, uint32_t *pBlockNbr, uint32_t Timeout)
Reads extended CSD register to get the sectors number of the device.
static void MMC_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
DMA MMC receive process complete callback.
HAL_StatusTypeDef HAL_MMC_WriteBlocks_DMA(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
Writes block(s) to a specified address in a card. The Data transfer is managed by DMA mode...
uint32_t SDMMC_ReadFIFO(SDMMC_TypeDef *SDMMCx)
Read data (word) from Rx FIFO in blocking mode (polling)
uint32_t SDMMC_CmdSetRelAdd(SDMMC_TypeDef *SDMMCx, uint16_t *pRCA)
Send the Send CSD command and check the response.
__IO uint8_t MaxBusClkFrec
uint32_t SDMMC_CmdSendCID(SDMMC_TypeDef *SDMMCx)
Send the Send CID command and check the response.
static void MMC_Read_IT(MMC_HandleTypeDef *hmmc)
Wrap up reading in non-blocking mode.
__IO uint8_t MaxRdCurrentVDDMax
__IO uint8_t ManufacturerID
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.
static uint32_t MMC_SendStatus(MMC_HandleTypeDef *hmmc, uint32_t *pCardStatus)
Returns the current card's status.
uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response)
Return the response received from the card for the last command.
static void MMC_DMATransmitCplt(DMA_HandleTypeDef *hdma)
DMA MMC transmit process complete callback.
static uint32_t MMC_InitCard(MMC_HandleTypeDef *hmmc)
Initializes the mmc card.
uint32_t SDMMC_CmdWriteSingleBlock(SDMMC_TypeDef *SDMMCx, uint32_t WriteAdd)
Send the Write Single Block command and check the response.
uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx)
Send the Stop Transfer command and check the response.
static void MMC_DMARxAbort(DMA_HandleTypeDef *hdma)
DMA MMC Rx Abort callback.
__IO uint8_t MaxWrBlockLen
__IO uint8_t SysSpecVersion
uint32_t HAL_MMC_CardStateTypeDef
uint32_t SDMMC_CmdGoIdleState(SDMMC_TypeDef *SDMMCx)
Send the Go Idle State command and check the response.
HAL_StatusTypeDef HAL_MMC_Abort_IT(MMC_HandleTypeDef *hmmc)
Abort the current transfer and disable the MMC (IT mode).
MMC Card Information Structure definition.
void HAL_MMCEx_Read_DMADoubleBuffer1CpltCallback(MMC_HandleTypeDef *hmmc)
Read DMA Buffer 1 Transfer completed callbacks.
HAL_StatusTypeDef HAL_MMC_GetCardCID(MMC_HandleTypeDef *hmmc, HAL_MMC_CardCIDTypeDef *pCID)
Returns information the information of the card which are stored on the CID register.
void HAL_MMC_MspDeInit(MMC_HandleTypeDef *hmmc)
De-Initialize MMC MSP.
__IO uint16_t CardComdClasses
void HAL_MMCEx_Write_DMADoubleBuffer1CpltCallback(MMC_HandleTypeDef *hmmc)
Write DMA Buffer 1 Transfer completed callbacks.
__IO uint8_t WrProtectGrEnable
__IO uint8_t MaxWrCurrentVDDMin
uint32_t SDMMC_CmdEraseEndAdd(SDMMC_TypeDef *SDMMCx, uint32_t EndAdd)
Send the End Address Erase command and check the response.
HAL_StatusTypeDef SDMMC_Init(SDMMC_TypeDef *SDMMCx, SDMMC_InitTypeDef Init)
Initializes the SDMMC according to the specified parameters in the SDMMC_InitTypeDef and create the a...
static void MMC_DMATxAbort(DMA_HandleTypeDef *hdma)
DMA MMC Tx Abort callback.
__IO uint8_t DeviceSizeMul
uint32_t SDMMC_CmdReadMultiBlock(SDMMC_TypeDef *SDMMCx, uint32_t ReadAdd)
Send the Read Multi Block command and check the response.
__IO uint8_t MaxRdCurrentVDDMin
uint32_t HAL_MMC_GetError(MMC_HandleTypeDef *hmmc)
Return the MMC error code.
uint32_t SDMMC_CmdEraseStartAdd(SDMMC_TypeDef *SDMMCx, uint32_t StartAdd)
Send the Start Address Erase command and check the response.
HAL_StatusTypeDef SDMMC_PowerState_ON(SDMMC_TypeDef *SDMMCx)
Set SDMMC Power state to ON.
HAL_StatusTypeDef HAL_MMC_GetCardCSD(MMC_HandleTypeDef *hmmc, HAL_MMC_CardCSDTypeDef *pCSD)
Returns information the information of the card which are stored on the CSD register.
HAL_StatusTypeDef HAL_MMC_WriteBlocks_IT(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
Writes block(s) to a specified address in a card. The Data transfer is managed in interrupt mode...
HAL_MMC_StateTypeDef HAL_MMC_GetState(MMC_HandleTypeDef *hmmc)
return the MMC state
HAL_StatusTypeDef HAL_MMC_GetCardInfo(MMC_HandleTypeDef *hmmc, HAL_MMC_CardInfoTypeDef *pCardInfo)
Gets the MMC card info.
HAL_StatusTypeDef SDMMC_WriteFIFO(SDMMC_TypeDef *SDMMCx, uint32_t *pWriteData)
Write data (word) to Tx FIFO in blocking mode (polling)
__IO uint8_t WriteBlockPaPartial
HAL_StatusTypeDef HAL_MMC_Init(MMC_HandleTypeDef *hmmc)
Initializes the MMC according to the specified parameters in the MMC_HandleTypeDef and create the ass...
void HAL_MMC_RxCpltCallback(MMC_HandleTypeDef *hmmc)
Rx Transfer completed callbacks.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
__IO uint8_t FileFormatGroup
HAL_StatusTypeDef SDMMC_PowerState_OFF(SDMMC_TypeDef *SDMMCx)
Set SDMMC Power state to OFF.
HAL_StatusTypeDef SDMMC_ConfigData(SDMMC_TypeDef *SDMMCx, SDMMC_DataInitTypeDef *Data)
Configure the SDMMC data path according to the specified parameters in the SDMMC_DataInitTypeDef.
void HAL_MMC_IRQHandler(MMC_HandleTypeDef *hmmc)
This function handles MMC card interrupt request.
HAL_StatusTypeDef HAL_MMC_ReadBlocks_DMA(MMC_HandleTypeDef *hmmc, uint8_t *pData, uint32_t BlockAdd, uint32_t NumberOfBlocks)
Reads block(s) from a specified address in a card. The Data transfer is managed by DMA mode...
__IO uint8_t PermWrProtect
static void MMC_PowerOFF(MMC_HandleTypeDef *hmmc)
Turns the SDMMC output signals off.