Support boards that auto-reset on serial open (DTR->RST), e.g. STM32W…#27
Open
Surfbee3 wants to merge 1 commit into
Open
Support boards that auto-reset on serial open (DTR->RST), e.g. STM32W…#27Surfbee3 wants to merge 1 commit into
Surfbee3 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…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).