Thanks to visit codestin.com
Credit goes to github.com

Skip to content

docs: Add reference for reset and boot sequence, document factory reset for esp32 & rp2. #15956

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

Merged
merged 4 commits into from
Nov 19, 2024

Conversation

projectgus
Copy link
Contributor

Summary

This started out as a task to document boot.py and main.py on the rp2 port (Closes #15230). However, I realised the boot sequence and reset types were documented per-port and sometimes inconsistent so I decided to consolidate these into a common reference page that each port can link to.

In follow-up commits I added port-specific factory reset docs for esp32 and rp2 ports. These ports don't have any MicroPython-specific recovery features like Safe Mode boots, the factory reset process is to erase the entire flash. However, now it's explicitly documented as such.

@projectgus
Copy link
Contributor Author

@TRadigk Interested if you have any comments on this PR. Does it look like it resolves your comment from here: #15230 (comment) ?

@projectgus projectgus force-pushed the doc/rp2_boot_py branch 3 times, most recently from 81fed50 to 6b401a2 Compare October 3, 2024 00:10
@projectgus projectgus changed the title docs: Add reference page for reset and boot sequence, add factory reset docs for esp32 & rp2 ports. docs: Add reference for reset and boot sequence, document factory reset for esp32 & rp2. Oct 3, 2024
@TRadigk
Copy link

TRadigk commented Oct 4, 2024

@projectgus I've checked all changes and fully agree with them. The boot sequence is clearly laid out and to be found on a top level 👍 (which helps to understand that this is not port port specific, but micropython specific). You added a way to recover from soft-bricking for every port allowing it to be found with the search and providing guidance to recover, which I also like very much.
I think this is a great addition to the docs! Thank you! 😎

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (97af100) to head (5f0a2a7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15956   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21335    21335           
=======================================
  Hits        21030    21030           
  Misses        305      305           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@projectgus
Copy link
Contributor Author

After discussion with @dpgeorge have added a commit which deprecates machine.soft_reset() and recommends sys.exit() instead.

Copy link

github-actions bot commented Oct 8, 2024

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Copy link
Contributor

@andrewleech andrewleech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look great thanks for writing them!

2. Find the serial port name of your board, and then use esptool to erase the
entire flash contents::

esptool.py -p PORTNAME erase_flash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most users these days the auto-detection of port works well - it's often only advanced users that have more than one com port on their computer at any one time. As such I'd remove the need to "find serial port name" as new users wont know how to do this.
If desired this could be split to show the basic esptool.py erase_flash first and then a short follow up paragraph on setting the port name as well if needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tries to imagine a world where there aren't nine serial devices plugged into a computer at all times
image

😁 In all seriousness, I think I agree. However, I suggest I submit a separate PR for this that also changes it in the esp32 tutorial. Also there are the download page instructions, although I'm not sure where these are generated from - maybe damien has to make that change somewhere internally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also there are the download page instructions, although I'm not sure where these are generated from

They should be in the various deploy.md files (part of the board.json and board.md set of files).

@projectgus
Copy link
Contributor Author

@andrewleech @dpgeorge Thanks for the great reviews! I've made some edits based on your suggestions, please take a look. (Apologies, I rebased so the "compare" feature in GitHub may show a lot of unrelated edits.)

@dpgeorge
Copy link
Member

I have reviewed the changes here and am happy with this PR now.

Except the commit that deprecates machine.soft_reset() in favour of sys.exit(), that needs reconsideration in the light of #15486 (comment)

@projectgus
Copy link
Contributor Author

After discussion with @dpgeorge, machine.soft_reset() is no longer deprecated as the sys.exit() behaviour may change in the future. Updated the relevant commit in this PR to document the current behaviour of sys.exit().

@projectgus
Copy link
Contributor Author

Also rewrote the suggested try/except/finally structure for main.py as the original version locked the user out of the REPL (reset in finally block). This version allows KeyboardInterrupt to drop to a REPL, a safer recommendation...

@projectgus projectgus requested a review from dpgeorge November 15, 2024 05:22
@dpgeorge
Copy link
Member

Also rewrote the suggested try/except/finally structure for main.py as the original version locked the user out of the REPL (reset in finally block). This version allows KeyboardInterrupt to drop to a REPL, a safer recommendation...

It's tricky to recommend something because in production you'd usually want the app to be as robust and secure as possible and hence not allow ctrl-C or anything to stop it, but that contradicts with having a convenient development cycle, eg using mpremote.

Anyway, what you have now is good!

Previously individual ports documented these aspects to varying degrees,
but most of the information is common to all ports.

In particular, this adds a canonical explanation of `boot.py` and
`main.py`.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
This is currently an implementation detail of MicroPython rather than by
design.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
@dpgeorge dpgeorge merged commit c5d74fe into micropython:master Nov 19, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If boot.py doesn't exit then rp2 port will never initialise USB (soft-bricked)
5 participants