STM32L4xx_HAL_Driver  1.14.0
MMC card related functions

Functions

HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState (MMC_HandleTypeDef *hmmc)
 Gets the current mmc card data state. More...
 
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. More...
 
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. More...
 
HAL_StatusTypeDef HAL_MMC_GetCardInfo (MMC_HandleTypeDef *hmmc, HAL_MMC_CardInfoTypeDef *pCardInfo)
 Gets the MMC card info. More...
 

Detailed Description

Function Documentation

◆ HAL_MMC_GetCardCID()

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.

Parameters
hmmcPointer to MMC handle
pCIDPointer to a HAL_MMC_CIDTypedef structure that contains all CID register parameters
Return values
HALstatus

Definition at line 2248 of file stm32l4xx_hal_mmc.c.

2249 {
2250  pCID->ManufacturerID = (uint8_t)((hmmc->CID[0] & 0xFF000000U) >> 24U);
2251 
2252  pCID->OEM_AppliID = (uint16_t)((hmmc->CID[0] & 0x00FFFF00U) >> 8U);
2253 
2254  pCID->ProdName1 = (((hmmc->CID[0] & 0x000000FFU) << 24U) | ((hmmc->CID[1] & 0xFFFFFF00U) >> 8U));
2255 
2256  pCID->ProdName2 = (uint8_t)(hmmc->CID[1] & 0x000000FFU);
2257 
2258  pCID->ProdRev = (uint8_t)((hmmc->CID[2] & 0xFF000000U) >> 24U);
2259 
2260  pCID->ProdSN = (((hmmc->CID[2] & 0x00FFFFFFU) << 8U) | ((hmmc->CID[3] & 0xFF000000U) >> 24U));
2261 
2262  pCID->Reserved1 = (uint8_t)((hmmc->CID[3] & 0x00F00000U) >> 20U);
2263 
2264  pCID->ManufactDate = (uint16_t)((hmmc->CID[3] & 0x000FFF00U) >> 8U);
2265 
2266  pCID->CID_CRC = (uint8_t)((hmmc->CID[3] & 0x000000FEU) >> 1U);
2267 
2268  pCID->Reserved2 = 1U;
2269 
2270  return HAL_OK;
2271 }
return HAL_OK

◆ HAL_MMC_GetCardCSD()

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.

Parameters
hmmcPointer to MMC handle
pCSDPointer to a HAL_MMC_CardCSDTypeDef structure that contains all CSD register parameters
Return values
HALstatus

< Reserved

Definition at line 2281 of file stm32l4xx_hal_mmc.c.

