STM32L4xx_HAL_Driver  1.14.0

Functions

static uint32_t MMC_InitCard (MMC_HandleTypeDef *hmmc)
 Initializes the mmc card. More...
 
static uint32_t MMC_PowerON (MMC_HandleTypeDef *hmmc)
 Enquires cards about their operating voltage and configures clock controls and stores MMC information that will be needed in future in the MMC handle. More...
 
static uint32_t MMC_SendStatus (MMC_HandleTypeDef *hmmc, uint32_t *pCardStatus)
 Returns the current card's status. More...
 
static void MMC_PowerOFF (MMC_HandleTypeDef *hmmc)
 Turns the SDMMC output signals off. More...
 
static void MMC_Write_IT (MMC_HandleTypeDef *hmmc)
 Wrap up writing in non-blocking mode. More...
 
static void MMC_Read_IT (MMC_HandleTypeDef *hmmc)
 Wrap up reading in non-blocking mode. More...
 
static void MMC_DMATransmitCplt (DMA_HandleTypeDef *hdma)
 DMA MMC transmit process complete callback. More...
 
static void MMC_DMAReceiveCplt (DMA_HandleTypeDef *hdma)
 DMA MMC receive process complete callback. More...
 
static void MMC_DMAError (DMA_HandleTypeDef *hdma)
 DMA MMC communication error callback. More...
 
static void MMC_DMATxAbort (DMA_HandleTypeDef *hdma)
 DMA MMC Tx Abort callback. More...
 
static void MMC_DMARxAbort (DMA_HandleTypeDef *hdma)
 DMA MMC Rx Abort callback. More...
 
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. More...
 

Detailed Description

Function Documentation

◆ MMC_DMAError()

static void MMC_DMAError ( DMA_HandleTypeDef hdma)
static

DMA MMC communication error callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 2794 of file stm32l4xx_hal_mmc.c.

2795 {
2796  MMC_HandleTypeDef* hmmc = (MMC_HandleTypeDef* )(hdma->Parent);
2797  HAL_MMC_CardStateTypeDef CardState;
2798  uint32_t RxErrorCode, TxErrorCode;
2799 
2800  RxErrorCode = hmmc->hdmarx->ErrorCode;
2801  TxErrorCode = hmmc->hdmatx->ErrorCode;
2802  if((RxErrorCode == HAL_DMA_ERROR_TE) || (TxErrorCode == HAL_DMA_ERROR_TE))
2803  {
2804  /* Clear All flags */
2805  __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
2806 
2807  /* Disable All interrupts */
2808  __HAL_MMC_DISABLE_IT(hmmc, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT|\
2809  SDMMC_IT_TXUNDERR| SDMMC_IT_RXOVERR);
2810 
2811  hmmc->ErrorCode |= HAL_MMC_ERROR_DMA;
2812  CardState = HAL_MMC_GetCardState(hmmc);
2813  if((CardState == HAL_MMC_CARD_RECEIVING) || (CardState == HAL_MMC_CARD_SENDING))
2814  {
2815  hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance);
2816  }
2817 
2818  hmmc->State= HAL_MMC_STATE_READY;
2819  }
2820 
2821 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
2822  hmmc->ErrorCallback(hmmc);
2823 #else
2824  HAL_MMC_ErrorCallback(hmmc);
2825 #endif
2826  }
struct __MMC_HandleTypeDef else typedef struct endif MMC_HandleTypeDef
MMC handle Structure definition.
void HAL_MMC_ErrorCallback(MMC_HandleTypeDef *hmmc)
MMC error callbacks.
HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState(MMC_HandleTypeDef *hmmc)
Gets the current mmc card data state.
uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx)
Send the Stop Transfer command and check the response.
uint32_t HAL_MMC_CardStateTypeDef

◆ MMC_DMAReceiveCplt()

static void MMC_DMAReceiveCplt ( DMA_HandleTypeDef hdma)
static

DMA MMC receive process complete callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 2753 of file stm32l4xx_hal_mmc.c.

