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

Add boot configuration for autoreload when writing to the CP drive #981

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading