From 267beca895c7335cd03d586818ae07cf4acf6bb1 Mon Sep 17 00:00:00 2001 From: Quziwen <66210756+ItsGettingWorse@users.noreply.github.com> Date: Sun, 24 Aug 2025 14:43:21 +0800 Subject: [PATCH] Update drv_usart.c Fixed bugs under different optimization levels --- bsp/stm32/libraries/HAL_Drivers/drivers/drv_usart.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drivers/drv_usart.c b/bsp/stm32/libraries/HAL_Drivers/drivers/drv_usart.c index 5174fbe769e..4a22585881e 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drivers/drv_usart.c +++ b/bsp/stm32/libraries/HAL_Drivers/drivers/drv_usart.c @@ -11,6 +11,7 @@ * 2020-05-02 whj4674672 support stm32h7 uart dma * 2020-09-09 forest-rain support stm32wl uart * 2020-10-14 Dozingfiretruck Porting for stm32wbxx + * 2025-08-24 ItsGettingWorse Fixed bugs under different optimization levels */ #include "board.h" @@ -353,7 +354,10 @@ static int stm32_putc(struct rt_serial_device *serial, char c) #else uart->handle.Instance->DR = c; #endif - while (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) == RESET && --block_timeout); + while (__HAL_UART_GET_FLAG(&(uart->handle), UART_FLAG_TC) == RESET && --block_timeout) + { + __DSB(); // Data Synchronization Barrier + } return (block_timeout != 0) ? 1 : -1; }