rules.mk 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #
  2. # Common make definition for all examples
  3. #
  4. # libc
  5. LIBS = -lgcc -lc -lm -lnosys
  6. # TinyUSB Stack source
  7. SRC_C += \
  8. src/common/tusb_fifo.c \
  9. src/device/usbd.c \
  10. src/device/usbd_control.c \
  11. src/class/msc/msc_device.c \
  12. src/class/cdc/cdc_device.c \
  13. src/class/hid/hid_device.c \
  14. src/class/midi/midi_device.c \
  15. src/tusb.c \
  16. src/portable/$(VENDOR)/$(CHIP_FAMILY)/dcd_$(CHIP_FAMILY).c
  17. # TinyUSB stack include
  18. INC += $(TOP)/src
  19. #
  20. CFLAGS += $(addprefix -I,$(INC))
  21. LDFLAGS += $(CFLAGS) -fshort-enums -Wl,-T,$(TOP)/$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nosys.specs -specs=nano.specs
  22. ASFLAGS += $(CFLAGS)
  23. # Assembly files can be name with upper case .S, convert it to .s
  24. SRC_S := $(SRC_S:.S=.s)
  25. # Due to GCC LTO bug https://bugs.launchpad.net/gcc-arm-embedded/+bug/1747966
  26. # assembly file should be placed first in linking order
  27. OBJ += $(addprefix $(BUILD)/obj/, $(SRC_S:.s=.o))
  28. OBJ += $(addprefix $(BUILD)/obj/, $(SRC_C:.c=.o))
  29. # Verbose mode
  30. ifeq ("$(V)","1")
  31. $(info CFLAGS $(CFLAGS) ) $(info )
  32. $(info LDFLAGS $(LDFLAGS)) $(info )
  33. $(info ASFLAGS $(ASFLAGS)) $(info )
  34. endif
  35. # Set all as default goal
  36. .DEFAULT_GOAL := all
  37. all: $(BUILD)/$(BOARD)-firmware.bin size
  38. uf2: $(BUILD)/$(BOARD)-firmware.uf2
  39. OBJ_DIRS = $(sort $(dir $(OBJ)))
  40. $(OBJ): | $(OBJ_DIRS)
  41. $(OBJ_DIRS):
  42. @$(MKDIR) -p $@
  43. $(BUILD)/$(BOARD)-firmware.elf: $(OBJ)
  44. @echo LINK $@
  45. @$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
  46. $(BUILD)/$(BOARD)-firmware.bin: $(BUILD)/$(BOARD)-firmware.elf
  47. @echo CREATE $@
  48. @$(OBJCOPY) -O binary $^ $@
  49. $(BUILD)/$(BOARD)-firmware.hex: $(BUILD)/$(BOARD)-firmware.elf
  50. @echo CREATE $@
  51. @$(OBJCOPY) -O ihex $^ $@
  52. UF2_FAMILY ?= 0x00
  53. $(BUILD)/$(BOARD)-firmware.uf2: $(BUILD)/$(BOARD)-firmware.hex
  54. @echo CREATE $@
  55. $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY) -c -o $@ $^
  56. # We set vpath to point to the top of the tree so that the source files
  57. # can be located. By following this scheme, it allows a single build rule
  58. # to be used to compile all .c files.
  59. vpath %.c . $(TOP)
  60. $(BUILD)/obj/%.o: %.c
  61. @echo CC $(notdir $@)
  62. @$(CC) $(CFLAGS) -c -MD -o $@ $<
  63. @# The following fixes the dependency file.
  64. @# See http://make.paulandlesley.org/autodep.html for details.
  65. @# Regex adjusted from the above to play better with Windows paths, etc.
  66. @$(CP) $(@:.o=.d) $(@:.o=.P); \
  67. $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
  68. -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
  69. $(RM) $(@:.o=.d)
  70. # ASM sources lower case .s
  71. vpath %.s . $(TOP)
  72. $(BUILD)/obj/%.o: %.s
  73. @echo AS $(notdir $@)
  74. @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $<
  75. # ASM sources upper case .S
  76. vpath %.S . $(TOP)
  77. $(BUILD)/obj/%.o: %.S
  78. @echo AS $(notdir $@)
  79. @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $<
  80. size: $(BUILD)/$(BOARD)-firmware.elf
  81. -@echo ''
  82. @$(SIZE) $<
  83. -@echo ''
  84. clean:
  85. rm -rf $(BUILD)
  86. # Flash binary using Jlink
  87. ifeq ($(OS),Windows_NT)
  88. JLINKEXE = JLink.exe
  89. else
  90. JLINKEXE = JLinkExe
  91. endif
  92. # Flash using jlink
  93. flash-jlink: $(BUILD)/$(BOARD)-firmware.hex
  94. @echo halt > $(BUILD)/$(BOARD).jlink
  95. @echo loadfile $^ >> $(BUILD)/$(BOARD).jlink
  96. @echo r >> $(BUILD)/$(BOARD).jlink
  97. @echo go >> $(BUILD)/$(BOARD).jlink
  98. @echo exit >> $(BUILD)/$(BOARD).jlink
  99. $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink