STM32L4xx_HAL_Driver  1.14.0
Initialization and de-initialization functions

Initialization and Configuration functions. More...

Functions

HAL_StatusTypeDef HAL_SMARTCARD_Init (SMARTCARD_HandleTypeDef *hsmartcard)
 Initialize the SMARTCARD mode according to the specified parameters in the SMARTCARD_HandleTypeDef and initialize the associated handle. More...
 
HAL_StatusTypeDef HAL_SMARTCARD_DeInit (SMARTCARD_HandleTypeDef *hsmartcard)
 DeInitialize the SMARTCARD peripheral. More...
 
void HAL_SMARTCARD_MspInit (SMARTCARD_HandleTypeDef *hsmartcard)
 Initialize the SMARTCARD MSP. More...
 
void HAL_SMARTCARD_MspDeInit (SMARTCARD_HandleTypeDef *hsmartcard)
 DeInitialize the SMARTCARD MSP. More...
 
HAL_StatusTypeDef HAL_SMARTCARD_RegisterCallback (SMARTCARD_HandleTypeDef *hsmartcard, HAL_SMARTCARD_CallbackIDTypeDef CallbackID, pSMARTCARD_CallbackTypeDef pCallback)
 Register a User SMARTCARD Callback To be used instead of the weak predefined callback. More...
 
HAL_StatusTypeDef HAL_SMARTCARD_UnRegisterCallback (SMARTCARD_HandleTypeDef *hsmartcard, HAL_SMARTCARD_CallbackIDTypeDef CallbackID)
 Unregister an SMARTCARD callback SMARTCARD callback is redirected to the weak predefined callback. More...
 

Detailed Description

Initialization and Configuration functions.

  ==============================================================================
              ##### Initialization and Configuration functions #####
  ==============================================================================
  [..]
  This subsection provides a set of functions allowing to initialize the USARTx
  associated to the SmartCard.
  (+) These parameters can be configured:
      (++) Baud Rate
      (++) Parity: parity should be enabled, frame Length is fixed to 8 bits plus parity
      (++) Receiver/transmitter modes
      (++) Synchronous mode (and if enabled, phase, polarity and last bit parameters)
      (++) Prescaler value
      (++) Guard bit time
      (++) NACK enabling or disabling on transmission error

  (+) The following advanced features can be configured as well:
      (++) TX and/or RX pin level inversion
      (++) data logical level inversion
      (++) RX and TX pins swap
      (++) RX overrun detection disabling
      (++) DMA disabling on RX error
      (++) MSB first on communication line
      (++) Time out enabling (and if activated, timeout value)
      (++) Block length
      (++) Auto-retry counter
  [..]
  The HAL_SMARTCARD_Init() API follows the USART synchronous configuration procedures
  (details for the procedures are available in reference manual).

The USART frame format is given in the following table:

Table 1. USART frame format. +------------------------------------------------------------—+ | M1M0 bits | PCE bit | USART frame | |--------------------—|------------------------------------—| | 01 | 1 | | SB | 8 bit data | PB | STB | | +------------------------------------------------------------—+

Function Documentation

◆ HAL_SMARTCARD_DeInit()

HAL_StatusTypeDef HAL_SMARTCARD_DeInit ( SMARTCARD_HandleTypeDef hsmartcard)

DeInitialize the SMARTCARD peripheral.

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

Definition at line 402 of file stm32l4xx_hal_smartcard.c.

