1
0
Fork 0
forked from forks/qmk_firmware

Move all the flash logic from tmk_core (#13927)

This commit is contained in:
Joel Challis 2021-08-15 21:55:23 +01:00 committed by GitHub
parent 4e3726bfe1
commit ab941ce614
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 278 additions and 269 deletions

View file

@ -375,6 +375,7 @@ ifneq ($(strip $(PROTOCOL)),)
else
include $(TMK_PATH)/protocol/$(PLATFORM_KEY).mk
endif
-include $(TOP_DIR)/platforms/$(PLATFORM_KEY)/flash.mk
# TODO: remove this bodge?
PROJECT_DEFS := $(OPT_DEFS)

View file

@ -0,0 +1,11 @@
# Hey Emacs, this is a -*- makefile -*-
##############################################################################
# Architecture or project specific options
#
flash: bin
ifneq ($(strip $(PROGRAM_CMD)),)
$(PROGRAM_CMD)
else
$(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_ARCH)"
endif

179
platforms/avr/flash.mk Normal file
View file

@ -0,0 +1,179 @@
# Hey Emacs, this is a -*- makefile -*-
##############################################################################
# Architecture or project specific options
#
# Autodetect teensy loader
ifndef TEENSY_LOADER_CLI
ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
TEENSY_LOADER_CLI ?= teensy-loader-cli
else
TEENSY_LOADER_CLI ?= teensy_loader_cli
endif
endif
define EXEC_TEENSY
$(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
endef
teensy: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_TEENSY)
DFU_PROGRAMMER ?= dfu-programmer
GREP ?= grep
define EXEC_DFU
if [ "$(1)" ]; then \
echo "Flashing '$(1)' for EE_HANDS split keyboard support." ;\
fi; \
if ! $(DFU_PROGRAMMER) $(MCU) get bootloader-version >/dev/null 2>/dev/null; then\
printf "$(MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY)" ;\
sleep $(BOOTLOADER_RETRY_TIME) ;\
while ! $(DFU_PROGRAMMER) $(MCU) get bootloader-version >/dev/null 2>/dev/null; do\
printf "." ;\
sleep $(BOOTLOADER_RETRY_TIME) ;\
done ;\
printf "\n" ;\
fi; \
$(DFU_PROGRAMMER) $(MCU) get bootloader-version ;\
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) erase --force; \
if [ "$(1)" ]; then \
$(DFU_PROGRAMMER) $(MCU) flash --force --eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
$(DFU_PROGRAMMER) $(MCU) flash --force $(BUILD_DIR)/$(TARGET).hex;\
else \
$(DFU_PROGRAMMER) $(MCU) erase; \
if [ "$(1)" ]; then \
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
$(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex;\
fi; \
$(DFU_PROGRAMMER) $(MCU) reset
endef
dfu: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
$(call EXEC_DFU)
dfu-start:
$(DFU_PROGRAMMER) $(MCU) reset
$(DFU_PROGRAMMER) $(MCU) start
dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) flash --force --eeprom $(BUILD_DIR)/$(TARGET).eep;\
else\
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep;\
fi
$(DFU_PROGRAMMER) $(MCU) reset
dfu-split-left: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
$(call EXEC_DFU,eeprom-lefthand.eep)
dfu-split-right: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
$(call EXEC_DFU,eeprom-righthand.eep)
AVRDUDE_PROGRAMMER ?= avrdude
define EXEC_AVRDUDE
list_devices() { \
if $(GREP) -q -s icrosoft /proc/version; then \
wmic.exe path Win32_SerialPort get DeviceID 2>/dev/null | LANG=C perl -pne 's/COM(\d+)/COM.($$1-1)/e' | sed 's!COM!/dev/ttyS!' | xargs echo -n | sort; \
elif [ "`uname`" = "FreeBSD" ]; then \
ls /dev/tty* | grep -v '\.lock$$' | grep -v '\.init$$'; \
else \
ls /dev/tty*; \
fi; \
}; \
USB= ;\
printf "Waiting for USB serial port - reset your controller now (Ctrl+C to cancel)"; \
TMP1=`mktemp`; \
TMP2=`mktemp`; \
list_devices > $$TMP1; \
while [ -z "$$USB" ]; do \
sleep $(BOOTLOADER_RETRY_TIME); \
printf "."; \
list_devices > $$TMP2; \
USB=`comm -13 $$TMP1 $$TMP2 | $(GREP) -o '/dev/tty.*'`; \
mv $$TMP2 $$TMP1; \
done; \
rm $$TMP1; \
echo ""; \
echo "Device $$USB has appeared; assuming it is the controller."; \
if $(GREP) -q -s 'MINGW\|MSYS\|icrosoft' /proc/version; then \
USB=`echo "$$USB" | LANG=C perl -pne 's/\/dev\/ttyS(\d+)/COM.($$1+1)/e'`; \
echo "Remapped USB port to $$USB"; \
sleep 1; \
else \
printf "Waiting for $$USB to become writable."; \
while [ ! -w "$$USB" ]; do sleep $(BOOTLOADER_RETRY_TIME); printf "."; done; echo ""; \
fi; \
if [ -z "$(1)" ]; then \
$(AVRDUDE_PROGRAMMER) -p $(MCU) -c avr109 -P $$USB -U flash:w:$(BUILD_DIR)/$(TARGET).hex; \
else \
$(AVRDUDE_PROGRAMMER) -p $(MCU) -c avr109 -P $$USB -U flash:w:$(BUILD_DIR)/$(TARGET).hex -U eeprom:w:$(QUANTUM_PATH)/split_common/$(1); \
fi
endef
avrdude: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_AVRDUDE)
avrdude-loop: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
while true; do \
$(call EXEC_AVRDUDE) ; \
done
avrdude-split-left: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_AVRDUDE,eeprom-lefthand.eep)
avrdude-split-right: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_AVRDUDE,eeprom-righthand.eep)
define EXEC_USBASP
$(AVRDUDE_PROGRAMMER) -p $(AVRDUDE_MCU) -c usbasp -U flash:w:$(BUILD_DIR)/$(TARGET).hex
endef
usbasp: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_USBASP)
BOOTLOADHID_PROGRAMMER ?= bootloadHID
define EXEC_BOOTLOADHID
# bootloadHid executable has no cross platform detect methods
# so keep running bootloadHid if the output contains "The specified device was not found"
until $(BOOTLOADHID_PROGRAMMER) -r $(BUILD_DIR)/$(TARGET).hex 2>&1 | tee /dev/stderr | grep -v "device was not found"; do\
printf "$(MSG_BOOTLOADER_NOT_FOUND)" ;\
sleep 5 ;\
done
endef
bootloadHID: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_BOOTLOADHID)
HID_BOOTLOADER_CLI ?= hid_bootloader_cli
define EXEC_HID_LUFA
$(HID_BOOTLOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
endef
hid_bootloader: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_HID_LUFA)
flash: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
ifneq ($(strip $(PROGRAM_CMD)),)
$(PROGRAM_CMD)
else ifeq ($(strip $(BOOTLOADER)), caterina)
$(call EXEC_AVRDUDE)
else ifeq ($(strip $(BOOTLOADER)), halfkay)
$(call EXEC_TEENSY)
else ifeq (dfu,$(findstring dfu,$(BOOTLOADER)))
$(call EXEC_DFU)
else ifeq ($(strip $(BOOTLOADER)), USBasp)
$(call EXEC_USBASP)
else ifeq ($(strip $(BOOTLOADER)), bootloadHID)
$(call EXEC_BOOTLOADHID)
else ifeq ($(strip $(BOOTLOADER)), qmk-hid)
$(call EXEC_HID_LUFA)
else
$(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_BOOTLOADER)"
endif

