aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLasse Dalegaard <dalegaard@gmail.com>2022-01-03 23:28:54 +0100
committerKevinOConnor <kevin@koconnor.net>2022-01-06 17:32:54 -0500
commit7c0559c6e62506af73d0e8f22733615705664dd5 (patch)
tree67553ceb7751b4cd7601e01d7b00dd45cebeb3cd /scripts
parent8a3727ef742f46923275ffca4651710952cfa114 (diff)
downloadkutter-7c0559c6e62506af73d0e8f22733615705664dd5.tar.gz
kutter-7c0559c6e62506af73d0e8f22733615705664dd5.tar.xz
kutter-7c0559c6e62506af73d0e8f22733615705664dd5.zip
rp2040: add make flash support
This adds `make flash` support for the rp2040 target. Flashing is performed using a custom `rp2040_flash` tool that uses the PICOBOOT protocol. Root is not required. The user specifies the serial device of the rp2040 they wish to flash as the device. This device is reset into bootsel mode and `rp2040_flash` is invoked on the original USB device path. If the device is already in bootloader mode, the user can specify 'first' as `FLASH_DEVICE` which will simply invoke `rp2040_flash` with no bus/address options. Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/flash_usb.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/scripts/flash_usb.py b/scripts/flash_usb.py
index 04e2ba3f..581aa5c0 100755
--- a/scripts/flash_usb.py
+++ b/scripts/flash_usb.py
@@ -162,6 +162,20 @@ def flash_atsamd(options, binfile):
options.device, str(e)))
sys.exit(-1)
+# Look for an rp2040 and flash it with rp2040_flash.
+def rp2040_flash(devpath, binfile):
+ args = ["lib/rp2040_flash/rp2040_flash", binfile]
+ if len(devpath) > 0:
+ with open(devpath + "/busnum") as f:
+ bus = f.read().strip()
+ with open(devpath + "/devnum") as f:
+ addr = f.read().strip()
+ args += [bus, addr]
+ sys.stderr.write(" ".join(args) + '\n\n')
+ res = subprocess.call(args)
+ if res != 0:
+ raise error("Error running rp2040_flash")
+
SMOOTHIE_HELP = """
Failed to flash to %s: %s
@@ -240,11 +254,39 @@ def flash_stm32f4(options, binfile):
options.device, str(e), options.device))
sys.exit(-1)
+RP2040_HELP = """
+Failed to flash to %s: %s
+
+If the device is already in bootloader mode, use 'first' as FLASH_DEVICE.
+This will use rp2040_flash to flash the first available rp2040.
+
+Alternatively, one can flash rp2040 boards like the Pico by manually
+entering bootloader mode(hold bootsel button during powerup), mount the
+device as a usb drive, and copy klipper.uf2 to the device.
+"""
+
+def flash_rp2040(options, binfile):
+ try:
+ if options.device.lower() == "first":
+ rp2040_flash("", binfile)
+ return
+
+ buspath, devpath = translate_serial_to_usb_path(options.device)
+ # We need one level up to get access to busnum/devnum files
+ devpath = os.path.dirname(devpath)
+ enter_bootloader(options.device)
+ wait_path(devpath)
+ rp2040_flash(devpath, binfile)
+
+ except error as e:
+ sys.stderr.write(RP2040_HELP % (options.device, str(e)))
+ sys.exit(-1)
+
MCUTYPES = {
'sam3': flash_atsam3, 'sam4': flash_atsam4, 'samd': flash_atsamd,
'lpc176': flash_lpc176x, 'stm32f103': flash_stm32f1,
'stm32f4': flash_stm32f4, 'stm32f042': flash_stm32f4,
- 'stm32f072': flash_stm32f4
+ 'stm32f072': flash_stm32f4, 'rp2040': flash_rp2040
}