403 {
404  /* Check the SMARTCARD handle allocation */
405  if (hsmartcard == NULL)
406  {
407  return HAL_ERROR;
408  }
409 
410  /* Check the USART/UART associated to the SMARTCARD handle */
411  assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance));
412 
413  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
414 
415  /* Disable the Peripheral */
416  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
417 
418  WRITE_REG(hsmartcard->Instance->CR1, 0x0U);
419  WRITE_REG(hsmartcard->Instance->CR2, 0x0U);
420  WRITE_REG(hsmartcard->Instance->CR3, 0x0U);
421  WRITE_REG(hsmartcard->Instance->RTOR, 0x0U);
422  WRITE_REG(hsmartcard->Instance->GTPR, 0x0U);
423 
424  /* DeInit the low level hardware */
425 #if USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1
426  if (hsmartcard->MspDeInitCallback == NULL)
427  {
429  }
430  /* DeInit the low level hardware */
431  hsmartcard->MspDeInitCallback(hsmartcard);
432 #else
433  HAL_SMARTCARD_MspDeInit(hsmartcard);
434 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
435 
436  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
437  hsmartcard->gState = HAL_SMARTCARD_STATE_RESET;
438  hsmartcard->RxState = HAL_SMARTCARD_STATE_RESET;
439 
440  /* Process Unlock */
441  __HAL_UNLOCK(hsmartcard);
442 
443  return HAL_OK;
444 }
void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsmartcard)
DeInitialize the SMARTCARD MSP.
__IO HAL_SMARTCARD_StateTypeDef gState
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
void(* MspDeInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef RxState
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_SMARTCARD_Init()

HAL_StatusTypeDef HAL_SMARTCARD_Init ( SMARTCARD_HandleTypeDef hsmartcard)

Initialize the SMARTCARD mode according to the specified parameters in the SMARTCARD_HandleTypeDef and initialize the associated handle.

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

Definition at line 329 of file stm32l4xx_hal_smartcard.c.

330 {
331  /* Check the SMARTCARD handle allocation */
332  if (hsmartcard == NULL)
333  {
334  return HAL_ERROR;
335  }
336 
337  /* Check the USART associated to the SMARTCARD handle */
338  assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance));
339 
340  if (hsmartcard->gState == HAL_SMARTCARD_STATE_RESET)
341  {
342  /* Allocate lock resource and initialize it */
343  hsmartcard->Lock = HAL_UNLOCKED;
344 
345 #if USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1
347 
348  if (hsmartcard->MspInitCallback == NULL)
349  {
351  }
352 
353  /* Init the low level hardware */
354  hsmartcard->MspInitCallback(hsmartcard);
355 #else
356  /* Init the low level hardware : GPIO, CLOCK */
357  HAL_SMARTCARD_MspInit(hsmartcard);
358 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
359  }
360 
361  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
362 
363  /* Disable the Peripheral to set smartcard mode */
364  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
365 
366  /* In SmartCard mode, the following bits must be kept cleared:
367  - LINEN in the USART_CR2 register,
368  - HDSEL and IREN bits in the USART_CR3 register.*/
369  CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_LINEN);
370  CLEAR_BIT(hsmartcard->Instance->CR3, (USART_CR3_HDSEL | USART_CR3_IREN));
371 
372  /* set the USART in SMARTCARD mode */
373  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_SCEN);
374 
375  /* Set the SMARTCARD Communication parameters */
376  if (SMARTCARD_SetConfig(hsmartcard) == HAL_ERROR)
377  {
378  return HAL_ERROR;
379  }
380 
381  /* Set the SMARTCARD transmission completion indication */
382  SMARTCARD_TRANSMISSION_COMPLETION_SETTING(hsmartcard);
383 
384  if (hsmartcard->AdvancedInit.AdvFeatureInit != SMARTCARD_ADVFEATURE_NO_INIT)
385  {
386  SMARTCARD_AdvFeatureConfig(hsmartcard);
387  }
388 
389  /* Enable the Peripheral */
390  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
391 
392  /* TEACK and/or REACK to check before moving hsmartcard->gState and hsmartcard->RxState to Ready */
393  return (SMARTCARD_CheckIdleState(hsmartcard));
394 }
static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsmartcard)
Configure the SMARTCARD associated USART peripheral advanced features.
static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard)
Configure the SMARTCARD associated USART peripheral.
__IO HAL_SMARTCARD_StateTypeDef gState
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsmartcard)
Initialize the SMARTCARD MSP.
void SMARTCARD_InitCallbacksToDefault(SMARTCARD_HandleTypeDef *hsmartcard)
Initialize the callbacks to their default values.
SMARTCARD_AdvFeatureInitTypeDef AdvancedInit
void(* MspInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard)
Check the SMARTCARD Idle State.

