From c157489aba7ab46f163a6d76cde6b29a3e48f510 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Mon, 3 Feb 2025 16:53:50 +0100 Subject: [PATCH] chore(uart): set LSE as source only if LSE is ready Fixes #2642. Signed-off-by: Frederic Pillon --- libraries/SrcWrapper/src/stm32/uart.c | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/libraries/SrcWrapper/src/stm32/uart.c b/libraries/SrcWrapper/src/stm32/uart.c index e762e007ab..0749fefb52 100644 --- a/libraries/SrcWrapper/src/stm32/uart.c +++ b/libraries/SrcWrapper/src/stm32/uart.c @@ -457,28 +457,30 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par if (baudrate <= 9600) { /* Enable the clock if not already set by user */ enableClock(LSE_CLOCK); - if (obj->uart == LPUART1) { - __HAL_RCC_LPUART1_CONFIG(RCC_LPUART1CLKSOURCE_LSE); - } + if (LL_RCC_LSE_IsReady()) { + if (obj->uart == LPUART1) { + __HAL_RCC_LPUART1_CONFIG(RCC_LPUART1CLKSOURCE_LSE); + } #if defined(LPUART2_BASE) - if (obj->uart == LPUART2) { - __HAL_RCC_LPUART2_CONFIG(RCC_LPUART2CLKSOURCE_LSE); - } + if (obj->uart == LPUART2) { + __HAL_RCC_LPUART2_CONFIG(RCC_LPUART2CLKSOURCE_LSE); + } #endif #if defined(LPUART3_BASE) - if (obj->uart == LPUART3) { - __HAL_RCC_LPUART3_CONFIG(RCC_LPUART3CLKSOURCE_LSE); - } + if (obj->uart == LPUART3) { + __HAL_RCC_LPUART3_CONFIG(RCC_LPUART3CLKSOURCE_LSE); + } #endif - if ((uart_rx == NP) && (uart_rx_swap == NP)) { - if (HAL_HalfDuplex_Init(huart) == HAL_OK) { + if ((uart_rx == NP) && (uart_rx_swap == NP)) { + if (HAL_HalfDuplex_Init(huart) == HAL_OK) { + return; + } + } else if (HAL_UART_Init(huart) == HAL_OK) { return; } - } else if (HAL_UART_Init(huart) == HAL_OK) { - return; } } - if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY)) { + if (LL_RCC_HSI_IsReady()) { if (obj->uart == LPUART1) { __HAL_RCC_LPUART1_CONFIG(RCC_LPUART1CLKSOURCE_HSI); }