A USART turns bytes into a stream of bits on one wire (TX) and collects them from another (RX). Both sides agree on a baud rate and a frame format, usually 8 data bits, no parity, 1 stop bit (8N1). There is no clock wire, so a wrong baud rate gives garbage characters.
On this board you do not even need a USB-serial adapter: USART3 is wired to the ST-LINK, which shows up on your PC as a virtual COM port. That makes the USART the easiest way to print debug text, and the first communication peripheral most people learn.
- Printing debug messages and values to a terminal on your PC (printf)
- Talking to GPS modules, Bluetooth/Wi-Fi modules and other boards
- RS-485 and Modbus links, with the driver-enable feature
- A simple command line to control your program from the PC
Read in this order
The shortest path through the documents. Each link opens the exact page; the line under it says what to look for.
- RM043348.2 USART main featuresp.2019What the peripheral can do, on two pages
- RM043348.4 USART implementationp.2020Which instances have which features (USART vs UART)
- RM043348.5.3 USART character descriptionp.2023What a frame looks like on the wire: start, data, parity, stop
- RM043348.5.5 USART transmitterp.2025The send procedure and the TXE/TC flags
- RM043348.5.6 USART receiverp.2029Receiving, RXNE, and the error flags (overrun, framing, noise)
- RM043348.5.7 USART baud rate generationp.2036How BRR is computed from the kernel clock
- UM24886.14 Virtual COM portp.15The board: USART3, 115200 8N1, through the ST-LINK on CN14
Registers to learn first
In the order you usually program them. The other 15 registers of the chapter can wait until you need them.
| 1 | RCC_APB1LENR | USART3EN: clock for USART3 (USART1 and USART6 are in RCC_APB2ENR) | p.461 |
| 2 | RCC_D2CCIP2R | Kernel clock for the USART: the clock BRR divides | p.415 |
| 3 | GPIOx_AFRL | Hand the TX/RX pins to the USART (AFRL for pins 0–7, AFRH for pins 8–15) | p.544 |
| 4 | USART_BRR | Baud rate divider: kernel clock / baud (with 16× oversampling) | p.2085 |
| 5 | USART_CR1 | Word length, parity, TE/RE (transmitter/receiver on), UE (enable), interrupts | p.2069 |
| 6 | USART_CR2 | Stop bits; leave at reset for 1 stop bit | p.2076 |
| 7 | USART_ISR | Status flags: TXE (can write), TC (sent), RXNE (byte received), errors | p.2088 |
| 8 | USART_TDR | Write a byte here to send it | p.2101 |
| 9 | USART_RDR | Read a received byte here | p.2101 |
| 10 | USART_ICR | Clear error flags like overrun (ORE), or reception stops | p.2099 |
All 26 registers in Universal synchronous/asynchronous receiver transmitter (USART/UART) and Low-power universal asynchronous receiver transmitter (LPUART)
On this board
| Net | Pin | Signal | Note |
|---|---|---|---|
| VCP_TX | PB10 | AF7 USART3_TX | USART3 TX → ST-LINK virtual COM port (to your PC) |
| VCP_RX | PB11 | AF7 USART3_RX | USART3 RX ← ST-LINK virtual COM port |
| ARD_D1 | PB6 | AF7 USART1_TX, AF8 LPUART1_TX, AF14 UART5_TX | Arduino D1 = USART1 TX (not the PC port, unlike on an Uno) |
| ARD_D0 | PB7 | AF7 USART1_RX, AF8 LPUART1_RX | Arduino D0 = USART1 RX |
| STMOD#2-TX | PD5 | AF7 USART2_TX | STMod+ connector TX |
| STMOD#3-RX | PD6 | AF7 USART2_RX | STMod+ connector RX |
Header pins you can wire to
Arduino and STMod+ header pins whose MCU pin can carry a USART signal (from the datasheet AF tables).
On this chip
9 instances found in the datasheet’s alternate-function tables, with every pin that can carry each signal.
| Instance | Signals and the pins that can carry them |
|---|---|
| LPUART1 | CTSPA11DEPA12RTSPA12RXPA10PB7TXPA9PB6 |
| UART4 | CTSPB0PB15DEPA15PB14RTSPA15PB14RXPA1PA11PB8PC11PD0PH14PI9TXPA0PA12PB9PC10PD1PH13 |
| UART5 | CTSPC9DEPC8RTSPC8RXPB5PB12PD2TXPB6PB13PC12 |
| UART7 | CTSPE10PF9DEPE9PF8RTSPE9PF8RXPA8PB3PE7PF6TXPA15PB4PE8PF7 |
| UART8 | CTSPD14DEPD15RTSPD15RXPE0PJ9TXPE1PJ8 |
| USART1 | CKPA8CTSPA11DEPA12NSSPA11RTSPA12RXPA10PB7PB15TXPA9PB6PB14 |
| USART2 | CKPA4PD7CTSPA0PD3DEPA1PD4NSSPA0PD3RTSPA1PD4RXPA3PD6TXPA2PD5 |
| USART3 | CKPB12PC12PD10CTSPB13PD11DEPB14PD12NSSPB13PD11RTSPB14PD12RXPB11PC11PD9TXPB10PC10PD8 |
| USART6 | CKPC8PG7CTSPG13PG15DEPG8PG12NSSPG13PG15RTSPG8PG12RXPC7PG9TXPC6PG14 |
Map of the chapter
Every reference-manual chapter has the same shape. Sections marked ● are in the reading order above.
- 48.1 USART introduction p.2018
- 48.2 USART main features p.2019
- 48.3 USART extended features p.2020
- 48.4 USART implementation p.2020
- 48.5 USART functional description p.2021
- 48.6 USART in low-power modes p.2067
- 48.7 USART interrupts p.2068
- 48.8 USART registers p.2069
- 49.1 LPUART introduction p.2105
- 49.2 LPUART main features p.2106
- 49.3 LPUART implementation p.2107
- 49.4 LPUART functional description p.2108
- 49.5 LPUART in low-power modes p.2131
- 49.6 LPUART interrupts p.2132
- 49.7 LPUART registers p.2133
Common mistakes
- Garbage characters: the baud rate does not match. Compute BRR from the USART kernel clock, not the CPU clock, and check the terminal is at 115200.
- Swapping TX and RX when wiring an external module: your TX goes to its RX.
- An overrun (
ORE) stops reception until you clear it inUSART_ICR. It happens when bytes arrive faster than you readRDR. - Writing
TDRwithout waiting forTXE: bytes are lost. Turning the USART off beforeTCcuts the last byte. - Connecting a 5 V device directly. The pins work at 3.3 V; check in the datasheet whether the pin is 5 V tolerant (FT).