rules.mk 3.2 KB

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