Skip to content

Commit

Permalink
Enable/disable the UART TX before changing the TX pin mode (betafligh…
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveCEvans committed Aug 7, 2023
1 parent 96ffb3a commit bd68d3d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/drivers/serial_uart_hal.c
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit bd68d3d

Please sign in to comment.