diff --git a/components/system/README.md b/components/system/README.md index cab0570b23..2c5ed5d528 100644 --- a/components/system/README.md +++ b/components/system/README.md @@ -63,6 +63,7 @@ over HTTPS, or HTTP on localhost; a `file://` copy loses the grant on reload. - [System Component](#system-component) - [Protocol (module 7, `espp.system` v1)](#protocol-module-7-esppsystem-v1) + - [Host side: release the device before it resets](#host-side-release-the-device-before-it-resets) - [Example](#example) @@ -96,6 +97,33 @@ u32), 22 capabilities (u32: bit0 reboot allowed, bit1 bootloader reboot allowed and supported). The delay is clamped to at least `Config::min_restart_delay` so the OK reply leaves the transport before the restart. +## Host side: release the device before it resets + +A host that sends **REBOOT_TO_BOOTLOADER** over USB must have let go of the +device before the reset fires. A device that is still open and claimed at that +moment (a WebUSB interface with an IN transfer pending, a pyusb handle, an open +serial port) can leave the host holding a stale record of it; macOS in +particular. Then the ROM's USB device, which has other ids, does not enumerate +until the board is unplugged and plugged back in. To the user it looks as if the +device hung on its way into the bootloader. + +So, in a host (a web page, a script, a tool): + +1. Ask for a delay long enough to close the connection first: at least + **1000 ms**. The System Console sends `max(1000, the delay box)` for a + bootloader reboot. +2. As soon as the OK reply arrives, stop anything that keeps transfers in + flight (e.g. a monitor stream), release the interface and close the device + (WebUSB: `releaseInterface()` then `close()`; Web Serial: cancel the reader + and `close()` the port). If the link drops before the OK, the device is + already on its way; close your side the same way. +3. Only then wait for the ROM's device: it enumerates with different ids + (USB-Serial-JTAG `303a:1001` or the ROM's USB CDC `303a:0009` on the + ESP32-S3), so look for it rather than reconnecting to the old one. + +A plain **REBOOT** comes back with the same ids and is reconnected the usual +way, but the same order (close, then let it reset) never hurts. + ## Example The [example](./example) exposes `SystemService` and `MonitorService` on the diff --git a/components/system/include/detail/system_protocol.hpp b/components/system/include/detail/system_protocol.hpp index 717f81ac82..1d4a328194 100644 --- a/components/system/include/detail/system_protocol.hpp +++ b/components/system/include/detail/system_protocol.hpp @@ -13,6 +13,11 @@ // 0x01 GET_INFO (no payload) // 0x02 REBOOT [delay_ms u16] // 0x03 REBOOT_TO_BOOTLOADER [delay_ms u16] +// A host should ask for a delay long enough to +// close its connection first (>= 1000 ms) and +// close it as soon as the OK arrives: see the +// component README, "Host side: release the +// device before it resets". // Replies (device -> host, high bit set = frame reply flag): // 0x81 INFO a list of tagged records [tag u8][len u8][value...]; a host // skips tags it does not know, so fields can be added without a diff --git a/components/system/web/system_console.html b/components/system/web/system_console.html index f8e69fdece..56b3e0f972 100644 --- a/components/system/web/system_console.html +++ b/components/system/web/system_console.html @@ -1659,8 +1659,17 @@