STM32L4xx_HAL_Driver  1.14.0
SMARTCARD Private Functions

Functions

void SMARTCARD_InitCallbacksToDefault (SMARTCARD_HandleTypeDef *hsmartcard)
 Initialize the callbacks to their default values. More...
 
static HAL_StatusTypeDef SMARTCARD_SetConfig (SMARTCARD_HandleTypeDef *hsmartcard)
 Configure the SMARTCARD associated USART peripheral. More...
 
static void SMARTCARD_AdvFeatureConfig (SMARTCARD_HandleTypeDef *hsmartcard)
 Configure the SMARTCARD associated USART peripheral advanced features. More...
 
static HAL_StatusTypeDef SMARTCARD_CheckIdleState (SMARTCARD_HandleTypeDef *hsmartcard)
 Check the SMARTCARD Idle State. More...
 
static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout (SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
 Handle SMARTCARD Communication Timeout. More...
 
static void SMARTCARD_EndTxTransfer (SMARTCARD_HandleTypeDef *hsmartcard)
 End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion). More...
 
static void SMARTCARD_EndRxTransfer (SMARTCARD_HandleTypeDef *hsmartcard)
 End ongoing Rx transfer on UART peripheral (following error detection or Reception completion). More...
 
static void SMARTCARD_DMATransmitCplt (DMA_HandleTypeDef *hdma)
 DMA SMARTCARD transmit process complete callback. More...
 
static void SMARTCARD_DMAReceiveCplt (DMA_HandleTypeDef *hdma)
 DMA SMARTCARD receive process complete callback. More...
 
static void SMARTCARD_DMAError (DMA_HandleTypeDef *hdma)
 DMA SMARTCARD communication error callback. More...
 
static void SMARTCARD_DMAAbortOnError (DMA_HandleTypeDef *hdma)
 DMA SMARTCARD communication abort callback, when initiated by HAL services on Error (To be called at end of DMA Abort procedure following error occurrence). More...
 
static void SMARTCARD_DMATxAbortCallback (DMA_HandleTypeDef *hdma)
 DMA SMARTCARD Tx communication abort callback, when initiated by user (To be called at end of DMA Tx Abort procedure following user abort request). More...
 
static void SMARTCARD_DMARxAbortCallback (DMA_HandleTypeDef *hdma)
 DMA SMARTCARD Rx communication abort callback, when initiated by user (To be called at end of DMA Rx Abort procedure following user abort request). More...
 
static void SMARTCARD_DMATxOnlyAbortCallback (DMA_HandleTypeDef *hdma)
 DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to HAL_SMARTCARD_AbortTransmit_IT API (Abort only Tx transfer) (This callback is executed at end of DMA Tx Abort procedure following user abort request, and leads to user Tx Abort Complete callback execution). More...
 
static void SMARTCARD_DMARxOnlyAbortCallback (DMA_HandleTypeDef *hdma)
 DMA SMARTCARD Rx communication abort callback, when initiated by user by a call to HAL_SMARTCARD_AbortReceive_IT API (Abort only Rx transfer) (This callback is executed at end of DMA Rx Abort procedure following user abort request, and leads to user Rx Abort Complete callback execution). More...
 
static void SMARTCARD_TxISR (SMARTCARD_HandleTypeDef *hsmartcard)
 Send an amount of data in non-blocking mode. More...
 
static void SMARTCARD_TxISR_FIFOEN (SMARTCARD_HandleTypeDef *hsmartcard)
 Send an amount of data in non-blocking mode. More...
 
static void SMARTCARD_EndTransmit_IT (SMARTCARD_HandleTypeDef *hsmartcard)
 Wrap up transmission in non-blocking mode. More...
 
static void SMARTCARD_RxISR (SMARTCARD_HandleTypeDef *hsmartcard)
 Receive an amount of data in non-blocking mode. More...
 
static void SMARTCARD_RxISR_FIFOEN (SMARTCARD_HandleTypeDef *hsmartcard)
 Receive an amount of data in non-blocking mode. More...
 

Detailed Description

Function Documentation

◆ SMARTCARD_AdvFeatureConfig()

static void SMARTCARD_AdvFeatureConfig ( SMARTCARD_HandleTypeDef hsmartcard)
static

Configure the SMARTCARD associated USART peripheral advanced features.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 2554 of file stm32l4xx_hal_smartcard.c.