2754 {
2755  MMC_HandleTypeDef* hmmc = (MMC_HandleTypeDef* )(hdma->Parent);
2756  uint32_t errorstate;
2757 
2758  /* Send stop command in multiblock write */
2759  if(hmmc->Context == (MMC_CONTEXT_READ_MULTIPLE_BLOCK | MMC_CONTEXT_DMA))
2760  {
2761  errorstate = SDMMC_CmdStopTransfer(hmmc->Instance);
2762  if(errorstate != HAL_MMC_ERROR_NONE)
2763  {
2764  hmmc->ErrorCode |= errorstate;
2765 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
2766  hmmc->ErrorCallback(hmmc);
2767 #else
2768  HAL_MMC_ErrorCallback(hmmc);
2769 #endif
2770  }
2771  }
2772 
2773  /* Disable the DMA transfer for transmit request by setting the DMAEN bit
2774  in the MMC DCTRL register */
2775  hmmc->Instance->DCTRL &= (uint32_t)~((uint32_t)SDMMC_DCTRL_DMAEN);
2776 
2777  /* Clear all the static flags */
2778  __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
2779 
2780  hmmc->State = HAL_MMC_STATE_READY;
2781 
2782 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
2783  hmmc->RxCpltCallback(hmmc);
2784 #else
2785  HAL_MMC_RxCpltCallback(hmmc);
2786 #endif
2787 }
struct __MMC_HandleTypeDef else typedef struct endif MMC_HandleTypeDef
MMC handle Structure definition.
void HAL_MMC_ErrorCallback(MMC_HandleTypeDef *hmmc)
MMC error callbacks.
uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx)
Send the Stop Transfer command and check the response.
void HAL_MMC_RxCpltCallback(MMC_HandleTypeDef *hmmc)
Rx Transfer completed callbacks.

◆ MMC_DMARxAbort()

static void MMC_DMARxAbort ( DMA_HandleTypeDef hdma)
static

DMA MMC Rx Abort callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 2878 of file stm32l4xx_hal_mmc.c.

2879 {
2880  MMC_HandleTypeDef* hmmc = (MMC_HandleTypeDef* )(hdma->Parent);
2881  HAL_MMC_CardStateTypeDef CardState;
2882 
2883  if(hmmc->hdmarx != NULL)
2884  {
2885  hmmc->hdmarx = NULL;
2886  }
2887 
2888  /* All DMA channels are aborted */
2889  if(hmmc->hdmatx == NULL)
2890  {
2891  CardState = HAL_MMC_GetCardState(hmmc);
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))
2895  {
2896  hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance);
2897 
2898  if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE)
2899  {
2900 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
2901  hmmc->AbortCpltCallback(hmmc);
2902 #else
2903  HAL_MMC_AbortCallback(hmmc);
2904 #endif
2905  }
2906  else
2907  {
2908 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
2909  hmmc->ErrorCallback(hmmc);
2910 #else
2911  HAL_MMC_ErrorCallback(hmmc);
2912 #endif
2913  }
2914  }
2915  }
2916 }
void HAL_MMC_AbortCallback(MMC_HandleTypeDef *hmmc)
MMC Abort callbacks.
struct __MMC_HandleTypeDef else typedef struct endif MMC_HandleTypeDef
MMC handle Structure definition.
void HAL_MMC_ErrorCallback(MMC_HandleTypeDef *hmmc)
MMC error callbacks.
HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState(MMC_HandleTypeDef *hmmc)
Gets the current mmc card data state.
uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx)
Send the Stop Transfer command and check the response.
uint32_t HAL_MMC_CardStateTypeDef

◆ MMC_DMATransmitCplt()

static void MMC_DMATransmitCplt ( DMA_HandleTypeDef hdma)
static

DMA MMC transmit process complete callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 2740 of file stm32l4xx_hal_mmc.c.

