From 96f8438ea2b8a06c66fdcd8a4e557224b2c8922a Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Fri, 14 Dec 2018 11:08:51 +0100 Subject: [PATCH] cpu/stm32_common/uart: Prevent uart from sending if not initialized Due to the stdio getting called after periph_init the uart may send before initialized. This adds a simple check so the uart does not get into a locked-up state. --- cpu/stm32_common/periph/uart.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpu/stm32_common/periph/uart.c b/cpu/stm32_common/periph/uart.c index 54adaea1d0..76c3d6d595 100644 --- a/cpu/stm32_common/periph/uart.c +++ b/cpu/stm32_common/periph/uart.c @@ -145,7 +145,12 @@ static inline void wait_for_tx_complete(uart_t uart) void uart_write(uart_t uart, const uint8_t *data, size_t len) { assert(uart < UART_NUMOF); - +#if DEVELHELP + /* If tx is not enabled don't try to send */ + if (!(dev(uart)->CR1 & USART_CR1_TE)) { + return; + } +#endif #ifdef MODULE_PERIPH_DMA if (!len) { return;