From 342b727a0d2fbb535167506baf7372ea3944bbde Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Sun, 22 Mar 2026 13:25:16 -0500 Subject: [PATCH 01/12] Firmware makefile cleanup Remove unused/empty variables. Replace AVRDIR with CROSS_COMPILE. Add line breaks for readability. Don't hide the compiler command line. Use pattern rules and pattern substitution to avoid duplication. Mark all phony targets as phony. Apply -DSINGLE_ENPOINT_INTERFACE to a non-phony target. Include the generated .d files for better dependency tracking. (Note that `make clean` is still required when switching variants.) --- AVR_Code/USB_BULK_TEST/Makefile | 316 ++++++++++---------------------- 1 file changed, 100 insertions(+), 216 deletions(-) mode change 100755 => 100644 AVR_Code/USB_BULK_TEST/Makefile diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile old mode 100755 new mode 100644 index d14e3a548..12d168147 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -23,220 +23,104 @@ # the suffix 0x01. It is recommended that this line in globals.h be left # commented-out, which ensures that `make 0x01` and `make 0x02` work as # expected. -EXECUTABLES := -LIB_DEP := -LIBS := -USER_OBJS := -OUTPUT_FILE_PATH := -OUTPUT_FILE_PATH =$(NAME).elf -OUTPUT_FILE_PATH_AS_ARGS +=$(NAME).elf -AVR_APP_PATH :=$$$AVR_APP_PATH$$$ -AVRDIR= -CC=$(AVRDIR)/bin/avr-gcc -INCLUDES=-I"./common/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained" -I"./common/services/usb/class/vendor/device/example" -I"./src/ASF/common/services/usb/udc" -I"./src/ASF/xmega/drivers/nvm" -I"./src/ASF/common/services/sleepmgr" -I"./src/ASF/common/services/clock" -I"./src/ASF/xmega/drivers/sleep" -I"./src/ASF/xmega/drivers/usb" -I"./src/ASF/xmega/drivers/cpu" -I"./src/ASF/common/services/usb/class/vendor" -I"./src/ASF/common/services/usb/class/vendor/device" -I"./src/ASF/common/services/usb" -I"./common/applications/user_application/user_board/config" -I"./src/ASF/xmega/utils" -I"./src/config" -I"./src/ASF/common/boards" -I"./src/ASF/xmega/utils/preprocessor" -I"./src/ASF/common/utils" -I"./src" -I"./src/ASF/common/boards/user_board" -I"./src/ASF/common/services/ioport" - -CFLAGS=-std=gnu99 -ffunction-sections -mmcu=atxmega32a4u -fsigned-char -funsigned-bitfields -fdata-sections -fshort-enums -fno-strict-aliasing -fno-jump-tables -fpack-struct -Wall -O2 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -NAME=labrafirm_$(SUFFIX) - -OBJS += \ -./src/tiny_calibration.o \ -./src/tiny_dig.o \ -./src/tiny_eeprom.o \ -./src/ASF/common/boards/user_board/init.o \ -./src/ASF/common/services/ioport/xmega/ioport_compat.o \ -./src/main.o \ -./src/tiny_adc.o \ -./src/tiny_dac.o \ -./src/tiny_dma.o \ -./src/tiny_timer.o \ -./src/tiny_uart.o \ -./src/ASF/common/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained/ui.o \ -./src/ASF/common/services/clock/xmega/sysclk.o \ -./src/ASF/common/services/sleepmgr/xmega/sleepmgr.o \ -./src/ASF/common/services/usb/class/vendor/device/udi_vendor.o \ -./src/ASF/common/services/usb/class/vendor/device/udi_vendor_desc.o \ -./src/ASF/common/services/usb/udc/udc.o \ -./src/ASF/xmega/drivers/nvm/nvm.o \ -./src/ASF/xmega/drivers/nvm/nvm_asm.o \ -./src/ASF/xmega/drivers/cpu/ccp.o \ -./src/ASF/xmega/drivers/usb/usb_device.o - -C_DEPS_AS_ARGS += \ -./src/tiny_calibration.d \ -./src/tiny_dig.d \ -./src/tiny_eeprom.d \ -./src/ASF/common/boards/user_board/init.d \ -./src/ASF/common/services/ioport/xmega/ioport_compat.d \ -./src/main.d \ -./src/tiny_adc.d \ -./src/tiny_dac.d \ -./src/tiny_dma.d \ -./src/tiny_timer.d \ -./src/tiny_uart.d \ -./src/ASF/common/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained/ui.d \ -./src/ASF/common/services/clock/xmega/sysclk.d \ -./src/ASF/common/services/sleepmgr/xmega/sleepmgr.d \ -./src/ASF/common/services/usb/class/vendor/device/udi_vendor.d \ -./src/ASF/common/services/usb/class/vendor/device/udi_vendor_desc.d \ -./src/ASF/common/services/usb/udc/udc.d \ -./src/ASF/xmega/drivers/nvm/nvm.d \ -./src/ASF/xmega/drivers/nvm/nvm_asm.d \ -./src/ASF/xmega/drivers/cpu/ccp.d \ -./src/ASF/xmega/drivers/usb/usb_device.d - -OBJS_AS_ARGS += \ -./src/tiny_calibration.o \ -./src/tiny_dig.o \ -./src/tiny_eeprom.o \ -./src/ASF/common/boards/user_board/init.o \ -./src/ASF/common/services/ioport/xmega/ioport_compat.o \ -./src/main.o \ -./src/tiny_adc.o \ -./src/tiny_dac.o \ -./src/tiny_dma.o \ -./src/tiny_timer.o \ -./src/tiny_uart.o \ -./src/ASF/common/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained/ui.o \ -./src/ASF/common/services/clock/xmega/sysclk.o \ -./src/ASF/common/services/sleepmgr/xmega/sleepmgr.o \ -./src/ASF/common/services/usb/class/vendor/device/udi_vendor.o \ -./src/ASF/common/services/usb/class/vendor/device/udi_vendor_desc.o \ -./src/ASF/common/services/usb/udc/udc.o \ -./src/ASF/xmega/drivers/nvm/nvm.o \ -./src/ASF/xmega/drivers/nvm/nvm_asm.o \ -./src/ASF/xmega/drivers/cpu/ccp.o \ -./src/ASF/xmega/drivers/usb/usb_device.o - -./src/tiny_calibration.o: ./src/tiny_calibration.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/tiny_dig.o: ./src/tiny_dig.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/tiny_eeprom.o: ./src/tiny_eeprom.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/common/boards/user_board/init.o: ./src/ASF/common/boards/user_board/init.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/common/services/ioport/xmega/ioport_compat.o: ./src/ASF/common/services/ioport/xmega/ioport_compat.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/main.o: ./src/main.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/tiny_adc.o: ./src/tiny_adc.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/tiny_dac.o: ./src/tiny_dac.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/tiny_dma.o: ./src/tiny_dma.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/tiny_timer.o: ./src/tiny_timer.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/tiny_uart.o: ./src/tiny_uart.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/common/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained/ui.o: ./src/ASF/common/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained/ui.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/common/services/clock/xmega/sysclk.o: ./src/ASF/common/services/clock/xmega/sysclk.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/common/services/sleepmgr/xmega/sleepmgr.o: ./src/ASF/common/services/sleepmgr/xmega/sleepmgr.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/common/services/usb/class/vendor/device/udi_vendor.o: ./src/ASF/common/services/usb/class/vendor/device/udi_vendor.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/common/services/usb/class/vendor/device/udi_vendor_desc.o: ./src/ASF/common/services/usb/class/vendor/device/udi_vendor_desc.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/common/services/usb/udc/udc.o: ./src/ASF/common/services/usb/udc/udc.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/xmega/drivers/cpu/ccp.o: ./src/ASF/xmega/drivers/cpu/ccp.s - @echo Building file: $< - @$(CC) -x assembler-with-cpp -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/xmega/drivers/nvm/nvm.o: ./src/ASF/xmega/drivers/nvm/nvm.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/xmega/drivers/nvm/nvm_asm.o: ./src/ASF/xmega/drivers/nvm/nvm_asm.s - @echo Building file: $< - @$(CC) -x assembler-with-cpp -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -./src/ASF/xmega/drivers/usb/usb_device.o: ./src/ASF/xmega/drivers/usb/usb_device.c - @echo Building file: $< - @$(CC) -DNDEBUG -DBOARD=USER_BOARD $(INCLUDES) $(CFLAGS) -c -o "$@" "$<" - @echo Finished building: $< - -0x01: SUFFIX=0x01 -0x01: $(OUTPUT_FILE_PATH) - -0x02: CFLAGS+=-DSINGLE_ENDPOINT_INTERFACE -0x02: SUFFIX=0x02 -0x02: $(OUTPUT_FILE_PATH) - -$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP) - @echo Building target: $@ - $(CC) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map=$(NAME)".map" -Wl,-lm -mmcu=atxmega32a4u -Wl,--gc-sections -Wl,--relax - $(AVRDIR)/bin/avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $(NAME)".elf" $(NAME)".hex" - $(AVRDIR)/bin/avr-objdump -h -S $(NAME)".elf" > $(NAME)".lss" - $(AVRDIR)/bin/avr-objcopy -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O binary $(NAME)".elf" $(NAME)".eep" || exit 0 - $(AVRDIR)/bin/avr-objcopy -O srec -R .eeprom -R .fuse -R .lock -R .signature $(NAME)".elf" $(NAME)".srec" - $(AVRDIR)/bin/avr-size $(NAME)".elf" - @echo Finished successfully: $(NAME) - -VARIANTS = 0x01 0x02 -clean : - -rm -rf $(OBJS_AS_ARGS) $(EXECUTABLES) - -rm -rf $(C_DEPS_AS_ARGS) - $(foreach SUFFIX,$(VARIANTS), \ - rm -rf $(NAME).hex ; \ - rm -rf $(NAME).lss ; \ - rm -rf $(NAME).eep ; \ - rm -rf $(NAME).srec ; \ - rm -rf $(NAME).elf $(NAME).a $(NAME).map) +CROSS_COMPILE = avr- +CC = $(CROSS_COMPILE)gcc +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump +SIZE = $(CROSS_COMPILE)size + +DEFINES = \ +-DNDEBUG \ +-DBOARD=USER_BOARD + +INCLUDES = \ +-Icommon/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained \ +-Icommon/services/usb/class/vendor/device/example \ +-Isrc/ASF/common/services/usb/udc \ +-Isrc/ASF/xmega/drivers/nvm \ +-Isrc/ASF/common/services/sleepmgr \ +-Isrc/ASF/common/services/clock \ +-Isrc/ASF/xmega/drivers/sleep \ +-Isrc/ASF/xmega/drivers/usb \ +-Isrc/ASF/xmega/drivers/cpu \ +-Isrc/ASF/common/services/usb/class/vendor \ +-Isrc/ASF/common/services/usb/class/vendor/device \ +-Isrc/ASF/common/services/usb \ +-Icommon/applications/user_application/user_board/config \ +-Isrc/ASF/xmega/utils \ +-Isrc/config \ +-Isrc/ASF/common/boards \ +-Isrc/ASF/xmega/utils/preprocessor \ +-Isrc/ASF/common/utils \ +-Isrc \ +-Isrc/ASF/common/boards/user_board \ +-Isrc/ASF/common/services/ioport + +CPPFLAGS = $(DEFINES) $(INCLUDES) + +CFLAGS = \ +-std=gnu99 \ +-ffunction-sections \ +-mmcu=atxmega32a4u \ +-fsigned-char \ +-funsigned-bitfields \ +-fdata-sections \ +-fshort-enums \ +-fno-strict-aliasing \ +-fno-jump-tables \ +-fpack-struct \ +-Wall \ +-O2 \ +-MD -MP -MF $(@:%.o=%.d) -MT $(@:%.o=%.d) -MT $(@:%.o=%.o) + +OBJS = \ +src/tiny_calibration.o \ +src/tiny_dig.o \ +src/tiny_eeprom.o \ +src/ASF/common/boards/user_board/init.o \ +src/ASF/common/services/ioport/xmega/ioport_compat.o \ +src/main.o \ +src/tiny_adc.o \ +src/tiny_dac.o \ +src/tiny_dma.o \ +src/tiny_timer.o \ +src/tiny_uart.o \ +src/ASF/common/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained/ui.o \ +src/ASF/common/services/clock/xmega/sysclk.o \ +src/ASF/common/services/sleepmgr/xmega/sleepmgr.o \ +src/ASF/common/services/usb/class/vendor/device/udi_vendor.o \ +src/ASF/common/services/usb/class/vendor/device/udi_vendor_desc.o \ +src/ASF/common/services/usb/udc/udc.o \ +src/ASF/xmega/drivers/nvm/nvm.o \ +src/ASF/xmega/drivers/nvm/nvm_asm.o \ +src/ASF/xmega/drivers/cpu/ccp.o \ +src/ASF/xmega/drivers/usb/usb_device.o + +.PHONY: 0x01 0x02 +0x01: labrafirm_0x01.elf +0x02: labrafirm_0x02.elf + +labrafirm_0x02.elf: DEFINES+=-DSINGLE_ENDPOINT_INTERFACE + +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< + +%.o: %.s + $(CC) -x assembler-with-cpp $(CPPFLAGS) $(CFLAGS) -c -o $@ $< + +labrafirm_%.elf: $(OBJS) + $(CC) -o $@ $(OBJS) -Wl,-Map=$(@:%.elf=%.map) -Wl,-lm -mmcu=atxmega32a4u -Wl,--gc-sections -Wl,--relax + $(SIZE) $@ + $(OBJDUMP) -h -S $@ > $(@:%.elf=%.lss) + $(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $@ $(@:%.elf=%.hex) + $(OBJCOPY) -O srec -R .eeprom -R .fuse -R .lock -R .signature $@ $(@:%.elf=%.srec) + $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O binary $@ $(@:%.elf=%.eep) || exit 0 + +.PHONY: clean +clean: + -rm -rf $(OBJS) $(OBJS:%.o=%.d) $(foreach variant,0x01 0x02,$(foreach ext,elf map hex srec eep lss,labrafirm_$(variant).$(ext))) + +ifneq ($(MAKECMDGOALS),clean) +-include $(OBJS:%.o=%.d) +endif From 284c6d953df85248a795d27f196a31d31e22397e Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Sun, 22 Mar 2026 21:17:45 -0500 Subject: [PATCH 02/12] Name the generated files to match existing conventions --- AVR_Code/USB_BULK_TEST/Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile index 12d168147..322a8c5f7 100644 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -97,11 +97,12 @@ src/ASF/xmega/drivers/nvm/nvm_asm.o \ src/ASF/xmega/drivers/cpu/ccp.o \ src/ASF/xmega/drivers/usb/usb_device.o +VERSION = 0007 .PHONY: 0x01 0x02 -0x01: labrafirm_0x01.elf -0x02: labrafirm_0x02.elf +0x01: labrafirm_$(VERSION)_01.elf +0x02: labrafirm_$(VERSION)_02.elf -labrafirm_0x02.elf: DEFINES+=-DSINGLE_ENDPOINT_INTERFACE +labrafirm_$(VERSION)_02.elf: DEFINES+=-DSINGLE_ENDPOINT_INTERFACE %.o: %.c $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< @@ -109,7 +110,7 @@ labrafirm_0x02.elf: DEFINES+=-DSINGLE_ENDPOINT_INTERFACE %.o: %.s $(CC) -x assembler-with-cpp $(CPPFLAGS) $(CFLAGS) -c -o $@ $< -labrafirm_%.elf: $(OBJS) +labrafirm_$(VERSION)_%.elf: $(OBJS) $(CC) -o $@ $(OBJS) -Wl,-Map=$(@:%.elf=%.map) -Wl,-lm -mmcu=atxmega32a4u -Wl,--gc-sections -Wl,--relax $(SIZE) $@ $(OBJDUMP) -h -S $@ > $(@:%.elf=%.lss) @@ -119,7 +120,7 @@ labrafirm_%.elf: $(OBJS) .PHONY: clean clean: - -rm -rf $(OBJS) $(OBJS:%.o=%.d) $(foreach variant,0x01 0x02,$(foreach ext,elf map hex srec eep lss,labrafirm_$(variant).$(ext))) + -rm -rf $(OBJS) $(OBJS:%.o=%.d) $(foreach variant,01 02,$(foreach ext,elf map lss hex srec eep,labrafirm_$(VERSION)_$(variant).$(ext))) ifneq ($(MAKECMDGOALS),clean) -include $(OBJS:%.o=%.d) From 370421a377bf5e6b98de26bda31da094f37833cb Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Sun, 22 Mar 2026 23:27:01 -0500 Subject: [PATCH 03/12] Normalize line endings and permissions in generated files --- AVR_Code/USB_BULK_TEST/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile index 322a8c5f7..4c9d0a48d 100644 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -114,9 +114,9 @@ labrafirm_$(VERSION)_%.elf: $(OBJS) $(CC) -o $@ $(OBJS) -Wl,-Map=$(@:%.elf=%.map) -Wl,-lm -mmcu=atxmega32a4u -Wl,--gc-sections -Wl,--relax $(SIZE) $@ $(OBJDUMP) -h -S $@ > $(@:%.elf=%.lss) - $(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $@ $(@:%.elf=%.hex) - $(OBJCOPY) -O srec -R .eeprom -R .fuse -R .lock -R .signature $@ $(@:%.elf=%.srec) - $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O binary $@ $(@:%.elf=%.eep) || exit 0 + $(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $@ $(@:%.elf=%.hex) && sed -i 's/\r$$//' $(@:%.elf=%.hex) && chmod -x $(@:%.elf=%.hex) + $(OBJCOPY) -O srec -R .eeprom -R .fuse -R .lock -R .signature $@ $(@:%.elf=%.srec) && sed -i 's/\r$$//' $(@:%.elf=%.srec) && chmod -x $(@:%.elf=%.srec) + $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O binary $@ $(@:%.elf=%.eep) && chmod -x $(@:%.elf=%.eep) || exit 0 .PHONY: clean clean: From 608ab7b90206cb4f63ebed7aeb7a9e9d9cc4d3ea Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Sun, 22 Mar 2026 23:35:51 -0500 Subject: [PATCH 04/12] Skip generating .srec and .eep files by default --- AVR_Code/USB_BULK_TEST/Makefile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile index 4c9d0a48d..927e43365 100644 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -99,9 +99,9 @@ src/ASF/xmega/drivers/usb/usb_device.o VERSION = 0007 .PHONY: 0x01 0x02 -0x01: labrafirm_$(VERSION)_01.elf -0x02: labrafirm_$(VERSION)_02.elf - +0x01: labrafirm_$(VERSION)_01.hex +0x02: labrafirm_$(VERSION)_02.hex +labrafirm_$(VERSION)_01.elf: labrafirm_$(VERSION)_02.elf: DEFINES+=-DSINGLE_ENDPOINT_INTERFACE %.o: %.c @@ -114,9 +114,15 @@ labrafirm_$(VERSION)_%.elf: $(OBJS) $(CC) -o $@ $(OBJS) -Wl,-Map=$(@:%.elf=%.map) -Wl,-lm -mmcu=atxmega32a4u -Wl,--gc-sections -Wl,--relax $(SIZE) $@ $(OBJDUMP) -h -S $@ > $(@:%.elf=%.lss) - $(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $@ $(@:%.elf=%.hex) && sed -i 's/\r$$//' $(@:%.elf=%.hex) && chmod -x $(@:%.elf=%.hex) - $(OBJCOPY) -O srec -R .eeprom -R .fuse -R .lock -R .signature $@ $(@:%.elf=%.srec) && sed -i 's/\r$$//' $(@:%.elf=%.srec) && chmod -x $(@:%.elf=%.srec) - $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O binary $@ $(@:%.elf=%.eep) && chmod -x $(@:%.elf=%.eep) || exit 0 + +%.hex: %.elf + $(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ && sed -i 's/\r$$//' $@ && chmod -x $@ + +%.srec: %.elf + $(OBJCOPY) -O srec -R .eeprom -R .fuse -R .lock -R .signature $< $@ && sed -i 's/\r$$//' $@ && chmod -x $@ + +%.eep: %.elf + $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O binary $< $@ && chmod -x $@ || exit 0 .PHONY: clean clean: From f6dc43491720b0fb38ca2c9f9d5aab504eca0fe0 Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Mon, 23 Mar 2026 22:57:01 -0500 Subject: [PATCH 05/12] Drop 0x prefix --- AVR_Code/USB_BULK_TEST/Makefile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile index 927e43365..61c33fc59 100644 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -1,15 +1,15 @@ # see https://github.com/espotek-org/Labrador/wiki/Building-from-source#building-the-firmware # Usage : -# make 0x01 +# make 01 # build a version of the firmware compatible with Windows x64 OSs -# make 0x02 +# make 02 # build a version of the firmware compatible with all other OSs # Here, OS refers to that of the machine with which the Labrador board will interface. -# After running 'make 0x01', to switch to building variant 0x02 instead, first run 'make clean'. -# The same goes for switching from building the 0x02 variant to building the 0x01 variant. +# After running 'make 01', to switch to building variant 02 instead, first run 'make clean'. +# The same goes for switching from building the 02 variant to building the 01 variant. # Some details: -# In the build process for variant 0x01, the macro SINGLE_ENDPOINT_INTERFACE -# is undefined, while in the build process for variant 0x02, +# In the build process for variant 01, the macro SINGLE_ENDPOINT_INTERFACE +# is undefined, while in the build process for variant 02, # SINGLE_ENDPOINT_INTERFACE is defined. In several regions of the source # code, the undefined/defined status of this macro determines which of two # possible code blocks are compiled into the firmware. The collective effect @@ -18,10 +18,10 @@ # endpoints to send the scope/logic analyzer data" (from # https://github.com/espotek-org/Labrador/issues/260) # *NOTE* : there is a commented-out line defining SINGLE_ENDPOINT_INTERFACE in -# globals.h. If it is uncommented, both 'make 0x01' and 'make 0x02' will -# produce variant 0x02. Further, 'make 0x01' will mislabel the firmware with -# the suffix 0x01. It is recommended that this line in globals.h be left -# commented-out, which ensures that `make 0x01` and `make 0x02` work as +# globals.h. If it is uncommented, both 'make 01' and 'make 02' will +# produce variant 02. Further, 'make 01' will mislabel the firmware with +# the suffix 01. It is recommended that this line in globals.h be left +# commented-out, which ensures that `make 01` and `make 02` work as # expected. CROSS_COMPILE = avr- @@ -98,9 +98,9 @@ src/ASF/xmega/drivers/cpu/ccp.o \ src/ASF/xmega/drivers/usb/usb_device.o VERSION = 0007 -.PHONY: 0x01 0x02 -0x01: labrafirm_$(VERSION)_01.hex -0x02: labrafirm_$(VERSION)_02.hex +.PHONY: 01 02 +01: labrafirm_$(VERSION)_01.hex +02: labrafirm_$(VERSION)_02.hex labrafirm_$(VERSION)_01.elf: labrafirm_$(VERSION)_02.elf: DEFINES+=-DSINGLE_ENDPOINT_INTERFACE From 6d869a17b866eb4c2fb4cf02e33f24db7926a4b7 Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Thu, 26 Mar 2026 23:59:42 -0500 Subject: [PATCH 06/12] Prerequisite fixes Listing files by name as targets prevents make from deleting them as intermediate. Fixes the problem where running `make` a second time will rebuild everything it just deleted, since it now finds a mention of the file in a .d file. Add a dependency on Makefile, so that objects get rebuilt if anything in the Makefile changes. There is no rule to rebuild .d files, so we don't need the conditional part to avoid including them (and potentially rebuilding them) if we're just going to delete them. Those plus the .map and .lss files are unmanaged side-effects. --- AVR_Code/USB_BULK_TEST/Makefile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile index 61c33fc59..a73235363 100644 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -97,11 +97,16 @@ src/ASF/xmega/drivers/nvm/nvm_asm.o \ src/ASF/xmega/drivers/cpu/ccp.o \ src/ASF/xmega/drivers/usb/usb_device.o +DEPS = $(OBJS:%.o=%.d) + VERSION = 0007 -.PHONY: 01 02 +VARIANTS = 01 02 +EXEEXTS = .elf .map .lss .hex .srec .eep +EXES = $(foreach variant,$(VARIANTS),$(foreach ext,$(EXEEXTS),labrafirm_$(VERSION)_$(variant)$(ext))) + +.PHONY: $(VARIANTS) 01: labrafirm_$(VERSION)_01.hex 02: labrafirm_$(VERSION)_02.hex -labrafirm_$(VERSION)_01.elf: labrafirm_$(VERSION)_02.elf: DEFINES+=-DSINGLE_ENDPOINT_INTERFACE %.o: %.c @@ -126,8 +131,7 @@ labrafirm_$(VERSION)_%.elf: $(OBJS) .PHONY: clean clean: - -rm -rf $(OBJS) $(OBJS:%.o=%.d) $(foreach variant,01 02,$(foreach ext,elf map lss hex srec eep,labrafirm_$(VERSION)_$(variant).$(ext))) + -rm -rf $(OBJS) $(DEPS) $(EXES) -ifneq ($(MAKECMDGOALS),clean) --include $(OBJS:%.o=%.d) -endif +$(OBJS) $(EXES): Makefile +-include $(DEPS) From dc01ec35fd2b46756d803007c60d3a72f1545566 Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Fri, 27 Mar 2026 00:11:06 -0500 Subject: [PATCH 07/12] Automatically add -D/-I to defines/includes --- AVR_Code/USB_BULK_TEST/Makefile | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile index a73235363..3fe9b8e50 100644 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -31,33 +31,33 @@ OBJDUMP = $(CROSS_COMPILE)objdump SIZE = $(CROSS_COMPILE)size DEFINES = \ --DNDEBUG \ --DBOARD=USER_BOARD +NDEBUG \ +BOARD=USER_BOARD INCLUDES = \ --Icommon/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained \ --Icommon/services/usb/class/vendor/device/example \ --Isrc/ASF/common/services/usb/udc \ --Isrc/ASF/xmega/drivers/nvm \ --Isrc/ASF/common/services/sleepmgr \ --Isrc/ASF/common/services/clock \ --Isrc/ASF/xmega/drivers/sleep \ --Isrc/ASF/xmega/drivers/usb \ --Isrc/ASF/xmega/drivers/cpu \ --Isrc/ASF/common/services/usb/class/vendor \ --Isrc/ASF/common/services/usb/class/vendor/device \ --Isrc/ASF/common/services/usb \ --Icommon/applications/user_application/user_board/config \ --Isrc/ASF/xmega/utils \ --Isrc/config \ --Isrc/ASF/common/boards \ --Isrc/ASF/xmega/utils/preprocessor \ --Isrc/ASF/common/utils \ --Isrc \ --Isrc/ASF/common/boards/user_board \ --Isrc/ASF/common/services/ioport - -CPPFLAGS = $(DEFINES) $(INCLUDES) +common/services/usb/class/vendor/device/example/atxmega256a3bu_xmega_a3bu_xplained \ +common/services/usb/class/vendor/device/example \ +src/ASF/common/services/usb/udc \ +src/ASF/xmega/drivers/nvm \ +src/ASF/common/services/sleepmgr \ +src/ASF/common/services/clock \ +src/ASF/xmega/drivers/sleep \ +src/ASF/xmega/drivers/usb \ +src/ASF/xmega/drivers/cpu \ +src/ASF/common/services/usb/class/vendor \ +src/ASF/common/services/usb/class/vendor/device \ +src/ASF/common/services/usb \ +common/applications/user_application/user_board/config \ +src/ASF/xmega/utils \ +src/config \ +src/ASF/common/boards \ +src/ASF/xmega/utils/preprocessor \ +src/ASF/common/utils \ +src \ +src/ASF/common/boards/user_board \ +src/ASF/common/services/ioport + +CPPFLAGS = $(addprefix -D,$(DEFINES)) $(addprefix -I,$(INCLUDES)) CFLAGS = \ -std=gnu99 \ @@ -107,7 +107,7 @@ EXES = $(foreach variant,$(VARIANTS),$(foreach ext,$(EXEEXTS),labrafirm_$(VERSIO .PHONY: $(VARIANTS) 01: labrafirm_$(VERSION)_01.hex 02: labrafirm_$(VERSION)_02.hex -labrafirm_$(VERSION)_02.elf: DEFINES+=-DSINGLE_ENDPOINT_INTERFACE +labrafirm_$(VERSION)_02.elf: DEFINES += SINGLE_ENDPOINT_INTERFACE %.o: %.c $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< From bfc7f608235ce7bde0cd266ac16cee6d36eee263 Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Fri, 27 Mar 2026 00:45:16 -0500 Subject: [PATCH 08/12] Add a 'mostlyclean' target --- AVR_Code/USB_BULK_TEST/Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile index 3fe9b8e50..ac31957a1 100644 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -129,9 +129,11 @@ labrafirm_$(VERSION)_%.elf: $(OBJS) %.eep: %.elf $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O binary $< $@ && chmod -x $@ || exit 0 -.PHONY: clean -clean: - -rm -rf $(OBJS) $(DEPS) $(EXES) +.PHONY: mostlyclean clean +mostlyclean: + -rm -f $(OBJS) $(DEPS) +clean: mostlyclean + -rm -f $(EXES) $(OBJS) $(EXES): Makefile -include $(DEPS) From 79d18c355a84c1b64f860986e82444b09708ef79 Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Fri, 27 Mar 2026 00:51:19 -0500 Subject: [PATCH 09/12] Update .gitignore with firmware file patterns --- .gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 74bc2e93a..7a10a8edf 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ AVR Code/USB_BULK_TEST/Release Desktop_Interface/debug Desktop_Interface/release !Desktop_Interface/resources/firmware/dfu-programmer.exe +*.d *.o *.a *.so @@ -41,6 +42,14 @@ Thumbs.db pinout.png *.mex +*.elf +*.map +*.lss +*.hex +*.srec +*.eep +!Desktop_Interface/resources/firmware/*.hex + libdfuprog/Makefile* Librador_API/___librador/MATLAB_Octave/octave-workspace From 300a7d2aca20f1f186130a6471e8030259849903 Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Fri, 27 Mar 2026 01:07:56 -0500 Subject: [PATCH 10/12] Define FIRMWARE_VERSION_ID from the Makefile --- AVR_Code/USB_BULK_TEST/Makefile | 7 +++++-- AVR_Code/USB_BULK_TEST/src/globals.h | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile index ac31957a1..fff791e87 100644 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -22,7 +22,9 @@ # produce variant 02. Further, 'make 01' will mislabel the firmware with # the suffix 01. It is recommended that this line in globals.h be left # commented-out, which ensures that `make 01` and `make 02` work as -# expected. +# expected. Similarly, FIRMWARE_VERSION_ID is commented out in globals.h +# and instead defined by this Makefile. Only uncomment either definition if +# you are using Atmel Studio or similar and are not using this Makefile to build. CROSS_COMPILE = avr- CC = $(CROSS_COMPILE)gcc @@ -107,7 +109,8 @@ EXES = $(foreach variant,$(VARIANTS),$(foreach ext,$(EXEEXTS),labrafirm_$(VERSIO .PHONY: $(VARIANTS) 01: labrafirm_$(VERSION)_01.hex 02: labrafirm_$(VERSION)_02.hex -labrafirm_$(VERSION)_02.elf: DEFINES += SINGLE_ENDPOINT_INTERFACE +labrafirm_$(VERSION)_01.elf: DEFINES += FIRMWARE_VERSION_ID=0x$(VERSION) +labrafirm_$(VERSION)_02.elf: DEFINES += FIRMWARE_VERSION_ID=0x$(VERSION) SINGLE_ENDPOINT_INTERFACE %.o: %.c $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< diff --git a/AVR_Code/USB_BULK_TEST/src/globals.h b/AVR_Code/USB_BULK_TEST/src/globals.h index e85cc0b87..ac89780d2 100644 --- a/AVR_Code/USB_BULK_TEST/src/globals.h +++ b/AVR_Code/USB_BULK_TEST/src/globals.h @@ -13,7 +13,7 @@ //#define VERO #define OVERCLOCK 48 -#define FIRMWARE_VERSION_ID 0x0007 +//#define FIRMWARE_VERSION_ID 0x0007 #define ATMEL_DFU_OFFSET 0x01fc #define TC_SPISLAVE TCD0 @@ -71,4 +71,4 @@ extern const unsigned char variant; #include "unified_debug_structure.h" extern unified_debug uds; -#endif /* GLOBALS_H_ */ \ No newline at end of file +#endif /* GLOBALS_H_ */ From 75ad5de7b862ea28893a402a9319201703cd4d4c Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Fri, 27 Mar 2026 01:13:19 -0500 Subject: [PATCH 11/12] Update wiki link and drop AVRDIR reference --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c99ded66a..798faa5bf 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ echo 'export PATH="/opt/homebrew/opt/qt@5/bin:$PATH"' >> ~/.zshrc ``` -To build the AVR software, I use Atmel Studio 7. Just load up the .atsln located in the `/AVR_Code` directory and push F7. You can alternatively use open-source command-line AVR tools from GNU if you don't want to install a full IDE. Instructions for doing so are given in the [Building the firmware](https://github.com/espotek-org/Labrador/wiki/Building-from-source/#building-the-desktop-interface) section of the wiki. If you already have the GNU AVR tools installed, you can jump straight to the [firmware Makefile](https://github.com/espotek-org/Labrador/blob/master/AVR_Code/USB_BULK_TEST/Makefile), set `AVRDIR` in it appropriately, and start building. The wiki includes troubleshooting tips in case you run into issues. +To build the AVR software, I use Atmel Studio 7. Just load up the .atsln located in the `/AVR_Code` directory and push F7. You can alternatively use open-source command-line AVR tools from GNU if you don't want to install a full IDE. Instructions for doing so are given in the [Building the firmware](https://github.com/espotek-org/Labrador/wiki/Building-from-source#building-the-firmware) section of the wiki. If you already have the GNU AVR tools installed, you can jump straight to the [firmware Makefile](https://github.com/espotek-org/Labrador/blob/master/AVR_Code/USB_BULK_TEST/Makefile) and start building. The wiki includes troubleshooting tips in case you run into issues. The PCB files can be edited in KiCAD 5.0 or later. From bcb1014797e9b62bd07c072d031ee07f1fb6ba8f Mon Sep 17 00:00:00 2001 From: Kyle Guinn Date: Fri, 27 Mar 2026 01:53:30 -0500 Subject: [PATCH 12/12] Document the mostlyclean target --- AVR_Code/USB_BULK_TEST/Makefile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/AVR_Code/USB_BULK_TEST/Makefile b/AVR_Code/USB_BULK_TEST/Makefile index fff791e87..83d14cd40 100644 --- a/AVR_Code/USB_BULK_TEST/Makefile +++ b/AVR_Code/USB_BULK_TEST/Makefile @@ -1,12 +1,16 @@ # see https://github.com/espotek-org/Labrador/wiki/Building-from-source#building-the-firmware # Usage : -# make 01 -# build a version of the firmware compatible with Windows x64 OSs -# make 02 -# build a version of the firmware compatible with all other OSs +# `make 01` +# build a variant of the firmware compatible with Windows x64 OSs +# `make 02` +# build a variant of the firmware compatible with all other OSs # Here, OS refers to that of the machine with which the Labrador board will interface. -# After running 'make 01', to switch to building variant 02 instead, first run 'make clean'. -# The same goes for switching from building the 02 variant to building the 01 variant. +# +# Whenever switching between building the two variants, always run either +# `make clean` (to delete everything) or `make mostlyclean` (to delete the +# object files and leave the .hex that you will load to the Labrador board) +# so that all objects will be rebuilt with the correct macro definitions. +# # Some details: # In the build process for variant 01, the macro SINGLE_ENDPOINT_INTERFACE # is undefined, while in the build process for variant 02, @@ -18,8 +22,8 @@ # endpoints to send the scope/logic analyzer data" (from # https://github.com/espotek-org/Labrador/issues/260) # *NOTE* : there is a commented-out line defining SINGLE_ENDPOINT_INTERFACE in -# globals.h. If it is uncommented, both 'make 01' and 'make 02' will -# produce variant 02. Further, 'make 01' will mislabel the firmware with +# globals.h. If it is uncommented, both `make 01` and `make 02` will +# produce variant 02. Further, `make 01` will mislabel the firmware with # the suffix 01. It is recommended that this line in globals.h be left # commented-out, which ensures that `make 01` and `make 02` work as # expected. Similarly, FIRMWARE_VERSION_ID is commented out in globals.h