Skip to content

Commit 0e7c390

Browse files
projectgusdpgeorge
authored andcommitted
docs: Add a "Reset and Boot Sequence" reference page.
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]>
1 parent cbffe61 commit 0e7c390

File tree

15 files changed

+311
-74
lines changed

15 files changed

+311
-74
lines changed

docs/esp8266/general.rst

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -74,40 +74,7 @@ as possible after use.
7474
Boot process
7575
------------
7676

77-
On boot, MicroPython EPS8266 port executes ``_boot.py`` script from internal
78-
frozen modules. It mounts filesystem in FlashROM, or if it's not available,
79-
performs first-time setup of the module and creates the filesystem. This
80-
part of the boot process is considered fixed, and not available for customization
81-
for end users (even if you build from source, please refrain from changes to
82-
it; customization of early boot process is available only to advanced users
83-
and developers, who can diagnose themselves any issues arising from
84-
modifying the standard process).
85-
86-
Once the filesystem is mounted, ``boot.py`` is executed from it. The standard
87-
version of this file is created during first-time module set up and has
88-
commands to start a WebREPL daemon (disabled by default, configurable
89-
with ``webrepl_setup`` module), etc. This
90-
file is customizable by end users (for example, you may want to set some
91-
parameters or add other services which should be run on
92-
a module start-up). But keep in mind that incorrect modifications to boot.py
93-
may still lead to boot loops or lock ups, requiring to reflash a module
94-
from scratch. (In particular, it's recommended that you use either
95-
``webrepl_setup`` module or manual editing to configure WebREPL, but not
96-
both).
97-
98-
As a final step of boot procedure, ``main.py`` is executed from filesystem,
99-
if exists. This file is a hook to start up a user application each time
100-
on boot (instead of going to REPL). For small test applications, you may
101-
name them directly as ``main.py``, and upload to module, but instead it's
102-
recommended to keep your application(s) in separate files, and have just
103-
the following in ``main.py``::
104-
105-
import my_app
106-
my_app.main()
107-
108-
This will allow to keep the structure of your application clear, as well as
109-
allow to install multiple applications on a board, and switch among them.
110-
77+
See :doc:`/reference/reset_boot`.
11178

11279
Known Issues
11380
------------

docs/esp8266/quickref.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ sys.stdin.read() if it's needed to read characters from the UART(0)
163163
while it's also used for the REPL (or detach, read, then reattach).
164164
When detached the UART(0) can be used for other purposes.
165165

