From: Patrice Chotard <patrice.chotard@foss.st.com>
Date: Wed, 31 May 2023 06:01:31 +0000 (+0200)
Subject: serial: stm32: BRR must be set only when usart is disable
X-Git-Tag: v2025.01-rc5-pxa1908~950^2~14^2
X-Git-Url: http://git.dujemihanovic.xyz/%22http:/kyber.dk/phpMyBuilder/static/%7B%7B%20.Permalink%20%7D%7D?a=commitdiff_plain;h=8ab9e8ffdf0977ce5101a4d71b75655667eced5e;p=u-boot.git

serial: stm32: BRR must be set only when usart is disable

To avoid spurious chars, BRR register must only be written when
USART is disabled.

Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

diff --git a/drivers/serial/serial_stm32.c b/drivers/serial/serial_stm32.c
index 93f70947ee..0085113f67 100644
--- a/drivers/serial/serial_stm32.c
+++ b/drivers/serial/serial_stm32.c
@@ -29,6 +29,10 @@ static void _stm32_serial_setbrg(fdt_addr_t base,
 {
 	bool stm32f4 = uart_info->stm32f4;
 	u32 int_div, mantissa, fraction, oversampling;
+	u8 uart_enable_bit = uart_info->uart_enable_bit;
+
+	/* BRR register must be set when uart is disabled */
+	clrbits_le32(base + CR1_OFFSET(stm32f4), BIT(uart_enable_bit));
 
 	int_div = DIV_ROUND_CLOSEST(clock_rate, baudrate);
 
@@ -44,6 +48,8 @@ static void _stm32_serial_setbrg(fdt_addr_t base,
 	fraction = int_div % oversampling;
 
 	writel(mantissa | fraction, base + BRR_OFFSET(stm32f4));
+
+	setbits_le32(base + CR1_OFFSET(stm32f4), BIT(uart_enable_bit));
 }
 
 static int stm32_serial_setbrg(struct udevice *dev, int baudrate)