2555 {
2556  /* Check whether the set of advanced features to configure is properly set */
2557  assert_param(IS_SMARTCARD_ADVFEATURE_INIT(hsmartcard->AdvancedInit.AdvFeatureInit));
2558 
2559  /* if required, configure TX pin active level inversion */
2560  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXINVERT_INIT))
2561  {
2562  assert_param(IS_SMARTCARD_ADVFEATURE_TXINV(hsmartcard->AdvancedInit.TxPinLevelInvert));
2563  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_TXINV, hsmartcard->AdvancedInit.TxPinLevelInvert);
2564  }
2565 
2566  /* if required, configure RX pin active level inversion */
2567  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXINVERT_INIT))
2568  {
2569  assert_param(IS_SMARTCARD_ADVFEATURE_RXINV(hsmartcard->AdvancedInit.RxPinLevelInvert));
2570  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_RXINV, hsmartcard->AdvancedInit.RxPinLevelInvert);
2571  }
2572 
2573  /* if required, configure data inversion */
2574  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DATAINVERT_INIT))
2575  {
2576  assert_param(IS_SMARTCARD_ADVFEATURE_DATAINV(hsmartcard->AdvancedInit.DataInvert));
2577  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_DATAINV, hsmartcard->AdvancedInit.DataInvert);
2578  }
2579 
2580  /* if required, configure RX/TX pins swap */
2581  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_SWAP_INIT))
2582  {
2583  assert_param(IS_SMARTCARD_ADVFEATURE_SWAP(hsmartcard->AdvancedInit.Swap));
2584  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_SWAP, hsmartcard->AdvancedInit.Swap);
2585  }
2586 
2587  /* if required, configure RX overrun detection disabling */
2588  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT))
2589  {
2590  assert_param(IS_SMARTCARD_OVERRUN(hsmartcard->AdvancedInit.OverrunDisable));
2591  MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_OVRDIS, hsmartcard->AdvancedInit.OverrunDisable);
2592  }
2593 
2594  /* if required, configure DMA disabling on reception error */
2595  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT))
2596  {
2597  assert_param(IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(hsmartcard->AdvancedInit.DMADisableonRxError));
2598  MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_DDRE, hsmartcard->AdvancedInit.DMADisableonRxError);
2599  }
2600 
2601  /* if required, configure MSB first on communication line */
2602  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
2603  {
2604  assert_param(IS_SMARTCARD_ADVFEATURE_MSBFIRST(hsmartcard->AdvancedInit.MSBFirst));
2605  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_MSBFIRST, hsmartcard->AdvancedInit.MSBFirst);
2606  }
2607 
2608 }
SMARTCARD_AdvFeatureInitTypeDef AdvancedInit
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ SMARTCARD_CheckIdleState()

static HAL_StatusTypeDef SMARTCARD_CheckIdleState ( SMARTCARD_HandleTypeDef hsmartcard)
static

Check the SMARTCARD Idle State.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
HALstatus

Definition at line 2616 of file stm32l4xx_hal_smartcard.c.

