diff --git a/docs/en/boot.md b/docs/en/boot.md index b61202cae..833536fd2 100644 --- a/docs/en/boot.md +++ b/docs/en/boot.md @@ -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, @@ -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. diff --git a/kmk/bootcfg.py b/kmk/bootcfg.py index 7e9ef183f..17954e79d 100644 --- a/kmk/bootcfg.py +++ b/kmk/bootcfg.py @@ -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, @@ -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 = [] @@ -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.