Topics / USART
Topic

USART Universal synchronous/asynchronous receiver transmitter

The serial port: send and receive bytes over a TX and an RX wire, for example to your PC.

What it is

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.

You need it for
  • 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.

  1. RM043348.2 USART main featuresp.2019What the peripheral can do, on two pages
  2. RM043348.4 USART implementationp.2020Which instances have which features (USART vs UART)
  3. RM043348.5.3 USART character descriptionp.2023What a frame looks like on the wire: start, data, parity, stop
  4. RM043348.5.5 USART transmitterp.2025The send procedure and the TXE/TC flags
  5. RM043348.5.6 USART receiverp.2029Receiving, RXNE, and the error flags (overrun, framing, noise)
  6. RM043348.5.7 USART baud rate generationp.2036How BRR is computed from the kernel clock
  7. 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.

1RCC_APB1LENRUSART3EN: clock for USART3 (USART1 and USART6 are in RCC_APB2ENR)p.461
2RCC_D2CCIP2RKernel clock for the USART: the clock BRR dividesp.415
3GPIOx_AFRLHand the TX/RX pins to the USART (AFRL for pins 0–7, AFRH for pins 8–15)p.544
4USART_BRRBaud rate divider: kernel clock / baud (with 16× oversampling)p.2085
5USART_CR1Word length, parity, TE/RE (transmitter/receiver on), UE (enable), interruptsp.2069
6USART_CR2Stop bits; leave at reset for 1 stop bitp.2076
7USART_ISRStatus flags: TXE (can write), TC (sent), RXNE (byte received), errorsp.2088
8USART_TDRWrite a byte here to send itp.2101
9USART_RDRRead a received byte herep.2101
10USART_ICRClear error flags like overrun (ORE), or reception stopsp.2099
All 26 registers in Universal synchronous/asynchronous receiver transmitter (USART/UART) + Low-power universal asynchronous receiver transmitter (LPUART)

On this board

NetPinSignalNote
VCP_TXPB10AF7 USART3_TXUSART3 TX → ST-LINK virtual COM port (to your PC)
VCP_RXPB11AF7 USART3_RXUSART3 RX ← ST-LINK virtual COM port
ARD_D1PB6AF7 USART1_TX, AF8 LPUART1_TX, AF14 UART5_TXArduino D1 = USART1 TX (not the PC port, unlike on an Uno)
ARD_D0PB7AF7 USART1_RX, AF8 LPUART1_RXArduino D0 = USART1 RX
STMOD#2-TXPD5AF7 USART2_TXSTMod+ connector TX
STMOD#3-RXPD6AF7 USART2_RXSTMod+ 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.

Map of the chapter

Every reference-manual chapter has the same shape. Sections marked ● are in the reading order above.

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 in USART_ICR. It happens when bytes arrive faster than you read RDR.
  • Writing TDR without waiting for TXE: bytes are lost. Turning the USART off before TC cuts 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).

Where to go next