From fc0b2ef920d4df1e2e608dabadb915c6fc953522 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 20 Mar 2020 10:03:16 +1100 Subject: [PATCH] HAL_ChibiOS: added half-duplex protection for non-inverted to prevent output bytes being seen as input bytes we disable half duplex during transmit. This was previously only done for non-inverted UARTs. This patch enables it whether we are inverted or not. This greatly reduces the number of bad input bytes. --- libraries/AP_HAL_ChibiOS/UARTDriver.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp index bb331c51613..29557864bee 100644 --- a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp +++ b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp @@ -929,12 +929,10 @@ void UARTDriver::half_duplex_setup_tx(void) if (!hd_tx_active) { chEvtGetAndClearFlags(&hd_listener); hd_tx_active = true; - if (_last_options & (OPTION_RXINV | OPTION_TXINV)) { - SerialDriver *sd = (SerialDriver*)(sdef.serial); - sdStop(sd); - sercfg.cr3 &= ~USART_CR3_HDSEL; - sdStart(sd, &sercfg); - } + SerialDriver *sd = (SerialDriver*)(sdef.serial); + sdStop(sd); + sercfg.cr3 &= ~USART_CR3_HDSEL; + sdStart(sd, &sercfg); } #endif } @@ -955,12 +953,10 @@ void UARTDriver::_timer_tick(void) half-duplex transmit has finished. We now re-enable the HDSEL bit for receive */ - if (_last_options & (OPTION_RXINV | OPTION_TXINV)) { - SerialDriver *sd = (SerialDriver*)(sdef.serial); - sdStop(sd); - sercfg.cr3 |= USART_CR3_HDSEL; - sdStart(sd, &sercfg); - } + SerialDriver *sd = (SerialDriver*)(sdef.serial); + sdStop(sd); + sercfg.cr3 |= USART_CR3_HDSEL; + sdStart(sd, &sercfg); hd_tx_active = false; } #endif