2617 {
2618  uint32_t tickstart;
2619 
2620  /* Initialize the SMARTCARD ErrorCode */
2621  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2622 
2623  /* Init tickstart for timeout management */
2624  tickstart = HAL_GetTick();
2625 
2626  /* Check if the Transmitter is enabled */
2627  if ((hsmartcard->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
2628  {
2629  /* Wait until TEACK flag is set */
2630  if (SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_TEACK, RESET, tickstart,
2631  SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK)
2632  {
2633  /* Timeout occurred */
2634  return HAL_TIMEOUT;
2635  }
2636  }
2637  /* Check if the Receiver is enabled */
2638  if ((hsmartcard->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
2639  {
2640  /* Wait until REACK flag is set */
2641  if (SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_REACK, RESET, tickstart,
2642  SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK)
2643  {
2644  /* Timeout occurred */
2645  return HAL_TIMEOUT;
2646  }
2647  }
2648 
2649  /* Initialize the SMARTCARD states */
2650  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2651  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2652 
2653  /* Process Unlocked */
2654  __HAL_UNLOCK(hsmartcard);
2655 
2656  return HAL_OK;
2657 }
__IO HAL_SMARTCARD_StateTypeDef gState
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
return HAL_OK
static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
Handle SMARTCARD Communication Timeout.
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ SMARTCARD_DMAAbortOnError()

static void SMARTCARD_DMAAbortOnError ( DMA_HandleTypeDef hdma)
static

DMA SMARTCARD communication abort callback, when initiated by HAL services on Error (To be called at end of DMA Abort procedure following error occurrence).

Parameters
hdmaDMA handle.
Return values
None

Definition at line 2839 of file stm32l4xx_hal_smartcard.c.

2840 {
2841  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2842  hsmartcard->RxXferCount = 0U;
2843  hsmartcard->TxXferCount = 0U;
2844 
2845 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2846  /* Call registered user error callback */
2847  hsmartcard->ErrorCallback(hsmartcard);
2848 #else
2849  /* Call legacy weak user error callback */
2850  HAL_SMARTCARD_ErrorCallback(hsmartcard);
2851 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2852 }
void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD error callback.
void(* ErrorCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD handle Structure definition.

◆ SMARTCARD_DMAError()

static void SMARTCARD_DMAError ( DMA_HandleTypeDef hdma)
static

DMA SMARTCARD communication error callback.

Parameters
hdmaPointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 2799 of file stm32l4xx_hal_smartcard.c.

2800 {
2801  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2802 
2803  /* Stop SMARTCARD DMA Tx request if ongoing */
2804  if (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX)
2805  {
2806  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
2807  {
2808  hsmartcard->TxXferCount = 0U;
2809  SMARTCARD_EndTxTransfer(hsmartcard);
2810  }
2811  }
2812 
2813  /* Stop SMARTCARD DMA Rx request if ongoing */
2814  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
2815  {
2816  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
2817  {
2818  hsmartcard->RxXferCount = 0U;
2819  SMARTCARD_EndRxTransfer(hsmartcard);
2820  }
2821  }
2822 
2823  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_DMA;
2824 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2825  /* Call registered user error callback */
2826  hsmartcard->ErrorCallback(hsmartcard);
2827 #else
2828  /* Call legacy weak user error callback */
2829  HAL_SMARTCARD_ErrorCallback(hsmartcard);
2830 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2831 }
static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsmartcard)
End ongoing Rx transfer on UART peripheral (following error detection or Reception completion)...
__IO HAL_SMARTCARD_StateTypeDef gState
static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsmartcard)
End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion)...
void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD error callback.
void(* ErrorCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef RxState
SMARTCARD handle Structure definition.

◆ SMARTCARD_DMAReceiveCplt()

static void SMARTCARD_DMAReceiveCplt ( DMA_HandleTypeDef hdma)
static

DMA SMARTCARD receive process complete callback.

Parameters
hdmaPointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 2768 of file stm32l4xx_hal_smartcard.c.

2769 {
2770  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2771  hsmartcard->RxXferCount = 0U;
2772 
2773  /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
2774  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
2775  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2776 
2777  /* Disable the DMA transfer for the receiver request by resetting the DMAR bit
2778  in the SMARTCARD associated USART CR3 register */
2779  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
2780 
2781  /* At end of Rx process, restore hsmartcard->RxState to Ready */
2782  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2783 
2784 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2785  /* Call registered Rx complete callback */
2786  hsmartcard->RxCpltCallback(hsmartcard);
2787 #else
2788  /* Call legacy weak Rx complete callback */
2789  HAL_SMARTCARD_RxCpltCallback(hsmartcard);
2790 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2791 }
void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
Rx Transfer completed callback.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void(* RxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef RxState
SMARTCARD handle Structure definition.

◆ SMARTCARD_DMARxAbortCallback()

static void SMARTCARD_DMARxAbortCallback ( DMA_HandleTypeDef hdma)
static

DMA SMARTCARD Rx communication abort callback, when initiated by user (To be called at end of DMA Rx Abort procedure following user abort request).

Note
When this callback is executed, User Abort complete call back is called only if no Abort still ongoing for Tx DMA Handle.
Parameters
hdmaDMA handle.
Return values
None

Definition at line 2911 of file stm32l4xx_hal_smartcard.c.

2912 {
2913  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2914 
2915  hsmartcard->hdmarx->XferAbortCallback = NULL;
2916 
2917  /* Check if an Abort process is still ongoing */
2918  if (hsmartcard->hdmatx != NULL)
2919  {
2920  if (hsmartcard->hdmatx->XferAbortCallback != NULL)
2921  {
2922  return;
2923  }
2924  }
2925 
2926  /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
2927  hsmartcard->TxXferCount = 0U;
2928  hsmartcard->RxXferCount = 0U;
2929 
2930  /* Reset errorCode */
2931  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2932 
2933  /* Clear the Error flags in the ICR register */
2934  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2935  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
2936  SMARTCARD_CLEAR_EOBF);
2937 
2938  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
2939  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2940  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2941 
2942 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2943  /* Call registered Abort complete callback */
2944  hsmartcard->AbortCpltCallback(hsmartcard);
2945 #else
2946  /* Call legacy weak Abort complete callback */
2947  HAL_SMARTCARD_AbortCpltCallback(hsmartcard);
2948 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2949 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
__IO HAL_SMARTCARD_StateTypeDef gState
void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Complete callback.
__IO HAL_SMARTCARD_StateTypeDef RxState
void(* AbortCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD handle Structure definition.

◆ SMARTCARD_DMARxOnlyAbortCallback()

static void SMARTCARD_DMARxOnlyAbortCallback ( DMA_HandleTypeDef hdma)
static

DMA SMARTCARD Rx communication abort callback, when initiated by user by a call to HAL_SMARTCARD_AbortReceive_IT API (Abort only Rx transfer) (This callback is executed at end of DMA Rx Abort procedure following user abort request, and leads to user Rx Abort Complete callback execution).

Parameters
hdmaDMA handle.
Return values
None

Definition at line 2989 of file stm32l4xx_hal_smartcard.c.

2990 {
2991  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2992 
2993  hsmartcard->RxXferCount = 0U;
2994 
2995  /* Clear the Error flags in the ICR register */
2996  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2997  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
2998  SMARTCARD_CLEAR_EOBF);
2999 
3000  /* Restore hsmartcard->RxState to Ready */
3001  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
3002 
3003 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
3004  /* Call registered Abort Receive Complete Callback */
3005  hsmartcard->AbortReceiveCpltCallback(hsmartcard);
3006 #else
3007  /* Call legacy weak Abort Receive Complete Callback */
3009 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
3010 }
void(* AbortReceiveCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Receive Complete callback.
__IO HAL_SMARTCARD_StateTypeDef RxState
SMARTCARD handle Structure definition.

◆ SMARTCARD_DMATransmitCplt()

static void SMARTCARD_DMATransmitCplt ( DMA_HandleTypeDef hdma)
static

DMA SMARTCARD transmit process complete callback.

Parameters
hdmaPointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module.
Return values
None

Definition at line 2749 of file stm32l4xx_hal_smartcard.c.

2750 {
2751  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2752  hsmartcard->TxXferCount = 0U;
2753 
2754  /* Disable the DMA transfer for transmit request by resetting the DMAT bit
2755  in the SMARTCARD associated USART CR3 register */
2756  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
2757 
2758  /* Enable the SMARTCARD Transmit Complete Interrupt */
2759  __HAL_SMARTCARD_ENABLE_IT(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication);
2760 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
SMARTCARD_AdvFeatureInitTypeDef AdvancedInit
SMARTCARD handle Structure definition.

◆ SMARTCARD_DMATxAbortCallback()

static void SMARTCARD_DMATxAbortCallback ( DMA_HandleTypeDef hdma)
static

DMA SMARTCARD Tx communication abort callback, when initiated by user (To be called at end of DMA Tx Abort procedure following user abort request).

Note
When this callback is executed, User Abort complete call back is called only if no Abort still ongoing for Rx DMA Handle.
Parameters
hdmaDMA handle.
Return values
None

Definition at line 2862 of file stm32l4xx_hal_smartcard.c.

2863 {
2864  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2865 
2866  hsmartcard->hdmatx->XferAbortCallback = NULL;
2867 
2868  /* Check if an Abort process is still ongoing */
2869  if (hsmartcard->hdmarx != NULL)
2870  {
2871  if (hsmartcard->hdmarx->XferAbortCallback != NULL)
2872  {
2873  return;
2874  }
2875  }
2876 
2877  /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
2878  hsmartcard->TxXferCount = 0U;
2879  hsmartcard->RxXferCount = 0U;
2880 
2881  /* Reset errorCode */
2882  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2883 
2884  /* Clear the Error flags in the ICR register */
2885  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2886  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
2887  SMARTCARD_CLEAR_EOBF);
2888 
2889  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
2890  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2891  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2892 
2893 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2894  /* Call registered Abort complete callback */
2895  hsmartcard->AbortCpltCallback(hsmartcard);
2896 #else
2897  /* Call legacy weak Abort complete callback */
2898  HAL_SMARTCARD_AbortCpltCallback(hsmartcard);
2899 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2900 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
__IO HAL_SMARTCARD_StateTypeDef gState
void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Complete callback.
__IO HAL_SMARTCARD_StateTypeDef RxState
void(* AbortCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD handle Structure definition.

◆ SMARTCARD_DMATxOnlyAbortCallback()

static void SMARTCARD_DMATxOnlyAbortCallback ( DMA_HandleTypeDef hdma)
static

DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to HAL_SMARTCARD_AbortTransmit_IT API (Abort only Tx transfer) (This callback is executed at end of DMA Tx Abort procedure following user abort request, and leads to user Tx Abort Complete callback execution).

Parameters
hdmaDMA handle.
Return values
None

Definition at line 2960 of file stm32l4xx_hal_smartcard.c.

2961 {
2962  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2963 
2964  hsmartcard->TxXferCount = 0U;
2965 
2966  /* Clear the Error flags in the ICR register */
2967  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF);
2968 
2969  /* Restore hsmartcard->gState to Ready */
2970  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2971 
2972 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2973  /* Call registered Abort Transmit Complete Callback */
2974  hsmartcard->AbortTransmitCpltCallback(hsmartcard);
2975 #else
2976  /* Call legacy weak Abort Transmit Complete Callback */
2978 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2979 }
void(* AbortTransmitCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef gState
void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Complete callback.
SMARTCARD handle Structure definition.

◆ SMARTCARD_EndRxTransfer()

static void SMARTCARD_EndRxTransfer ( SMARTCARD_HandleTypeDef hsmartcard)
static

End ongoing Rx transfer on UART peripheral (following error detection or Reception completion).

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 2728 of file stm32l4xx_hal_smartcard.c.

2729 {
2730  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
2731 #if defined(USART_CR1_FIFOEN)
2732  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE));
2733 #else
2734  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
2735 #endif /* USART_CR1_FIFOEN */
2736  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2737 
2738  /* At end of Rx process, restore hsmartcard->RxState to Ready */
2739  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2740 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ SMARTCARD_EndTransmit_IT()

static void SMARTCARD_EndTransmit_IT ( SMARTCARD_HandleTypeDef hsmartcard)
static

Wrap up transmission in non-blocking mode.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 3095 of file stm32l4xx_hal_smartcard.c.

3096 {
3097  /* Disable the SMARTCARD Transmit Complete Interrupt */
3098  __HAL_SMARTCARD_DISABLE_IT(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication);
3099 
3100  /* Check if a receive process is ongoing or not. If not disable ERR IT */
3101  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
3102  {
3103  /* Disable the SMARTCARD Error Interrupt: (Frame error) */
3104  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
3105  }
3106 
3107  /* Re-enable Rx at end of transmission if initial mode is Rx/Tx */
3108  if (hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX)
3109  {
3110  /* Disable the Peripheral first to update modes */
3111  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
3112  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
3113  /* Enable the Peripheral */
3114  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
3115  }
3116 
3117  /* Tx process is ended, restore hsmartcard->gState to Ready */
3118  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
3119 
3120  /* Clear TxISR function pointer */
3121  hsmartcard->TxISR = NULL;
3122 
3123 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
3124  /* Call registered Tx complete callback */
3125  hsmartcard->TxCpltCallback(hsmartcard);
3126 #else
3127  /* Call legacy weak Tx complete callback */
3128  HAL_SMARTCARD_TxCpltCallback(hsmartcard);
3129 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
3130 }
void(* TxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* TxISR)(struct __SMARTCARD_HandleTypeDef *huart)
__IO HAL_SMARTCARD_StateTypeDef gState
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
SMARTCARD_AdvFeatureInitTypeDef AdvancedInit
__IO HAL_SMARTCARD_StateTypeDef RxState
void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
Tx Transfer completed callback.

◆ SMARTCARD_EndTxTransfer()

static void SMARTCARD_EndTxTransfer ( SMARTCARD_HandleTypeDef hsmartcard)
static

End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion).

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 2707 of file stm32l4xx_hal_smartcard.c.

2708 {
2709  /* Disable TXEIE, TCIE and ERR (Frame error, noise error, overrun error) interrupts */
2710 #if defined(USART_CR1_FIFOEN)
2711  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE));
2712 #else
2713  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
2714 #endif /* USART_CR1_FIFOEN */
2715  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2716 
2717  /* At end of Tx process, restore hsmartcard->gState to Ready */
2718  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2719 }
__IO HAL_SMARTCARD_StateTypeDef gState
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)

◆ SMARTCARD_InitCallbacksToDefault()

void SMARTCARD_InitCallbacksToDefault ( SMARTCARD_HandleTypeDef hsmartcard)

Initialize the callbacks to their default values.

Parameters
hsmartcardSMARTCARD handle.
Return values
none

Definition at line 2375 of file stm32l4xx_hal_smartcard.c.

2376 {
2377  /* Init the SMARTCARD Callback settings */
2378  hsmartcard->TxCpltCallback = HAL_SMARTCARD_TxCpltCallback; /* Legacy weak TxCpltCallback */
2379  hsmartcard->RxCpltCallback = HAL_SMARTCARD_RxCpltCallback; /* Legacy weak RxCpltCallback */
2380  hsmartcard->ErrorCallback = HAL_SMARTCARD_ErrorCallback; /* Legacy weak ErrorCallback */
2381  hsmartcard->AbortCpltCallback = HAL_SMARTCARD_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
2382  hsmartcard->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
2383  hsmartcard->AbortReceiveCpltCallback = HAL_SMARTCARD_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
2384 #if defined(USART_CR1_FIFOEN)
2385  hsmartcard->RxFifoFullCallback = HAL_SMARTCARDEx_RxFifoFullCallback; /* Legacy weak RxFifoFullCallback */
2386  hsmartcard->TxFifoEmptyCallback = HAL_SMARTCARDEx_TxFifoEmptyCallback; /* Legacy weak TxFifoEmptyCallback */
2387 #endif /* USART_CR1_FIFOEN */
2388 
2389 }
void(* TxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* AbortTransmitCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* TxFifoEmptyCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void HAL_SMARTCARDEx_TxFifoEmptyCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD TX Fifo empty callback.
void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
Rx Transfer completed callback.
void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD error callback.
void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Complete callback.
void(* AbortReceiveCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* ErrorCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Receive Complete callback.
void HAL_SMARTCARDEx_RxFifoFullCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD RX Fifo full callback.
void(* RxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Complete callback.
void(* RxFifoFullCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
Tx Transfer completed callback.
void(* AbortCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)

◆ SMARTCARD_RxISR()

static void SMARTCARD_RxISR ( SMARTCARD_HandleTypeDef hsmartcard)
static

Receive an amount of data in non-blocking mode.

Note
Function called under interruption only, once interruptions have been enabled by HAL_SMARTCARD_Receive_IT() and when the FIFO mode is disabled.
Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 3141 of file stm32l4xx_hal_smartcard.c.

3142 {
3143  /* Check that a Rx process is ongoing */
3144  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
3145  {
3146  *hsmartcard->pRxBuffPtr = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0xFF);
3147  hsmartcard->pRxBuffPtr++;
3148 
3149  hsmartcard->RxXferCount--;
3150  if (hsmartcard->RxXferCount == 0U)
3151  {
3152 #if defined(USART_CR1_FIFOEN)
3153  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE_RXFNEIE);
3154 #else
3155  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE);
3156 #endif /* USART_CR1_FIFOEN */
3157 
3158  /* Check if a transmit process is ongoing or not. If not disable ERR IT */
3159  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
3160  {
3161  /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
3162  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
3163  }
3164 
3165  /* Disable the SMARTCARD Parity Error Interrupt */
3166  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
3167 
3168  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
3169 
3170  /* Clear RxISR function pointer */
3171  hsmartcard->RxISR = NULL;
3172 
3173 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
3174  /* Call registered Rx complete callback */
3175  hsmartcard->RxCpltCallback(hsmartcard);
3176 #else
3177  /* Call legacy weak Rx complete callback */
3178  HAL_SMARTCARD_RxCpltCallback(hsmartcard);
3179 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
3180  }
3181  }
3182  else
3183  {
3184  /* Clear RXNE interrupt flag */
3185  __HAL_SMARTCARD_SEND_REQ(hsmartcard, SMARTCARD_RXDATA_FLUSH_REQUEST);
3186  }
3187 }
void(* RxISR)(struct __SMARTCARD_HandleTypeDef *huart)
__IO HAL_SMARTCARD_StateTypeDef gState
void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
Rx Transfer completed callback.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void(* RxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ SMARTCARD_RxISR_FIFOEN()

static void SMARTCARD_RxISR_FIFOEN ( SMARTCARD_HandleTypeDef hsmartcard)
static

Receive an amount of data in non-blocking mode.

Note
Function called under interruption only, once interruptions have been enabled by HAL_SMARTCARD_Receive_IT() and when the FIFO mode is enabled.
Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 3199 of file stm32l4xx_hal_smartcard.c.

3200 {
3201  uint16_t nb_rx_data;
3202  uint16_t rxdatacount;
3203 
3204  /* Check that a Rx process is ongoing */
3205  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
3206  {
3207  for (nb_rx_data = hsmartcard->NbRxDataToProcess ; nb_rx_data > 0U ; nb_rx_data--)
3208  {
3209  *hsmartcard->pRxBuffPtr = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0xFF);
3210  hsmartcard->pRxBuffPtr++;
3211 
3212  hsmartcard->RxXferCount--;
3213  if (hsmartcard->RxXferCount == 0U)
3214  {
3215  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE_RXFNEIE);
3216 
3217  /* Check if a transmit process is ongoing or not. If not disable ERR IT */
3218  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
3219  {
3220  /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
3221  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
3222  }
3223 
3224  /* Disable the SMARTCARD Parity Error Interrupt */
3225  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
3226 
3227  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
3228 
3229  /* Clear RxISR function pointer */
3230  hsmartcard->RxISR = NULL;
3231 
3232 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
3233  /* Call registered Rx complete callback */
3234  hsmartcard->RxCpltCallback(hsmartcard);
3235 #else
3236  /* Call legacy weak Rx complete callback */
3237  HAL_SMARTCARD_RxCpltCallback(hsmartcard);
3238 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
3239  }
3240  }
3241 
3242  /* When remaining number of bytes to receive is less than the RX FIFO
3243  threshold, next incoming frames are processed as if FIFO mode was
3244  disabled (i.e. one interrupt per received frame).
3245  */
3246  rxdatacount = hsmartcard->RxXferCount;
3247  if (((rxdatacount != 0U)) && (rxdatacount < hsmartcard->NbRxDataToProcess))
3248  {
3249  /* Disable the UART RXFT interrupt*/
3250  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_RXFTIE);
3251 
3252  /* Update the RxISR function pointer */
3253  hsmartcard->RxISR = SMARTCARD_RxISR;
3254 
3255  /* Enable the UART Data Register Not Empty interrupt */
3256  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE_RXFNEIE);
3257  }
3258  }
3259  else
3260  {
3261  /* Clear RXNE interrupt flag */
3262  __HAL_SMARTCARD_SEND_REQ(hsmartcard, SMARTCARD_RXDATA_FLUSH_REQUEST);
3263  }
3264 }
void(* RxISR)(struct __SMARTCARD_HandleTypeDef *huart)
__IO HAL_SMARTCARD_StateTypeDef gState
void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
Rx Transfer completed callback.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
static void SMARTCARD_RxISR(SMARTCARD_HandleTypeDef *hsmartcard)
Receive an amount of data in non-blocking mode.
void(* RxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ SMARTCARD_SetConfig()

static HAL_StatusTypeDef SMARTCARD_SetConfig ( SMARTCARD_HandleTypeDef hsmartcard)
static

Configure the SMARTCARD associated USART peripheral.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
HALstatus

Definition at line 2398 of file stm32l4xx_hal_smartcard.c.

2399 {
2400  uint32_t tmpreg;
2401  SMARTCARD_ClockSourceTypeDef clocksource;
2402  HAL_StatusTypeDef ret = HAL_OK;
2403 #if defined(USART_PRESC_PRESCALER)
2404  const uint16_t SMARTCARDPrescTable[12] = {1U, 2U, 4U, 6U, 8U, 10U, 12U, 16U, 32U, 64U, 128U, 256U};
2405 #endif /* USART_PRESC_PRESCALER */
2406 
2407  /* Check the parameters */
2408  assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance));
2409  assert_param(IS_SMARTCARD_BAUDRATE(hsmartcard->Init.BaudRate));
2410  assert_param(IS_SMARTCARD_WORD_LENGTH(hsmartcard->Init.WordLength));
2411  assert_param(IS_SMARTCARD_STOPBITS(hsmartcard->Init.StopBits));
2412  assert_param(IS_SMARTCARD_PARITY(hsmartcard->Init.Parity));
2413  assert_param(IS_SMARTCARD_MODE(hsmartcard->Init.Mode));
2414  assert_param(IS_SMARTCARD_POLARITY(hsmartcard->Init.CLKPolarity));
2415  assert_param(IS_SMARTCARD_PHASE(hsmartcard->Init.CLKPhase));
2416  assert_param(IS_SMARTCARD_LASTBIT(hsmartcard->Init.CLKLastBit));
2417  assert_param(IS_SMARTCARD_ONE_BIT_SAMPLE(hsmartcard->Init.OneBitSampling));
2418  assert_param(IS_SMARTCARD_NACK(hsmartcard->Init.NACKEnable));
2419  assert_param(IS_SMARTCARD_TIMEOUT(hsmartcard->Init.TimeOutEnable));
2420  assert_param(IS_SMARTCARD_AUTORETRY_COUNT(hsmartcard->Init.AutoRetryCount));
2421 #if defined(USART_PRESC_PRESCALER)
2422  assert_param(IS_SMARTCARD_CLOCKPRESCALER(hsmartcard->Init.ClockPrescaler));
2423 #endif /* USART_PRESC_PRESCALER */
2424 
2425  /*-------------------------- USART CR1 Configuration -----------------------*/
2426  /* In SmartCard mode, M and PCE are forced to 1 (8 bits + parity).
2427  * Oversampling is forced to 16 (OVER8 = 0).
2428  * Configure the Parity and Mode:
2429  * set PS bit according to hsmartcard->Init.Parity value
2430  * set TE and RE bits according to hsmartcard->Init.Mode value */
2431 #if defined(USART_CR1_FIFOEN)
2432  tmpreg = (uint32_t) hsmartcard->Init.Parity | hsmartcard->Init.Mode;
2433  tmpreg |= (uint32_t) hsmartcard->Init.WordLength | hsmartcard->FifoMode;
2434 #else
2435  tmpreg = (uint32_t)(hsmartcard->Init.Parity | hsmartcard->Init.Mode | hsmartcard->Init.WordLength);
2436 #endif /* USART_CR1_FIFOEN */
2437  MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_FIELDS, tmpreg);
2438 
2439  /*-------------------------- USART CR2 Configuration -----------------------*/
2440  tmpreg = hsmartcard->Init.StopBits;
2441  /* Synchronous mode is activated by default */
2442  tmpreg |= (uint32_t) USART_CR2_CLKEN | hsmartcard->Init.CLKPolarity;
2443  tmpreg |= (uint32_t) hsmartcard->Init.CLKPhase | hsmartcard->Init.CLKLastBit;
2444  tmpreg |= (uint32_t) hsmartcard->Init.TimeOutEnable;
2445  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_FIELDS, tmpreg);
2446 
2447  /*-------------------------- USART CR3 Configuration -----------------------*/
2448  /* Configure
2449  * - one-bit sampling method versus three samples' majority rule
2450  * according to hsmartcard->Init.OneBitSampling
2451  * - NACK transmission in case of parity error according
2452  * to hsmartcard->Init.NACKEnable
2453  * - autoretry counter according to hsmartcard->Init.AutoRetryCount */
2454 
2455  tmpreg = (uint32_t) hsmartcard->Init.OneBitSampling | hsmartcard->Init.NACKEnable;
2456  tmpreg |= ((uint32_t)hsmartcard->Init.AutoRetryCount << USART_CR3_SCARCNT_Pos);
2457  MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_FIELDS, tmpreg);
2458 
2459 #if defined(USART_PRESC_PRESCALER)
2460  /*--------------------- SMARTCARD clock PRESC Configuration ----------------*/
2461  /* Configure
2462  * - SMARTCARD Clock Prescaler: set PRESCALER according to hsmartcard->Init.ClockPrescaler value */
2463  MODIFY_REG(hsmartcard->Instance->PRESC, USART_PRESC_PRESCALER, hsmartcard->Init.ClockPrescaler);
2464 #endif /* USART_PRESC_PRESCALER */
2465 
2466  /*-------------------------- USART GTPR Configuration ----------------------*/
2467  tmpreg = (hsmartcard->Init.Prescaler | ((uint32_t)hsmartcard->Init.GuardTime << USART_GTPR_GT_Pos));
2468  MODIFY_REG(hsmartcard->Instance->GTPR, (uint16_t)(USART_GTPR_GT | USART_GTPR_PSC), (uint16_t)tmpreg);
2469 
2470  /*-------------------------- USART RTOR Configuration ----------------------*/
2471  tmpreg = ((uint32_t)hsmartcard->Init.BlockLength << USART_RTOR_BLEN_Pos);
2472  if (hsmartcard->Init.TimeOutEnable == SMARTCARD_TIMEOUT_ENABLE)
2473  {
2474  assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
2475  tmpreg |= (uint32_t) hsmartcard->Init.TimeOutValue;
2476  }
2477  MODIFY_REG(hsmartcard->Instance->RTOR, (USART_RTOR_RTO | USART_RTOR_BLEN), tmpreg);
2478 
2479  /*-------------------------- USART BRR Configuration -----------------------*/
2480  SMARTCARD_GETCLOCKSOURCE(hsmartcard, clocksource);
2481  tmpreg = 0U;
2482  switch (clocksource)
2483  {
2485 #if defined(USART_PRESC_PRESCALER)
2486  tmpreg = (uint16_t)(((HAL_RCC_GetPCLK1Freq() / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2487 #else
2488  tmpreg = (uint16_t)((HAL_RCC_GetPCLK1Freq() + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2489 #endif /* USART_PRESC_PRESCALER */
2490  break;
2492 #if defined(USART_PRESC_PRESCALER)
2493  tmpreg = (uint16_t)(((HAL_RCC_GetPCLK2Freq() / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2494 #else
2495  tmpreg = (uint16_t)((HAL_RCC_GetPCLK2Freq() + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2496 #endif /* USART_PRESC_PRESCALER */
2497  break;
2499 #if defined(USART_PRESC_PRESCALER)
2500  tmpreg = (uint16_t)(((HSI_VALUE / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2501 #else
2502  tmpreg = (uint16_t)((HSI_VALUE + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2503 #endif /* USART_PRESC_PRESCALER */
2504  break;
2506 #if defined(USART_PRESC_PRESCALER)
2507  tmpreg = (uint16_t)(((HAL_RCC_GetSysClockFreq() / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2508 #else
2509  tmpreg = (uint16_t)((HAL_RCC_GetSysClockFreq() + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2510 #endif /* USART_PRESC_PRESCALER */
2511  break;
2513 #if defined(USART_PRESC_PRESCALER)
2514  tmpreg = (uint16_t)(((uint16_t)(LSE_VALUE / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2515 #else
2516  tmpreg = (uint16_t)((LSE_VALUE + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2517 #endif /* USART_PRESC_PRESCALER */
2518  break;
2519  default:
2520  ret = HAL_ERROR;
2521  break;
2522  }
2523 
2524  /* USARTDIV must be greater than or equal to 0d16 */
2525  if ((tmpreg >= USART_BRR_MIN) && (tmpreg <= USART_BRR_MAX))
2526  {
2527  hsmartcard->Instance->BRR = tmpreg;
2528  }
2529  else
2530  {
2531  ret = HAL_ERROR;
2532  }
2533 
2534 #if defined(USART_CR1_FIFOEN)
2535  /* Initialize the number of data to process during RX/TX ISR execution */
2536  hsmartcard->NbTxDataToProcess = 1U;
2537  hsmartcard->NbRxDataToProcess = 1U;
2538 #endif /* USART_CR1_FIFOEN */
2539 
2540  /* Clear ISR function pointers */
2541  hsmartcard->RxISR = NULL;
2542  hsmartcard->TxISR = NULL;
2543 
2544  return ret;
2545 }
void(* RxISR)(struct __SMARTCARD_HandleTypeDef *huart)
void(* TxISR)(struct __SMARTCARD_HandleTypeDef *huart)
uint32_t HAL_RCC_GetPCLK2Freq(void)
Return the PCLK2 frequency.
return HAL_OK
SMARTCARD_ClockSourceTypeDef
SMARTCARD clock sources.
uint32_t HAL_RCC_GetSysClockFreq(void)
Return the SYSCLK frequency.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
uint32_t HAL_RCC_GetPCLK1Freq(void)
Return the PCLK1 frequency.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ SMARTCARD_TxISR()

static void SMARTCARD_TxISR ( SMARTCARD_HandleTypeDef hsmartcard)
static

Send an amount of data in non-blocking mode.

Note
Function called under interruption only, once interruptions have been enabled by HAL_SMARTCARD_Transmit_IT() and when the FIFO mode is disabled.
Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 3021 of file stm32l4xx_hal_smartcard.c.

3022 {
3023  /* Check that a Tx process is ongoing */
3024  if (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX)
3025  {
3026  if (hsmartcard->TxXferCount == 0U)
3027  {
3028  /* Disable the SMARTCARD Transmit Data Register Empty Interrupt */
3029 #if defined(USART_CR1_FIFOEN)
3030  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE_TXFNFIE);
3031 #else
3032  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE);
3033 #endif /* USART_CR1_FIFOEN */
3034 
3035  /* Enable the SMARTCARD Transmit Complete Interrupt */
3036  __HAL_SMARTCARD_ENABLE_IT(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication);
3037  }
3038  else
3039  {
3040  hsmartcard->Instance->TDR = (uint8_t)(*hsmartcard->pTxBuffPtr & 0xFFU);
3041  hsmartcard->pTxBuffPtr++;
3042  hsmartcard->TxXferCount--;
3043  }
3044  }
3045 }
__IO HAL_SMARTCARD_StateTypeDef gState
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
SMARTCARD_AdvFeatureInitTypeDef AdvancedInit

◆ SMARTCARD_TxISR_FIFOEN()

static void SMARTCARD_TxISR_FIFOEN ( SMARTCARD_HandleTypeDef hsmartcard)
static

Send an amount of data in non-blocking mode.

Note
Function called under interruption only, once interruptions have been enabled by HAL_SMARTCARD_Transmit_IT() and when the FIFO mode is enabled.
Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 3057 of file stm32l4xx_hal_smartcard.c.

3058 {
3059  uint16_t nb_tx_data;
3060 
3061  /* Check that a Tx process is ongoing */
3062  if (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX)
3063  {
3064  for (nb_tx_data = hsmartcard->NbTxDataToProcess ; nb_tx_data > 0U ; nb_tx_data--)
3065  {
3066  if (hsmartcard->TxXferCount == 0U)
3067  {
3068  /* Disable the SMARTCARD Transmit Data Register Empty Interrupt */
3069  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE_TXFNFIE);
3070 
3071  /* Enable the SMARTCARD Transmit Complete Interrupt */
3072  __HAL_SMARTCARD_ENABLE_IT(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication);
3073  }
3074  else if (READ_BIT(hsmartcard->Instance->ISR, USART_ISR_TXE_TXFNF) != 0U)
3075  {
3076  hsmartcard->Instance->TDR = (uint8_t)(*hsmartcard->pTxBuffPtr & 0xFFU);
3077  hsmartcard->pTxBuffPtr++;
3078  hsmartcard->TxXferCount--;
3079  }
3080  else
3081  {
3082  /* Nothing to do */
3083  }
3084  }
3085  }
3086 }
__IO HAL_SMARTCARD_StateTypeDef gState
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
SMARTCARD_AdvFeatureInitTypeDef AdvancedInit

◆ SMARTCARD_WaitOnFlagUntilTimeout()

static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout ( SMARTCARD_HandleTypeDef hsmartcard,
uint32_t  Flag,
FlagStatus  Status,
uint32_t  Tickstart,
uint32_t  Timeout 
)
static

Handle SMARTCARD Communication Timeout.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
FlagSpecifies the SMARTCARD flag to check.
StatusThe new Flag status (SET or RESET).
TickstartTick start value
TimeoutTimeout duration.
Return values
HALstatus

Definition at line 2669 of file stm32l4xx_hal_smartcard.c.

2671 {
2672  /* Wait until flag is set */
2673  while ((__HAL_SMARTCARD_GET_FLAG(hsmartcard, Flag) ? SET : RESET) == Status)
2674  {
2675  /* Check for the Timeout */
2676  if (Timeout != HAL_MAX_DELAY)
2677  {
2678  if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
2679  {
2680  /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
2681 #if defined(USART_CR1_FIFOEN)
2682  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | USART_CR1_TXEIE_TXFNFIE));
2683 #else
2684  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
2685 #endif /* USART_CR1_FIFOEN */
2686  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2687 
2688  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2689  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2690 
2691  /* Process Unlocked */
2692  __HAL_UNLOCK(hsmartcard);
2693  return HAL_TIMEOUT;
2694  }
2695  }
2696  }
2697  return HAL_OK;
2698 }
__IO HAL_SMARTCARD_StateTypeDef gState
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
__IO HAL_SMARTCARD_StateTypeDef RxState