rules.mk 3.0 KB

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