Skip to content

Commit

Permalink
chore(uart): set LSE as source only if LSE is ready
Browse files Browse the repository at this point in the history
Fixes #2642.

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
  • Loading branch information
fpistm committed Feb 3, 2025
1 parent eebd0e3 commit c157489
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions libraries/SrcWrapper/src/stm32/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c157489

Please sign in to comment.