STM32L4xx_HAL_Driver  1.14.0
Peripheral Control functions

management functions More...

Functions

HAL_StatusTypeDef HAL_SD_ConfigWideBusOperation (SD_HandleTypeDef *hsd, uint32_t WideMode)
 Enables wide bus operation for the requested card if supported by card. More...
 
HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation (SD_HandleTypeDef *hsd, uint32_t SpeedMode)
 Configure the speed bus mode. More...
 
HAL_StatusTypeDef HAL_SD_GetCardCID (SD_HandleTypeDef *hsd, HAL_SD_CardCIDTypeDef *pCID)
 Returns information the information of the card which are stored on the CID register. More...
 
HAL_StatusTypeDef HAL_SD_GetCardCSD (SD_HandleTypeDef *hsd, HAL_SD_CardCSDTypeDef *pCSD)
 Returns information the information of the card which are stored on the CSD register. More...
 
HAL_StatusTypeDef HAL_SD_GetCardStatus (SD_HandleTypeDef *hsd, HAL_SD_CardStatusTypeDef *pStatus)
 Gets the SD status info. More...
 
HAL_StatusTypeDef HAL_SD_GetCardInfo (SD_HandleTypeDef *hsd, HAL_SD_CardInfoTypeDef *pCardInfo)
 Gets the SD card info. More...
 
HAL_SD_CardStateTypeDef HAL_SD_GetCardState (SD_HandleTypeDef *hsd)
 Gets the current sd card data state. More...
 
HAL_StatusTypeDef HAL_SD_Abort (SD_HandleTypeDef *hsd)
 Abort the current transfer and disable the SD. More...
 
HAL_StatusTypeDef HAL_SD_Abort_IT (SD_HandleTypeDef *hsd)
 Abort the current transfer and disable the SD (IT mode). More...
 

Detailed Description

management functions

  ==============================================================================
                      ##### Peripheral Control functions #####
  ==============================================================================
  [..]
    This subsection provides a set of functions allowing to control the SD card
    operations and get the related information

Function Documentation

◆ HAL_SD_Abort()

HAL_StatusTypeDef HAL_SD_Abort ( SD_HandleTypeDef hsd)

Abort the current transfer and disable the SD.

Parameters
hsdpointer to a SD_HandleTypeDef structure that contains the configuration information for SD module.
Return values
HALstatus

Definition at line 2973 of file stm32l4xx_hal_sd.c.

2974 {
2975  HAL_SD_CardStateTypeDef CardState;
2976 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx)
2977  uint32_t context = hsd->Context;
2978 #endif
2979 
2980  /* DIsable All interrupts */
2981  __HAL_SD_DISABLE_IT(hsd, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT|\
2982  SDMMC_IT_TXUNDERR| SDMMC_IT_RXOVERR);
2983 
2984  /* Clear All flags */
2985  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
2986 
2987 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
2988  /* If IDMA Context, disable Internal DMA */
2989  hsd->Instance->IDMACTRL = SDMMC_DISABLE_IDMA;
2990 #else
2991  CLEAR_BIT(hsd->Instance->DCTRL, SDMMC_DCTRL_DTEN);
2992 
2993  if ((context & SD_CONTEXT_DMA) != 0U)
2994  {
2995  /* Disable the SD DMA request */
2996  hsd->Instance->DCTRL &= (uint32_t)~((uint32_t)SDMMC_DCTRL_DMAEN);
2997 
2998  /* Abort the SD DMA Tx channel */
2999  if (((context & SD_CONTEXT_WRITE_SINGLE_BLOCK) != 0U) || ((context & SD_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U))
3000  {
3001  if(HAL_DMA_Abort(hsd->hdmatx) != HAL_OK)
3002  {
3003  hsd->ErrorCode |= HAL_SD_ERROR_DMA;
3004  }
3005  }
3006  /* Abort the SD DMA Rx channel */
3007  else if (((context & SD_CONTEXT_READ_SINGLE_BLOCK) != 0U) || ((context & SD_CONTEXT_READ_MULTIPLE_BLOCK) != 0U))
3008  {
3009  if(HAL_DMA_Abort(hsd->hdmarx) != HAL_OK)
3010  {
3011  hsd->ErrorCode |= HAL_SD_ERROR_DMA;
3012  }
3013  }
3014  else
3015  {
3016  /* Nothing to do */
3017  }
3018  }
3019 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
3020 
3021  hsd->State = HAL_SD_STATE_READY;
3022 
3023  /* Initialize the SD operation */
3024  hsd->Context = SD_CONTEXT_NONE;
3025 
3026  CardState = HAL_SD_GetCardState(hsd);
3027  if((CardState == HAL_SD_CARD_RECEIVING) || (CardState == HAL_SD_CARD_SENDING))
3028  {
3029  hsd->ErrorCode = SDMMC_CmdStopTransfer(hsd->Instance);
3030  }
3031  if(hsd->ErrorCode != HAL_SD_ERROR_NONE)
3032  {
3033  return HAL_ERROR;
3034  }
3035  return HAL_OK;
3036 }
HAL_SD_CardStateTypeDef HAL_SD_GetCardState(SD_HandleTypeDef *hsd)
Gets the current sd card data state.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.
uint32_t HAL_SD_CardStateTypeDef
uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx)
Send the Stop Transfer command and check the response.

◆ HAL_SD_Abort_IT()

HAL_StatusTypeDef HAL_SD_Abort_IT ( SD_HandleTypeDef hsd)

Abort the current transfer and disable the SD (IT mode).

Parameters
hsdpointer to a SD_HandleTypeDef structure that contains the configuration information for SD module.
Return values
HALstatus

Definition at line 3044 of file stm32l4xx_hal_sd.c.

3045 {
3046  HAL_SD_CardStateTypeDef CardState;
3047 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx)
3048  uint32_t context = hsd->Context;
3049 #endif
3050 
3051  /* Disable All interrupts */
3052  __HAL_SD_DISABLE_IT(hsd, SDMMC_IT_DATAEND | SDMMC_IT_DCRCFAIL | SDMMC_IT_DTIMEOUT|\
3053  SDMMC_IT_TXUNDERR| SDMMC_IT_RXOVERR);
3054 
3055 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
3056  /* If IDMA Context, disable Internal DMA */
3057  hsd->Instance->IDMACTRL = SDMMC_DISABLE_IDMA;
3058 
3059  /* Clear All flags */
3060  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
3061 
3062  CardState = HAL_SD_GetCardState(hsd);
3063  hsd->State = HAL_SD_STATE_READY;
3064 
3065  if((CardState == HAL_SD_CARD_RECEIVING) || (CardState == HAL_SD_CARD_SENDING))
3066  {
3067  hsd->ErrorCode = SDMMC_CmdStopTransfer(hsd->Instance);
3068  }
3069 
3070  if(hsd->ErrorCode != HAL_SD_ERROR_NONE)
3071  {
3072  return HAL_ERROR;
3073  }
3074  else
3075  {
3076 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
3077  hsd->AbortCpltCallback(hsd);
3078 #else
3079  HAL_SD_AbortCallback(hsd);
3080 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
3081  }
3082 #else
3083  CLEAR_BIT(hsd->Instance->DCTRL, SDMMC_DCTRL_DTEN);
3084 
3085  if ((context & SD_CONTEXT_DMA) != 0U)
3086  {
3087  /* Disable the SD DMA request */
3088  hsd->Instance->DCTRL &= (uint32_t)~((uint32_t)SDMMC_DCTRL_DMAEN);
3089 
3090  /* Abort the SD DMA Tx channel */
3091  if (((context & SD_CONTEXT_WRITE_SINGLE_BLOCK) != 0U) || ((context & SD_CONTEXT_WRITE_MULTIPLE_BLOCK) != 0U))
3092  {
3093  hsd->hdmatx->XferAbortCallback = SD_DMATxAbort;
3094  if(HAL_DMA_Abort_IT(hsd->hdmatx) != HAL_OK)
3095  {
3096  hsd->hdmatx = NULL;
3097  }
3098  }
3099  /* Abort the SD DMA Rx channel */
3100  else if (((context & SD_CONTEXT_READ_SINGLE_BLOCK) != 0U) || ((context & SD_CONTEXT_READ_MULTIPLE_BLOCK) != 0U))
3101  {
3102  hsd->hdmarx->XferAbortCallback = SD_DMARxAbort;
3103  if(HAL_DMA_Abort_IT(hsd->hdmarx) != HAL_OK)
3104  {
3105  hsd->hdmarx = NULL;
3106  }
3107  }
3108  else
3109  {
3110  /* Nothing to do */
3111  }
3112  }
3113  /* No transfer ongoing on both DMA channels*/
3114  else
3115  {
3116  /* Clear All flags */
3117  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_DATA_FLAGS);
3118 
3119  CardState = HAL_SD_GetCardState(hsd);
3120  hsd->State = HAL_SD_STATE_READY;
3121  hsd->Context = SD_CONTEXT_NONE;
3122  if((CardState == HAL_SD_CARD_RECEIVING) || (CardState == HAL_SD_CARD_SENDING))
3123  {
3124  hsd->ErrorCode = SDMMC_CmdStopTransfer(hsd->Instance);
3125  }
3126  if(hsd->ErrorCode != HAL_SD_ERROR_NONE)
3127  {
3128  return HAL_ERROR;
3129  }
3130  else
3131  {
3132 #if defined (USE_HAL_SD_REGISTER_CALLBACKS) && (USE_HAL_SD_REGISTER_CALLBACKS == 1U)
3133  hsd->AbortCpltCallback(hsd);
3134 #else
3135  HAL_SD_AbortCallback(hsd);
3136 #endif /* USE_HAL_SD_REGISTER_CALLBACKS */
3137  }
3138  }
3139 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
3140 
3141  return HAL_OK;
3142 }
HAL_SD_CardStateTypeDef HAL_SD_GetCardState(SD_HandleTypeDef *hsd)
Gets the current sd card data state.
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
static void SD_DMARxAbort(DMA_HandleTypeDef *hdma)
DMA SD Rx Abort callback.
static void SD_DMATxAbort(DMA_HandleTypeDef *hdma)
DMA SD Tx Abort callback.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
uint32_t HAL_SD_CardStateTypeDef
uint32_t SDMMC_CmdStopTransfer(SDMMC_TypeDef *SDMMCx)
Send the Stop Transfer command and check the response.
void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd)
SD Abort callbacks.