2741 {
2742  MMC_HandleTypeDef* hmmc = (MMC_HandleTypeDef* )(hdma->Parent);
2743 
2744  /* Enable DATAEND Interrupt */
2745  __HAL_MMC_ENABLE_IT(hmmc, (SDMMC_IT_DATAEND));
2746 }
struct __MMC_HandleTypeDef else typedef struct endif MMC_HandleTypeDef
MMC handle Structure definition.

◆ MMC_DMATxAbort()

static void MMC_DMATxAbort ( DMA_HandleTypeDef hdma)
static

DMA MMC Tx Abort callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 2833 of file stm32l4xx_hal_mmc.c.

2834 {
2835  MMC_HandleTypeDef* hmmc = (MMC_HandleTypeDef* )(hdma->Parent);
2836  HAL_MMC_CardStateTypeDef CardState;
2837 
2838  if(hmmc->hdmatx != NULL)
2839  {
2840  hmmc->hdmatx = NULL;
2841  }
2842 
2843  /* All DMA channels are aborted */
2844  if(hmmc->hdmarx == NULL)
2845  {
2846  CardState = HAL_MMC_GetCardState(hmmc);
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))
2850  {
2851  hmmc->ErrorCode |= SDMMC_CmdStopTransfer(hmmc->Instance);
2852 
2853  if(hmmc->ErrorCode != HAL_MMC_ERROR_NONE)
2854  {
2855 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
2856  hmmc->AbortCpltCallback(hmmc);
2857 #else
2858  HAL_MMC_AbortCallback(hmmc);
2859 #endif
2860  }
2861  else
2862  {
2863 #if defined (USE_HAL_MMC_REGISTER_CALLBACKS) && (USE_HAL_MMC_REGISTER_CALLBACKS == 1U)
2864  hmmc->ErrorCallback(hmmc);
2865 #else
2866  HAL_MMC_ErrorCallback(hmmc);
2867 #endif
2868  }
2869  }
2870  }
2871 }
void HAL_MMC_AbortCallback(MMC_HandleTypeDef *hmmc)
MMC Abort callbacks.
struct __MMC_HandleTypeDef else typedef struct endif MMC_HandleTypeDef
MMC handle Structure definition.
void HAL_MMC_ErrorCallback(MMC_HandleTypeDef *hmmc)
MMC error callbacks.
HAL_MMC_CardStateTypeDef HAL_MMC_GetCardState(MMC_HandleTypeDef *hmmc)
Gets the current mmc card data state.
uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx)
Send the Stop Transfer command and check the response.
uint32_t HAL_MMC_CardStateTypeDef

◆ MMC_InitCard()

static uint32_t MMC_InitCard ( MMC_HandleTypeDef hmmc)
static

Initializes the mmc card.

Parameters
hmmcPointer to MMC handle
Return values
MMCCard error state

Definition at line 2924 of file stm32l4xx_hal_mmc.c.

