Revision History
Capabilities
This driver supports SmartCard mode.
Instances
Hardware resource relating to driver instance is shown in the table below:
Driver Instance | Hardware Resource |
Driver_USART1 | USART1 |
Driver_USART2 | USART2 |
Driver_USART3 | USART3 |
Driver_USART6 | USART6 |
Driver_USART10 | USART10 |
Driver_USART11 | USART11 |
- Note
- The CMSIS Driver:USART (API):USART component in the Manage Run-Time Environment dialog adds multiple C source files to the project.
The interface selection in STM32CubeMX selects the actual implementation that is compiled: IrDA, SmartCard, UART or USART.
Limitations
STM32 HAL limitations:
- Rx Timeout event disables further reception
- No callback available for Rx Idle event
Configuration
STM32CubeMX
The USART driver requires:
- USART peripheral clock
- USART peripheral configured as SmartCard with Card Clock
- USART TX and CK pins
- optional DMA configuration for transfers
NUCLEO-H563ZI Board Configuration
These settings are relevant for this board, for different board please refer to the board schematic for proper configuration.
Link to NUCLEO-H563ZI board schematic.
STM32CubeMX
Required peripherals for the NUCLEO-H563ZI board are listed in the table below:
Peripheral | Mode | Description |
USART2 | SmartCard with Card Clock | USART2 Controller |
PD5 | Alternate Function Push Pull | USART2 TX Pin |
PD7 | Alternate Function Push Pull | USART2 CK Pin |
- Note
- All settings have to be configured as described in the procedure below. Important settings, typically the ones different from default, are emphasized in bold.
Pinout & Configuration tab
- In the Pinout view window click on a pin and select it's functionality:
Pin | Functionality |
PD5 | USART2_TX |
PD7 | USART2_CK |
Under Categories: Connectivity select USART2:
Mode:
- Mode: SmartCard with Card Clock
- Hardware Flow Control (RS232): Disable
- Slave Select(NSS) Management: Disable
Configuration:
- Parameter Settings:
- Basic parameters:
- Baud Rate: 115200
- Word Length: 9
- Parity: Even
- Stop Bits: 1.5
- Advanced parameters:
- Data direction: Receive and Transmit
- NACK if parity error: Disable
- Guard Time: 0
- Receiver TimeOut State: Disable
- SmartCard Block Length: 0
- Number of retries in receive and transmit mode: 0
- Single Sample: Disable
- Fifo mode: Disable
- Txfifo Threshold: 1 eighth full configuration
- Rxfifo Threshold: 1 eighth full configuration
- ClockPrescaler: 2
- Clock Parameters
- Prescaler: 10
- SmartCard Clock Frequency: 3.125 MHz
- Clock polarity: Low
- Clock Phase: One Edge
- Clock Last Bit: Disable
- Advanced features
- TX Pin Active Level Inversion: Disable
- Rx Pin Active Level Inversion: Disable
- Data inversion: Disable
- TX and RX pin Swapping: Disable
- Overrun: Enable
- DMA on RX Error: Enable
- MSB First: Disable
- User Constants: not used
- NVIC Settings: configured in later step (under Category: System Core: NVIC)
- DMA Settings: configured in later step (under Category: System Core: DMA)
- GPIO Settings:
Pin Name | Signal on Pin | Pin Context.. | GPIO output.. | GPIO mode | GPIO Pull-up/Pull.. | Maximum out.. | Fast Mode | User Label |
PD5 | USART2_TX | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | Low | n/a | . |
PD7 | USART2_CK | n/a | n/a | Alternate Function Push Pull | No pull-up and no.. | Low | n/a | . |
Under Categories: System Core select DMA:
Configuration:
- DMA1, DMA2:
Click Add button and add DMA Requests as in table below:
DMA Request | Stream | Direction | Priority |
USART2_TX | DMA1 Stream 0 | Peripheral to Memory | Low |
USART2_CK | DMA1 Stream 1 | Memory to Peripheral | Low |
Under Categories: System Core select NVIC:
Configuration:
- NVIC:
NVIC Interrupt Table | Enabled | Preemption Priority | Sub Priority |
DMA1 stream0 global interrupt | checked | 0 | 0 |
DMA1 stream1 global interrupt | checked | 0 | 0 |
USART2 global interrupt | checked | 0 | 0 |
- Code generation:
Enabled interrupt table | Select for.. | Generate Enable in.. | Generate IRQ h.. | Call HAL handler |
DMA1 stream0 global interrupt | unchecked | checked | checked | checked |
DMA1 stream1 global interrupt | unchecked | checked | checked | checked |
USART2 global interrupt | unchecked | checked | checked | checked |
Clock Configuration tab
- Configure To USART2 (MHz): 250
Project Manager tab
Under Advanced Settings:
Generated Function Calls:
Generate Code | Function Name | Peripheral Inst.. | Do not generate .. | Visibility (Static) |
checked | MX_USART2_SMARTCARD_Init | USART2 | checked | checked |
Generate Code
Generate source code by clicking on the GENERATE CODE button on the toolbar.