◆ HAL_SD_ConfigSpeedBusOperation()

HAL_StatusTypeDef HAL_SD_ConfigSpeedBusOperation ( SD_HandleTypeDef hsd,
uint32_t  SpeedMode 
)

Configure the speed bus mode.

Parameters
hsdPointer to the SD handle
SpeedModeSpecifies the SD card speed bus mode This parameter can be one of the following values:
  • SDMMC_SPEED_MODE_AUTO: Max speed mode supported by the card
  • SDMMC_SPEED_MODE_DEFAULT: Default Speed/SDR12 mode
  • SDMMC_SPEED_MODE_HIGH: High Speed/SDR25 mode
  • SDMMC_SPEED_MODE_ULTRA: Ultra high speed mode
Return values
HALstatus

Definition at line 2760 of file stm32l4xx_hal_sd.c.

2761 {
2762  uint32_t tickstart;
2763  HAL_StatusTypeDef status = HAL_OK;
2764 
2765  /* Check the parameters */
2766  assert_param(IS_SDMMC_SPEED_MODE(SpeedMode));
2767  /* Change State */
2768  hsd->State = HAL_SD_STATE_BUSY;
2769 
2770  if(hsd->Init.Transceiver == SDMMC_TRANSCEIVER_ENABLE)
2771  {
2772  switch (SpeedMode)
2773  {
2774  case SDMMC_SPEED_MODE_AUTO:
2775  {
2776  if ((hsd->SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED) ||
2777  (hsd->SdCard.CardType == CARD_SDHC_SDXC))
2778  {
2779  hsd->Instance->CLKCR |= 0x00100000U;
2780  /* Enable Ultra High Speed */
2781  if (SD_UltraHighSpeed(hsd) != HAL_SD_ERROR_NONE)
2782  {
2783  if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
2784  {
2785  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2786  status = HAL_ERROR;
2787  }
2788  }
2789  }
2790  else if (hsd->SdCard.CardSpeed == CARD_HIGH_SPEED)
2791  {
2792  /* Enable High Speed */
2793  if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
2794  {
2795  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2796  status = HAL_ERROR;
2797  }
2798  }
2799  else
2800  {
2801  /*Nothing to do, Use defaultSpeed */
2802  }
2803  break;
2804  }
2805  case SDMMC_SPEED_MODE_ULTRA:
2806  {
2807  if ((hsd->SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED) ||
2808  (hsd->SdCard.CardType == CARD_SDHC_SDXC))
2809  {
2810  hsd->Instance->CLKCR |= 0x00100000U;
2811  /* Enable UltraHigh Speed */
2812  if (SD_UltraHighSpeed(hsd) != HAL_SD_ERROR_NONE)
2813  {
2814  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2815  status = HAL_ERROR;
2816  }
2817  }
2818  else
2819  {
2820  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2821  status = HAL_ERROR;
2822  }
2823  break;
2824  }
2825  case SDMMC_SPEED_MODE_DDR:
2826  {
2827  if ((hsd->SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED) ||
2828  (hsd->SdCard.CardType == CARD_SDHC_SDXC))
2829  {
2830  hsd->Instance->CLKCR |= 0x00100000U;
2831  /* Enable DDR Mode*/
2832  if (SD_DDR_Mode(hsd) != HAL_SD_ERROR_NONE)
2833  {
2834  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2835  status = HAL_ERROR;
2836  }
2837  }
2838  else
2839  {
2840  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2841  status = HAL_ERROR;
2842  }
2843  break;
2844  }
2845  case SDMMC_SPEED_MODE_HIGH:
2846  {
2847  if ((hsd->SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED) ||
2848  (hsd->SdCard.CardSpeed == CARD_HIGH_SPEED) ||
2849  (hsd->SdCard.CardType == CARD_SDHC_SDXC))
2850  {
2851  /* Enable High Speed */
2852  if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
2853  {
2854  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2855  status = HAL_ERROR;
2856  }
2857  }
2858  else
2859  {
2860  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2861  status = HAL_ERROR;
2862  }
2863  break;
2864  }
2865  case SDMMC_SPEED_MODE_DEFAULT:
2866  break;
2867  default:
2868  hsd->ErrorCode |= HAL_SD_ERROR_PARAM;
2869  status = HAL_ERROR;
2870  break;
2871  }
2872  }
2873  else
2874  {
2875  switch (SpeedMode)
2876  {
2877  case SDMMC_SPEED_MODE_AUTO:
2878  {
2879  if ((hsd->SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED) ||
2880  (hsd->SdCard.CardSpeed == CARD_HIGH_SPEED) ||
2881  (hsd->SdCard.CardType == CARD_SDHC_SDXC))
2882  {
2883  /* Enable High Speed */
2884  if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
2885  {
2886  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2887  status = HAL_ERROR;
2888  }
2889  }
2890  else
2891  {
2892  /*Nothing to do, Use defaultSpeed */
2893  }
2894  break;
2895  }
2896  case SDMMC_SPEED_MODE_HIGH:
2897  {
2898  if ((hsd->SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED) ||
2899  (hsd->SdCard.CardSpeed == CARD_HIGH_SPEED) ||
2900  (hsd->SdCard.CardType == CARD_SDHC_SDXC))
2901  {
2902  /* Enable High Speed */
2903  if (SD_HighSpeed(hsd) != HAL_SD_ERROR_NONE)
2904  {
2905  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2906  status = HAL_ERROR;
2907  }
2908  }
2909  else
2910  {
2911  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2912  status = HAL_ERROR;
2913  }
2914  break;
2915  }
2916  case SDMMC_SPEED_MODE_DEFAULT:
2917  break;
2918  case SDMMC_SPEED_MODE_ULTRA: /*not valid without transceiver*/
2919  default:
2920  hsd->ErrorCode |= HAL_SD_ERROR_PARAM;
2921  status = HAL_ERROR;
2922  break;
2923  }
2924  }
2925 
2926 
2927  /* Verify that SD card is ready to use after Speed mode switch*/
2928  tickstart = HAL_GetTick();
2929  while ((HAL_SD_GetCardState(hsd) != HAL_SD_CARD_TRANSFER))
2930  {
2931  if ((HAL_GetTick() - tickstart) >= SDMMC_DATATIMEOUT)
2932  {
2933  hsd->ErrorCode = HAL_SD_ERROR_TIMEOUT;
2934  hsd->State = HAL_SD_STATE_READY;
2935  return HAL_TIMEOUT;
2936  }
2937  }
2938 
2939  /* Change State */
2940  hsd->State = HAL_SD_STATE_READY;
2941  return status;
2942 }
static uint32_t SD_DDR_Mode(SD_HandleTypeDef *hsd)
Switches the SD card to Double Data Rate (DDR) mode. This API must be used after "Transfer State"...
uint32_t SD_HighSpeed(SD_HandleTypeDef *hsd)
Switches the SD card to High Speed mode. This API must be used after "Transfer State".
static uint32_t SD_UltraHighSpeed(SD_HandleTypeDef *hsd)
Switches the SD card to Ultra High Speed mode. This API must be used after "Transfer State"...
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
HAL_SD_CardStateTypeDef HAL_SD_GetCardState(SD_HandleTypeDef *hsd)
Gets the current sd card data state.
return HAL_OK
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_SD_ConfigWideBusOperation()

