-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(reset): Automatically reconnect if port disconnects during reset. (ESPTOOL-862) #980
Conversation
👋 Hello andrewleech, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. Click to see more instructions ...
Review and merge process you can expect ...
|
e3e0ecb
to
c5d7c15
Compare
c5d7c15
to
970e037
Compare
Hello @andrewleech, The idea of reopening the port when it disappears seems good to me.
For this reason, I would suggest implementing the wrapper on the Other notes:
Thank you! |
Thanks for the feedback @radimkarnis sorry I didn't get back to you, got pulled away. I'll think more about how to reproduce the issue I'm trying to solve here - it will only occur on devices where the USB stack / connection gets reset when the chip gets reset. So certainly external usb-serial or internal usb/cdc/jtag stack is not affected. I'll look into writing a |
Thank you @andrewleech! We have merged your solution and expanded it to whole reset strategies. If you can, please try to confirm this still does the trick for you! |
That sounds great thanks! I'll certainly endeavour to test master in the next day or two. |
I've just tested master with a S3 and it's not quite performing the same - it looks like the timeout is enough for my use case.
In above log I have a S3 device running micropython updated to handle the RTS/DTR reset At the start of the log above it's connected at After this, I switched back to my branch of esptool and the install works first time. The longer timeout during the reset / retries give enough time to wait for the device to restart and reconnect to the PC in bootloader mode. I then switched back to I've used native / in-mcu usb devices a lot over the years and often find it takes up to 3-5 seconds for some devices to be fully enumerated on some PC's. This can blow out even longer if it's being used in a VM or similar! That was my rationale for initially suggesting 10 seconds for the timeout to try to capture all use cases. I'm pretty sure this timeout only comes into play after esptool has sucessfully connected to the device initially to trigger the reset? If for instance I have a different app connected to the device to start with, esptool immediately exits with a For situations like you mentioned previously during a test suite with a not responding device; perhaps the retry loop could check and wait for a more narrow range of errors, to continue to retry when the device is completely missing but error out faster if the device exists but doesn't respond? |
I also had a chance to test with S2 now, with current release esptool it fails in a similar way to the S3 for me
With this updated version (master + increased timeout), it still failed! Looks to be a different problem, in some way though. The S2 takes a long time to reset after esptool runs the RTS/DTR reset sequence, the USB bus / connection flashes up and down a couple of times before leaving the device reset back in application mode again, not in the bootloader. At this point, the new reset logic seems to just retry again, resetting it again, after which it still ends up back in application mode.... until timeout is hit. I tried adding Do you know if an application code needs to implement something specific for S2 / usb_serial_jtag_cdc hardware to handle RTS/DTR reboots to bootloader? I can't see anything in official S2 docs or Arduino HWCDC that suggests as such? |
Please note that the S2 doesn't have USB_SERIAL_JTAG peripheral, so |
Oh whoops my bad, yes I was thinking it was "only USB_SERIAL_JTAG" rather than "only native stack", of course it's the Cx chips with only USB_SERIAL_JTAG. |
Thanks for the explanation, we will consider extending the timeout to cover these cases!
That's right, if an error happens during the first instance of the port being open, this retry mechanism is not applied. |
When RTS/DTS reset is used on S3, the device / usb controller may reset as well causing the port to disconnect.
This change detects the exception thrown when this happens (only during reset) and automatically tries to reconnect the port to continue the operatrion.
This change fixes the following bug(s):
First seen during implementation of micropython/micropython#15108
When OTG is used on S3, we need to switch back to SerialJtag controller before rebooting to bootloader after detecting RTS/DTR reset pattern on the OTG port.
Currently, esptool throws a BusError or OSError during this like
I have tested this change with the following hardware & software combinations:
I've tested this only on a LilyGO T-Display-S3 so far. I don't have access to any other S3 (or S2) devices currently.
I have run the esptool.py automated integration tests with this change and the above hardware:
NO TESTING