Skip to content

Commit da21c30

Browse files
committed
chore(uart): set LSE as source only if LSE is ready
Fixes #2642. Signed-off-by: Frederic Pillon <[email protected]>
1 parent ee9c0dd commit da21c30

File tree

1 file changed

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

1 file changed

+17
-14
lines changed

Diff for: libraries/SrcWrapper/src/stm32/uart.c

+17-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "uart.h"
1616
#include "Arduino.h"
1717
#include "PinAF_STM32F1.h"
18+
#include "stm32yyxx_ll_rcc.h"
1819

1920
#ifdef __cplusplus
2021
extern "C" {
@@ -457,28 +458,30 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par
457458
if (baudrate <= 9600) {
458459
/* Enable the clock if not already set by user */
459460
enableClock(LSE_CLOCK);
460-
if (obj->uart == LPUART1) {
461-
__HAL_RCC_LPUART1_CONFIG(RCC_LPUART1CLKSOURCE_LSE);
462-
}
461+
if (LL_RCC_LSE_IsReady()) {
462+
if (obj->uart == LPUART1) {
463+
__HAL_RCC_LPUART1_CONFIG(RCC_LPUART1CLKSOURCE_LSE);
464+
}
463465
#if defined(LPUART2_BASE)
464-
if (obj->uart == LPUART2) {
465-
__HAL_RCC_LPUART2_CONFIG(RCC_LPUART2CLKSOURCE_LSE);
466-
}
466+
if (obj->uart == LPUART2) {
467+
__HAL_RCC_LPUART2_CONFIG(RCC_LPUART2CLKSOURCE_LSE);
468+
}
467469
#endif
468470
#if defined(LPUART3_BASE)
469-
if (obj->uart == LPUART3) {
470-
__HAL_RCC_LPUART3_CONFIG(RCC_LPUART3CLKSOURCE_LSE);
471-
}
471+
if (obj->uart == LPUART3) {
472+
__HAL_RCC_LPUART3_CONFIG(RCC_LPUART3CLKSOURCE_LSE);
473+
}
472474
#endif
473-
if ((uart_rx == NP) && (uart_rx_swap == NP)) {
474-
if (HAL_HalfDuplex_Init(huart) == HAL_OK) {
475+
if ((uart_rx == NP) && (uart_rx_swap == NP)) {
476+
if (HAL_HalfDuplex_Init(huart) == HAL_OK) {
477+
return;
478+
}
479+
} else if (HAL_UART_Init(huart) == HAL_OK) {
475480
return;
476481
}
477-
} else if (HAL_UART_Init(huart) == HAL_OK) {
478-
return;
479482
}
480483
}
481-
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY)) {
484+
if (LL_RCC_HSI_IsReady()) {
482485
if (obj->uart == LPUART1) {
483486
__HAL_RCC_LPUART1_CONFIG(RCC_LPUART1CLKSOURCE_HSI);
484487
}

0 commit comments

Comments
 (0)