HAL_StatusTypeDef HAL_SD_ConfigWideBusOperation ( SD_HandleTypeDef hsd,
uint32_t  WideMode 
)

Enables wide bus operation for the requested card if supported by card.

Parameters
hsdPointer to SD handle
WideModeSpecifies the SD card wide bus mode This parameter can be one of the following values:
  • SDMMC_BUS_WIDE_8B: 8-bit data transfer
  • SDMMC_BUS_WIDE_4B: 4-bit data transfer
  • SDMMC_BUS_WIDE_1B: 1-bit data transfer
Return values
HALstatus

Definition at line 2654 of file stm32l4xx_hal_sd.c.

2655 {
2656  SDMMC_InitTypeDef Init;
2657  uint32_t errorstate;
2658 
2659  /* Check the parameters */
2660  assert_param(IS_SDMMC_BUS_WIDE(WideMode));
2661 
2662  /* Change State */
2663  hsd->State = HAL_SD_STATE_BUSY;
2664 
2665  if(hsd->SdCard.CardType != CARD_SECURED)
2666  {
2667  if(WideMode == SDMMC_BUS_WIDE_8B)
2668  {
2669  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2670  }
2671  else if(WideMode == SDMMC_BUS_WIDE_4B)
2672  {
2673  errorstate = SD_WideBus_Enable(hsd);
2674 
2675  hsd->ErrorCode |= errorstate;
2676  }
2677  else if(WideMode == SDMMC_BUS_WIDE_1B)
2678  {
2679  errorstate = SD_WideBus_Disable(hsd);
2680 
2681  hsd->ErrorCode |= errorstate;
2682  }
2683  else
2684  {
2685  /* WideMode is not a valid argument*/
2686  hsd->ErrorCode |= HAL_SD_ERROR_PARAM;
2687  }
2688  }
2689  else
2690  {
2691  /* MMC Card does not support this feature */
2692  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2693  }
2694 
2695  if(hsd->ErrorCode != HAL_SD_ERROR_NONE)
2696  {
2697  /* Clear all the static flags */
2698  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_FLAGS);
2699  hsd->State = HAL_SD_STATE_READY;
2700  return HAL_ERROR;
2701  }
2702  else
2703  {
2704  /* Configure the SDMMC peripheral */
2705  Init.ClockEdge = hsd->Init.ClockEdge;
2706 #if !defined(STM32L4R5xx) && !defined(STM32L4R7xx) && !defined(STM32L4R9xx) && !defined(STM32L4S5xx) && !defined(STM32L4S7xx) && !defined(STM32L4S9xx)
2707  Init.ClockBypass = hsd->Init.ClockBypass;
2708 #endif /* !STM32L4R5xx && !STM32L4R7xx && !STM32L4R9xx && !STM32L4S5xx && !STM32L4S7xx && !STM32L4S9xx */
2709  Init.ClockPowerSave = hsd->Init.ClockPowerSave;
2710  Init.BusWide = WideMode;
2711  Init.HardwareFlowControl = hsd->Init.HardwareFlowControl;
2712 
2713 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
2714  /* Check if user Clock div < Normal speed 25Mhz, no change in Clockdiv */
2715  if(hsd->Init.ClockDiv >= SDMMC_NSpeed_CLK_DIV)
2716  {
2717  Init.ClockDiv = hsd->Init.ClockDiv;
2718  }
2719  else if (hsd->SdCard.CardSpeed == CARD_ULTRA_HIGH_SPEED)
2720  {
2721  /* UltraHigh speed SD card,user Clock div */
2722  Init.ClockDiv = hsd->Init.ClockDiv;
2723  }
2724  else if (hsd->SdCard.CardSpeed == CARD_HIGH_SPEED)
2725  {
2726  /* High speed SD card, Max Frequency = 50Mhz */
2727  Init.ClockDiv = SDMMC_HSpeed_CLK_DIV;
2728  }
2729  else
2730  {
2731  /* No High speed SD card, Max Frequency = 25Mhz */
2732  Init.ClockDiv = SDMMC_NSpeed_CLK_DIV;
2733  }
2734 #else
2735  Init.ClockDiv = hsd->Init.ClockDiv;
2736 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
2737 
2738  (void)SDMMC_Init(hsd->Instance, Init);
2739  }
2740 
2741  /* Change State */
2742  hsd->State = HAL_SD_STATE_READY;
2743 
2744  return HAL_OK;
2745 }
static uint32_t SD_WideBus_Disable(SD_HandleTypeDef *hsd)
Disables the SDMMC wide bus mode.
static uint32_t SD_WideBus_Enable(SD_HandleTypeDef *hsd)
Enables the SDMMC wide bus mode.
WWDG_InitTypeDef Init
return HAL_OK
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...
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_SD_GetCardCID()

