From a54bc47e1bac6101421d1dfde5fe542d59b3152a Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Tue, 8 Aug 2023 06:49:51 +0100 Subject: [PATCH] Enable/disable the UART TX before changing the TX pin mode (#13017) --- src/main/drivers/stm32/serial_uart_hal.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/drivers/stm32/serial_uart_hal.c b/src/main/drivers/stm32/serial_uart_hal.c index 136ececcb0..6913df56ec 100644 --- a/src/main/drivers/stm32/serial_uart_hal.c +++ b/src/main/drivers/stm32/serial_uart_hal.c @@ -251,6 +251,10 @@ bool checkUsartTxOutput(uartPort_t *s) // Enable USART TX output uart->txPinState = TX_PIN_ACTIVE; IOConfigGPIOAF(txIO, IOCFG_AF_PP, uart->tx.af); + + // Enable the UART transmitter + SET_BIT(s->Handle.Instance->CR1, USART_CR1_TE); + return true; } else { // TX line is pulled low so don't enable USART TX @@ -268,6 +272,9 @@ void uartTxMonitor(uartPort_t *s) if (uart->txPinState == TX_PIN_ACTIVE) { IO_t txIO = IOGetByTag(uart->tx.pin); + // Disable the UART transmitter + CLEAR_BIT(s->Handle.Instance->CR1, USART_CR1_TE); + // Switch TX to an input with pullup so it's state can be monitored uart->txPinState = TX_PIN_MONITOR; IOConfigGPIO(txIO, IOCFG_IPU);