diff --git a/ROMFS/px4fmu_common/init.d/rcS b/ROMFS/px4fmu_common/init.d/rcS index fc4d8a2b34f..745cd969f2a 100644 --- a/ROMFS/px4fmu_common/init.d/rcS +++ b/ROMFS/px4fmu_common/init.d/rcS @@ -550,10 +550,12 @@ else else commander start - # PASSTHRU_EN > 0 (serial passthrough or ESC configuration): - # leave the ESC lines free, it is reset below for the next boot - if ! param greater -s PASSTHRU_EN 0 + if param greater -s PASSTHRU_EN 0 then + # serial passthrough requested: leave the ESC lines free and + # reset so the next boot starts the outputs normally + param set PASSTHRU_EN 0 + else dshot start pwm_out start fi @@ -619,12 +621,6 @@ else fi fi - # After cdcacm_autostart, which reads PASSTHRU_EN=2 at start - if param greater -s PASSTHRU_EN 0 - then - param set PASSTHRU_EN 0 - fi - # # Play the startup tune (if not disabled or there is an error) # diff --git a/Tools/esc_4way.py b/Tools/esc_4way.py index e032ea58732..28a9038217e 100755 --- a/Tools/esc_4way.py +++ b/Tools/esc_4way.py @@ -34,7 +34,7 @@ """ESC configuration over a flight controller's MSP + 4way interface. -Talks to the PX4 esc_4way server (USB port after PASSTHRU_EN=2), any other +Talks to the PX4 esc_4way server (USB port with SYS_USB_AUTO=1) or any other MSP + 4way flight controller. Tools/esc_4way.py [--setup] [--no-exit] [-d DEVICE] [--target N] COMMAND @@ -49,10 +49,10 @@ MSP + 4way flight controller. settings AM32 settings block, raw and decoded direction set 0|1 AM32 motor direction (or: direction toggle) -A port that sends MAVLink heartbeats is switched to the ESC configuration -server first (PASSTHRU_EN=2 and a reboot, needs pymavlink), and the tool waits -for MAVLink to come back after the session; --setup does that switch without -listening for heartbeats first. --no-exit leaves the session open: the port then +A port that sends MAVLink heartbeats is first freed for the ESC configuration +server: the tool sets SYS_USB_AUTO=1, which stays set, and reboots the board +(needs pymavlink); --setup does that without listening for heartbeats first. +--no-exit leaves the session open: the port then keeps DTR raised after it is closed, also for other programs, until a run without --no-exit or the board's next reboot. Exit code 0 on success. @@ -381,7 +381,7 @@ def run(fd, no_esc, variant, target, toggle_direction=False): step('InterfaceExit') -# MAVLink entry and exit (PX4 only) +# MAVLink entry (PX4 only) def _wait_port(path, timeout=30): """Wait for a serial device to drop and come back (a reboot); returns its current path. @@ -449,43 +449,35 @@ def _after_reboot(path, timeout, baud): raise CheckFailed(f'{path}: {e}') -def mavlink_esc_mode(path, enter=True, baud=115200): - """Move a PX4 board on a MAVLink serial port into or out of the ESC configuration server. +def mavlink_esc_mode(path, baud=115200): + """Free the MAVLink USB port of a PX4 board for the ESC configuration server. - enter=True: PASSTHRU_EN=2, wait for its echo and the parameter autosave, reboot, wait for - the port to return and confirm it is quiet (no heartbeat for 3 s). Returns the port path. - enter=False: after InterfaceExit of a served session the board reboots; wait for the port and - its heartbeat (normal MAVLink mode). Returns the port path. + SYS_USB_AUTO=1 (the port then starts whatever talks to it first, and stays that way), wait for + its echo and the parameter autosave, reboot, wait for the port to return and confirm it is + quiet (no heartbeat for 3 s). Returns the port path. """ mavutil = _mavutil() - - if not enter: - path, hb = _after_reboot(path, 30, baud) - check(hb, f'{path}: no heartbeat after the session') - print(f'MAVLink heartbeat on {path} (sysid {hb.get_srcSystem()}): normal mode restored') - return path - mav = mavutil.mavlink_connection(path, baud=baud) hb = _heartbeat(mav, 3) if hb is None: mav.close() - print(f'{path}: no heartbeat, assuming the ESC configuration server is already running') + print(f'{path}: no heartbeat, assuming the port already waits for its first program') return path mav.target_system, mav.target_component = hb.get_srcSystem(), hb.get_srcComponent() - print('Setting PASSTHRU_EN=2') - mav.mav.param_set_send(mav.target_system, mav.target_component, b'PASSTHRU_EN', - struct.unpack(' info`. -The server is started manually in this case, so `PASSTHRU_EN` and USB auto-detection are not involved. +The server is started manually in this case, so USB auto-detection is not involved. Stop it with `esc_4way stop`, or reboot the flight controller. ## USB Vendor ID @@ -114,7 +103,7 @@ CONFIG_SERIALPASSTHROUGH_BITBANG=y CONFIG_DRIVERS_ESC_4WAY=y ``` -`PASSTHRU_EN=2` and USB auto-detection need the board's USB port to be managed by `cdcacm_autostart` (`CONFIG_DRIVERS_CDCACM_AUTOSTART=y`); without it, start the server manually with `esc_4way start -d `. +USB auto-detection needs the board's USB port to be managed by `cdcacm_autostart` (`CONFIG_DRIVERS_CDCACM_AUTOSTART=y`); without it, start the server manually with `esc_4way start -d `. On STM32 boards the UART bit timing comes from a spare hardware timer, `CONFIG_UART_BITBANG_TIMER` (default `13`). That timer must be enabled in the board's NuttX configuration (`CONFIG_STM32H7_TIM13=y` or `CONFIG_STM32F7_TIM13=y` in `nuttx-config/nsh/defconfig`), and nothing else on the board may use it: not the HRT, the tone alarm, an LED, or a PWM/DShot output timer. diff --git a/src/drivers/cdcacm_autostart/cdcacm_autostart.cpp b/src/drivers/cdcacm_autostart/cdcacm_autostart.cpp index 1096ce6e661..1cd93de4e62 100644 --- a/src/drivers/cdcacm_autostart/cdcacm_autostart.cpp +++ b/src/drivers/cdcacm_autostart/cdcacm_autostart.cpp @@ -92,13 +92,6 @@ int CdcAcmAutostart::Start() PX4_INFO("Starting CDC/ACM autostart"); UpdateParams(true); -#if defined(CONFIG_DRIVERS_ESC_4WAY) - // Read before rcS resets PASSTHRU_EN for the next boot - int32_t passthru_en = 0; - param_get(param_find("PASSTHRU_EN"), &passthru_en); - _esc_4way = (passthru_en == 2); -#endif - ScheduleNow(); return PX4_OK; @@ -228,8 +221,7 @@ void CdcAcmAutostart::state_connecting() // /dev/ttyACM0 immediately, but open() returns -ENOTCONN until the host has // enumerated. mavlink exits if its own open retries run out, so only spawn it // once the port is known to be openable, then release the probe. - // PASSTHRU_EN=2 starts the ESC configuration server the same way, instead of MAVLink. - if (_sys_usb_auto.get() == 2 || _esc_4way) { + if (_sys_usb_auto.get() == 2) { if (_ttyacm_fd < 0) { _ttyacm_fd = px4_open(USB_DEVICE_PATH, O_RDONLY | O_NONBLOCK); } @@ -240,11 +232,11 @@ void CdcAcmAutostart::state_connecting() } close_ttyacm(); - PX4_INFO("Starting %s on %s", _esc_4way ? "esc_4way" : "mavlink", USB_DEVICE_PATH); + PX4_INFO("Starting mavlink on %s (SYS_USB_AUTO=2)", USB_DEVICE_PATH); - if (_esc_4way ? start_esc_4way() : start_mavlink()) { + if (start_mavlink()) { _state = UsbAutoStartState::connected; - _active_protocol = _esc_4way ? UsbProtocol::esc_4way : UsbProtocol::mavlink; + _active_protocol = UsbProtocol::mavlink; } else { _state = UsbAutoStartState::disconnecting; @@ -603,6 +595,7 @@ bool CdcAcmAutostart::start_nsh() return execute_process(argv) > 0; } +#if defined(CONFIG_DRIVERS_ESC_4WAY) // The server stops the output drivers itself at the first valid request bool CdcAcmAutostart::start_esc_4way() { @@ -618,12 +611,9 @@ bool CdcAcmAutostart::start_esc_4way() char *argv[] { (char *)"esc_4way", (char *)"start", (char *)"-d", (char *)USB_DEVICE_PATH, (char *)"-r", request, nullptr }; - if (request[0] == '\0') { - argv[4] = nullptr; - } - return execute_process(argv) > 0; } +#endif #if defined(CONFIG_SERIAL_PASSTHRU_UBLOX) bool CdcAcmAutostart::start_ublox_serial_passthru(speed_t baudrate) diff --git a/src/drivers/cdcacm_autostart/cdcacm_autostart.h b/src/drivers/cdcacm_autostart/cdcacm_autostart.h index 3f6f125a40a..2609ce99627 100644 --- a/src/drivers/cdcacm_autostart/cdcacm_autostart.h +++ b/src/drivers/cdcacm_autostart/cdcacm_autostart.h @@ -107,7 +107,9 @@ private: bool start_mavlink(); void stop_mavlink(); bool start_nsh(); +#if defined(CONFIG_DRIVERS_ESC_4WAY) bool start_esc_4way(); +#endif #if defined(CONFIG_SERIAL_PASSTHRU_UBLOX) bool start_ublox_serial_passthru(speed_t baudrate); #endif @@ -120,12 +122,13 @@ private: UsbProtocol _active_protocol{UsbProtocol::none}; bool _vbus_present{false}; bool _vbus_present_prev{false}; - bool _esc_4way{false}; ///< PASSTHRU_EN=2 at boot: ESC configuration server instead of MAVLink int _ttyacm_fd{-1}; char _buffer[80] {}; int _bytes_read{0}; - int _msp_offset{-1}; ///< start of the MSP request found in _buffer, handed to esc_4way +#if defined(CONFIG_DRIVERS_ESC_4WAY) + int _msp_offset {-1}; ///< start of the MSP request found in _buffer, handed to esc_4way +#endif uint32_t _reschedule_time{0}; diff --git a/src/drivers/esc_4way/Kconfig b/src/drivers/esc_4way/Kconfig index 700244bc862..de0e0508297 100644 --- a/src/drivers/esc_4way/Kconfig +++ b/src/drivers/esc_4way/Kconfig @@ -6,6 +6,7 @@ menuconfig DRIVERS_ESC_4WAY Serves the BLHeli/AM32 4way interface protocol to ESC configurators (am32.ca, esc-configurator.com) through the flight controller: MSP on the host side, the ESC bootloader protocol on the ESC signal pins via - the bit-bang UART backend. Started by cdcacm_autostart when - PASSTHRU_EN=2 or by "esc_4way start -d ". The outputs are - stopped for the session and the board reboots afterwards. + the bit-bang UART backend. Started by cdcacm_autostart on an MSP + request when SYS_USB_AUTO=1, or by "esc_4way start -d ". + The outputs are stopped for the session and the board reboots + afterwards. diff --git a/src/drivers/esc_4way/esc_4way.cpp b/src/drivers/esc_4way/esc_4way.cpp index e1e833e4f4a..e8f0d02390d 100644 --- a/src/drivers/esc_4way/esc_4way.cpp +++ b/src/drivers/esc_4way/esc_4way.cpp @@ -877,7 +877,8 @@ on the outputs assigned to motors. At the first valid request it stops the dshot session ends with a reboot when the configurator disconnects, the USB host closes the port or the serial device goes away. Requests are ignored while armed. -Started by cdcacm_autostart on the USB port when `PASSTHRU_EN` is 2, or manually on any serial port. +Started by cdcacm_autostart on the USB port when `SYS_USB_AUTO` is 1 and an ESC configurator +connects first, or manually on any serial port. ### Examples $ esc_4way start -d /dev/ttyACM0 diff --git a/src/drivers/serialpassthrough/module.yaml b/src/drivers/serialpassthrough/module.yaml index 036ace3f170..dc42709c9bc 100644 --- a/src/drivers/serialpassthrough/module.yaml +++ b/src/drivers/serialpassthrough/module.yaml @@ -5,12 +5,11 @@ parameters: definitions: PASSTHRU_EN: description: - short: Serial passthrough mode - long: When not 0, dshot and pwm_out are not started at boot and the parameter resets to 0, so the next boot starts them again. - type: enum - values: - 0: Disabled - 1: MAVLink serial passthrough (SERIAL_CONTROL to the ESC pins) - 2: USB ESC configuration server (esc_4way instead of MAVLink, for am32.ca or esc-configurator.com) + short: Serial passthrough enable + long: | + When enabled, the serial passthrough mode is active and the + normal motor output drivers (dshot, pwm_out) are not started + at boot. + type: boolean default: 0 reboot_required: true