HAL_StatusTypeDef HAL_SD_GetCardCID ( SD_HandleTypeDef hsd,
HAL_SD_CardCIDTypeDef pCID 
)

Returns information the information of the card which are stored on the CID register.

Parameters
hsdPointer to SD handle
pCIDPointer to a HAL_SD_CardCIDTypeDef structure that contains all CID register parameters
Return values
HALstatus

Definition at line 2428 of file stm32l4xx_hal_sd.c.

2429 {
2430  pCID->ManufacturerID = (uint8_t)((hsd->CID[0] & 0xFF000000U) >> 24U);
2431 
2432  pCID->OEM_AppliID = (uint16_t)((hsd->CID[0] & 0x00FFFF00U) >> 8U);
2433 
2434  pCID->ProdName1 = (((hsd->CID[0] & 0x000000FFU) << 24U) | ((hsd->CID[1] & 0xFFFFFF00U) >> 8U));
2435 
2436  pCID->ProdName2 = (uint8_t)(hsd->CID[1] & 0x000000FFU);
2437 
2438  pCID->ProdRev = (uint8_t)((hsd->CID[2] & 0xFF000000U) >> 24U);
2439 
2440  pCID->ProdSN = (((hsd->CID[2] & 0x00FFFFFFU) << 8U) | ((hsd->CID[3] & 0xFF000000U) >> 24U));
2441 
2442  pCID->Reserved1 = (uint8_t)((hsd->CID[3] & 0x00F00000U) >> 20U);
2443 
2444  pCID->ManufactDate = (uint16_t)((hsd->CID[3] & 0x000FFF00U) >> 8U);
2445 
2446  pCID->CID_CRC = (uint8_t)((hsd->CID[3] & 0x000000FEU) >> 1U);
2447 
2448  pCID->Reserved2 = 1U;
2449 
2450  return HAL_OK;
2451 }
return HAL_OK
__IO uint16_t ManufactDate

