Baud rate errors
This took me a while to find, but I tried setting up a L073 Nucleo with a very simple serial output on USART2. In STM32CUBEMX, I set baud rate at 115200 and 16x over sampling. When I chedked the BRR register in the UART, it was set at 278 (decimal), which is what I would expect if the input clock to the UART was 32Mhz.
I got garbage out of the USB UART. I work on a Linux system and use minicom to connect to /dev/ttyACM0. I tried this with a Win10 machine and saw the same garbage.
I looked in the reference manual for the chp and see
Example 2
To obtain 921.6 Kbaud with fCK = 32 MHz.
• In case of oversampling by 16:
USARTDIV = 32 000 000/921 600
BRR = USARTDIV = 35d = 23h
• In case of oversampling by 8:
USARTDIV = 2 * 32 000 000/921 600
USARTDIV = 70d = 46h
BRR3:0 = USARTDIV3:0 >> 1 = 6h >> 1 = 3h
BRR = 0x43
On a hunch, I set the baud rate in minicom to 57,600 and saw my printfs appear.
On another hunch, I set oversampling to 8 in STM32CUBEMX, 115200 baud and recompiled the code. It is still prints out at 57.6 kbaud.
BRR is 550 decimal. That is the correct value for 115200, but output is at 57.6 kb.
On another hunch, I set the UART source to the HSI 16 MHz clock.
I now get output at 115200 kb.
TL;DR: Macros which compute BRR value in at least one HAL SDK are picking the 16 MHz clock, without regard to the actual UART input clock rate.