Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
cubexHal.pdf
Скачиваний:
111
Добавлен:
10.02.2016
Размер:
16.16 Mб
Скачать

HAL SMARTCARD Generic Driver

UM1725

54.2SMARTCARD Firmware driver API description

54.2.1How to use this driver

The SMARTCARD HAL driver can be used as follows:

1.Declare a SMARTCARD_HandleTypeDef handle structure.

2.Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API:

a.Enable the USARTx interface clock.

b.SMARTCARD pins configuration:

Enable the clock for the SMARTCARD GPIOs.

Configure these SMARTCARD pins as alternate function pull-up.

c.NVIC configuration if you need to use interrupt process

(HAL_SMARTCARD_Transmit_IT() and HAL_SMARTCARD_Receive_IT() APIs):

Configure the USARTx interrupt priority.

Enable the NVIC USART IRQ handle.

d. DMA Configuration if you need to use DMA process

(HAL_SMARTCARD_Transmit_DMA() and HAL_SMARTCARD_Receive_DMA()

APIs):

Declare a DMA handle structure for the Tx/Rx stream.

Enable the DMAx interface clock.

Configure the declared DMA handle structure with the required Tx/Rx parameters.

Configure the DMA Tx/Rx Stream.

Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle.

Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream.

3.Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware flow control and Mode(Receiver/Transmitter) in the SMARTCARD Init structure.

4.Initialize the SMARTCARD registers by calling the HAL_SMARTCARD_Init() API:

These APIs configure also the low level Hardware GPIO, CLOCK,

CORTEX...etc) by calling the customized HAL_SMARTCARD_MspInit() API.

The specific SMARTCARD interrupts (Transmission complete interrupt, RXNE interrupt and Error Interrupts) will be managed using the macros __HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process.

Three operation modes are available within this driver :

Polling mode IO operation

Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit()

Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive()

Interrupt mode IO operation

Send an amount of data in non blocking mode using HAL_SMARTCARD_Transmit_IT()

724/900

DOCID025834 Rev 2

UM1725

HAL SMARTCARD Generic Driver

At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback

Receive an amount of data in non blocking mode using

HAL_SMARTCARD_Receive_IT()

At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback

In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback

DMA mode IO operation

Send an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Transmit_DMA()

At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback

Receive an amount of data in non blocking mode (DMA) using

HAL_SMARTCARD_Receive_DMA()

At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback

In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback

SMARTCARD HAL driver macros list

Below the list of most used macros in SMARTCARD HAL driver.

__HAL_SMARTCARD_ENABLE: Enable the SMARTCARD peripheral

__HAL_SMARTCARD_DISABLE: Disable the SMARTCARD peripheral

__HAL_SMARTCARD_GET_FLAG : Check whether the specified SMARTCARD flag is set or not

__HAL_SMARTCARD_CLEAR_FLAG : Clear the specified SMARTCARD pending flag

__HAL_SMARTCARD_ENABLE_IT: Enable the specified SMARTCARD interrupt

__HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt

You can refer to the SMARTCARD HAL driver header file for more useful macros

54.2.2Initialization and Configuration functions

This subsection provides a set of functions allowing to initialize the USART in Smartcard mode.

The Smartcard interface is designed to support asynchronous protocol Smartcards as defined in the ISO 7816-3 standard.

DOCID025834 Rev 2

725/900

HAL SMARTCARD Generic Driver

UM1725

The USART can provide a clock to the smartcard through the SCLK output. In smartcard mode, SCLK is not associated to the communication but is simply derived from the internal peripheral input clock through a 5-bit prescaler.

For the Smartcard mode only these parameters can be configured:

Baud Rate

Word Length => Should be 9 bits (8 bits + parity)

Stop Bit

Parity: => Should be enabled

 

+-------------------------------------------------------------

+

| M bit | PCE bit | SMARTCARD frame |

 

|---------------------

|---------------------------------------

|

| 1 | 1 | | SB | 8 bit data | PB | STB | |

 

+-------------------------------------------------------------

+

USART polarity

USART phase

USART LastBit

Receiver/transmitter modes

Prescaler

GuardTime

NACKState: The Smartcard NACK state

Recommended SmartCard interface configuration to get the Answer to Reset from the Card:

Word Length = 9 Bits

1.5 Stop Bit

Even parity

BaudRate = 12096 baud

Tx and Rx enabled

Please refer to the ISO 7816-3 specification for more details. -@- It is also possible to choose 0.5 stop bit for receiving but it is recommended to use 1.5 stop bits for both transmitting and receiving to avoid switching between the two configurations.

The HAL_SMARTCARD_Init() function follows the USART SmartCard configuration procedure (details for the procedure are available in reference manual (RM0329)).

This section contains the following APIs:

HAL_SMARTCARD_Init()

HAL_SMARTCARD_DeInit()

HAL_SMARTCARD_MspInit()

HAL_SMARTCARD_MspDeInit()

HAL_SMARTCARD_ReInit()

54.2.3IO operation functions

Smartcard is a single wire half duplex communication protocol. The Smartcard interface is designed to support asynchronous protocol Smartcards as defined in the ISO 7816-3 standard. The USART should be configured as: (+) 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register (+) 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register.

1.There are two modes of transfer:

Blocking mode: The communication is performed in polling mode. The HAL status of all data processing is returned by the same function after finishing transfer.

726/900

DOCID025834 Rev 2

UM1725

HAL SMARTCARD Generic Driver

Non Blocking mode: The communication is performed using Interrupts or DMA, These APIs return the HAL status. The end of the data processing will be indicated through the dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks will be executed respectively at the end of the Transmit or Receive process The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication error is detected

2.Blocking mode APIs are :

HAL_SMARTCARD_Transmit()

HAL_SMARTCARD_Receive()

3.Non Blocking mode APIs with Interrupt are :

HAL_SMARTCARD_Transmit_IT()

HAL_SMARTCARD_Receive_IT()

HAL_SMARTCARD_IRQHandler()

4.Non Blocking mode functions with DMA are :

HAL_SMARTCARD_Transmit_DMA()

HAL_SMARTCARD_Receive_DMA()

5.A set of Transfer Complete Callbacks are provided in non Blocking mode:

HAL_SMARTCARD_TxCpltCallback()

HAL_SMARTCARD_RxCpltCallback()

HAL_SMARTCARD_ErrorCallback()

Smartcard is a single wire half duplex communication protocol. The Smartcard interface is designed to support asynchronous protocol Smartcards as defined in the ISO 7816-3 standard. The USART should be configured as:

8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register

1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register. (#) There are two modes of transfer:

Blocking mode: The communication is performed in polling mode. The HAL status of all data processing is returned by the same function after finishing transfer.

Non Blocking mode: The communication is performed using Interrupts or DMA, These APIs return the HAL status. The end of the data processing will be indicated through the dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks will be executed respectively at the end of the Transmit or Receive process The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication error is detected (#) Blocking mode APIs are :

HAL_SMARTCARD_Transmit()

HAL_SMARTCARD_Receive() (#) Non Blocking mode APIs with Interrupt are :

HAL_SMARTCARD_Transmit_IT()

HAL_SMARTCARD_Receive_IT()

HAL_SMARTCARD_IRQHandler() (#) Non Blocking mode functions with DMA are :

HAL_SMARTCARD_Transmit_DMA()

HAL_SMARTCARD_Receive_DMA() (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:

HAL_SMARTCARD_TxCpltCallback()

HAL_SMARTCARD_RxCpltCallback()

HAL_SMARTCARD_ErrorCallback()

This section contains the following APIs:

DOCID025834 Rev 2

727/900

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]