STM32: USARTv1: improve baud rate calculation accuracity

This commit is contained in:
Andrey Gusakov 2024-06-17 13:52:40 +03:00
parent a173d119f1
commit adeb3c34cf
1 changed files with 2 additions and 2 deletions

View File

@ -108,9 +108,9 @@ static void usart_init(SerialDriver *sdp, const SerialConfig *config) {
#else
if (sdp->usart == USART1)
#endif
fck = STM32_PCLK2 / config->speed;
fck = (STM32_PCLK2 + config->speed / 2) / config->speed;
else
fck = STM32_PCLK1 / config->speed;
fck = (STM32_PCLK1 + config->speed / 2) / config->speed;
/* Correcting USARTDIV when oversampling by 8 instead of 16.
Fraction is still 4 bits wide, but only lower 3 bits used.