From 6f536efad6df12a38da941ac0c41eabaae17e1a1 Mon Sep 17 00:00:00 2001 From: Peter van der Perk Date: Mon, 13 Apr 2026 14:48:17 +0200 Subject: [PATCH] feat(mavlink): add a raw UART mode flag The -a flag configures the port as a raw 8-bit local line without touching the baud rate, instead of the serial port setup PX4 applies to real UARTs. Virtual ttys such as the i.MX95 RPMsg proxy port to Linux need this. Co-authored-by: Hamish Willee Co-authored-by: Andre Heinemans --- src/modules/mavlink/mavlink_main.cpp | 16 +++++++++++++++- src/modules/mavlink/mavlink_main.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/mavlink/mavlink_main.cpp b/src/modules/mavlink/mavlink_main.cpp index 78626f509d5..cfa5d1c4567 100644 --- a/src/modules/mavlink/mavlink_main.cpp +++ b/src/modules/mavlink/mavlink_main.cpp @@ -790,6 +790,15 @@ Mavlink::mavlink_open_uart(const int baud, const char *uart_name, const FLOW_CON cfmakeraw(&uart_config); #endif + if (_raw_mode) { + /* no input/output processing, 8N1, no modem control; keep the baud rate */ + memset(&uart_config, 0, sizeof(uart_config)); + uart_config.c_cflag = CS8 | CREAD | CLOCAL; + uart_config.c_cc[VMIN] = 1; + cfsetispeed(&uart_config, speed); + cfsetospeed(&uart_config, speed); + } + if ((termios_state = tcsetattr(_uart_fd, TCSANOW, &uart_config)) < 0) { PX4_WARN("ERR SET CONF %s\n", uart_name); ::close(_uart_fd); @@ -2409,7 +2418,7 @@ Mavlink::task_main(int argc, char *argv[]) int temp_int_arg; #endif - while ((ch = px4_getopt(argc, argv, "b:r:d:n:u:o:m:t:c:F:fswxzZp", &myoptind, &myoptarg)) != EOF) { + while ((ch = px4_getopt(argc, argv, "b:r:d:n:u:o:m:t:c:F:fswxzZpa", &myoptind, &myoptarg)) != EOF) { switch (ch) { case 'b': if (px4_get_parameter_value(myoptarg, _baudrate) != 0) { @@ -2653,6 +2662,10 @@ Mavlink::task_main(int argc, char *argv[]) _flow_control = FLOW_CONTROL_OFF; break; + case 'a': + _raw_mode = true; + break; + default: err_flag = true; break; @@ -4028,6 +4041,7 @@ $ mavlink stream -u 14556 -s HIGHRES_IMU -r 50 PRINT_MODULE_USAGE_PARAM_FLAG('x', "Enable FTP", true); PRINT_MODULE_USAGE_PARAM_FLAG('z', "Force hardware flow control always on", true); PRINT_MODULE_USAGE_PARAM_FLAG('Z', "Force hardware flow control always off", true); + PRINT_MODULE_USAGE_PARAM_FLAG('a', "Configure serial port in raw mode (8N1, no termios processing), e.g. for NuttX RPMsg ttys", true); PRINT_MODULE_USAGE_COMMAND_DESCR("stop-all", "Stop all instances"); diff --git a/src/modules/mavlink/mavlink_main.h b/src/modules/mavlink/mavlink_main.h index 03342417852..a117351a20c 100644 --- a/src/modules/mavlink/mavlink_main.h +++ b/src/modules/mavlink/mavlink_main.h @@ -696,6 +696,7 @@ private: bool _udp_initialised{false}; FLOW_CONTROL_MODE _flow_control_mode{Mavlink::FLOW_CONTROL_OFF}; + bool _raw_mode{false}; uint64_t _last_write_success_time{0}; uint64_t _last_write_try_time{0};