◆ HAL_SD_GetCardCSD()

HAL_StatusTypeDef HAL_SD_GetCardCSD ( SD_HandleTypeDef hsd,
HAL_SD_CardCSDTypeDef pCSD 
)

Returns information the information of the card which are stored on the CSD register.

Parameters
hsdPointer to SD handle
pCSDPointer to a HAL_SD_CardCSDTypeDef structure that contains all CSD register parameters
Return values
HALstatus

< Reserved

Definition at line 2461 of file stm32l4xx_hal_sd.c.

2462 {
2463  pCSD->CSDStruct = (uint8_t)((hsd->CSD[0] & 0xC0000000U) >> 30U);
2464 
2465  pCSD->SysSpecVersion = (uint8_t)((hsd->CSD[0] & 0x3C000000U) >> 26U);
2466 
2467  pCSD->Reserved1 = (uint8_t)((hsd->CSD[0] & 0x03000000U) >> 24U);
2468 
2469  pCSD->TAAC = (uint8_t)((hsd->CSD[0] & 0x00FF0000U) >> 16U);
2470 
2471  pCSD->NSAC = (uint8_t)((hsd->CSD[0] & 0x0000FF00U) >> 8U);
2472 
2473  pCSD->MaxBusClkFrec = (uint8_t)(hsd->CSD[0] & 0x000000FFU);
2474 
2475  pCSD->CardComdClasses = (uint16_t)((hsd->CSD[1] & 0xFFF00000U) >> 20U);
2476 
2477  pCSD->RdBlockLen = (uint8_t)((hsd->CSD[1] & 0x000F0000U) >> 16U);
2478 
2479  pCSD->PartBlockRead = (uint8_t)((hsd->CSD[1] & 0x00008000U) >> 15U);
2480 
2481  pCSD->WrBlockMisalign = (uint8_t)((hsd->CSD[1] & 0x00004000U) >> 14U);
2482 
2483  pCSD->RdBlockMisalign = (uint8_t)((hsd->CSD[1] & 0x00002000U) >> 13U);
2484 
2485  pCSD->DSRImpl = (uint8_t)((hsd->CSD[1] & 0x00001000U) >> 12U);
2486 
2487  pCSD->Reserved2 = 0U;
2489  if(hsd->SdCard.CardType == CARD_SDSC)
2490  {
2491  pCSD->DeviceSize = (((hsd->CSD[1] & 0x000003FFU) << 2U) | ((hsd->CSD[2] & 0xC0000000U) >> 30U));
2492 
2493  pCSD->MaxRdCurrentVDDMin = (uint8_t)((hsd->CSD[2] & 0x38000000U) >> 27U);
2494 
2495  pCSD->MaxRdCurrentVDDMax = (uint8_t)((hsd->CSD[2] & 0x07000000U) >> 24U);
2496 
2497  pCSD->MaxWrCurrentVDDMin = (uint8_t)((hsd->CSD[2] & 0x00E00000U) >> 21U);
2498 
2499  pCSD->MaxWrCurrentVDDMax = (uint8_t)((hsd->CSD[2] & 0x001C0000U) >> 18U);
2500 
2501  pCSD->DeviceSizeMul = (uint8_t)((hsd->CSD[2] & 0x00038000U) >> 15U);
2502 
2503  hsd->SdCard.BlockNbr = (pCSD->DeviceSize + 1U) ;
2504  hsd->SdCard.BlockNbr *= (1UL << ((pCSD->DeviceSizeMul & 0x07U) + 2U));
2505  hsd->SdCard.BlockSize = (1UL << (pCSD->RdBlockLen & 0x0FU));
2506 
2507  hsd->SdCard.LogBlockNbr = (hsd->SdCard.BlockNbr) * ((hsd->SdCard.BlockSize) / 512U);
2508  hsd->SdCard.LogBlockSize = 512U;
2509  }
2510  else if(hsd->SdCard.CardType == CARD_SDHC_SDXC)
2511  {
2512  /* Byte 7 */
2513  pCSD->DeviceSize = (((hsd->CSD[1] & 0x0000003FU) << 16U) | ((hsd->CSD[2] & 0xFFFF0000U) >> 16U));
2514 
2515  hsd->SdCard.BlockNbr = ((pCSD->DeviceSize + 1U) * 1024U);
2516  hsd->SdCard.LogBlockNbr = hsd->SdCard.BlockNbr;
2517  hsd->SdCard.BlockSize = 512U;
2518  hsd->SdCard.LogBlockSize = hsd->SdCard.BlockSize;
2519  }
2520  else
2521  {
2522  /* Clear all the static flags */
2523  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_FLAGS);
2524  hsd->ErrorCode |= HAL_SD_ERROR_UNSUPPORTED_FEATURE;
2525  hsd->State = HAL_SD_STATE_READY;
2526  return HAL_ERROR;
2527  }
2528 
2529  pCSD->EraseGrSize = (uint8_t)((hsd->CSD[2] & 0x00004000U) >> 14U);
2530 
2531  pCSD->EraseGrMul = (uint8_t)((hsd->CSD[2] & 0x00003F80U) >> 7U);
2532 
2533  pCSD->WrProtectGrSize = (uint8_t)(hsd->CSD[2] & 0x0000007FU);
2534 
2535  pCSD->WrProtectGrEnable = (uint8_t)((hsd->CSD[3] & 0x80000000U) >> 31U);
2536 
2537  pCSD->ManDeflECC = (uint8_t)((hsd->CSD[3] & 0x60000000U) >> 29U);
2538 
2539  pCSD->WrSpeedFact = (uint8_t)((hsd->CSD[3] & 0x1C000000U) >> 26U);
2540 
2541  pCSD->MaxWrBlockLen= (uint8_t)((hsd->CSD[3] & 0x03C00000U) >> 22U);
2542 
2543  pCSD->WriteBlockPaPartial = (uint8_t)((hsd->CSD[3] & 0x00200000U) >> 21U);
2544 
2545  pCSD->Reserved3 = 0;
2546 
2547  pCSD->ContentProtectAppli = (uint8_t)((hsd->CSD[3] & 0x00010000U) >> 16U);
2548 
2549  pCSD->FileFormatGroup = (uint8_t)((hsd->CSD[3] & 0x00008000U) >> 15U);
2550 
2551  pCSD->CopyFlag = (uint8_t)((hsd->CSD[3] & 0x00004000U) >> 14U);
2552 
2553  pCSD->PermWrProtect = (uint8_t)((hsd->CSD[3] & 0x00002000U) >> 13U);
2554 
2555  pCSD->TempWrProtect = (uint8_t)((hsd->CSD[3] & 0x00001000U) >> 12U);
2556 
2557  pCSD->FileFormat = (uint8_t)((hsd->CSD[3] & 0x00000C00U) >> 10U);
2558 
2559  pCSD->ECC= (uint8_t)((hsd->CSD[3] & 0x00000300U) >> 8U);
2560 
2561  pCSD->CSD_CRC = (uint8_t)((hsd->CSD[3] & 0x000000FEU) >> 1U);
2562 
2563  pCSD->Reserved4 = 1;
2564 
2565  return HAL_OK;
2566 }
__IO uint16_t CardComdClasses
__IO uint8_t MaxRdCurrentVDDMax
__IO uint8_t ContentProtectAppli
__IO uint8_t MaxWrCurrentVDDMax
__IO uint8_t WriteBlockPaPartial
__IO uint8_t WrProtectGrSize
__IO uint8_t MaxRdCurrentVDDMin
return HAL_OK
__IO uint8_t MaxWrCurrentVDDMin
__IO uint8_t FileFormatGroup
__IO uint8_t RdBlockMisalign
__IO uint8_t WrBlockMisalign
__IO uint8_t WrProtectGrEnable

