Skip to content

Instantly share code, notes, and snippets.

@Mark-Booth
Last active March 12, 2023 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mark-Booth/6dd637fc65c03a0ede393a8c718b02c1 to your computer and use it in GitHub Desktop.
Save Mark-Booth/6dd637fc65c03a0ede393a8c718b02c1 to your computer and use it in GitHub Desktop.
Generic CircuitPython boot.py with additional notes for QT Py 2040
# CircuitPython boot.py crib sheet
# https://gist.github.com/Mark-Booth/6dd637fc65c03a0ede393a8c718b02c1
# Version history (most recent at top)
# Add details of how to enter safe mode on the QT Py 2040
# Initial commit & commit with link back to gist
# Based on the Adafruit Customizing USB Devices in CircuitPython page
# https://learn.adafruit.com/customizing-usb-devices-in-circuitpython/circuitpy-midi-serial
# If things aren't working as expected, check the Adafruit troubleshooting page
# https://learn.adafruit.com/adafruit-neokey-trinkey/troubleshooting
# Once configured, delete comments to save space.
import usb_hid
# These are the default HID devices
#usb_hid.enable((
# usb_hid.Device.KEYBOARD,
# usb_hid.Device.CONSUMER_CONTROL,
# usb_hid.Device.MOUSE,
#))
# You don't need to write this explicitly if you want these default HID devices
#usb_hid.enable((usb_hid.Device.KEYBOARD,)) # Enable just KEYBOARD
#usb_hid.enable(()) # Disable all HID devices
#usb_hid.disable() # Another way to disable all the devices
import usb_midi
#usb_midi.enable() # Default
#usb_midi.disable()
import usb_cdc
#usb_cdc.enable(console=True, data=False) # Default, enable just the REPL console
#usb_cdc.enable(console=True, data=True) # Enable console and data
#usb_cdc.enable(console=False, data=False) # Disable both serial devices.
#usb_cdc.disable() # Another way to disable both devices Disable
import storage # Only disable storage after configuring other devices
# Once storage is disabled or made read-only, you will need to boot into safe
# mode to change boot options, such as re-enabling strage or making it writeable
#storage.disable_usb_drive()
#storage.enable_usb_drive() # Default, storage mounted on PC
# By default, storage is writable by PC but not by CircuitPython
# If you make storage writable by CircuitPython, it becomes readonly on the PC
#storage.remount("/", readonly=False)
#storage.remount("/", readonly=True) # Default, writeable by PC
# To use a switch to determine remount options for some common devices, see
# https://learn.adafruit.com/circuitpython-essentials/circuitpython-storage
# For the QT Py RP2040, the Boot switch is on GPIO21, aka board.Button, but this
# doesn't appear to work for this purpose.
# To enter safe mode on the QT Py 2040, press the reset button twice, like a
# slow double tap, but you have to learn the cadence to do it reliably
# * If you double tap too quickly, it may enter bootloader mode, as if you had
# held the boot button down while preessing reset
# * If you double tap too slowly, the QT Py 2040 will just reset twice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment