This document describes a firmware and hardware Smartcard interface solution based on
the STM32F10x USART peripheral. The main purpose of this firmware and hardware
package is to provide resources that facilitate the development of an application using the
USART peripheral in Smartcard mode.
The firmware interface consists of library source files developed so as to support the
ISO 7816-3/4 specification. An application example based on STMicroelectronics
STM3210B-EVAL, STM3210E-EVAL and STM3210C-EVAL evaluation boards is also
provided.
This document and its associated firmware are available for download from the
STMicroelectronics website: www.st.com.
Glossary
Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.
Medium-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 32 and 128 Kbytes. Medium-density devices are
implemented in the STMicroelectronics STM32F103xx evaluation board.
High-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 256 and 512 Kbytes. High-density devices are
implemented in the STMicroelectronics STM3210E-EVAL evaluation board.
Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
The Smartcard interface is developed using the USART Smartcard mode. For the
description of the USART registers, please refer to the STM32F10x reference manual. The
USART Smartcard mode supports asynchronous protocol Smartcards as defined in the
ISO 7816-3 standard.
With the Smartcard mode enabled, the USART must be configured as:
●eight data bits plus parity
●0.5 or 1.5 stop bits
A 5-bit prescaler and the Smartcard clock generator provide the clock to the Smartcard.
GPIO pins in conjunction with software are used to provide the rest of the functions required
to interface to the Smartcard.
The inverse signalling convention as defined in ISO 7816-3, inverted data and MSB first, is
not handled in the software.
1.2 External interface
Table 1.Smartcard pins
STM32F10x pinSmartcard pinFunction
USART CKCLKSmartcard clock
USART_TXIOIO serial data: open drain
Any GPIORSTReset to card
Any GPIOV
Any GPIOV
The Smartcard_RST (Smartcard reset), Smartcard_3/5V (3 V or 5 V), Smartcard_CMDVCC
(command for V
GPIO bits of the I/O ports under software control. Programming the GPIO bits of the port for
alternate function open-drain mode connects the USART_TX data signal to the
Smartcard_IO pin with the correct driver type and the clock generator to the
Smartcard_CLK pin configured in alternate function output push-pull.
1.3 Protocol
The ISO 7816-3 standard defines the bit times for the asynchronous protocol in terms of
time units called ETUs (elementary time units), that are related to the clock frequency input
to the card. The length of an ETU is a bit time. The USART transmitter output and receiver
input are internally connected through the Rx_SW line. For the transmission of data from the
STM32F10x to the Smartcard, the USART must be set up in Smartcard mode.
CC
PP
), and Smartcard_OFF signals (signal for card detection) are provided by
CC
Supply voltage
Programming voltage
6/40Doc ID 13750 Rev 3
AN2598Smartcard interface description
Sabcde fghP
Start
bit
8 data bits
Parity
bit
ETU
Line pulled low by receiver during
stop in case of parity error
ai14612
Figure 1.ISO 7816-3 asynchronous protocol
1.4 Smartcard clock generator
The Smartcard clock generator provides a clock signal to the connected Smartcard. The
Smartcard uses this clock to derive the baud rate clock for the serial I/O between the
Smartcard and another USART. The clock is also used for the CPU in the card, if present.
Operation of the Smartcard interface requires that the clock rate to the card is adjusted while
the CPU in the card is running code so that the baud rate can be changed or the
performance of the card can be increased. The protocols that govern the negotiation of
these clock rates and the altering of the clock rate are detailed in the ISO 7816-3 standard.
The clock is used as the CPU clock for the Smartcard, therefore updates to the
microcontroller clock rate must be synchronized to the Smartcard clock, that is the clock
high or low pulse widths must not be shorter than either the old or new programmed value.
Doc ID 13750 Rev 37/40
Smartcard reader hardware connectionAN2598
2 Smartcard reader hardware connection
To interface to the Smartcard, the ST8024 device was used. The ST8024 is a complete lowcost, analog interface for asynchronous 3 V and 5 V Smartcards. It is placed between the
Smartcard and the STM32F10x with few external components to perform all supply
protection and control functions.
Governs the dimension and location of
the chip contacts
1-V
CC
2-RST
3-CLK
4-RFURFU-8
I/O-7
VPP-6
GND-5
Only one location accepted by ISO since 1/1/93.
Chip can still be on the front or back of the card.
ai14617
3 ISO 7816: protocol overview
3.1 Introduction
"ISO 7816: Identification cards -- Integrated circuit(s) cards with contacts" provides the basis
to transition the relatively simple identification card from a token that can be compromised
through forgery, theft, or loss into a tamper-resistant and "intelligent" integrated circuit card
(ICC), more popularly known as a Smartcard. ISO 7816 includes at least six approved parts
and has several additional parts under review:
●Part 1: Physical characteristics
●Part 2: Dimensions and location of the contacts
●Part 3: Electrical interface and transmission protocols
●Part 3: Amendment 2-Revision of protocol type selection
●Part 4: Organization, security and commands for interchange
●Part 5: Registration of application providers
3.2 ISO 7816-2 – pin location
ISO 7816-2 specifies an ICC with eight electrical contacts present in a standardized position
on the front face of the card. These are referred to as C1 through C8. Some of these
contacts are electrically connected to the microprocessor chip embedded within the card;
some are not, having been defined to allow for enhancements but unused at the present
time. Figure 3 shows the contact positions.
Figure 3.Contact definitions for Smartcards
10/40Doc ID 13750 Rev 3
AN2598ISO 7816: protocol overview
Table 3.Pin assignment
PinsFunctions
C1V
CC
C2Reset
C3Clock
C4RFU
C5GND
C6V
PP
C7I/O
C8RFU
= 5 V or 3.3 V
Doc ID 13750 Rev 311/40
ISO 7816-3 – Electronic signal and transmission protocolAN2598
Reader state diagram
Card removal
Reader
"idle"
Card insertion
Powe r
the cord
Protocol
negotiation
Protocol
fail
Card
removal
No ATR
Idle
command
Set protocol
Wait for
response
Command
completion
wait
Partial response
Send APDU to card
Request command
completion
Receive full
response
Powe r
off
Card reset
Prepare
AT R
APDU
dispatch
idle
APDU
processing
Dispatch APDU
to processor
Receive ATR
Issue ATR
Issue response
to reader
Card state diagram
ai14618
4 ISO 7816-3 – Electronic signal and transmission
protocol
ISO 7816-3 begins to delve into the specification of the "intelligent" aspects of the
Smartcard. This standard describes the relationship between the Smartcard and the reader
as one of "slave" (the Smartcard) and "master" (the reader). Communications are
established by the reader signaling to the Smartcard through the contacts noted previously
and are continued by the Smartcard responding accordingly.
Communication between the card and reader proceed according to various state transitions
illustrated in Figure 4.
Figure 4.Reader and card FSM
The communication channel is single-threaded; once the reader sends a command to the
Smartcard, it blocks until a response is received.
12/40Doc ID 13750 Rev 3
Loading...
+ 28 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.