Skip to content

Commit c157489

Browse files
committed
chore(uart): set LSE as source only if LSE is ready
Fixes #2642. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent eebd0e3 commit c157489

File tree

1 file changed

+16
-14
lines changed
  • libraries/SrcWrapper/src/stm32

1 file changed

+16
-14
lines changed

libraries/SrcWrapper/src/stm32/uart.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -457,28 +457,30 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par
457457
if (baudrate <= 9600) {
458458
/* Enable the clock if not already set by user */
459459
enableClock(LSE_CLOCK);
460-
if (obj->uart == LPUART1) {
461-
__HAL_RCC_LPUART1_CONFIG(RCC_LPUART1CLKSOURCE_LSE);
462-
}
460+
if (LL_RCC_LSE_IsReady()) {
461+
if (obj->uart == LPUART1) {
462+
__HAL_RCC_LPUART1_CONFIG(RCC_LPUART1CLKSOURCE_LSE);
463+
}
463464
#if defined(LPUART2_BASE)
464-
if (obj->uart == LPUART2) {
465-
__HAL_RCC_LPUART2_CONFIG(RCC_LPUART2CLKSOURCE_LSE);
466-
}
465+
if (obj->uart == LPUART2) {
466+
__HAL_RCC_LPUART2_CONFIG(RCC_LPUART2CLKSOURCE_LSE);
467+
}
467468
#endif
468469
#if defined(LPUART3_BASE)
469-
if (obj->uart == LPUART3) {
470-
__HAL_RCC_LPUART3_CONFIG(RCC_LPUART3CLKSOURCE_LSE);
471-
}
470+
if (obj->uart == LPUART3) {
471+
__HAL_RCC_LPUART3_CONFIG(RCC_LPUART3CLKSOURCE_LSE);
472+
}
472473
#endif
473-
if ((uart_rx == NP) && (uart_rx_swap == NP)) {
474-
if (HAL_HalfDuplex_Init(huart) == HAL_OK) {
474+
if ((uart_rx == NP) && (uart_rx_swap == NP)) {
475+
if (HAL_HalfDuplex_Init(huart) == HAL_OK) {
476+
return;
477+
}
478+
} else if (HAL_UART_Init(huart) == HAL_OK) {
475479
return;
476480
}
477-
} else if (HAL_UART_Init(huart) == HAL_OK) {
478-
return;
479481
}
480482
}
481-
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY)) {
483+
if (LL_RCC_HSI_IsReady()) {
482484
if (obj->uart == LPUART1) {
483485
__HAL_RCC_LPUART1_CONFIG(RCC_LPUART1CLKSOURCE_HSI);
484486
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy