From bd68d3d4a9092c4c497d201617e98ac6bc15f33c Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Mon, 7 Aug 2023 23:50:12 +0100 Subject: [PATCH] Enable/disable the UART TX before changing the TX pin mode (#13018) --- src/main/drivers/serial_uart_hal.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/serial_uart_hal.c b/src/main/drivers/serial_uart_hal.c index 30360777a9..a7074ad5b3 100644 --- a/src/main/drivers/serial_uart_hal.c +++ b/src/main/drivers/serial_uart_hal.c @@ -249,6 +249,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 @@ -262,9 +266,13 @@ bool checkUsartTxOutput(uartPort_t *s) void uartTxMonitor(uartPort_t *s) { uartDevice_t *uart = container_of(s, uartDevice_t, port); - IO_t txIO = IOGetByTag(uart->tx.pin); 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);