166-
If there are no objects in any of the dupterm slots when the REPL is
167-
started (on hard or soft reset) then UART(0) is automatically attached.
168-
Without this, the only way to recover a board without a REPL would be to
169-
completely erase and reflash (which would install the default boot.py which
166+
If there are no objects in any of the dupterm slots when the REPL is started (on
167+
:doc:`hard or soft reset </reference/reset_boot>`) then UART(0) is automatically
168+
attached. Without this, the only way to recover a board without a REPL would be
169+
to completely erase and reflash (which would install the default boot.py which
170170
attaches the REPL).
171171

172172
To detach the REPL from UART0, use::

docs/library/builtins.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ Exceptions
170170

171171
.. exception:: KeyboardInterrupt
172172

173+
|see_cpython| `python:KeyboardInterrupt`.
174+
175+
See also in the context of :ref:`soft_bricking`.
176+
173177
.. exception:: KeyError
174178

175179
.. exception:: MemoryError

docs/library/machine.RTC.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Methods
8383
a `bytes` object.
8484

8585
Data written to RTC user memory is persistent across restarts, including
86-
`machine.soft_reset()` and `machine.deepsleep()`.
86+
:ref:`soft_reset` and `machine.deepsleep()`.
8787

8888
The maximum length of RTC user memory is 2048 bytes by default on esp32,
8989
and 492 bytes on esp8266.

docs/library/machine.USBDevice.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ Managing a runtime USB interface can be tricky, especially if you are communicat
3232
with MicroPython over a built-in USB-CDC serial port that's part of the same USB
3333
device.
3434

35-
- A MicroPython soft reset will always clear all runtime USB interfaces, which
36-
results in the entire USB device disconnecting from the host. If MicroPython
37-
is also providing a built-in USB-CDC serial port then this will re-appear
38-
after the soft reset.
35+
- A MicroPython :ref:`soft reset <soft_reset>` will always clear all runtime USB
36+
interfaces, which results in the entire USB device disconnecting from the
37+
host. If MicroPython is also providing a built-in USB-CDC serial port then
38+
this will re-appear after the soft reset.
3939

4040
This means some functions (like ``mpremote run``) that target the USB-CDC
4141
serial port will immediately fail if a runtime USB interface is active,
@@ -44,9 +44,9 @@ device.
4444
no more runtime USB interface.
4545

4646
- To configure a runtime USB device on every boot, it's recommended to place the
47-
configuration code in the ``boot.py`` file on the :ref:`device VFS
47+
configuration code in the :ref:`boot.py` file on the :ref:`device VFS
4848
<filesystem>`. On each reset this file is executed before the USB subsystem is
49-
initialised (and before ``main.py``), so it allows the board to come up with the runtime
49+
initialised (and before :ref:`main.py`), so it allows the board to come up with the runtime
5050
USB device immediately.
5151

5252
- For development or debugging, it may be convenient to connect a hardware

docs/library/machine.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ Reset related functions
6262

6363
.. function:: reset()
6464

65-
Resets the device in a manner similar to pushing the external RESET
66-
button.
65+
:ref:`Hard resets <hard_reset>` the device in a manner similar to pushing the
66+
external RESET button.
6767

6868
.. function:: soft_reset()
6969

70-
Performs a soft reset of the interpreter, deleting all Python objects and
71-
resetting the Python heap. It tries to retain the method by which the user
72-
is connected to the MicroPython REPL (eg serial, USB, Wifi).
70+
Performs a :ref:`soft reset <soft_reset>` of the interpreter, deleting all
71+
Python objects and resetting the Python heap.
7372

7473
.. function:: reset_cause()
7574

docs/library/pyb.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ Power related functions
147147
(internal oscillator) directly. The higher frequencies use the HSE to
148148
drive the PLL (phase locked loop), and then use the output of the PLL.
149149

150-
Note that if you change the frequency while the USB is enabled then
151-
the USB may become unreliable. It is best to change the frequency
152-
in boot.py, before the USB peripheral is started. Also note that sysclk
153-
frequencies below 36MHz do not allow the USB to function correctly.
150+
Note that if you change the frequency while the USB is enabled then the USB
151+
may become unreliable. It is best to change the frequency in :ref:`boot.py`,
152+
before the USB peripheral is started. Also note that sysclk frequencies below
153+
36MHz do not allow the USB to function correctly.
154154

155155
.. function:: wfi()
156156

@@ -205,8 +205,9 @@ Miscellaneous functions
205205

206206
.. function:: main(filename)
207207

208-
Set the filename of the main script to run after boot.py is finished. If
209-
this function is not called then the default file main.py will be executed.
208+
Set the filename of the main script to run after :ref:`boot.py` is finished.
209+
If this function is not called then the default file :ref:`main.py` will be
210+
executed.
210211

211212
It only makes sense to call this function from within boot.py.
212213

docs/pyboard/tutorial/reset.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ execution of ``boot.py`` and ``main.py`` and gives default USB settings.
1010
If you have problems with the filesystem you can do a factory reset,
1111
which restores the filesystem to its original state.
1212

13+
For more information, see :doc:`/reference/reset_boot`.
14+
1315
Safe mode
1416
---------
1517

docs/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ implementation and the best practices to use them.
2121

2222
glossary.rst
2323
repl.rst
24+
reset_boot.rst
2425
mpremote.rst
2526
mpyfiles.rst
2627
isr_rules.rst

docs/reference/mpremote.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,9 @@ device at ``/dev/ttyACM1``, printing each result.
547547
548548
mpremote resume exec "print_state_info()" soft-reset
549549
550-
Connect to the device without triggering a soft reset and execute the
551-
``print_state_info()`` function (e.g. to find out information about the current
552-
program state), then trigger a soft reset.
550+
Connect to the device without triggering a :ref:`soft reset <soft_reset>` and
551+
execute the ``print_state_info()`` function (e.g. to find out information about
552+
the current program state), then trigger a soft reset.
553553

554554
.. code-block:: bash
555555

0 commit comments

Comments
 (0)