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)
This commit is contained in:
Karl Palsson 2017-10-24 23:57:56 +00:00
parent 874af2e846
commit 5dd0b46298

View File

@ -50,13 +50,12 @@ void usart_set_baudrate(uint32_t usart, uint32_t baud)
{ {
uint32_t clock = rcc_apb1_frequency; uint32_t clock = rcc_apb1_frequency;
#if defined STM32F2 || defined STM32F4 #if defined USART1
if ((usart == USART1) || if ((usart == USART1)
(usart == USART6)) { #if defined USART6
clock = rcc_apb2_frequency; || (usart == USART6)
} #endif
#else ) {
if (usart == USART1) {
clock = rcc_apb2_frequency; clock = rcc_apb2_frequency;
} }
#endif #endif