2925 {
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;
2931 #endif
2932 
2933  /* Check the power State */
2934  if(SDMMC_GetPowerState(hmmc->Instance) == 0U)
2935  {
2936  /* Power off */
2937  return HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE;
2938  }
2939 
2940  /* Send CMD2 ALL_SEND_CID */
2941  errorstate = SDMMC_CmdSendCID(hmmc->Instance);
2942  if(errorstate != HAL_MMC_ERROR_NONE)
2943  {
2944  return errorstate;
2945  }
2946  else
2947  {
2948  /* Get Card identification number data */
2949  hmmc->CID[0U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP1);
2950  hmmc->CID[1U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP2);
2951  hmmc->CID[2U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP3);
2952  hmmc->CID[3U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP4);
2953  }
2954 
2955  /* Send CMD3 SET_REL_ADDR with argument 0 */
2956  /* MMC Card publishes its RCA. */
2957  errorstate = SDMMC_CmdSetRelAdd(hmmc->Instance, &mmc_rca);
2958  if(errorstate != HAL_MMC_ERROR_NONE)
2959  {
2960  return errorstate;
2961  }
2962 
2963  /* Get the MMC card RCA */
2964  hmmc->MmcCard.RelCardAdd = mmc_rca;
2965 
2966  /* Send CMD9 SEND_CSD with argument as card's RCA */
2967  errorstate = SDMMC_CmdSendCSD(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U));
2968  if(errorstate != HAL_MMC_ERROR_NONE)
2969  {
2970  return errorstate;
2971  }
2972  else
2973  {
2974  /* Get Card Specific Data */
2975  hmmc->CSD[0U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP1);
2976  hmmc->CSD[1U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP2);
2977  hmmc->CSD[2U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP3);
2978  hmmc->CSD[3U] = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP4);
2979  }
2980 
2981  /* Get the Card Class */
2982  hmmc->MmcCard.Class = (SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP2) >> 20U);
2983 
2984 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx)
2985  /* Get CSD parameters */
2986  if (HAL_MMC_GetCardCSD(hmmc, &CSD) != HAL_OK)
2987  {
2988  return hmmc->ErrorCode;
2989  }
2990 
2991  /* Select the Card */
2992  errorstate = SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
2993  if(errorstate != HAL_MMC_ERROR_NONE)
2994  {
2995  return errorstate;
2996  }
2997 
2998  /* Configure SDMMC peripheral interface */
2999  (void)SDMMC_Init(hmmc->Instance, hmmc->Init);
3000 #else
3001  /* Select the Card */
3002  errorstate = SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
3003  if(errorstate != HAL_MMC_ERROR_NONE)
3004  {
3005  return errorstate;
3006  }
3007 
3008  /* Get CSD parameters */
3009  if (HAL_MMC_GetCardCSD(hmmc, &CSD) != HAL_OK)
3010  {
3011  return hmmc->ErrorCode;
3012  }
3013 
3014  /* While card is not ready for data and trial number for sending CMD13 is not exceeded */
3015  errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
3016  if(errorstate != HAL_MMC_ERROR_NONE)
3017  {
3018  hmmc->ErrorCode |= errorstate;
3019  }
3020 
3021  /* Configure the SDMMC peripheral */
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;
3027  (void)SDMMC_Init(hmmc->Instance, Init);
3028 #endif
3029 
3030  /* All cards are initialized */
3031  return HAL_MMC_ERROR_NONE;
3032 }
uint32_t SDMMC_CmdSelDesel(SDMMC_TypeDef *SDMMCx, uint64_t Addr)
Send the Select Deselect 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_GetPowerState(SDMMC_TypeDef *SDMMCx)
Get SDMMC Power state.
uint32_t SDMMC_CmdSendCSD(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Send the Send CSD command and check the response.
WWDG_InitTypeDef Init
return HAL_OK
uint32_t SDMMC_CmdSetRelAdd(SDMMC_TypeDef *SDMMCx, uint16_t *pRCA)
Send the Send CSD command and check the response.
uint32_t SDMMC_CmdSendCID(SDMMC_TypeDef *SDMMCx)
Send the Send CID command and check the response.
uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response)
Return the response received from the card for the last command.
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...
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.

◆ MMC_PowerOFF()

static void MMC_PowerOFF ( MMC_HandleTypeDef hmmc)
static

Turns the SDMMC output signals off.

Parameters
hmmcPointer to MMC handle
Return values
None

Definition at line 3093 of file stm32l4xx_hal_mmc.c.

3094 {
3095  /* Set Power State to OFF */
3096  (void)SDMMC_PowerState_OFF(hmmc->Instance);
3097 }
HAL_StatusTypeDef SDMMC_PowerState_OFF(SDMMC_TypeDef *SDMMCx)
Set SDMMC Power state to OFF.

◆ MMC_PowerON()

static uint32_t MMC_PowerON ( MMC_HandleTypeDef hmmc)
static

Enquires cards about their operating voltage and configures clock controls and stores MMC information that will be needed in future in the MMC handle.

Parameters
hmmcPointer to MMC handle
Return values
errorstate

Definition at line 3041 of file stm32l4xx_hal_mmc.c.

