Skip to content

Commit

Permalink
Add boot configuration for autoreload when writing to the CP drive
Browse files Browse the repository at this point in the history
  • Loading branch information
xs5871 committed Jun 9, 2024
1 parent a596e26 commit 61ba161
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/en/boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bootcfg(
sense: [microcontroller.Pin, digitalio.DigitalInOut],
# optional:
source: Optional[microcontroller.Pin, digitalio.DigitalInOut] = None,
autoreload: bool = True,
boot_device: int = 0,
cdc_console: bool = True,
cdc_data: bool = False,
Expand Down Expand Up @@ -66,6 +67,13 @@ Common matrix and direct pin configurations (see also the examples below):
|direct pin |direct pin |`None` |


#### `autoreload`
CircuitPython will automatically reload when any data or meta data is written to
the CircuitPython drive.
Certain operating systems tend to do that without asking; in that case
`autoreload` can be disabled as a workaround.


#### `boot_device`
Boot HID device configuration for `usb_hid`, see the [`usb_hid` documentation](https://docs.circuitpython.org/en/latest/shared-bindings/usb_hid/index.html#usb_hid.enable)
for details.
Expand Down
13 changes: 10 additions & 3 deletions kmk/bootcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
def bootcfg(
sense: [microcontroller.Pin, digitalio.DigitalInOut],
source: Optional[microcontroller.Pin, digitalio.DigitalInOut] = None,
autoreload: bool = True,
boot_device: int = 0,
cdc_console: bool = True,
cdc_data: bool = False,
Expand Down Expand Up @@ -38,9 +39,10 @@ def bootcfg(
source.direction = digitalio.Direction.OUTPUT
source.value = False

# sense pulled low -> skip boot configuration
if not sense.value:
return False
if not autoreload:
import supervisor

supervisor.runtime.autoreload = False

# configure HID devices
devices = []
Expand Down Expand Up @@ -84,6 +86,11 @@ def bootcfg(

usb_cdc.enable(data=True)

# sense pulled low -> Skip boot configuration that may disable debug or
# rescue facilities.
if not sense.value:
return False

# Entries for serial console (REPL) and storage are intentionally evaluated
# last to ensure the board is debuggable, mountable and rescueable, in case
# any of the previous code throws an exception.
Expand Down

0 comments on commit 61ba161

Please sign in to comment.