HAL SMARTCARD How to Use

group SMARTCARD_How_To_Use

How to use the SMARTCARD HAL driver :

Declare a hal_smartcard_handle_t handle structure

Configure the low level hardware (GPIO, CLOCK, NVIC…etc):

  • Enable the SMARTCARDx interface clock if you have set USE_HAL_SMARTCARD_CLK_ENABLE_MODEL to HAL_CLK_ENABLE_NO (in other cases HAL_SMARTCARD_Init() will enable the clock).

  • SMARTCARDx pins configuration :

    • Enable the clock for the SMARTCARDx GPIOs

      • Configure SMARTCARDx pins as alternate function open-drain

    • NVIC configuration if you need to use interrupt process

      • Configure the SMARTCARDx interrupt priority

      • Enable the NVIC SMARTCARDx IRQ Channel

Initialize the SMARTCARDx driver with an USART HW instance

Configure the communication baud rate, stop bit, first bit, parity mode, NACK, smartcard clock prescaler,

source clock prescaler, clock polarity, clock phase, clock output enabling, guard time and auto retry count by calling HAL_SMARTCARD_SetConfig() .

Configure and/or enable advanced features.

For SMARTCARDx IO operations modes, polling, interrupt and DMA are available

within this driver.

Callback registration

  • When the compilation flag USE_HAL_SMARTCARD_REGISTER_CALLBACKS is set to 1, it allows the user to configure dynamically the driver callbacks via its own method:

Callback name

Default value

Callback registration function

TxHalfCpltCallback

HAL_SMARTCARD_TxHalfCpltCallback()

HAL_SMARTCARD_RegisterTxHalfCpltCallback()

TxCpltCallback

HAL_SMARTCARD_TxCpltCallback()

HAL_SMARTCARD_RegisterTxCpltCallback()

RxHalfCpltCallback

HAL_SMARTCARD_RxHalfCpltCallback()

HAL_SMARTCARD_RegisterRxHalfCpltCallback()

RxCpltCallback

HAL_SMARTCARD_RxCpltCallback()

HAL_SMARTCARD_RegisterRxCpltCallback()

ErrorCallback

HAL_SMARTCARD_ErrorCallback()

HAL_SMARTCARD_RegisterErrorCallback()

AbortCpltCallback

HAL_SMARTCARD_AbortCpltCallback()

HAL_SMARTCARD_RegisterAbortCpltCallback()

RxFifoFullCallback

HAL_SMARTCARD_RxFifoFullCallback()

HAL_SMARTCARD_RegisterRxFifoFullCallback()

TxFifoEmptyCallback

HAL_SMARTCARD_TxFifoEmptyCallback()

HAL_SMARTCARD_RegisterTxFifoEmptyCallback()

  • If one needs to unregister a callback, register the default callback via the registration function.

  • By default, after the HAL_SMARTCARD_Init() and when the state is HAL_SMARTCARD_STATE_INIT, all callbacks are set to the corresponding default weak functions.

  • Callbacks can be registered in handle global_state HAL_SMARTCARD_STATE_INIT and HAL_SMARTCARD_STATE_CONFIGURED.

  • When the compilation flag USE_HAL_SMARTCARD_REGISTER_CALLBACKS is set to 0 or not defined, the callback registration feature is not available and all callbacks are set to the corresponding weak functions.

Acquire/Release the SMARTCARD bus

Note

In SMARTCARD case, etu (Elementary Time Unit) is equivalent to the baud period duration