2282 {
2283 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
2284  uint32_t block_nbr = 0;
2285 #endif
2286 
2287  pCSD->CSDStruct = (uint8_t)((hmmc->CSD[0] & 0xC0000000U) >> 30U);
2288 
2289  pCSD->SysSpecVersion = (uint8_t)((hmmc->CSD[0] & 0x3C000000U) >> 26U);
2290 
2291  pCSD->Reserved1 = (uint8_t)((hmmc->CSD[0] & 0x03000000U) >> 24U);
2292 
2293  pCSD->TAAC = (uint8_t)((hmmc->CSD[0] & 0x00FF0000U) >> 16U);
2294 
2295  pCSD->NSAC = (uint8_t)((hmmc->CSD[0] & 0x0000FF00U) >> 8U);
2296 
2297  pCSD->MaxBusClkFrec = (uint8_t)(hmmc->CSD[0] & 0x000000FFU);
2298 
2299  pCSD->CardComdClasses = (uint16_t)((hmmc->CSD[1] & 0xFFF00000U) >> 20U);
2300 
2301  pCSD->RdBlockLen = (uint8_t)((hmmc->CSD[1] & 0x000F0000U) >> 16U);
2302 
2303  pCSD->PartBlockRead = (uint8_t)((hmmc->CSD[1] & 0x00008000U) >> 15U);
2304 
2305  pCSD->WrBlockMisalign = (uint8_t)((hmmc->CSD[1] & 0x00004000U) >> 14U);
2306 
2307  pCSD->RdBlockMisalign = (uint8_t)((hmmc->CSD[1] & 0x00002000U) >> 13U);
2308 
2309  pCSD->DSRImpl = (uint8_t)((hmmc->CSD[1] & 0x00001000U) >> 12U);
2310 
2311  pCSD->Reserved2 = 0U;
2313 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
2314  if(MMC_ReadExtCSD(hmmc, &block_nbr, 0x0FFFFFFFU) != HAL_OK)
2315  {
2316  return HAL_ERROR;
2317  }
2318 
2319  if(hmmc->MmcCard.CardType == MMC_LOW_CAPACITY_CARD)
2320  {
2321 #endif
2322  pCSD->DeviceSize = (((hmmc->CSD[1] & 0x000003FFU) << 2U) | ((hmmc->CSD[2] & 0xC0000000U) >> 30U));
2323 
2324  pCSD->MaxRdCurrentVDDMin = (uint8_t)((hmmc->CSD[2] & 0x38000000U) >> 27U);
2325 
2326  pCSD->MaxRdCurrentVDDMax = (uint8_t)((hmmc->CSD[2] & 0x07000000U) >> 24U);
2327 
2328  pCSD->MaxWrCurrentVDDMin = (uint8_t)((hmmc->CSD[2] & 0x00E00000U) >> 21U);
2329 
2330  pCSD->MaxWrCurrentVDDMax = (uint8_t)((hmmc->CSD[2] & 0x001C0000U) >> 18U);
2331 
2332  pCSD->DeviceSizeMul = (uint8_t)((hmmc->CSD[2] & 0x00038000U) >> 15U);
2333 
2334  hmmc->MmcCard.BlockNbr = (pCSD->DeviceSize + 1U) ;
2335  hmmc->MmcCard.BlockNbr *= (1UL << ((pCSD->DeviceSizeMul & 0x07U) + 2U));
2336  hmmc->MmcCard.BlockSize = (1UL << (pCSD->RdBlockLen & 0x0FU));
2337 
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)
2341  }
2342  else if(hmmc->MmcCard.CardType == MMC_HIGH_CAPACITY_CARD)
2343  {
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;
2348  }
2349  else
2350  {
2351  /* Clear all the static flags */
2352  __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
2353  hmmc->ErrorCode |= HAL_MMC_ERROR_UNSUPPORTED_FEATURE;
2354  hmmc->State = HAL_MMC_STATE_READY;
2355  return HAL_ERROR;
2356  }
2357 #endif
2358 
2359  pCSD->EraseGrSize = (uint8_t)((hmmc->CSD[2] & 0x00004000U) >> 14U);
2360 
2361  pCSD->EraseGrMul = (uint8_t)((hmmc->CSD[2] & 0x00003F80U) >> 7U);
2362 
2363  pCSD->WrProtectGrSize = (uint8_t)(hmmc->CSD[2] & 0x0000007FU);
2364 
2365  pCSD->WrProtectGrEnable = (uint8_t)((hmmc->CSD[3] & 0x80000000U) >> 31U);
2366 
2367  pCSD->ManDeflECC = (uint8_t)((hmmc->CSD[3] & 0x60000000U) >> 29U);
2368 
2369  pCSD->WrSpeedFact = (uint8_t)((hmmc->CSD[3] & 0x1C000000U) >> 26U);
2370 
2371  pCSD->MaxWrBlockLen= (uint8_t)((hmmc->CSD[3] & 0x03C00000U) >> 22U);
2372 
2373  pCSD->WriteBlockPaPartial = (uint8_t)((hmmc->CSD[3] & 0x00200000U) >> 21U);
2374 
2375  pCSD->Reserved3 = 0;
2376 
2377  pCSD->ContentProtectAppli = (uint8_t)((hmmc->CSD[3] & 0x00010000U) >> 16U);
2378 
2379  pCSD->FileFormatGroup = (uint8_t)((hmmc->CSD[3] & 0x00008000U) >> 15U);
2380 
2381  pCSD->CopyFlag = (uint8_t)((hmmc->CSD[3] & 0x00004000U) >> 14U);
2382 
2383  pCSD->PermWrProtect = (uint8_t)((hmmc->CSD[3] & 0x00002000U) >> 13U);
2384 
2385  pCSD->TempWrProtect = (uint8_t)((hmmc->CSD[3] & 0x00001000U) >> 12U);
2386 
2387  pCSD->FileFormat = (uint8_t)((hmmc->CSD[3] & 0x00000C00U) >> 10U);
2388 
2389  pCSD->ECC= (uint8_t)((hmmc->CSD[3] & 0x00000300U) >> 8U);
2390 
2391  pCSD->CSD_CRC = (uint8_t)((hmmc->CSD[3] & 0x000000FEU) >> 1U);
2392 
2393  pCSD->Reserved4 = 1;
2394 
2395  return HAL_OK;
2396 }
__IO uint8_t ContentProtectAppli
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.
return HAL_OK
__IO uint8_t WriteBlockPaPartial

◆ HAL_MMC_GetCardInfo()

HAL_StatusTypeDef HAL_MMC_GetCardInfo ( MMC_HandleTypeDef hmmc,
HAL_MMC_CardInfoTypeDef pCardInfo 
)

Gets the MMC card info.

Parameters
hmmcPointer to MMC handle
pCardInfoPointer to the HAL_MMC_CardInfoTypeDef structure that will contain the MMC card status information
Return values
HALstatus

Definition at line 2405 of file stm32l4xx_hal_mmc.c.

2406 {
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);
2414 
2415  return HAL_OK;
2416 }
return HAL_OK

◆ HAL_MMC_GetCardState()

HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState ( MMC_HandleTypeDef hmmc)

Gets the current mmc card data state.

Parameters
hmmcpointer to MMC handle
Return values
Cardstate

Definition at line 2564 of file stm32l4xx_hal_mmc.c.

2565 {
2566  uint32_t cardstate;
2567  uint32_t errorstate;
2568  uint32_t resp1 = 0U;
2569 
2570  errorstate = MMC_SendStatus(hmmc, &resp1);
2571  if(errorstate != HAL_MMC_ERROR_NONE)
2572  {
2573  hmmc->ErrorCode |= errorstate;
2574  }
2575 
2576  cardstate = ((resp1 >> 9U) & 0x0FU);
2577 
2578  return (HAL_MMC_CardStateTypeDef)cardstate;
2579 }
static uint32_t MMC_SendStatus(MMC_HandleTypeDef *hmmc, uint32_t *pCardStatus)
Returns the current card&#39;s status.
uint32_t HAL_MMC_CardStateTypeDef