summaryrefslogtreecommitdiff
path: root/platforms/chibios
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-08-15 21:55:23 +0100
committerGitHub <noreply@github.com>2021-08-15 21:55:23 +0100
commitab941ce614e19a7f4bb5bd34dd0ab9eee86bdc27 (patch)
treeff8bfefacffaac38893dd423d018c84068258bd1 /platforms/chibios
parent4e3726bfe11b02757c5724211d2a0fc62c7f66e8 (diff)
Move all the flash logic from tmk_core (#13927)
Diffstat (limited to 'platforms/chibios')
-rw-r--r--platforms/chibios/flash.mk87
1 files changed, 87 insertions, 0 deletions
diff --git a/platforms/chibios/flash.mk b/platforms/chibios/flash.mk
new file mode 100644
index 0000000000..46aff6e4b0
--- /dev/null
+++ b/platforms/chibios/flash.mk
@@ -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