Section 3.3 Configuring USART2 at the Register Level
Understanding what
uart2_init() does inside prepares you to configure any UART peripheral in any STM32 project. There are four steps: configure the GPIO pins for alternate function, enable the USART clock, set the baud rate, and enable the transmitter, receiver, and peripheral (in that order).
The diagram below shows the internal architecture of the USART peripheral. The registers we’ll use are
USART_TDR (transmit data register), USART_RDR (receive data register), USART_BRR (baud rate), USART_CR1 (control), and USART_ISR (status flags). The TX and RX shift registers handle the actual bit-by-bit serialization in hardware.

