From 6be833305d555a2e4f38fe9c510dba41b40142ed Mon Sep 17 00:00:00 2001 From: wimalopaan Date: Fri, 13 Mar 2026 12:00:41 +0100 Subject: [PATCH 1/3] Target NEXUSX(R): swap rx/tx line for port A, B, C --- src/main/common/log.h | 1 + src/main/drivers/serial.h | 2 ++ src/main/drivers/serial_uart_hal.c | 8 +++++++- src/main/rx/crsf.c | 15 ++++++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/common/log.h b/src/main/common/log.h index bc6795e5dd9..ac45e48e89c 100644 --- a/src/main/common/log.h +++ b/src/main/common/log.h @@ -30,6 +30,7 @@ typedef enum { LOG_TOPIC_POS_ESTIMATOR, // 8, mask = 256 LOG_TOPIC_VTX, // 9, mask = 512 LOG_TOPIC_OSD, // 10, mask = 1024 + LOG_TOPIC_SERIAL, // 11, mask = 2048 LOG_TOPIC_COUNT, } logTopic_e; diff --git a/src/main/drivers/serial.h b/src/main/drivers/serial.h index 8e66b5f8445..12e2bb1fc64 100644 --- a/src/main/drivers/serial.h +++ b/src/main/drivers/serial.h @@ -53,6 +53,8 @@ typedef enum portOptions_t { SERIAL_LONGSTOP = 0 << 6, SERIAL_SHORTSTOP = 1 << 6, + + SERIAL_RXTX_SWAP = 1 << 7 } portOptions_t; typedef void (*serialReceiveCallbackPtr)(uint16_t data, void *rxCallbackData); // used by serial drivers to return frames to app diff --git a/src/main/drivers/serial_uart_hal.c b/src/main/drivers/serial_uart_hal.c index cce38422848..6a397385f55 100644 --- a/src/main/drivers/serial_uart_hal.c +++ b/src/main/drivers/serial_uart_hal.c @@ -27,6 +27,7 @@ #include "platform.h" #include "build/build_config.h" +#include "build/debug.h" #include "common/utils.h" #include "drivers/io.h" @@ -86,6 +87,11 @@ static void uartReconfigure(uartPort_t *uartPort) usartConfigurePinInversion(uartPort); + if (uartPort->port.options & SERIAL_RXTX_SWAP) { + debug[0] = 1; + SET_BIT(uartPort->USARTx->CR2, USART_CR2_SWAP); + } + if (uartPort->port.options & SERIAL_BIDIR) { HAL_HalfDuplex_Init(&uartPort->Handle); @@ -111,6 +117,7 @@ static void uartReconfigure(uartPort_t *uartPort) /* Enable the UART Transmit Data Register Empty Interrupt */ SET_BIT(uartPort->USARTx->CR1, USART_CR1_TXEIE); } + return; } @@ -155,7 +162,6 @@ serialPort_t *uartOpen(USART_TypeDef *USARTx, serialReceiveCallbackPtr callback, return (serialPort_t *)s; } - // common serial initialisation code should move to serialPort::init() s->port.rxBufferHead = s->port.rxBufferTail = 0; s->port.txBufferHead = s->port.txBufferTail = 0; diff --git a/src/main/rx/crsf.c b/src/main/rx/crsf.c index e5855205642..b287bb19b9f 100755 --- a/src/main/rx/crsf.c +++ b/src/main/rx/crsf.c @@ -29,6 +29,7 @@ #include "common/crc.h" #include "common/maths.h" #include "common/utils.h" +#include "common/log.h" #include "drivers/time.h" #include "drivers/serial.h" @@ -329,13 +330,25 @@ bool crsfRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig) return false; } + portOptions_t options = CRSF_PORT_OPTIONS | (tristateWithDefaultOffIsActive(rxConfig->halfDuplex) ? SERIAL_BIDIR : 0); + +#if defined(NEXUSX) + if ((portConfig->identifier == SERIAL_PORT_USART3) || // Port C + (portConfig->identifier == SERIAL_PORT_USART4) || // Port A + (portConfig->identifier == SERIAL_PORT_USART6)) // Port B + { + LOG_DEBUG(SERIAL, "crsfRxInit rxtx swap"); + options |= SERIAL_RXTX_SWAP; + } +#endif + serialPort = openSerialPort(portConfig->identifier, FUNCTION_RX_SERIAL, crsfDataReceive, NULL, CRSF_BAUDRATE, CRSF_PORT_MODE, - CRSF_PORT_OPTIONS | (tristateWithDefaultOffIsActive(rxConfig->halfDuplex) ? SERIAL_BIDIR : 0) + options ); return serialPort != NULL; From 9bb689a72b9f6a86f6fb0b9b75bc91e89d9df62c Mon Sep 17 00:00:00 2001 From: wimalopaan Date: Fri, 13 Mar 2026 12:11:26 +0100 Subject: [PATCH 2/3] removed debug value, formatting --- src/main/drivers/serial_uart_hal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/drivers/serial_uart_hal.c b/src/main/drivers/serial_uart_hal.c index 6a397385f55..e473db85ce0 100644 --- a/src/main/drivers/serial_uart_hal.c +++ b/src/main/drivers/serial_uart_hal.c @@ -87,8 +87,8 @@ static void uartReconfigure(uartPort_t *uartPort) usartConfigurePinInversion(uartPort); - if (uartPort->port.options & SERIAL_RXTX_SWAP) { - debug[0] = 1; + if (uartPort->port.options & SERIAL_RXTX_SWAP) + { SET_BIT(uartPort->USARTx->CR2, USART_CR2_SWAP); } From 96f6ee5a52697fb7b9142f87e77504b170d5bb0e Mon Sep 17 00:00:00 2001 From: wimalopaan Date: Sat, 14 Mar 2026 17:33:15 +0100 Subject: [PATCH 3/3] intermediate commit: do not merge first step towards dynamic rx/tx swap for CRSF RX serial --- src/main/config/parameter_group_ids.h | 3 ++- src/main/fc/config.c | 7 +++++++ src/main/fc/config.h | 7 +++++++ src/main/fc/settings.yaml | 10 ++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/config/parameter_group_ids.h b/src/main/config/parameter_group_ids.h index 2acb9c8172e..2797cbe200f 100644 --- a/src/main/config/parameter_group_ids.h +++ b/src/main/config/parameter_group_ids.h @@ -132,7 +132,8 @@ #define PG_GEOZONE_CONFIG 1042 #define PG_GEOZONES 1043 #define PG_GEOZONE_VERTICES 1044 -#define PG_INAV_END PG_GEOZONE_VERTICES +#define PG_CRSFRXPORT_CONFIG 1045 +#define PG_INAV_END PG_CRSFRXPORT_CONFIG // OSD configuration (subject to change) //#define PG_OSD_FONT_CONFIG 2047 diff --git a/src/main/fc/config.c b/src/main/fc/config.c index d3021317ae5..130576d742f 100755 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -131,6 +131,13 @@ PG_RESET_TEMPLATE(beeperConfig_t, beeperConfig, .pwmMode = SETTING_BEEPER_PWM_MODE_DEFAULT, ); +PG_REGISTER_WITH_RESET_TEMPLATE(crsfRxPortConfig_t, crsfRxPortConfig, PG_CRSFRXPORT_CONFIG, 1); + +PG_RESET_TEMPLATE(crsfRxPortConfig_t, crsfRxPortConfig, + .swap = 0, + .preferred_swap = 0 +); + PG_REGISTER_WITH_RESET_TEMPLATE(adcChannelConfig_t, adcChannelConfig, PG_ADC_CHANNEL_CONFIG, 0); PG_RESET_TEMPLATE(adcChannelConfig_t, adcChannelConfig, diff --git a/src/main/fc/config.h b/src/main/fc/config.h index e3bde5f3eb7..f26ac0bc9b2 100644 --- a/src/main/fc/config.h +++ b/src/main/fc/config.h @@ -94,6 +94,13 @@ typedef struct beeperConfig_s { PG_DECLARE(beeperConfig_t, beeperConfig); +typedef struct CrsfRxPortConfig_s { + bool swap; + bool preferred_swap; +} crsfRxPortConfig_t; + +PG_DECLARE(crsfRxPortConfig_t, crsfRxPortConfig); + typedef struct adcChannelConfig_s { uint8_t adcFunctionChannel[ADC_FUNCTION_COUNT]; } adcChannelConfig_t; diff --git a/src/main/fc/settings.yaml b/src/main/fc/settings.yaml index 476dfe09ff7..8afda2614f4 100644 --- a/src/main/fc/settings.yaml +++ b/src/main/fc/settings.yaml @@ -4244,6 +4244,16 @@ groups: default_value: OFF description: "Allows disabling PWM mode for beeper on some targets. Switch from ON to OFF if the external beeper sound is weak. Do not switch from OFF to ON without checking if the board supports PWM beeper mode" + - name: PG_CRSFRXPORT_CONFIG + type: crsfRxPortConfig_t + headers: [ "fc/config.h" ] + members: + - name: crsf_rx_swap + field: swap + type: bool + default_value: OFF + description: "Swaps rx/tx for CRSF RX uart" + - name: PG_POWER_LIMITS_CONFIG type: powerLimitsConfig_t headers: ["flight/power_limits.h"]