From cceec91c7c767d2d1d0c3a5d9def7b33501da692 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Tue, 6 Aug 2024 13:36:00 +0100 Subject: [PATCH] AP_HAL_ChibiOS: correctly uninvert RX/TX on F4 with inverter support --- libraries/AP_HAL_ChibiOS/UARTDriver.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp index 23a7390c64..6e22d62ed4 100644 --- a/libraries/AP_HAL_ChibiOS/UARTDriver.cpp +++ b/libraries/AP_HAL_ChibiOS/UARTDriver.cpp @@ -1623,22 +1623,38 @@ bool UARTDriver::set_options(uint16_t options) cr2 &= ~USART_CR2_SWAP; _cr2_options &= ~USART_CR2_SWAP; } -#else // STM32F4 +#elif defined(STM32F4) // STM32F4 // F4 can do inversion by GPIO if enabled in hwdef.dat, using // TXINV and RXINV options if (options & OPTION_RXINV) { if (sdef.rxinv_gpio >= 0) { hal.gpio->write(sdef.rxinv_gpio, sdef.rxinv_polarity); + if (arx_line != 0) { + palLineSetPushPull(arx_line, PAL_PUSHPULL_PULLDOWN); + } } else { ret = false; } + } else if (sdef.rxinv_gpio >= 0) { + hal.gpio->write(sdef.rxinv_gpio, !sdef.rxinv_polarity); + if (arx_line != 0) { + palLineSetPushPull(arx_line, PAL_PUSHPULL_PULLUP); + } } if (options & OPTION_TXINV) { if (sdef.txinv_gpio >= 0) { hal.gpio->write(sdef.txinv_gpio, sdef.txinv_polarity); + if (atx_line != 0) { + palLineSetPushPull(atx_line, PAL_PUSHPULL_PULLDOWN); + } } else { ret = false; } + } else if (sdef.txinv_gpio >= 0) { + hal.gpio->write(sdef.txinv_gpio, !sdef.txinv_polarity); + if (atx_line != 0) { + palLineSetPushPull(atx_line, PAL_PUSHPULL_PULLUP); + } } if (options & OPTION_SWAP) { ret = false;