rules.mk 3.9 KB

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