◆ HAL_SD_GetCardInfo()

HAL_StatusTypeDef HAL_SD_GetCardInfo ( SD_HandleTypeDef hsd,
HAL_SD_CardInfoTypeDef pCardInfo 
)

Gets the SD card info.

Parameters
hsdPointer to SD handle
pCardInfoPointer to the HAL_SD_CardInfoTypeDef structure that will contain the SD card status information
Return values
HALstatus

Definition at line 2629 of file stm32l4xx_hal_sd.c.

2630 {
2631  pCardInfo->CardType = (uint32_t)(hsd->SdCard.CardType);
2632  pCardInfo->CardVersion = (uint32_t)(hsd->SdCard.CardVersion);
2633  pCardInfo->Class = (uint32_t)(hsd->SdCard.Class);
2634  pCardInfo->RelCardAdd = (uint32_t)(hsd->SdCard.RelCardAdd);
2635  pCardInfo->BlockNbr = (uint32_t)(hsd->SdCard.BlockNbr);
2636  pCardInfo->BlockSize = (uint32_t)(hsd->SdCard.BlockSize);
2637  pCardInfo->LogBlockNbr = (uint32_t)(hsd->SdCard.LogBlockNbr);
2638  pCardInfo->LogBlockSize = (uint32_t)(hsd->SdCard.LogBlockSize);
2639 
2640  return HAL_OK;
2641 }
return HAL_OK

