STM32L4xx_HAL_Driver  1.14.0

SD Extended HAL module driver. More...

Modules

 SDEx Exported Functions
 

Functions

uint32_t SD_HighSpeed (SD_HandleTypeDef *hsd)
 Switches the SD card to High Speed mode. This API must be used after "Transfer State". More...
 

Detailed Description

SD Extended HAL module driver.

Function Documentation

◆ SD_HighSpeed()

uint32_t SD_HighSpeed ( SD_HandleTypeDef hsd)

Switches the SD card to High Speed mode. This API must be used after "Transfer State".

Note
This operation should be followed by the configuration of PLL to have SDMMCCK clock between 50 and 120 MHz
Parameters
hsdSD handle
Return values
SDCard error state

Definition at line 4044 of file stm32l4xx_hal_sd.c.

4045 {
4046  uint32_t errorstate = HAL_SD_ERROR_NONE;
4047  SDMMC_DataInitTypeDef sdmmc_datainitstructure;
4048  uint32_t SD_hs[16] = {0};
4049  uint32_t count, loop = 0 ;
4050  uint32_t Timeout = HAL_GetTick();
4051 
4052  if(hsd->SdCard.CardSpeed == CARD_NORMAL_SPEED)
4053  {
4054  /* Standard Speed Card <= 12.5Mhz */
4055  return HAL_SD_ERROR_REQUEST_NOT_APPLICABLE;
4056  }
4057 
4058  if(hsd->SdCard.CardSpeed == CARD_HIGH_SPEED)
4059  {
4060  /* Initialize the Data control register */
4061  hsd->Instance->DCTRL = 0;
4062  errorstate = SDMMC_CmdBlockLength(hsd->Instance, 64);
4063 
4064  if (errorstate != HAL_SD_ERROR_NONE)
4065  {
4066  return errorstate;
4067  }
4068 
4069  /* Configure the SD DPSM (Data Path State Machine) */
4070  sdmmc_datainitstructure.DataTimeOut = SDMMC_DATATIMEOUT;
4071  sdmmc_datainitstructure.DataLength = 64;
4072  sdmmc_datainitstructure.DataBlockSize = SDMMC_DATABLOCK_SIZE_64B ;
4073  sdmmc_datainitstructure.TransferDir = SDMMC_TRANSFER_DIR_TO_SDMMC;
4074  sdmmc_datainitstructure.TransferMode = SDMMC_TRANSFER_MODE_BLOCK;
4075  sdmmc_datainitstructure.DPSM = SDMMC_DPSM_ENABLE;
4076 
4077  if ( SDMMC_ConfigData(hsd->Instance, &sdmmc_datainitstructure) != HAL_OK)
4078  {
4079  return (HAL_SD_ERROR_GENERAL_UNKNOWN_ERR);
4080  }
4081 
4082 
4083  errorstate = SDMMC_CmdSwitch(hsd->Instance,SDMMC_SDR25_SWITCH_PATTERN);
4084  if(errorstate != HAL_SD_ERROR_NONE)
4085  {
4086  return errorstate;
4087  }
4088 
4089  while(!__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DBCKEND| SDMMC_FLAG_DATAEND ))
4090  {
4091  if (__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXFIFOHF))
4092  {
4093  for (count = 0U; count < 8U; count++)
4094  {
4095  SD_hs[(8U*loop)+count] = SDMMC_ReadFIFO(hsd->Instance);
4096  }
4097  loop ++;
4098  }
4099 
4100  if((HAL_GetTick()-Timeout) >= SDMMC_DATATIMEOUT)
4101  {
4102  hsd->ErrorCode = HAL_SD_ERROR_TIMEOUT;
4103  hsd->State= HAL_SD_STATE_READY;
4104  return HAL_SD_ERROR_TIMEOUT;
4105  }
4106  }
4107 
4108  if (__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_DTIMEOUT))
4109  {
4110  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_FLAG_DTIMEOUT);
4111 
4112  errorstate = 0;
4113 
4114  return errorstate;
4115  }
4116  else if (__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_DCRCFAIL))
4117  {
4118  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_FLAG_DCRCFAIL);
4119 
4120  errorstate = SDMMC_ERROR_DATA_CRC_FAIL;
4121 
4122  return errorstate;
4123  }
4124  else if (__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXOVERR))
4125  {
4126  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_FLAG_RXOVERR);
4127 
4128  errorstate = SDMMC_ERROR_RX_OVERRUN;
4129 
4130  return errorstate;
4131  }
4132  else
4133  {
4134  /* No error flag set */
4135  }
4136 
4137  /* Clear all the static flags */
4138  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
4139 
4140  /* Test if the switch mode HS is ok */
4141  if ((((uint8_t*)SD_hs)[13] & 2U) != 2U)
4142  {
4143  errorstate = SDMMC_ERROR_UNSUPPORTED_FEATURE;
4144  }
4145 
4146  }
4147 
4148  return errorstate;
4149 }
uint32_t SDMMC_CmdBlockLength(SDMMC_TypeDef *SDMMCx, uint32_t BlockSize)
Send the Data Block Lenght command and check the response.
SDMMC Data Control structure.
uint32_t SDMMC_CmdSwitch(SDMMC_TypeDef *SDMMCx, uint32_t Argument)
Checks switchable function and switch card function. SDMMC_CMD_HS_SWITCH comand.
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.