Skip to content

Support boards that auto-reset on serial open (DTR->RST), e.g. STM32W…#27

Open
Surfbee3 wants to merge 1 commit into
meshcore-dev:masterfrom
Surfbee3:support-serial-open-reset-boards
Open

Support boards that auto-reset on serial open (DTR->RST), e.g. STM32W…#27
Surfbee3 wants to merge 1 commit into
meshcore-dev:masterfrom
Surfbee3:support-serial-open-reset-boards

Conversation

@Surfbee3

Copy link
Copy Markdown

…L/Wio-E5

Some boards (e.g. Seeed Wio-E5 / STM32WL on a USB-UART bridge) wire DTR -> RST through a cap, so opening the serial port asserts DTR and resets the MCU. The connection then fires its handshake (deviceQuery) immediately and races the boot (~1.2-1.9 s measured), so the query is lost and the connection times out. These boards currently cannot connect to the web app / CLI at all.

This makes the client tolerate the open-time reset:

  • De-assert DTR/RTS right after open() so the line sits steady (Chrome's Web Serial and Node serialport assert DTR on open). Wrapped in try/catch; a no-op on boards that don't wire DTR to reset, and setting both low is the run-normally state for ESP-style auto-reset circuits (won't trigger the bootloader).

  • Add an optional bootDelayMs to wait for boot before handshaking. Default 0, so behaviour is unchanged for native-USB boards. Reset-on-open boards pass e.g. 2500.

    Web: WebSerialConnection.open({ bootDelayMs: 2500 })
    Node: new NodeJSSerialConnection(path, 2500)

Verified on a Seeed Wio-E5 (STM32WL) companion: getSelfInfo() round-trips with bootDelayMs=2500 where it previously timed out.

Note for app integrators: if you pass bootDelayMs, size your overall connection timeout >= bootDelayMs + handshake (the library handshake has no internal timeout).

…L/Wio-E5

Some boards (e.g. Seeed Wio-E5 / STM32WL on a USB-UART bridge) wire DTR -> RST
through a cap, so opening the serial port asserts DTR and resets the MCU. The
connection then fires its handshake (deviceQuery) immediately and races the boot
(~1.2-1.9 s measured), so the query is lost and the connection times out. These
boards currently cannot connect to the web app / CLI at all.

This makes the client tolerate the open-time reset:

- De-assert DTR/RTS right after open() so the line sits steady (Chrome's Web
  Serial and Node serialport assert DTR on open). Wrapped in try/catch; a no-op on
  boards that don't wire DTR to reset, and setting both low is the run-normally
  state for ESP-style auto-reset circuits (won't trigger the bootloader).
- Add an optional bootDelayMs to wait for boot before handshaking. Default 0, so
  behaviour is unchanged for native-USB boards. Reset-on-open boards pass e.g. 2500.

  Web:  WebSerialConnection.open({ bootDelayMs: 2500 })
  Node: new NodeJSSerialConnection(path, 2500)

Verified on a Seeed Wio-E5 (STM32WL) companion: getSelfInfo() round-trips with
bootDelayMs=2500 where it previously timed out.

Note for app integrators: if you pass bootDelayMs, size your overall connection
timeout >= bootDelayMs + handshake (the library handshake has no internal timeout).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant