Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for producing UF2-format binaries. #12435

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.eep
*.elf
*.hex
*.uf2
*.qmk
!util/bootloader.hex
!quantum/tools/eeprom_reset.hex
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ clean:

.PHONY: distclean
distclean: clean
echo -n 'Deleting *.bin and *.hex ... '
rm -f *.bin *.hex
echo -n 'Deleting *.bin, *.hex, and *.uf2 ... '
rm -f *.bin *.hex *.uf2
echo 'done.'

#Compatibility with the old make variables, anything you specify directly on the command line
Expand Down
2 changes: 2 additions & 0 deletions message.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for flashing:
MSG_UF2 = Creating UF2 file for deployment:
MSG_EEPROM = Creating load file for EEPROM:
MSG_BIN = Creating binary load file for flashing:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_EXECUTING = Executing:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_COMPILING_CXX = Compiling:
Expand Down
24 changes: 24 additions & 0 deletions quantum/mcu_selection.mk
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ ifneq ($(findstring STM32F042, $(MCU)),)
# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11

# UF2 settings
UF2_FAMILY ?= STM32F0
endif

ifneq ($(findstring STM32F072, $(MCU)),)
Expand Down Expand Up @@ -172,6 +175,9 @@ ifneq ($(findstring STM32F072, $(MCU)),)
# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11

# UF2 settings
UF2_FAMILY ?= STM32F0
endif

ifneq ($(findstring STM32F103, $(MCU)),)
Expand Down Expand Up @@ -205,6 +211,9 @@ ifneq ($(findstring STM32F103, $(MCU)),)
# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11

# UF2 settings
UF2_FAMILY ?= STM32F1
endif

ifneq ($(findstring STM32F303, $(MCU)),)
Expand Down Expand Up @@ -238,6 +247,9 @@ ifneq ($(findstring STM32F303, $(MCU)),)
# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11

# UF2 settings
UF2_FAMILY ?= STM32F3
endif

ifneq ($(findstring STM32F401, $(MCU)),)
Expand Down Expand Up @@ -271,6 +283,9 @@ ifneq ($(findstring STM32F401, $(MCU)),)
# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11

# UF2 settings
UF2_FAMILY ?= STM32F4
endif

ifneq ($(findstring STM32F411, $(MCU)),)
Expand Down Expand Up @@ -304,6 +319,9 @@ ifneq ($(findstring STM32F411, $(MCU)),)
# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11

# UF2 settings
UF2_FAMILY ?= STM32F4
endif

ifneq ($(findstring STM32G431, $(MCU)),)
Expand Down Expand Up @@ -337,6 +355,9 @@ ifneq ($(findstring STM32G431, $(MCU)),)
# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11

# UF2 settings
UF2_FAMILY ?= STM32G4
endif

ifneq ($(findstring STM32G474, $(MCU)),)
Expand Down Expand Up @@ -370,6 +391,9 @@ ifneq ($(findstring STM32G474, $(MCU)),)
# Options to pass to dfu-util when flashing
DFU_ARGS ?= -d 0483:DF11 -a 0 -s 0x08000000:leave
DFU_SUFFIX_ARGS ?= -v 0483 -p DF11

# UF2 settings
UF2_FAMILY ?= STM32G4
endif

ifneq (,$(filter $(MCU),at90usb162 atmega16u2 atmega32u2 atmega16u4 atmega32u4 at90usb646 at90usb647 at90usb1286 at90usb1287))
Expand Down
31 changes: 25 additions & 6 deletions tmk_core/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ ifneq ($(filter Darwin FreeBSD,$(shell uname -s)),)
MD5SUM = md5
endif

# UF2 format settings
# To produce a UF2 file in your build, add to your keyboard's rules.mk:
# FIRMWARE_FORMAT = uf2
UF2CONV = $(TOP_DIR)/util/uf2conv.py
UF2_FAMILY ?= 0x0

# Compiler flags to generate dependency files.
#GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
GENDEPFLAGS = -MMD -MP -MF $(patsubst %.o,%.td,$@)
Expand Down Expand Up @@ -255,6 +261,7 @@ DFU_SUFFIX_ARGS ?=

elf: $(BUILD_DIR)/$(TARGET).elf
hex: $(BUILD_DIR)/$(TARGET).hex
uf2: $(BUILD_DIR)/$(TARGET).uf2
cpfirmware: $(FIRMWARE_FORMAT)
$(SILENT) || printf "Copying $(TARGET).$(FIRMWARE_FORMAT) to qmk_firmware folder" | $(AWK_CMD)
$(COPY) $(BUILD_DIR)/$(TARGET).$(FIRMWARE_FORMAT) $(TARGET).$(FIRMWARE_FORMAT) && $(PRINT_OK)
Expand Down Expand Up @@ -283,32 +290,44 @@ gccversion :

# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
$(eval CMD=$(HEX) $< $@)
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
@$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
@$(BUILD_CMD)

%.uf2: %.hex
$(eval CMD=$(UF2CONV) $(BUILD_DIR)/$(TARGET).hex -o $(BUILD_DIR)/$(TARGET).uf2 -c -f $(UF2_FAMILY) >/dev/null 2>&1)
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
@$(SILENT) || printf "$(MSG_UF2) $@" | $(AWK_CMD)
@$(BUILD_CMD)

%.eep: %.elf
@$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
$(eval CMD=$(EEP) $< $@ || exit 0)
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
@$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
@$(BUILD_CMD)

# Create extended listing file from ELF output file.
%.lss: %.elf
@$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
$(eval CMD=$(OBJDUMP) -h -S -z $< > $@)
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
@$(SILENT) || printf "$(MSG_EXTENDED_LISTING) $@" | $(AWK_CMD)
@$(BUILD_CMD)

# Create a symbol table from ELF output file.
%.sym: %.elf
@$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
$(eval CMD=$(NM) -n $< > $@ )
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
@$(SILENT) || printf "$(MSG_SYMBOL_TABLE) $@" | $(AWK_CMD)
@$(BUILD_CMD)

%.bin: %.elf
@$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
$(eval CMD=$(BIN) $< $@ || exit 0)
#@$(SILENT) || printf "$(MSG_EXECUTING) '$(CMD)':\n"
@$(SILENT) || printf "$(MSG_BIN) $@" | $(AWK_CMD)
@$(BUILD_CMD)
if [ ! -z "$(DFU_SUFFIX_ARGS)" ]; then \
#$(SILENT) || printf "$(MSG_EXECUTING) '$(DFU_SUFFIX) $(DFU_SUFFIX_ARGS) -a $(BUILD_DIR)/$(TARGET).bin 1>/dev/null':\n" ;\
$(DFU_SUFFIX) $(DFU_SUFFIX_ARGS) -a $(BUILD_DIR)/$(TARGET).bin 1>/dev/null ;\
fi
$(COPY) $(BUILD_DIR)/$(TARGET).bin $(TARGET).bin;
Expand Down Expand Up @@ -476,7 +495,7 @@ $(eval $(foreach OUTPUT,$(OUTPUTS),$(shell mkdir -p $(OUTPUT) 2>/dev/null)))

# Listing of phony targets.
.PHONY : all dump_vars finish sizebefore sizeafter qmkversion \
gccversion build elf hex eep lss sym coff extcoff \
gccversion build elf hex uf2 eep lss sym coff extcoff \
clean clean_list debug gdb-config show_path \
program teensy dfu dfu-ee dfu-start \
flash dfu-split-left dfu-split-right \
Expand Down
Loading