From 2bface8f893f3f13ddb9a3e10c0f362819d09c5c Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Mon, 7 Mar 2022 17:59:06 +0100 Subject: [PATCH] Add flash target for UF2 bootloaders (#16525) --- docs/flashing.md | 11 +++++++++++ platforms/chibios/flash.mk | 14 ++++++++++++++ util/uf2conv.py | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/flashing.md b/docs/flashing.md index 83f4bf82ae1..ae31f9c621c 100644 --- a/docs/flashing.md +++ b/docs/flashing.md @@ -347,3 +347,14 @@ Flashing sequence: 2. Wait for the OS to detect the device 3. Copy the .uf2 file to the new USB disk 4. Wait for the keyboard to become available + +or + +CLI Flashing sequence: + +1. Enter the bootloader using any of the following methods: + * Tap the `RESET` keycode + * Double-tap the `nRST` button on the PCB. +2. Wait for the OS to detect the device +3. Flash via QMK CLI eg. `qmk flash --keyboard handwired/onekey/blackpill_f411_tinyuf2 --keymap default` +4. Wait for the keyboard to become available diff --git a/platforms/chibios/flash.mk b/platforms/chibios/flash.mk index 6ee53172d26..a91ef2cf35f 100644 --- a/platforms/chibios/flash.mk +++ b/platforms/chibios/flash.mk @@ -40,6 +40,18 @@ endef dfu-util: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter $(call EXEC_DFU_UTIL) +define EXEC_UF2_UTIL_DEPLOY + if ! $(UF2CONV) --deploy $(BUILD_DIR)/$(TARGET).uf2 2>/dev/null; then \ + printf "$(MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY)" ;\ + sleep $(BOOTLOADER_RETRY_TIME) ;\ + while ! $(UF2CONV) --deploy $(BUILD_DIR)/$(TARGET).uf2 2>/dev/null; do \ + printf "." ;\ + sleep $(BOOTLOADER_RETRY_TIME) ;\ + done ;\ + printf "\n" ;\ + fi +endef + # TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS # within the emulated eeprom via dfu-util or another tool ifneq (,$(filter $(MAKECMDGOALS),dfu-util-split-left)) @@ -90,6 +102,8 @@ ifneq ($(strip $(PROGRAM_CMD)),) $(UNSYNC_OUTPUT_CMD) && $(PROGRAM_CMD) else ifeq ($(strip $(BOOTLOADER)),kiibohd) $(UNSYNC_OUTPUT_CMD) && $(call EXEC_DFU_UTIL) +else ifeq ($(strip $(BOOTLOADER)),tinyuf2) + $(UNSYNC_OUTPUT_CMD) && $(call EXEC_UF2_UTIL_DEPLOY) else ifeq ($(strip $(MCU_FAMILY)),KINETIS) $(UNSYNC_OUTPUT_CMD) && $(call EXEC_TEENSY) else ifeq ($(strip $(MCU_FAMILY)),MIMXRT1062) diff --git a/util/uf2conv.py b/util/uf2conv.py index efc7263f834..fb82fd03ca6 100755 --- a/util/uf2conv.py +++ b/util/uf2conv.py @@ -267,7 +267,7 @@ def load_families(): def main(): global appstartaddr, familyid def error(msg): - print(msg) + print(msg, file=sys.stderr) sys.exit(1) parser = argparse.ArgumentParser(description='Convert to UF2 or flash directly.') parser.add_argument('input', metavar='INPUT', type=str, nargs='?',