rules.mk 3.6 KB

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