rules.mk 3.6 KB

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