◆ HAL_SD_GetCardState()

HAL_SD_CardStateTypeDef HAL_SD_GetCardState ( SD_HandleTypeDef hsd)

Gets the current sd card data state.

Parameters
hsdpointer to SD handle
Return values
Cardstate

Definition at line 2950 of file stm32l4xx_hal_sd.c.

2951 {
2952  uint32_t cardstate;
2953  uint32_t errorstate;
2954  uint32_t resp1 = 0;
2955 
2956  errorstate = SD_SendStatus(hsd, &resp1);
2957  if(errorstate != HAL_SD_ERROR_NONE)
2958  {
2959  hsd->ErrorCode |= errorstate;
2960  }
2961 
2962  cardstate = ((resp1 >> 9U) & 0x0FU);
2963 
2964  return (HAL_SD_CardStateTypeDef)cardstate;
2965 }
uint32_t HAL_SD_CardStateTypeDef
static uint32_t SD_SendStatus(SD_HandleTypeDef *hsd, uint32_t *pCardStatus)
Returns the current card&#39;s status.

◆ HAL_SD_GetCardStatus()

HAL_StatusTypeDef HAL_SD_GetCardStatus ( SD_HandleTypeDef hsd,
HAL_SD_CardStatusTypeDef pStatus 
)

Gets the SD status info.

Parameters
hsdPointer to SD handle
pStatusPointer to the HAL_SD_CardStatusTypeDef structure that will contain the SD card status information
Return values
HALstatus

Definition at line 2575 of file stm32l4xx_hal_sd.c.

2576 {
2577  uint32_t sd_status[16];
2578  uint32_t errorstate;
2579 
2580  errorstate = SD_SendSDStatus(hsd, sd_status);
2581  if(errorstate != HAL_SD_ERROR_NONE)
2582  {
2583  /* Clear all the static flags */
2584  __HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_FLAGS);
2585  hsd->ErrorCode |= errorstate;
2586  hsd->State = HAL_SD_STATE_READY;
2587  return HAL_ERROR;
2588  }
2589  else
2590  {
2591  pStatus->DataBusWidth = (uint8_t)((sd_status[0] & 0xC0U) >> 6U);
2592 
2593  pStatus->SecuredMode = (uint8_t)((sd_status[0] & 0x20U) >> 5U);
2594 
2595  pStatus->CardType = (uint16_t)(((sd_status[0] & 0x00FF0000U) >> 8U) | ((sd_status[0] & 0xFF000000U) >> 24U));
2596 
2597  pStatus->ProtectedAreaSize = (((sd_status[1] & 0xFFU) << 24U) | ((sd_status[1] & 0xFF00U) << 8U) |
2598  ((sd_status[1] & 0xFF0000U) >> 8U) | ((sd_status[1] & 0xFF000000U) >> 24U));
2599 
2600  pStatus->SpeedClass = (uint8_t)(sd_status[2] & 0xFFU);
2601 
2602  pStatus->PerformanceMove = (uint8_t)((sd_status[2] & 0xFF00U) >> 8U);
2603 
2604  pStatus->AllocationUnitSize = (uint8_t)((sd_status[2] & 0xF00000U) >> 20U);
2605 
2606  pStatus->EraseSize = (uint16_t)(((sd_status[2] & 0xFF000000U) >> 16U) | (sd_status[3] & 0xFFU));
2607 
2608  pStatus->EraseTimeout = (uint8_t)((sd_status[3] & 0xFC00U) >> 10U);
2609 
2610  pStatus->EraseOffset = (uint8_t)((sd_status[3] & 0x0300U) >> 8U);
2611 
2612 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
2613  pStatus->UhsSpeedGrade = (uint8_t)((sd_status[3] & 0x00F0U) >> 4U);
2614  pStatus->UhsAllocationUnitSize = (uint8_t)(sd_status[3] & 0x000FU) ;
2615  pStatus->VideoSpeedClass = (uint8_t)((sd_status[4] & 0xFF000000U) >> 24U);
2616 #endif
2617  }
2618 
2619  return HAL_OK;
2620 }
__IO uint8_t UhsAllocationUnitSize
static uint32_t SD_SendSDStatus(SD_HandleTypeDef *hsd, uint32_t *pSDstatus)
Send Status info command.
return HAL_OK