◆ HAL_SMARTCARD_MspDeInit()

__weak void HAL_SMARTCARD_MspDeInit ( SMARTCARD_HandleTypeDef hsmartcard)

DeInitialize the SMARTCARD MSP.

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

Definition at line 468 of file stm32l4xx_hal_smartcard.c.

469 {
470  /* Prevent unused argument(s) compilation warning */
471  UNUSED(hsmartcard);
472 
473  /* NOTE : This function should not be modified, when the callback is needed,
474  the HAL_SMARTCARD_MspDeInit can be implemented in the user file
475  */
476 }

◆ HAL_SMARTCARD_MspInit()

__weak void HAL_SMARTCARD_MspInit ( SMARTCARD_HandleTypeDef hsmartcard)

Initialize the SMARTCARD MSP.

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

Definition at line 452 of file stm32l4xx_hal_smartcard.c.

453 {
454  /* Prevent unused argument(s) compilation warning */
455  UNUSED(hsmartcard);
456 
457  /* NOTE : This function should not be modified, when the callback is needed,
458  the HAL_SMARTCARD_MspInit can be implemented in the user file
459  */
460 }

◆ HAL_SMARTCARD_RegisterCallback()

HAL_StatusTypeDef HAL_SMARTCARD_RegisterCallback ( SMARTCARD_HandleTypeDef hsmartcard,
HAL_SMARTCARD_CallbackIDTypeDef  CallbackID,
pSMARTCARD_CallbackTypeDef  pCallback 
)

Register a User SMARTCARD Callback To be used instead of the weak predefined callback.

Parameters
hsmartcardsmartcard handle
CallbackIDID of the callback to be registered This parameter can be one of the following values:
pCallbackpointer to the Callback function
Return values
HALstatus

Definition at line 498 of file stm32l4xx_hal_smartcard.c.