3042 {
3043  __IO uint32_t count = 0U;
3044  uint32_t response = 0U, validvoltage = 0U;
3045  uint32_t errorstate;
3046 
3047  /* CMD0: GO_IDLE_STATE */
3048  errorstate = SDMMC_CmdGoIdleState(hmmc->Instance);
3049  if(errorstate != HAL_MMC_ERROR_NONE)
3050  {
3051  return errorstate;
3052  }
3053 
3054  while(validvoltage == 0U)
3055  {
3056  if(count++ == SDMMC_MAX_VOLT_TRIAL)
3057  {
3058  return HAL_MMC_ERROR_INVALID_VOLTRANGE;
3059  }
3060 
3061  /* SEND CMD1 APP_CMD with MMC_HIGH_VOLTAGE_RANGE(0xC0FF8000) as argument */
3062  errorstate = SDMMC_CmdOpCondition(hmmc->Instance, eMMC_HIGH_VOLTAGE_RANGE);
3063  if(errorstate != HAL_MMC_ERROR_NONE)
3064  {
3065  return HAL_MMC_ERROR_UNSUPPORTED_FEATURE;
3066  }
3067 
3068  /* Get command response */
3069  response = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP1);
3070 
3071  /* Get operating voltage*/
3072  validvoltage = (((response >> 31U) == 1U) ? 1U : 0U);
3073  }
3074 
3075  /* When power routine is finished and command returns valid voltage */
3076  if (((response & (0xFF000000U)) >> 24) == 0xC0U)
3077  {
3078  hmmc->MmcCard.CardType = MMC_HIGH_CAPACITY_CARD;
3079  }
3080  else
3081  {
3082  hmmc->MmcCard.CardType = MMC_LOW_CAPACITY_CARD;
3083  }
3084 
3085  return HAL_MMC_ERROR_NONE;
3086 }
uint32_t SDMMC_CmdOpCondition(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Sends host capacity support information and activates the card&#39;s initialization process. Send SDMMC_CMD_SEND_OP_COND command.
uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response)
Return the response received from the card for the last command.
uint32_t SDMMC_CmdGoIdleState(SDMMC_TypeDef *SDMMCx)
Send the Go Idle State command and check the response.

◆ MMC_Read_IT()

static void MMC_Read_IT ( MMC_HandleTypeDef hmmc)
static

Wrap up reading in non-blocking mode.

Parameters
hmmcpointer to a MMC_HandleTypeDef structure that contains the configuration information.
Return values
None

Definition at line 3239 of file stm32l4xx_hal_mmc.c.

3240 {
3241  uint32_t count, data, dataremaining;
3242  uint8_t* tmp;
3243 
3244  tmp = hmmc->pRxBuffPtr;
3245  dataremaining = hmmc->RxXferSize;
3246 
3247  if (dataremaining > 0U)
3248  {
3249  /* Read data from SDMMC Rx FIFO */
3250  for(count = 0U; count < 8U; count++)
3251  {
3252  data = SDMMC_ReadFIFO(hmmc->Instance);
3253  *tmp = (uint8_t)(data & 0xFFU);
3254  tmp++;
3255  dataremaining--;
3256  *tmp = (uint8_t)((data >> 8U) & 0xFFU);
3257  tmp++;
3258  dataremaining--;
3259  *tmp = (uint8_t)((data >> 16U) & 0xFFU);
3260  tmp++;
3261  dataremaining--;
3262  *tmp = (uint8_t)((data >> 24U) & 0xFFU);
3263  tmp++;
3264  dataremaining--;
3265  }
3266 
3267  hmmc->pRxBuffPtr = tmp;
3268  hmmc->RxXferSize = dataremaining;
3269  }
3270 }
uint32_t SDMMC_ReadFIFO(SDMMC_TypeDef *SDMMCx)
Read data (word) from Rx FIFO in blocking mode (polling)

◆ MMC_ReadExtCSD()

HAL_StatusTypeDef MMC_ReadExtCSD ( MMC_HandleTypeDef hmmc,
uint32_t *  pBlockNbr,
uint32_t  Timeout 
)
static

