You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/06/15 22:20:03 UTC

[incubator-nuttx] 01/02: stm32l4 serial fix: clock divider for baud rate was not correctly set

This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 3f1e89e30f3890664d500afcaef368b06149f5d0
Author: Matias Nitsche <mn...@dc.uba.ar>
AuthorDate: Sun Apr 19 17:48:16 2020 -0300

    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 b083e3f..2fa430f 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 */