Replies: 2 comments 2 replies
-
|
After several discussions about machine.reset() and a current search on AI doing machine.reset() is not the same as pressing the reset button.
|
Beta Was this translation helpful? Give feedback.
-
Good point. I'll need to add that to the diagram. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was triggered by reading a comment from @robert-hh that
main.pyis not executed when runningmachine.reset()in raw-REPLand I had various other tidbits drifting around on boot.mpy main.mpy not being executed from the filesystem.
To me a picture helps clarify matters , so that is what I coded (in Mermaid) .
but because I cannot test everything on all board, and there appear to be a few inconsistencies in the docs
I'm looking for:
P.S. If you want to see the mermaid code, just use the copy button and paste somewhere
MicroPython reset and boot flow
This diagram summarizes reset entry points and the startup sequence described in
the reset/boot reference.
flowchart TD COLD["Cold start (power on)"] RESET["Reset button"] M_RESET["machine.reset()"] %% order of the main stages HW --> VM HARD --> VM_INIT BOOT --> APPSTAGE --> REPLSTAGE %% SOFT_RESET --> VM_RESET COLD --> HARD RESET --> HARD M_RESET --> HARD subgraph HW["Hardware stage"] HARD["full MCU reset and hardware re-init"] end VM_INIT --> VM_RESET VM_RESET--> SAFE_MODE %%------------------------------------------------------------------- subgraph VM["MicroPyton VM"] VM_INIT@{ shape: start, label: "VM init" } VM_RESET SAFE_MODE@{ shape: card, label: "Safe mode ? STM32 and renesas-ra only" } SAFE_MODE -- NORMAL --> BOOT SAFE_MODE -- SAFE --> REPL %%------------------------------------------------------------------- subgraph BOOT["Boot stage"] %%HAS_PBOOT(["_boot.py ?"]) RUN_PBOOT@{ shape: card, label: "if exist: exec _boot.py" } %%HAS_BOOT(["boot.py ?"]) RUN_BOOT@{ shape: card, label: "if exist: exec boot.py" } end RUN_PBOOT --> RUN_BOOT --> HAS_MAIN %%------------------------------------------------------------------- subgraph APPSTAGE["Application stage"] HAS_MAIN@{ shape: card, label: "if exist: main.py, AND NOT in raw REPL"} subgraph YOURAPP["YOURAPP"] RUNMAIN["exec main.py"] A@{ shape: processes, label: "imported modules" } end end %% SOFT_RESET --> VM_RESET %%HAS_PBOOT -- Yes --> RUN_PBOOT --> HAS_BOOT %%HAS_PBOOT -- No --> HAS_BOOT %%HAS_BOOT -- Yes --> RUN_BOOT --> HAS_MAIN %%HAS_BOOT -- No --> HAS_MAIN HAS_MAIN -- No --> REPL HAS_MAIN -- Yes --> RUNMAIN --> REPL %%------------------------------------------------------------------- subgraph REPLSTAGE["REPL"] TO_RESET@{ shape: start } REPL["Interactive REPL"] RAWREPL["RAW REPL"] %% PASTEMODE["Paste mode"] end %% REPL REPL -- CTRL-A --> RAWREPL %%REPL -- CTRL-B --> CTRL_B %%REPL -- CTRL-C --> CTRL_C REPL -- CTRL-D --> TO_RESET RAWREPL -- CTRL-B --> REPL RAWREPL -- CTRL-D --> TO_RESET TO_RESET --> VM_RESET %% Paste mode not relevant for boot flow, but included for completeness %% REPL -- CTRL-E --> PASTEMODE %% PASTEMODE -- CTRL-D --> REPL %% PASTEMODE -- CTRL-C --> REPL endNotes
machine.reset().machine.soft_reset()andCtrl-Dat REPL._boot.pyruns first (frozen in firmware), thenboot.py, thenmain.py.main.pyis missing, or it exits, the REPL starts.main.pystartup.boot.pyandmain.py.main.pyexists, it is run first and cannot beoverridden by filesystem
main.pyormain.mpy.modules because filesystem paths are searched before
.frozenby defaultsys.pathorder.boot.mpy/main.mpyon the filesystem are not auto-executed as startupentry points.
.mpyat startup, import pre-compiled modules fromboot.pyormain.py, or freeze modules namedboot.py/main.pyinto firmware.port specifics
Port-specific startup-script selection hooks:
pyb.main(filename)is supported on stm32 and renesas-ra, andmachine.main(filename)is supported on cc3200/WiPy. These are intended tobe called from
boot.pyto choose which script is run in the main stage.Built-in safe-boot mode (skip
boot.py/main.py) is implemented only on:stm32/pyboard, renesas-ra, and wipy/cc3200.
Beta Was this translation helpful? Give feedback.
All reactions