Reads extended CSD register to get the sectors number of the device.

Parameters
hmmcPointer to MMC handle
pBlockNbrPointer to the read buffer
TimeoutSpecify timeout value
Return values
HALstatus

Definition at line 3136 of file stm32l4xx_hal_mmc.c.

3137 {
3138  SDMMC_DataInitTypeDef config;
3139  uint32_t errorstate;
3140  uint32_t tickstart = HAL_GetTick();
3141  uint32_t count;
3142  uint32_t i = 0;
3143  uint32_t tmp_data;
3144 
3145  hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
3146 
3147  /* Initialize data control register */
3148  hmmc->Instance->DCTRL = 0;
3149 
3150  /* Configure the MMC DPSM (Data Path State Machine) */
3151  config.DataTimeOut = SDMMC_DATATIMEOUT;
3152  config.DataLength = 0;
3153  config.DataBlockSize = SDMMC_DATABLOCK_SIZE_1B;
3154  config.TransferDir = SDMMC_TRANSFER_DIR_TO_SDMMC;
3155  config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
3156  config.DPSM = SDMMC_DPSM_DISABLE;
3157  (void)SDMMC_ConfigData(hmmc->Instance, &config);
3158 
3159  /* Set Block Size for Card */
3160  errorstate = SDMMC_CmdBlockLength(hmmc->Instance, MMC_BLOCKSIZE);
3161  if(errorstate != HAL_MMC_ERROR_NONE)
3162  {
3163  /* Clear all the static flags */
3164  __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
3165  hmmc->ErrorCode |= errorstate;
3166  hmmc->State = HAL_MMC_STATE_READY;
3167  return HAL_ERROR;
3168  }
3169 
3170  /* Configure the MMC DPSM (Data Path State Machine) */
3171  config.DataTimeOut = SDMMC_DATATIMEOUT;
3172  config.DataLength = 512;
3173  config.DataBlockSize = SDMMC_DATABLOCK_SIZE_512B;
3174  config.TransferDir = SDMMC_TRANSFER_DIR_TO_SDMMC;
3175  config.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
3176  config.DPSM = SDMMC_DPSM_ENABLE;
3177  (void)SDMMC_ConfigData(hmmc->Instance, &config);
3178 
3179  /* Set Block Size for Card */
3180  errorstate = SDMMC_CmdSendEXTCSD(hmmc->Instance, 0);
3181  if(errorstate != HAL_MMC_ERROR_NONE)
3182  {
3183  /* Clear all the static flags */
3184  __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
3185  hmmc->ErrorCode |= errorstate;
3186  hmmc->State = HAL_MMC_STATE_READY;
3187  return HAL_ERROR;
3188  }
3189 
3190  /* Poll on SDMMC flags */
3191  while(!__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DATAEND))
3192  {
3193  if(__HAL_MMC_GET_FLAG(hmmc, SDMMC_FLAG_RXFIFOHF))
3194  {
3195  /* Read data from SDMMC Rx FIFO */
3196  for(count = 0U; count < 8U; count++)
3197  {
3198  tmp_data = SDMMC_ReadFIFO(hmmc->Instance);
3199  if ((i == 48U) && (count == 5U))
3200  {
3201  *pBlockNbr = tmp_data;
3202  }
3203  }
3204  i += 8U;
3205  }
3206 
3207  if(((HAL_GetTick()-tickstart) >= Timeout) || (Timeout == 0U))
3208  {
3209  /* Clear all the static flags */
3210  __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
3211  hmmc->ErrorCode |= HAL_MMC_ERROR_TIMEOUT;
3212  hmmc->State= HAL_MMC_STATE_READY;
3213  return HAL_TIMEOUT;
3214  }
3215  }
3216 
3217  /* While card is not ready for data and trial number for sending CMD13 is not exceeded */
3218  errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16));
3219  if(errorstate != HAL_MMC_ERROR_NONE)
3220  {
3221  hmmc->ErrorCode |= errorstate;
3222  }
3223 
3224  /* Clear all the static flags */
3225  __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_DATA_FLAGS);
3226 
3227  hmmc->State = HAL_MMC_STATE_READY;
3228 
3229  return HAL_OK;
3230 }
uint32_t SDMMC_CmdBlockLength(SDMMC_TypeDef *SDMMCx, uint32_t BlockSize)
Send the Data Block Lenght command and check the response.
uint32_t SDMMC_CmdSendEXTCSD(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Send the Send EXT_CSD command and check the response.
SDMMC Data Control structure.
uint32_t SDMMC_CmdSendStatus(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Send the Status command and check the response.
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
return HAL_OK
uint32_t SDMMC_ReadFIFO(SDMMC_TypeDef *SDMMCx)
Read data (word) from Rx FIFO in blocking mode (polling)
HAL_StatusTypeDef SDMMC_ConfigData(SDMMC_TypeDef *SDMMCx, SDMMC_DataInitTypeDef *Data)
Configure the SDMMC data path according to the specified parameters in the SDMMC_DataInitTypeDef.

◆ MMC_SendStatus()

static uint32_t MMC_SendStatus ( MMC_HandleTypeDef hmmc,
uint32_t *  pCardStatus 
)
static

Returns the current card's status.

Parameters
hmmcPointer to MMC handle
pCardStatuspointer to the buffer that will contain the MMC card status (Card Status register)
Return values
errorstate

Definition at line 3106 of file stm32l4xx_hal_mmc.c.

3107 {
3108  uint32_t errorstate;
3109 
3110  if(pCardStatus == NULL)
3111  {
3112  return HAL_MMC_ERROR_PARAM;
3113  }
3114 
3115  /* Send Status command */
3116  errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U));
3117  if(errorstate != HAL_MMC_ERROR_NONE)
3118  {
3119  return errorstate;
3120  }
3121 
3122  /* Get MMC card status */
3123  *pCardStatus = SDMMC_GetResponse(hmmc->Instance, SDMMC_RESP1);
3124 
3125  return HAL_MMC_ERROR_NONE;
3126 }
uint32_t SDMMC_CmdSendStatus(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Send the Status command and check the response.
uint32_t SDMMC_GetResponse(SDMMC_TypeDef *SDMMCx, uint32_t Response)
Return the response received from the card for the last command.

◆ MMC_Write_IT()

static void MMC_Write_IT ( MMC_HandleTypeDef hmmc)
static

Wrap up writing in non-blocking mode.

Parameters
hmmcpointer to a MMC_HandleTypeDef structure that contains the configuration information.
Return values
None

Definition at line 3278 of file stm32l4xx_hal_mmc.c.

3279 {
3280  uint32_t count, data, dataremaining;
3281  uint8_t* tmp;
3282 
3283  tmp = hmmc->pTxBuffPtr;
3284  dataremaining = hmmc->TxXferSize;
3285 
3286  if (dataremaining > 0U)
3287  {
3288  /* Write data to SDMMC Tx FIFO */
3289  for(count = 0U; count < 8U; count++)
3290  {
3291  data = (uint32_t)(*tmp);
3292  tmp++;
3293  dataremaining--;
3294  data |= ((uint32_t)(*tmp) << 8U);
3295  tmp++;
3296  dataremaining--;
3297  data |= ((uint32_t)(*tmp) << 16U);
3298  tmp++;
3299  dataremaining--;
3300  data |= ((uint32_t)(*tmp) << 24U);
3301  tmp++;
3302  dataremaining--;
3303  (void)SDMMC_WriteFIFO(hmmc->Instance, &data);
3304  }
3305 
3306  hmmc->pTxBuffPtr = tmp;
3307  hmmc->TxXferSize = dataremaining;
3308  }
3309 }
HAL_StatusTypeDef SDMMC_WriteFIFO(SDMMC_TypeDef *SDMMCx, uint32_t *pWriteData)
Write data (word) to Tx FIFO in blocking mode (polling)