Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


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.

With your description, it more like a bug in HAL lib. You may discuss it to ST support, as the HAL lib is provided by ST.

BTW,I had experienced some issues on UART baud rate issue on STM32. On STM32F0Discovery board, which is only HSI available, I can easily to configure/run the USART1 and 2 on UART mode with baud rate to 921600; but on STM32F4Discovery board, which has external oscillator available, I have to sacrifice Usb clock and make same other tweaking on clock settings to make UART rate above 115200.

BBlue


>With your description, it more like a bug in HAL lib. You may discuss it to ST support, as the HAL lib is provided by ST.

True.

I posted it here in case other people who were using the STM32CubeMX and SW4ST combination ran into the problem.


“Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?

I looked through the docs and it sounds like the 16X oversampling is your issue. I think you have to adjust your baud rate divisor to take into consideration the /16 instead of a /8.

The rest of it is just clock circuitry, so the only place where there is a factor of two would be the oversampling. As for why cube would get the two mixed up... they’re working on it.


A