HAL SMARTCARD Overview

Introducing SMARTCARD

group SMARTCARD_Introduction

  • The SMARTCARD hardware abstraction layer provides a set of APIs to interface with the STM32 USART (Universal Synchronous/Asynchronous Receiver Transmitter) peripheral to support the T = 0 and T = 1 asynchronous protocols for smartcards as defined in the ISO/IEC 7816-3 standard.

  • It simplifies the configuration, initialization, and management of SMARTCARD communication by supporting various modes such as polling, interrupt, and DMA for efficient data transfer.

  • This abstraction layer ensures portability and ease of use across different STM32 series.

Module and files

The following diagram illustrates the SMARTCARD module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the SMARTCARD module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.

@startuml

!$ppp = "SMARTCARD"
!use_ppp_ll = 1
!use_ppp_isr = 1
!$use_hal_service = 1
!$use_hal_rcc = 1
!$use_hal_dma = 1
!$hal_api_itf = "HAL " + $ppp + " API"
!$appli_itf = "User Callback"
!$ppp_name = "HAL_"+$ppp
!$ppp_ISR  = $ppp+" ISR"
!$ll_ppp   = "LL_"+$ppp
!$hal_dma_itf = "HAL_DMA_StartDirectXfer()\nHAL_DMA_Abort_IT"
!$hal_rcc_itf = "\t\t\t\tGetClockFreq()\n\t\t\t\tHAL_RCC_"+$ppp+"_EnableClock()"
!$hal_ppp_itf = "DMA CallBacks\nDMA Half transfer complete CallBack\nError CallBacks"
!$hal_generic_itf = "HAL_GetTick()"
!$ll_ppp_itf = "LL " + $ppp +" API"
!$ppp_xIRQ = $ppp+"x_IRQ"

<style>
componentDiagram {
   arrow {
      FontSize 8
   }
   interface {
      FontSize 8
   }
}
</style>

title SMARTCARD Software Component Diagram

Package "Application Layer" #DarkMagenta {
  component [Appli]
  interface "$appli_itf" as APPLI_Interface
  [Appli] -r- APPLI_Interface
}

package "HAL" #DarkOrange {
    [$ppp_name]
    !if ($use_hal_dma == 1)
      interface "$hal_ppp_itf" as HAL_PPP_Interface
      [$ppp_name] -d- HAL_PPP_Interface
    !endif
    interface "$hal_api_itf" as HAL_PPP_APPLI_Interface
    [$ppp_name] -u- HAL_PPP_APPLI_Interface

    !if ($use_hal_service == 1)
      [HAL_SERVICE]
      interface "$hal_generic_itf" as HAL_Service_Interface
      [HAL_SERVICE] -r- HAL_Service_Interface
      [$ppp_name] -l-( HAL_Service_Interface
    !endif

    !if ($use_hal_dma == 1)
      [HAL_DMA]
      interface "$hal_dma_itf" as HAL_DMA_Interface
      [HAL_DMA] -u- HAL_DMA_Interface
      [HAL_DMA] -u-( HAL_PPP_Interface
      [$ppp_name] --( HAL_DMA_Interface
    !endif
    !if ($use_hal_rcc == 1)
      [HAL_RCC]
      interface "$hal_rcc_itf" as HAL_RCC_Interface
      [HAL_RCC] -l- HAL_RCC_Interface
      [$ppp_name] -r-( HAL_RCC_Interface
    !endif

}

[Appli] -d-( HAL_PPP_APPLI_Interface
[$ppp_name] -u-( APPLI_Interface

package "Low Layer" #Technology {
    !if (use_ppp_ll == 1)
      [$ll_ppp]
      interface "$ll_ppp_itf" as LL_PPP_Interface
      [$ll_ppp]  -u- LL_PPP_Interface
    !endif
    interface "$ppp_ISR" as PPP_ISR

    [$ppp_ISR] -U- PPP_ISR
    [CMSIS-Devices]
    [$ppp_ISR]
    !if ($use_hal_dma == 1)
      [DMA ISR]
      interface "DMA ISR" as DMA_ISR
      [DMA ISR] -u- DMA_ISR
    !endif

}

package "HW" #LightCyan {
    [STM32_HW]
    interface "$ppp_xIRQ" as PPPx_IRQ
    [STM32_HW] -u- PPPx_IRQ
    !if ($use_hal_dma == 1)
      interface "DMAx_IRQ_Ch" as DMA_IRQ_CH
      [STM32_HW] -u- DMA_IRQ_CH
      [DMA ISR] -d-( DMA_IRQ_CH
      [HAL_DMA] --( DMA_ISR
    !endif  
}
!if (use_ppp_ll == 1)
    [$ppp_name] -d-( LL_PPP_Interface
    [$ll_ppp] .r.> [CMSIS-Devices]: $ppp register def
    [STM32_HW] <.u. [$ll_ppp] : $ppp registers R/W
!else
    [$ppp_name] .d.> [CMSIS-Devices]: $ppp register def 
    [STM32_HW] <.l. [$ppp_name] : $ppp registers R/W
!endif
[$ppp_ISR] -d-( PPPx_IRQ
[$ppp_name] -d-( PPP_ISR

@enduml

Configuration table

The following table lists the configuration defines for the HAL SMARTCARD module, specifying their locations, default values, and descriptions:

group SMARTCARD_Configuration_Table

Configuration inside the SMARTCARD driver

Software configuration defined in stm32c5xx_hal_conf.h:

Preprocessor flags

Default value

Comment

USE_HAL_SMARTCARD_MODULE

1

Enable HAL SMARTCARD driver module

USE_HAL_SMARTCARD_REGISTER_CALLBACKS

0

Allow the user to define their own callback

USE_HAL_SMARTCARD_DMA

1

Enable DMA code inside SMARTCARD

USE_HAL_CHECK_PARAM

0

Enable runtime parameter checks

USE_HAL_SMARTCARD_CLK_ENABLE_MODEL

HAL_CLK_ENABLE_NO

Enable the gating of the peripheral clock

USE_HAL_CHECK_PROCESS_STATE

0

Enable atomicity of process state checks

USE_HAL_MUTEX

0

Enable semaphore creation for OS

USE_HAL_SMARTCARD_USER_DATA

0

Add user data inside the HAL SMARTCARD handle

USE_HAL_SMARTCARD_GET_LAST_ERRORS

0

Enable retrieval of last process error codes

USE_HAL_SMARTCARD_FIFO

1

Enable the FIFO feature

Software configuration defined in preprocessor environment:

Preprocessor flags

Default value

Comment

USE_ASSERT_DBG_PARAM

Not defined

Enable parameter checks for HAL and LL

USE_ASSERT_DBG_STATE

Not defined

Enable state checks for HAL