View file

@ -0,0 +1,87 @@
# Hey Emacs, this is a -*- makefile -*-
##############################################################################
# Architecture or project specific options
#
DFU_ARGS ?=
ifneq ("$(SERIAL)","")
DFU_ARGS += -S $(SERIAL)
endif
DFU_UTIL ?= dfu-util
define EXEC_DFU_UTIL
if ! $(DFU_UTIL) -l | grep -q "Found DFU"; then \
printf "$(MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY)" ;\
sleep $(BOOTLOADER_RETRY_TIME) ;\
while ! $(DFU_UTIL) -l | grep -q "Found DFU"; do \
printf "." ;\
sleep $(BOOTLOADER_RETRY_TIME) ;\
done ;\
printf "\n" ;\
fi
$(DFU_UTIL) $(DFU_ARGS) -D $(BUILD_DIR)/$(TARGET).bin
endef
dfu-util: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
$(call EXEC_DFU_UTIL)
# 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))
OPT_DEFS += -DINIT_EE_HANDS_LEFT
endif
ifneq (,$(filter $(MAKECMDGOALS),dfu-util-split-right))
OPT_DEFS += -DINIT_EE_HANDS_RIGHT
endif
dfu-util-split-left: dfu-util
dfu-util-split-right: dfu-util
ST_LINK_CLI ?= st-link_cli
ST_LINK_ARGS ?=
st-link-cli: $(BUILD_DIR)/$(TARGET).hex sizeafter
$(ST_LINK_CLI) $(ST_LINK_ARGS) -q -c SWD -p $(BUILD_DIR)/$(TARGET).hex -Rst
ST_FLASH ?= st-flash
ST_FLASH_ARGS ?=
st-flash: $(BUILD_DIR)/$(TARGET).hex sizeafter
$(ST_FLASH) $(ST_FLASH_ARGS) --reset --format ihex write $(BUILD_DIR)/$(TARGET).hex
# Autodetect teensy loader
ifndef TEENSY_LOADER_CLI
ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
TEENSY_LOADER_CLI ?= teensy-loader-cli
else
TEENSY_LOADER_CLI ?= teensy_loader_cli
endif
endif
TEENSY_LOADER_CLI_MCU ?= $(MCU_LDSCRIPT)
define EXEC_TEENSY
$(TEENSY_LOADER_CLI) -mmcu=$(TEENSY_LOADER_CLI_MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
endef
teensy: $(BUILD_DIR)/$(TARGET).hex cpfirmware sizeafter
$(call EXEC_TEENSY)
flash: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
ifneq ($(strip $(PROGRAM_CMD)),)
$(PROGRAM_CMD)
else ifeq ($(strip $(BOOTLOADER)),kiibohd)
$(call EXEC_DFU_UTIL)
else ifeq ($(strip $(MCU_FAMILY)),KINETIS)
$(call EXEC_TEENSY)
else ifeq ($(strip $(MCU_FAMILY)),MIMXRT1062)
$(call EXEC_TEENSY)
else ifeq ($(strip $(MCU_FAMILY)),STM32)
$(call EXEC_DFU_UTIL)
else
$(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_BOOTLOADER)"
endif

View file

@ -54,10 +54,3 @@ EXTRALIBDIRS =
bin: $(BUILD_DIR)/$(TARGET).hex
$(OBJCOPY) -Iihex -Obinary $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
$(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin;
flash: bin
ifneq ($(strip $(PROGRAM_CMD)),)
$(PROGRAM_CMD)
else
$(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_ARCH)"
endif

View file

@ -89,162 +89,6 @@ DEBUG_PORT = 4242
DEBUG_HOST = localhost
#============================================================================
# Autodetect teensy loader
ifndef TEENSY_LOADER_CLI
ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
TEENSY_LOADER_CLI ?= teensy-loader-cli
else
TEENSY_LOADER_CLI ?= teensy_loader_cli
endif
endif
define EXEC_TEENSY
$(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
endef
teensy: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_TEENSY)
DFU_PROGRAMMER ?= dfu-programmer
GREP ?= grep
define EXEC_DFU
if [ "$(1)" ]; then \
echo "Flashing '$(1)' for EE_HANDS split keyboard support." ;\
fi; \
if ! $(DFU_PROGRAMMER) $(MCU) get bootloader-version >/dev/null 2>/dev/null; then\
printf "$(MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY)" ;\
sleep $(BOOTLOADER_RETRY_TIME) ;\
while ! $(DFU_PROGRAMMER) $(MCU) get bootloader-version >/dev/null 2>/dev/null; do\
printf "." ;\
sleep $(BOOTLOADER_RETRY_TIME) ;\
done ;\
printf "\n" ;\
fi; \
$(DFU_PROGRAMMER) $(MCU) get bootloader-version ;\
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) erase --force; \
if [ "$(1)" ]; then \
$(DFU_PROGRAMMER) $(MCU) flash --force --eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
$(DFU_PROGRAMMER) $(MCU) flash --force $(BUILD_DIR)/$(TARGET).hex;\
else \
$(DFU_PROGRAMMER) $(MCU) erase; \
if [ "$(1)" ]; then \
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
$(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex;\
fi; \
$(DFU_PROGRAMMER) $(MCU) reset
endef
dfu: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
$(call EXEC_DFU)
dfu-start:
$(DFU_PROGRAMMER) $(MCU) reset
$(DFU_PROGRAMMER) $(MCU) start
dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) flash --force --eeprom $(BUILD_DIR)/$(TARGET).eep;\
else\
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep;\
fi
$(DFU_PROGRAMMER) $(MCU) reset
dfu-split-left: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
$(call EXEC_DFU,eeprom-lefthand.eep)
dfu-split-right: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
$(call EXEC_DFU,eeprom-righthand.eep)
AVRDUDE_PROGRAMMER ?= avrdude
define EXEC_AVRDUDE
list_devices() { \
if $(GREP) -q -s icrosoft /proc/version; then \
wmic.exe path Win32_SerialPort get DeviceID 2>/dev/null | LANG=C perl -pne 's/COM(\d+)/COM.($$1-1)/e' | sed 's!COM!/dev/ttyS!' | xargs echo -n | sort; \
elif [ "`uname`" = "FreeBSD" ]; then \
ls /dev/tty* | grep -v '\.lock$$' | grep -v '\.init$$'; \
else \
ls /dev/tty*; \
fi; \
}; \
USB= ;\
printf "Waiting for USB serial port - reset your controller now (Ctrl+C to cancel)"; \
TMP1=`mktemp`; \
TMP2=`mktemp`; \
list_devices > $$TMP1; \
while [ -z "$$USB" ]; do \
sleep $(BOOTLOADER_RETRY_TIME); \
printf "."; \
list_devices > $$TMP2; \
USB=`comm -13 $$TMP1 $$TMP2 | $(GREP) -o '/dev/tty.*'`; \
mv $$TMP2 $$TMP1; \
done; \
rm $$TMP1; \
echo ""; \
echo "Device $$USB has appeared; assuming it is the controller."; \
if $(GREP) -q -s 'MINGW\|MSYS\|icrosoft' /proc/version; then \
USB=`echo "$$USB" | LANG=C perl -pne 's/\/dev\/ttyS(\d+)/COM.($$1+1)/e'`; \
echo "Remapped USB port to $$USB"; \
sleep 1; \
else \
printf "Waiting for $$USB to become writable."; \
while [ ! -w "$$USB" ]; do sleep $(BOOTLOADER_RETRY_TIME); printf "."; done; echo ""; \
fi; \
if [ -z "$(1)" ]; then \
$(AVRDUDE_PROGRAMMER) -p $(MCU) -c avr109 -P $$USB -U flash:w:$(BUILD_DIR)/$(TARGET).hex; \
else \
$(AVRDUDE_PROGRAMMER) -p $(MCU) -c avr109 -P $$USB -U flash:w:$(BUILD_DIR)/$(TARGET).hex -U eeprom:w:$(QUANTUM_PATH)/split_common/$(1); \
fi
endef
avrdude: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_AVRDUDE)
avrdude-loop: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
while true; do \
$(call EXEC_AVRDUDE) ; \
done
avrdude-split-left: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_AVRDUDE,eeprom-lefthand.eep)
avrdude-split-right: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_AVRDUDE,eeprom-righthand.eep)
define EXEC_USBASP
$(AVRDUDE_PROGRAMMER) -p $(AVRDUDE_MCU) -c usbasp -U flash:w:$(BUILD_DIR)/$(TARGET).hex
endef
usbasp: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_USBASP)
BOOTLOADHID_PROGRAMMER ?= bootloadHID
define EXEC_BOOTLOADHID
# bootloadHid executable has no cross platform detect methods
# so keep running bootloadHid if the output contains "The specified device was not found"
until $(BOOTLOADHID_PROGRAMMER) -r $(BUILD_DIR)/$(TARGET).hex 2>&1 | tee /dev/stderr | grep -v "device was not found"; do\
printf "$(MSG_BOOTLOADER_NOT_FOUND)" ;\
sleep 5 ;\
done
endef
bootloadHID: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_BOOTLOADHID)
HID_BOOTLOADER_CLI ?= hid_bootloader_cli
define EXEC_HID_LUFA
$(HID_BOOTLOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
endef
hid_bootloader: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
$(call EXEC_HID_LUFA)
# Convert hex to bin.
bin: $(BUILD_DIR)/$(TARGET).hex
@ -335,22 +179,3 @@ production: $(BUILD_DIR)/$(TARGET).hex bootloader cpfirmware
@cat $(TARGET)_bootloader.hex >> $(TARGET)_production.hex
echo "File sizes:"
$(SIZE) $(TARGET).hex $(TARGET)_bootloader.hex $(TARGET)_production.hex
flash: $(BUILD_DIR)/$(TARGET).hex check-size cpfirmware
ifneq ($(strip $(PROGRAM_CMD)),)
$(PROGRAM_CMD)
else ifeq ($(strip $(BOOTLOADER)), caterina)
$(call EXEC_AVRDUDE)
else ifeq ($(strip $(BOOTLOADER)), halfkay)
$(call EXEC_TEENSY)
else ifeq (dfu,$(findstring dfu,$(BOOTLOADER)))
$(call EXEC_DFU)
else ifeq ($(strip $(BOOTLOADER)), USBasp)
$(call EXEC_USBASP)
else ifeq ($(strip $(BOOTLOADER)), bootloadHID)
$(call EXEC_BOOTLOADHID)
else ifeq ($(strip $(BOOTLOADER)), qmk-hid)
$(call EXEC_HID_LUFA)
else
$(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_BOOTLOADER)"
endif

View file

@ -325,95 +325,8 @@ MCUFLAGS = -mcpu=$(MCU)
DEBUG = gdb
DFU_ARGS ?=
ifneq ("$(SERIAL)","")
DFU_ARGS += -S $(SERIAL)
endif
ST_LINK_ARGS ?=
ST_FLASH_ARGS ?=
# List any extra directories to look for libraries here.
EXTRALIBDIRS = $(RULESPATH)/ld
DFU_UTIL ?= dfu-util
ST_LINK_CLI ?= st-link_cli
ST_FLASH ?= st-flash
define EXEC_DFU_UTIL
if ! $(DFU_UTIL) -l | grep -q "Found DFU"; then \
printf "$(MSG_BOOTLOADER_NOT_FOUND_QUICK_RETRY)" ;\
sleep $(BOOTLOADER_RETRY_TIME) ;\
while ! $(DFU_UTIL) -l | grep -q "Found DFU"; do \
printf "." ;\
sleep $(BOOTLOADER_RETRY_TIME) ;\
done ;\
printf "\n" ;\
fi
$(DFU_UTIL) $(DFU_ARGS) -D $(BUILD_DIR)/$(TARGET).bin
endef
dfu-util: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
$(call EXEC_DFU_UTIL)
# Legacy alias
dfu-util-wait: dfu-util
# 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))
OPT_DEFS += -DINIT_EE_HANDS_LEFT
endif
ifneq (,$(filter $(MAKECMDGOALS),dfu-util-split-right))
OPT_DEFS += -DINIT_EE_HANDS_RIGHT
endif
dfu-util-split-left: dfu-util
dfu-util-split-right: 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
st-flash: $(BUILD_DIR)/$(TARGET).hex sizeafter
$(ST_FLASH) $(ST_FLASH_ARGS) --reset --format ihex write $(BUILD_DIR)/$(TARGET).hex
# Autodetect teensy loader
ifndef TEENSY_LOADER_CLI
ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
TEENSY_LOADER_CLI ?= teensy-loader-cli
else
TEENSY_LOADER_CLI ?= teensy_loader_cli
endif
endif
TEENSY_LOADER_CLI_MCU ?= $(MCU_LDSCRIPT)
define EXEC_TEENSY
$(TEENSY_LOADER_CLI) -mmcu=$(TEENSY_LOADER_CLI_MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
endef
teensy: $(BUILD_DIR)/$(TARGET).hex cpfirmware sizeafter
$(call EXEC_TEENSY)
bin: $(BUILD_DIR)/$(TARGET).bin sizeafter
$(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin;
flash: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
ifneq ($(strip $(PROGRAM_CMD)),)
$(PROGRAM_CMD)
else ifeq ($(strip $(BOOTLOADER)),kiibohd)
$(call EXEC_DFU_UTIL)
else ifeq ($(strip $(MCU_FAMILY)),KINETIS)
$(call EXEC_TEENSY)
else ifeq ($(strip $(MCU_FAMILY)),MIMXRT1062)
$(call EXEC_TEENSY)
else ifeq ($(strip $(MCU_FAMILY)),STM32)
$(call EXEC_DFU_UTIL)
else
$(PRINT_OK); $(SILENT) || printf "$(MSG_FLASH_BOOTLOADER)"
endif