[patch] improved rounding of UART clocks on STM32

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Post Reply
tridge
Posts: 141
Joined: Mon Sep 25, 2017 8:27 am
Has thanked: 10 times
Been thanked: 20 times

[patch] improved rounding of UART clocks on STM32

Post by tridge »

This patch fixes the rounding in calculating BRR for UARTv1 and UARTv2 for STM32. It was originally done by Jon Challenger, and I'm submitting it here for him.
It fixes an issue with a STM32 talking to a RaspberryPi at 921600 baud. With STM32_PCLK1=42000000 and speed=921600 the code would come up with a BRR of 45. With this fix the BRR comes out as 46.
A value of 45 gives an error of 1.27% in the desired baudrate. A value of 46 gives an error of 0.94%. Perhaps surprisingly, this makes all the difference when talking to the RaspberryPi, and the link starts working.
Patch is against branch 18.2.x, tested on STM32F427, STM32F405 and STM32F765
Cheers, Tridge
Attachments
chibios_stm32_uart_clock_rounding.zip
(1.03 KiB) Downloaded 522 times
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [patch] improved rounding of UART clocks on STM32

Post by Giovanni »

bump
Post Reply