diff options
| author | hathach <[email protected]> | 2019-05-02 20:30:44 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-05-02 20:30:44 +0700 |
| commit | 867e69ed9d1ef44a7574ccf6543c8a46ef8d8e6c (patch) | |
| tree | 59b0e0aad89d7735585737be52fd2daffdbab5c0 /examples/rules.mk | |
| parent | 2341ecb4188b1998e1e682a09e9b04570929a5a4 (diff) | |
| parent | 7e2088765daf15f59f43c9e7cffb46b9ae997e19 (diff) | |
Merge pull request #61 from hathach/develop
enhance HID, add HID out endpoint support
Diffstat (limited to 'examples/rules.mk')
| -rw-r--r-- | examples/rules.mk | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/examples/rules.mk b/examples/rules.mk new file mode 100644 index 000000000..df9ffb7e5 --- /dev/null +++ b/examples/rules.mk @@ -0,0 +1,111 @@ +# +# Common make definition for all examples +# + +# libc +LIBS = -lgcc -lc -lm -lnosys + +# TinyUSB Stack source +SRC_C += \ + src/common/tusb_fifo.c \ + src/device/usbd.c \ + src/device/usbd_control.c \ + src/class/msc/msc_device.c \ + src/class/cdc/cdc_device.c \ + src/class/hid/hid_device.c \ + src/tusb.c \ + src/portable/$(VENDOR)/$(CHIP_FAMILY)/dcd_$(CHIP_FAMILY).c + +# TinyUSB stack include +INC += $(TOP)/src + +# +CFLAGS += $(addprefix -I,$(INC)) +LDFLAGS += $(CFLAGS) -fshort-enums -Wl,-T,$(TOP)/$(LD_FILE) -Wl,[email protected] -Wl,-cref -Wl,-gc-sections -specs=nosys.specs -specs=nano.specs + +# Assembly files can be name with upper case .S, convert it to .s +SRC_S := $(SRC_S:.S=.s) + +# Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966 +# assembly file should be placed first in linking order +OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=.o)) +OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o)) + +# Verbose mode +ifeq ("$(V)","1") +$(info CFLAGS $(CFLAGS) ) $(info ) +$(info LDFLAGS $(LDFLAGS)) $(info ) +$(info ASFLAGS $(ASFLAGS)) $(info ) +endif + +# Set all as default goal +.DEFAULT_GOAL := all +all: $(BUILD)/$(BOARD)-firmware.bin size + +OBJ_DIRS = $(sort $(dir $(OBJ))) +$(OBJ): | $(OBJ_DIRS) +$(OBJ_DIRS): + @$(MKDIR) -p $@ + +$(BUILD)/$(BOARD)-firmware.elf: $(OBJ) + @echo LINK $@ + @$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group + +$(BUILD)/$(BOARD)-firmware.bin: $(BUILD)/$(BOARD)-firmware.elf + @echo CREATE $@ + @$(OBJCOPY) -O binary -j .vectors -j .text -j .data $^ $@ + +$(BUILD)/$(BOARD)-firmware.hex: $(BUILD)/$(BOARD)-firmware.elf + @echo CREATE $@ + @$(OBJCOPY) -O ihex $^ $@ + +# We set vpath to point to the top of the tree so that the source files +# can be located. By following this scheme, it allows a single build rule +# to be used to compile all .c files. +vpath %.c . $(TOP) +$(BUILD)/obj/%.o: %.c + @echo CC $(notdir $@) + @$(CC) $(CFLAGS) -c -MD -o $@ $< + @# The following fixes the dependency file. + @# See http://make.paulandlesley.org/autodep.html for details. + @# Regex adjusted from the above to play better with Windows paths, etc. + @$(CP) $(@:.o=.d) $(@:.o=.P); \ + $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \ + -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \ + $(RM) $(@:.o=.d) + +# ASM sources lower case .s +vpath %.s . $(TOP) +$(BUILD)/obj/%.o: %.s + @echo AS $(notdir $@) + @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $< + +# ASM sources upper case .S +vpath %.S . $(TOP) +$(BUILD)/obj/%.o: %.S + @echo AS $(notdir $@) + @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $< + +size: $(BUILD)/$(BOARD)-firmware.elf + -@echo '' + @$(SIZE) $< + -@echo '' + +clean: + rm -rf build-$(BOARD) + +# Flash binary using Jlink +ifeq ($(OS),Windows_NT) + JLINKEXE = JLink.exe +else + JLINKEXE = JLinkExe +endif + +# Flash using jlink +flash-jlink: $(BUILD)/$(BOARD)-firmware.hex + @echo halt > $(BUILD)/$(BOARD).jlink + @echo loadfile $^ >> $(BUILD)/$(BOARD).jlink + @echo r >> $(BUILD)/$(BOARD).jlink + @echo go >> $(BUILD)/$(BOARD).jlink + @echo exit >> $(BUILD)/$(BOARD).jlink + $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -speed auto -CommandFile $(BUILD)/$(BOARD).jlink |
