From 5dd0b46298024c42fc931a2895993f425c2e7df2 Mon Sep 17 00:00:00 2001 From: Karl Palsson Date: Tue, 24 Oct 2017 23:57:56 +0000 Subject: [PATCH] stm32: usart_common_all: fix bug in baudrate calculation This function was using apb1 for quite a few families instead of apb2. This only mattered for L1 and F3, and for USART1/USART6, and only if apb1 speed != apb2 speed. Instead of using families explicitly, just check for the peripherals themselves. On F0,F1,F2,F3,F4,F7,H7,L0,L1,L4, usart1/6 are _always_ in the rcc_apb2 register and the other uarts are all on apb1. (F0 doesn't actually _have_ apb2, but it's still called the apb2 register) --- lib/stm32/common/usart_common_all.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/stm32/common/usart_common_all.c b/lib/stm32/common/usart_common_all.c index 4e42f2a9..5c411779 100644 --- a/lib/stm32/common/usart_common_all.c +++ b/lib/stm32/common/usart_common_all.c @@ -50,13 +50,12 @@ void usart_set_baudrate(uint32_t usart, uint32_t baud) { uint32_t clock = rcc_apb1_frequency; -#if defined STM32F2 || defined STM32F4 - if ((usart == USART1) || - (usart == USART6)) { - clock = rcc_apb2_frequency; - } -#else - if (usart == USART1) { +#if defined USART1 + if ((usart == USART1) +#if defined USART6 + || (usart == USART6) +#endif + ) { clock = rcc_apb2_frequency; } #endif