500 {
501  HAL_StatusTypeDef status = HAL_OK;
502 
503  if (pCallback == NULL)
504  {
505  /* Update the error code */
506  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
507 
508  return HAL_ERROR;
509  }
510  /* Process locked */
511  __HAL_LOCK(hsmartcard);
512 
513  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
514  {
515  switch (CallbackID)
516  {
517 
519  hsmartcard->TxCpltCallback = pCallback;
520  break;
521 
523  hsmartcard->RxCpltCallback = pCallback;
524  break;
525 
527  hsmartcard->ErrorCallback = pCallback;
528  break;
529 
531  hsmartcard->AbortCpltCallback = pCallback;
532  break;
533 
535  hsmartcard->AbortTransmitCpltCallback = pCallback;
536  break;
537 
539  hsmartcard->AbortReceiveCpltCallback = pCallback;
540  break;
541 
542 #if defined(USART_CR1_FIFOEN)
544  hsmartcard->RxFifoFullCallback = pCallback;
545  break;
546 
548  hsmartcard->TxFifoEmptyCallback = pCallback;
549  break;
550 #endif /* USART_CR1_FIFOEN */
551 
553  hsmartcard->MspInitCallback = pCallback;
554  break;
555 
557  hsmartcard->MspDeInitCallback = pCallback;
558  break;
559 
560  default :
561  /* Update the error code */
562  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
563 
564  /* Return error status */
565  status = HAL_ERROR;
566  break;
567  }
568  }
569  else if (hsmartcard->gState == HAL_SMARTCARD_STATE_RESET)
570  {
571  switch (CallbackID)
572  {
574  hsmartcard->MspInitCallback = pCallback;
575  break;
576 
578  hsmartcard->MspDeInitCallback = pCallback;
579  break;
580 
581  default :
582  /* Update the error code */
583  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
584 
585  /* Return error status */
586  status = HAL_ERROR;
587  break;
588  }
589  }
590  else
591  {
592  /* Update the error code */
593  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
594 
595  /* Return error status */
596  status = HAL_ERROR;
597  }
598 
599  /* Release Lock */
600  __HAL_UNLOCK(hsmartcard);
601 
602  return status;
603 }
void(* TxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* AbortTransmitCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef gState
void(* TxFifoEmptyCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
void(* AbortReceiveCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* ErrorCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* MspInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* MspDeInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* RxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* RxFifoFullCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* AbortCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)

◆ HAL_SMARTCARD_UnRegisterCallback()

HAL_StatusTypeDef HAL_SMARTCARD_UnRegisterCallback ( SMARTCARD_HandleTypeDef hsmartcard,
HAL_SMARTCARD_CallbackIDTypeDef  CallbackID 
)

Unregister an SMARTCARD callback SMARTCARD callback is redirected to the weak predefined callback.

Parameters
hsmartcardsmartcard handle
CallbackIDID of the callback to be unregistered This parameter can be one of the following values:
Return values
HALstatus

Definition at line 623 of file stm32l4xx_hal_smartcard.c.

625 {
626  HAL_StatusTypeDef status = HAL_OK;
627 
628  /* Process locked */
629  __HAL_LOCK(hsmartcard);
630 
631  if (HAL_SMARTCARD_STATE_READY == hsmartcard->gState)
632  {
633  switch (CallbackID)
634  {
636  hsmartcard->TxCpltCallback = HAL_SMARTCARD_TxCpltCallback; /* Legacy weak TxCpltCallback */
637  break;
638 
640  hsmartcard->RxCpltCallback = HAL_SMARTCARD_RxCpltCallback; /* Legacy weak RxCpltCallback */
641  break;
642 
644  hsmartcard->ErrorCallback = HAL_SMARTCARD_ErrorCallback; /* Legacy weak ErrorCallback */
645  break;
646 
648  hsmartcard->AbortCpltCallback = HAL_SMARTCARD_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
649  break;
650 
652  hsmartcard->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
653  break;
654 
656  hsmartcard->AbortReceiveCpltCallback = HAL_SMARTCARD_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
657  break;
658 
659 #if defined(USART_CR1_FIFOEN)
661  hsmartcard->RxFifoFullCallback = HAL_SMARTCARDEx_RxFifoFullCallback; /* Legacy weak RxFifoFullCallback */
662  break;
663 
665  hsmartcard->TxFifoEmptyCallback = HAL_SMARTCARDEx_TxFifoEmptyCallback; /* Legacy weak TxFifoEmptyCallback */
666  break;
667 #endif /* USART_CR1_FIFOEN */
668 
670  hsmartcard->MspInitCallback = HAL_SMARTCARD_MspInit; /* Legacy weak MspInitCallback */
671  break;
672 
674  hsmartcard->MspDeInitCallback = HAL_SMARTCARD_MspDeInit; /* Legacy weak MspDeInitCallback */
675  break;
676 
677  default :
678  /* Update the error code */
679  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
680 
681  /* Return error status */
682  status = HAL_ERROR;
683  break;
684  }
685  }
686  else if (HAL_SMARTCARD_STATE_RESET == hsmartcard->gState)
687  {
688  switch (CallbackID)
689  {
692  break;
693 
696  break;
697 
698  default :
699  /* Update the error code */
700  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
701 
702  /* Return error status */
703  status = HAL_ERROR;
704  break;
705  }
706  }
707  else
708  {
709  /* Update the error code */
710  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
711 
712  /* Return error status */
713  status = HAL_ERROR;
714  }
715 
716  /* Release Lock */
717  __HAL_UNLOCK(hsmartcard);
718 
719  return status;
720 }
void(* TxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsmartcard)
DeInitialize the SMARTCARD MSP.
void(* AbortTransmitCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef gState
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.
__HAL_UNLOCK(hrtc)
void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsmartcard)
Initialize the SMARTCARD MSP.
__HAL_LOCK(hrtc)
return HAL_OK
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(* MspInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void HAL_SMARTCARDEx_RxFifoFullCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD RX Fifo full callback.
void(* MspDeInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
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)