espflasher: add USB-JTAG/Serial reset support for ESP32-S3/C3/C6/H2#29
Merged
deadprogram merged 1 commit intomainfrom Apr 13, 2026
Merged
espflasher: add USB-JTAG/Serial reset support for ESP32-S3/C3/C6/H2#29deadprogram merged 1 commit intomainfrom
deadprogram merged 1 commit intomainfrom
Conversation
Add proper handling for chips connected via the built-in USB-JTAG/Serial peripheral (ttyACM/usbmodem ports), where DTR/RTS ioctls on a disconnected cdc_acm fd block for ~5s each on Linux. Key changes: - Add connectViaUSBJTAG() which runs usbJTAGSerialReset in a goroutine with a 500ms timeout, then closes the stale port and reopens after USB re-enumeration. Used by ResetUSBJTAG and ResetAuto modes. - Fix usbJTAGSerialReset to match esptool's full USBJTAGSerialReset sequence: idle → set IO0 → trigger reset through (1,1) → release EN. - Fix hardReset to deassert DTR before toggling RTS on USB connections, so GPIO0=HIGH at reset and the chip boots into user code instead of bootloader mode. - Fix Reset() to use flashEnd(reboot=false) to keep the stub running and USB alive for the subsequent hardReset, and run hardReset in a goroutine to avoid blocking on the dead fd after the chip resets. - Make 64-byte USB CDC write chunking conditional on usesUSB flag to avoid unnecessary syscall overhead on UART bridge connections. - Optimize sync() to drain extra ROM responses via direct frame reads instead of sending dummy commands. - After failed sync, try reopening the port and syncing again before looping back to issue another reset. Signed-off-by: deadprogram <ron@hybridgroup.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.
Add proper handling for chips connected via the built-in USB-JTAG/Serial peripheral (ttyACM/usbmodem ports), where DTR/RTS ioctls on a disconnected cdc_acm fd block for ~5s each on Linux.
Key changes:
Add connectViaUSBJTAG() which runs usbJTAGSerialReset in a goroutine with a 500ms timeout, then closes the stale port and reopens after USB re-enumeration. Used by ResetUSBJTAG and ResetAuto modes.
Fix usbJTAGSerialReset to match esptool's full USBJTAGSerialReset sequence: idle → set IO0 → trigger reset through (1,1) → release EN.
Fix hardReset to deassert DTR before toggling RTS on USB connections, so GPIO0=HIGH at reset and the chip boots into user code instead of bootloader mode.
Fix Reset() to use flashEnd(reboot=false) to keep the stub running and USB alive for the subsequent hardReset, and run hardReset in a goroutine to avoid blocking on the dead fd after the chip resets.
Make 64-byte USB CDC write chunking conditional on usesUSB flag to avoid unnecessary syscall overhead on UART bridge connections.
Optimize sync() to drain extra ROM responses via direct frame reads instead of sending dummy commands.
After failed sync, try reopening the port and syncing again before looping back to issue another reset.