rules.mk 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. OBJ_DIRS = $(sort $(dir $(OBJ)))
  38. $(OBJ): | $(OBJ_DIRS)
  39. $(OBJ_DIRS):
  40. @$(MKDIR) -p $@
  41. $(BUILD)/$(BOARD)-firmware.elf: $(OBJ)
  42. @echo LINK $@
  43. @$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
  44. $(BUILD)/$(BOARD)-firmware.bin: $(BUILD)/$(BOARD)-firmware.elf
  45. @echo CREATE $@
  46. @$(OBJCOPY) -O binary $^ $@
  47. $(BUILD)/$(BOARD)-firmware.hex: $(BUILD)/$(BOARD)-firmware.elf
  48. @echo CREATE $@
  49. @$(OBJCOPY) -O ihex $^ $@
  50. # We set vpath to point to the top of the tree so that the source files
  51. # can be located. By following this scheme, it allows a single build rule
  52. # to be used to compile all .c files.
  53. vpath %.c . $(TOP)
  54. $(BUILD)/obj/%.o: %.c
  55. @echo CC $(notdir $@)
  56. @$(CC) $(CFLAGS) -c -MD -o $@ $<
  57. @# The following fixes the dependency file.
  58. @# See http://make.paulandlesley.org/autodep.html for details.
  59. @# Regex adjusted from the above to play better with Windows paths, etc.
  60. @$(CP) $(@:.o=.d) $(@:.o=.P); \
  61. $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
  62. -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
  63. $(RM) $(@:.o=.d)
  64. # ASM sources lower case .s
  65. vpath %.s . $(TOP)
  66. $(BUILD)/obj/%.o: %.s
  67. @echo AS $(notdir $@)
  68. @$(CC) -x assembler-with-cpp $(ASFLAGS) -c -o $@ $<
  69. # ASM sources upper 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. size: $(BUILD)/$(BOARD)-firmware.elf
  75. -@echo ''
  76. @$(SIZE) $<
  77. -@echo ''
  78. clean:
  79. rm -rf build-$(BOARD)
  80. # Flash binary using Jlink
  81. ifeq ($(OS),Windows_NT)
  82. JLINKEXE = JLink.exe
  83. else
  84. JLINKEXE = JLinkExe
  85. endif
  86. # Flash using jlink
  87. flash-jlink: $(BUILD)/$(BOARD)-firmware.hex
  88. @echo halt > $(BUILD)/$(BOARD).jlink
  89. @echo loadfile $^ >> $(BUILD)/$(BOARD).jlink
  90. @echo r >> $(BUILD)/$(BOARD).jlink
  91. @echo go >> $(BUILD)/$(BOARD).jlink
  92. @echo exit >> $(BUILD)/$(BOARD).jlink
  93. $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $(BUILD)/$(BOARD).jlink