From 3f1e89e30f3890664d500afcaef368b06149f5d0 Mon Sep 17 00:00:00 2001 From: Matias Nitsche Date: Sun, 19 Apr 2020 17:48:16 -0300 Subject: [PATCH] stm32l4 serial fix: clock divider for baud rate was not correctly set --- arch/arm/src/stm32l4/stm32l4_serial.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/stm32l4/stm32l4_serial.c b/arch/arm/src/stm32l4/stm32l4_serial.c index b083e3f9fc..2fa430ffd0 100644 --- a/arch/arm/src/stm32l4/stm32l4_serial.c +++ b/arch/arm/src/stm32l4/stm32l4_serial.c @@ -963,11 +963,14 @@ static void stm32l4serial_setformat(FAR struct uart_dev_s *dev) /* Use oversamply by 8 only if the divisor is small. But what is small? */ cr1 = stm32l4serial_getreg(priv, STM32L4_USART_CR1_OFFSET); + brr = stm32l4serial_getreg(priv, STM32L4_USART_BRR_OFFSET); + brr &= ~(USART_BRR_MANT_MASK | USART_BRR_FRAC_MASK); + if (usartdiv8 > 100) { /* Use usartdiv16 */ - brr = (usartdiv8 + 1) >> 1; + brr |= (usartdiv8 + 1) >> 1; /* Clear oversampling by 8 to enable oversampling by 16 */ @@ -979,7 +982,7 @@ static void stm32l4serial_setformat(FAR struct uart_dev_s *dev) /* Perform mysterious operations on bits 0-3 */ - brr = ((usartdiv8 & 0xfff0) | ((usartdiv8 & 0x000f) >> 1)); + brr |= ((usartdiv8 & 0xfff0) | ((usartdiv8 & 0x000f) >> 1)); /* Set oversampling by 8 */