From 34e7a5ceebb69daa7d730d0c41908385992f3301 Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Tue, 24 Oct 2023 14:12:14 +0100 Subject: [PATCH] Check tx on MSP and GPS only (#13100) --- src/main/drivers/serial.h | 3 +++ src/main/drivers/stm32/serial_uart_stm32f4xx.c | 2 +- src/main/drivers/stm32/serial_uart_stm32f7xx.c | 2 +- src/main/drivers/stm32/serial_uart_stm32g4xx.c | 2 +- src/main/drivers/stm32/serial_uart_stm32h7xx.c | 2 +- src/main/io/gps.c | 7 ++++++- src/main/msp/msp_serial.c | 2 ++ 7 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/drivers/serial.h b/src/main/drivers/serial.h index 8f13d9ca4..ea23e7e44 100644 --- a/src/main/drivers/serial.h +++ b/src/main/drivers/serial.h @@ -55,6 +55,9 @@ typedef enum { SERIAL_BIDIR_PP = 1 << 4, SERIAL_BIDIR_NOPULL = 1 << 5, // disable pulls in BIDIR RX mode SERIAL_BIDIR_PP_PD = 1 << 6, // PP mode, normall inverted, but with PullDowns, to fix SA after bidir issue fixed (#10220) + + // If this option is set then switch the TX line to input when not in use to detect it being pulled low + SERIAL_CHECK_TX = 1 << 7, } portOptions_e; // Define known line control states which may be passed up by underlying serial driver callback diff --git a/src/main/drivers/stm32/serial_uart_stm32f4xx.c b/src/main/drivers/stm32/serial_uart_stm32f4xx.c index 0ec064728..6dfa08cc8 100644 --- a/src/main/drivers/stm32/serial_uart_stm32f4xx.c +++ b/src/main/drivers/stm32/serial_uart_stm32f4xx.c @@ -342,7 +342,7 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_e mode, if ((mode & MODE_TX) && txIO) { IOInit(txIO, OWNER_SERIAL_TX, RESOURCE_INDEX(device)); - if (((options & SERIAL_INVERTED) == SERIAL_NOT_INVERTED) && !(options & SERIAL_BIDIR_PP_PD)) { + if (options & SERIAL_CHECK_TX) { uart->txPinState = TX_PIN_ACTIVE; // Switch TX to an input with pullup so it's state can be monitored uartTxMonitor(s); diff --git a/src/main/drivers/stm32/serial_uart_stm32f7xx.c b/src/main/drivers/stm32/serial_uart_stm32f7xx.c index cceaafe86..a63ff201d 100644 --- a/src/main/drivers/stm32/serial_uart_stm32f7xx.c +++ b/src/main/drivers/stm32/serial_uart_stm32f7xx.c @@ -376,7 +376,7 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_e mode, if ((mode & MODE_TX) && txIO) { IOInit(txIO, OWNER_SERIAL_TX, RESOURCE_INDEX(device)); - if (((options & SERIAL_INVERTED) == SERIAL_NOT_INVERTED) && !(options & SERIAL_BIDIR_PP_PD)) { + if (options & SERIAL_CHECK_TX) { uartdev->txPinState = TX_PIN_MONITOR; // Switch TX to UART output whilst UART sends idle preamble checkUsartTxOutput(s); diff --git a/src/main/drivers/stm32/serial_uart_stm32g4xx.c b/src/main/drivers/stm32/serial_uart_stm32g4xx.c index 41ba0791a..f98dfcac7 100644 --- a/src/main/drivers/stm32/serial_uart_stm32g4xx.c +++ b/src/main/drivers/stm32/serial_uart_stm32g4xx.c @@ -309,7 +309,7 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_e mode, if ((mode & MODE_TX) && txIO) { IOInit(txIO, OWNER_SERIAL_TX, RESOURCE_INDEX(device)); - if (((options & SERIAL_INVERTED) == SERIAL_NOT_INVERTED) && !(options & SERIAL_BIDIR_PP_PD)) { + if (options & SERIAL_CHECK_TX) { uartdev->txPinState = TX_PIN_ACTIVE; // Switch TX to an input with pullup so it's state can be monitored uartTxMonitor(s); diff --git a/src/main/drivers/stm32/serial_uart_stm32h7xx.c b/src/main/drivers/stm32/serial_uart_stm32h7xx.c index 4c5b82a07..c21a908d4 100644 --- a/src/main/drivers/stm32/serial_uart_stm32h7xx.c +++ b/src/main/drivers/stm32/serial_uart_stm32h7xx.c @@ -486,7 +486,7 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_e mode, if ((mode & MODE_TX) && txIO) { IOInit(txIO, OWNER_SERIAL_TX, RESOURCE_INDEX(device)); - if (((options & SERIAL_INVERTED) == SERIAL_NOT_INVERTED) && !(options & SERIAL_BIDIR_PP_PD)) { + if (options & SERIAL_CHECK_TX) { uartdev->txPinState = TX_PIN_ACTIVE; // Switch TX to an input with pullup so it's state can be monitored uartTxMonitor(s); diff --git a/src/main/io/gps.c b/src/main/io/gps.c index 9ceb4498a..bb82b182b 100644 --- a/src/main/io/gps.c +++ b/src/main/io/gps.c @@ -435,6 +435,7 @@ void gpsInit(void) gpsData.tempBaudRateIndex = gpsData.userBaudRateIndex; portMode_e mode = MODE_RXTX; + portOptions_e options = SERIAL_NOT_INVERTED; #if defined(GPS_NMEA_TX_ONLY) if (gpsConfig()->provider == GPS_NMEA) { @@ -442,8 +443,12 @@ void gpsInit(void) } #endif + if ((gpsPortConfig->identifier >= SERIAL_PORT_USART1) && (gpsPortConfig->identifier <= SERIAL_PORT_USART_MAX)){ + options |= SERIAL_CHECK_TX; + } + // no callback - buffer will be consumed in gpsUpdate() - gpsPort = openSerialPort(gpsPortConfig->identifier, FUNCTION_GPS, NULL, NULL, baudRates[gpsInitData[gpsData.userBaudRateIndex].baudrateIndex], mode, SERIAL_NOT_INVERTED); + gpsPort = openSerialPort(gpsPortConfig->identifier, FUNCTION_GPS, NULL, NULL, baudRates[gpsInitData[gpsData.userBaudRateIndex].baudrateIndex], mode, options); if (!gpsPort) { return; } diff --git a/src/main/msp/msp_serial.c b/src/main/msp/msp_serial.c index 08b1c0ba6..af2ced073 100644 --- a/src/main/msp/msp_serial.c +++ b/src/main/msp/msp_serial.c @@ -69,6 +69,8 @@ void mspSerialAllocatePorts(void) if (mspConfig()->halfDuplex) { options |= SERIAL_BIDIR; + } else if ((portConfig->identifier >= SERIAL_PORT_USART1) && (portConfig->identifier <= SERIAL_PORT_USART_MAX)){ + options |= SERIAL_CHECK_TX; } serialPort_t *serialPort = openSerialPort(portConfig->identifier, FUNCTION_MSP, NULL, NULL, baudRates[portConfig->msp_baudrateIndex], MODE_RXTX, options); -- 2.11.4.GIT