Skip to content

Commit

Permalink
Align flashing behaviour of dfu-util (qmk#6578)
Browse files Browse the repository at this point in the history
* Align flashing retry logic of dfu-util

* Align bootloader wait messages

Co-Authored-By: Drashna Jaelre <[email protected]>
  • Loading branch information
zvecr and drashna committed Aug 22, 2019
1 parent 1c805b3 commit ae44ec9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
6 changes: 2 additions & 4 deletions docs/flashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,5 @@ Flashing sequence:

There are a number of DFU commands that you can use to flash firmware to a STM32 device:

* `:dfu-util` - The default command for flashing to STM32 devices.
* `:dfu-util-wait` - This works like the default command, but it gives you a (configurable) 10 second timeout before it attempts to flash the firmware. You can use `TIME_DELAY=20` from the command line to change the timeout.
* Eg: `make <keyboard>:<keymap>:dfu-util TIME_DELAY=5`
* `:st-link-cli` - This allows you to flash the firmware via ST-LINK's CLI utility, rather than dfu-util.
* `:dfu-util` - The default command for flashing to STM32 devices.
* `:st-link-cli` - This allows you to flash the firmware via ST-LINK's CLI utility, rather than dfu-util.
22 changes: 6 additions & 16 deletions tmk_core/chibios.mk
Original file line number Diff line number Diff line change
Expand Up @@ -235,28 +235,18 @@ qmk: $(BUILD_DIR)/$(TARGET).bin
printf "@ $(TARGET).json\n@=info.json\n" | zipnote -w $(TARGET).qmk

define EXEC_DFU_UTIL
until $(DFU_UTIL) -l | grep -q "Found DFU"; do\
echo "Error: Bootloader not found. Trying again in 5s." ;\
sleep 5 ;\
done
$(DFU_UTIL) $(DFU_ARGS) -D $(BUILD_DIR)/$(TARGET).bin
endef

dfu-util: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
$(call EXEC_DFU_UTIL)

ifneq ($(strip $(TIME_DELAY)),)
TIME_DELAY = $(strip $(TIME_DELAY))
else
TIME_DELAY = 10
endif
dfu-util-wait: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
echo "Preparing to flash firmware. Please enter bootloader now..." ;\
COUNTDOWN=$(TIME_DELAY) ;\
while [[ $$COUNTDOWN -ge 1 ]] ; do \
echo "Flashing in $$COUNTDOWN ..."; \
sleep 1 ;\
((COUNTDOWN = COUNTDOWN - 1)) ; \
done; \
echo "Flashing $(TARGET).bin" ;\
sleep 1 ;\
$(call EXEC_DFU_UTIL)
# Legacy alias
dfu-util-wait: dfu-util

st-link-cli: $(BUILD_DIR)/$(TARGET).hex sizeafter
$(ST_LINK_CLI) $(ST_LINK_ARGS) -q -c SWD -p $(BUILD_DIR)/$(TARGET).hex -Rst
Expand Down

0 comments on commit ae44ec9

Please sign in to comment.