Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Jul 17, 2024

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 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:

$ 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)
[...]

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.

@2opremio
Copy link
Contributor Author

This is a counterpart to espressif/esp-idf-monitor#15

@2opremio
Copy link
Contributor Author

2opremio commented Jul 17, 2024

CC @sudeep-mohanty who I am sure will appreciate the feaure when developing ULP code :)

Copy link

github-actions bot commented Jul 17, 2024

Messages
📖 🎉 Good Job! All checks are passing!

👋 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 ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests via this public GitHub repository.

This GitHub project is public mirror of our internal git repository

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved, we synchronize it into our internal git repository.
4. In the internal git repository we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
5. If the change is approved and passes the tests it is merged into the default branch.
5. On next sync from the internal git repository merged change will appear in this public GitHub repository.

Generated by 🚫 dangerJS against 940e1dc

@github-actions github-actions bot changed the title feat(esptool): Add --retry-open-serial flag, config file entry and envar feat(esptool): Add --retry-open-serial flag, config file entry and envar (ESPTOOL-890) Jul 17, 2024
2opremio added a commit to 2opremio/esp-idf that referenced this pull request Jul 17, 2024
@sudeep-mohanty
Copy link

CC @sudeep-mohanty who I am sure will appreciate the feaure when developing ULP code :)

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! :)

@2opremio
Copy link
Contributor Author

I am not sure I understand the linux-arm32 error on CI but it seems it's also failing in master

2opremio added a commit to 2opremio/esp-idf that referenced this pull request Jul 17, 2024
2opremio added a commit to 2opremio/esp-idf that referenced this pull request Jul 17, 2024
@2opremio 2opremio force-pushed the retry-open branch 2 times, most recently from d44c4f6 to 2f9a384 Compare July 18, 2024 23:46
2opremio added a commit to 2opremio/esp-idf that referenced this pull request Jul 19, 2024
2opremio added a commit to 2opremio/esp-idf that referenced this pull request Jul 27, 2024
Copy link
Collaborator

@peterdragun peterdragun left a 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!

docs/en/esptool/configuration-file.rst Outdated Show resolved Hide resolved
esptool/__init__.py Outdated Show resolved Hide resolved
esptool/__init__.py Outdated Show resolved Hide resolved
esptool/__init__.py Outdated Show resolved Hide resolved
@2opremio
Copy link
Contributor Author

2opremio commented Aug 5, 2024 via email

`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)
[...]
@2opremio
Copy link
Contributor Author

2opremio commented Aug 25, 2024

@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).

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.

3 participants