-
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(esptool): Add --retry-open-serial flag, config file entry and envar (ESPTOOL-890) #995
Conversation
This is a counterpart to espressif/esp-idf-monitor#15 |
CC @sudeep-mohanty who I am sure will appreciate the feaure when developing ULP code :) |
👋 Hello 2opremio, 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 ...
|
Until espressif/esp-idf-monitor#15 and espressif/esptool#995 are upstreamed
Thanks for the contribution @2opremio! Seems like a useful feature! But, I'd let our colleagues from the esptool team to further evaluate the changes. Thanks! :) |
I am not sure I understand the |
Until espressif/esp-idf-monitor#15 and espressif/esptool#995 are upstreamed
Until espressif/esp-idf-monitor#15 and espressif/esptool#995 are upstreamed
d44c4f6
to
2f9a384
Compare
Until espressif/esp-idf-monitor#15 and espressif/esptool#995 are upstreamed
Until espressif/esp-idf-monitor#15 and espressif/esptool#995 are upstreamed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, first of all, thank you for your contribution, and I am sorry for the late response.
We have discussed this with the team and we think that this would be a nice addition to esptool. Overall we like the feature, but I have left some comments regarding the implementation.
Please let me know if you want to address them, if not we will do it by ourselves.
Thank you!
I am away this week, so, feel free to address the comments yourselves.
Otherwise I will do so next week once I am back.
On August 5, 2024, GitHub ***@***.***> wrote:
@peterdragun commented on this pull request.
Hi, first of all, thank you for your contribution, and I am sorry for
the late response.
We have discussed this with the team and we think that this would be a
nice addition to esptool. Overall we like the feature, but I have left
some comments regarding the implementation.
Please let me know if you want to address them, if not we will do it
by ourselves.
Thank you!
In docs/en/esptool/configuration-file.rst
<#995 (comment)>:
> @@ -109,6 +109,8 @@ Complete list configurable options:
+------------------------------
+-----------------------------------------------------------
+----------+ | custom_reset_sequence | Custom reset sequence for
resetting into the bootloader | | +------------------------------
+-----------------------------------------------------------
+----------+ +| retry_open_serial | Retry opening the serial port
indefinitely | False |
Please fix the indentation to match the rest of the table
In esptool/__init__.py
<#995 (comment)>:
> + parser.add_argument( + "--retry-open-serial", + help=( + "Retry
opening the serial port indefinitely. " + "Default: %s" %
DEFAULT_RETRY_OPEN_SERIAL + ), +
default=os.environ.get("ESPTOOL_RETRY_OPEN_SERIAL",
DEFAULT_RETRY_OPEN_SERIAL), + action="store_true", + )
We are trying to keep the number of arguments for esptool as slim as
possible. It should be sufficient to configure this function using ENV
and config variables.
In esptool/__init__.py
<#995 (comment)>:
> + _esp = get_default_specific_connected_device( + chip, + each_port,
+ initial_baud, + trace, + before, + connect_attempts, +
retry_open_serial, + )
I think it only makes sense to run the retry open if the user has
specified the port. In this case, it will also trigger on the auto-
detected port.
In esptool/__init__.py
<#995 (comment)>:
> + ) as e: + if not retry_open_serial: + raise + if _esp and
_esp._port: + _esp._port.close() + _esp = None + if retry_attempts ==
0: + print(e) + print("Retrying failed connection ", end="",
flush=True) + else: + if retry_attempts % 9 == 0: + # print a dot
every second + print(".", end="", flush=True) + time.sleep(0.1) +
retry_attempts += 1 + continue
this continue is not necessary
—
Reply to this email directly, view it on GitHub
<#995 (review)-
2218676394>, or unsubscribe
<https://github.com/notifications/unsubscribe-
auth/AASA4JDD7Q35K52GJ7XXKEDZP5NADAVCNFSM6AAAAABK7TMW2SVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDEMJYGY3TMMZZGQ>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
`esptool` frequently fails when trying to open the serial port of a device which deep-sleeps often: $ esptool.py --chip esp32s3 -p /dev/cu.usbmodem6101 [...] write_flash foo.bin Serial port /dev/cu.usbmodem6101 A fatal error occurred: Could not open /dev/cu.usbmodem6101, the port is busy or doesn't exist. ([Errno 35] Could not exclusively lock port [...]: [Errno 35] Resource temporarily unavailable) This makes developers add unnecessarily long sleeps when the main CPU is awake, in order to give `esptool` the chance to find the serial port. This PR adds a new flag `--retry-open-serial` (with corresponding env variable and cfg file entry) which retries opening the port indefinitely until the device shows up: $ esptool.py --chip esp32s3 -p /dev/cu.usbmodem6101 [...] write_flash --retry-open-serial foo.bin Serial port /dev/cu.usbmodem6101 [Errno 35] Could not exclusively lock port [...]: [Errno 35] Resource temporarily unavailable Retrying to open port ......................... Connecting.... Chip is ESP32-S3 (QFN56) (revision v0.2) [...]
@peterdragun PTAL. I've rebased the pre-existing code into a single commit and addressed all the comments (into a separate commit to differentiate it). |
esptool
frequently fails when trying to open the serial port of a device which deep-sleeps often:This makes developers add unnecessarily long sleepswhen the main CPU is awake, in order to give
esptool
the chance to find the serial port.This PR adds a new flag
--retry-open-serial
(with corresponding env variable and cfg file entry) which retries opening the port indefinitely until the device shows up:I have tested this change with the following hardware & software combinations:
ESP32S3 + esptool master branch
I have run the esptool.py automated integration tests with this change and the above hardware:
"NO TESTING" (I can do so if considered necessary in order to merge)
I did test the flag, the env variable and the config file entry though.