From f8f62cd65b01fc7a7265add19ea3101ea91c9d59 Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Sat, 4 Jul 2026 11:21:10 +0200 Subject: [PATCH] drop serial on reboot for ESP --- zephcore/adapters/board/ZephyrBoard.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/zephcore/adapters/board/ZephyrBoard.cpp b/zephcore/adapters/board/ZephyrBoard.cpp index 1436adc..7a5dd16 100644 --- a/zephcore/adapters/board/ZephyrBoard.cpp +++ b/zephcore/adapters/board/ZephyrBoard.cpp @@ -20,6 +20,18 @@ #define NRF52_GPREGRET 1 #endif +/* ESP32 boards whose console is the native USB-Serial-JTAG: sys_reboot() does + * a digital soft reset but does not detach the USB PHY, so the D+ pull-up stays + * asserted and the host never sees a disconnect. On macOS the serial port then + * wedges after a settings reboot (GH #43). Drop the pad before rebooting so the + * host gets a clean disconnect/re-enumerate. Gated to exactly the boards that + * both exhibit the defect and expose the PHY knob to fix it. */ +#if defined(CONFIG_SOC_FAMILY_ESPRESSIF_ESP32) && \ + DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), espressif_esp32_usb_serial) +#include +#define ESP32_USB_SERIAL_DETACH 1 +#endif + /* LoRa TX activity LED (optional — defined per-board via DT alias) */ #if DT_NODE_EXISTS(DT_ALIAS(lora_tx_led)) static const struct gpio_dt_spec tx_led = @@ -248,6 +260,12 @@ void ZephyrBoard::onAfterTransmit() void ZephyrBoard::reboot() { k_msleep(50); /* Let UART/USB flush */ +#ifdef ESP32_USB_SERIAL_DETACH + /* Drop the D+ pull-up so the host sees a clean USB disconnect before the + * soft reset (GH #43 — wedged serial port on macOS). */ + usb_serial_jtag_ll_phy_enable_pad(false); + k_msleep(100); /* Hold SE0 long enough for host disconnect debounce */ +#endif sys_reboot(SYS_REBOOT_COLD); }