Makefile 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. ##########################################################################################################################
  2. # File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Fri Mar 17 14:45:20 CST 2023]
  3. ##########################################################################################################################
  4. # ------------------------------------------------
  5. # Generic Makefile (based on gcc)
  6. #
  7. # ChangeLog :
  8. # 2017-02-10 - Several enhancements + project update mode
  9. # 2015-07-22 - first version
  10. # ------------------------------------------------
  11. ######################################
  12. # target
  13. ######################################
  14. TARGET = WeighingSensor
  15. ######################################
  16. # building variables
  17. ######################################
  18. # debug build?
  19. DEBUG = 1
  20. # optimization
  21. OPT = -O2
  22. #######################################
  23. # paths
  24. #######################################
  25. # Build path
  26. BUILD_DIR = build
  27. ######################################
  28. # source
  29. ######################################
  30. # C sources
  31. #STM32 HAL Lib
  32. STD_SOURCES = \
  33. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
  34. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
  35. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
  36. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
  37. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
  38. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
  39. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
  40. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
  41. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
  42. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
  43. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
  44. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
  45. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
  46. Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_can.c
  47. USER_SOURCES = $(wildcard ./hardware/*.c)
  48. USER_SOURCES += $(wildcard ./software/*.c)
  49. USER_SOURCES += $(wildcard ./Helper_Func/*.c)
  50. USER_SOURCES += $(wildcard ./User_Src/*.c)
  51. C_SOURCES = $(STD_SOURCES)
  52. C_SOURCES += $(USER_SOURCES)
  53. # ASM sources
  54. ASM_SOURCES = \
  55. startup_stm32f103xb.s
  56. #######################################
  57. # binaries
  58. #######################################
  59. PREFIX = arm-none-eabi-
  60. # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
  61. # either it can be added to the PATH environment variable.
  62. ifdef GCC_PATH
  63. CC = $(GCC_PATH)/$(PREFIX)gcc
  64. AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
  65. CP = $(GCC_PATH)/$(PREFIX)objcopy
  66. SZ = $(GCC_PATH)/$(PREFIX)size
  67. else
  68. CC = $(PREFIX)gcc
  69. AS = $(PREFIX)gcc -x assembler-with-cpp
  70. CP = $(PREFIX)objcopy
  71. SZ = $(PREFIX)size
  72. endif
  73. HEX = $(CP) -O ihex
  74. BIN = $(CP) -O binary -S
  75. #######################################
  76. # CFLAGS
  77. #######################################
  78. # cpu
  79. CPU = -mcpu=cortex-m3
  80. # fpu
  81. # NONE for Cortex-M0/M0+/M3
  82. # float-abi
  83. # mcu
  84. MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
  85. # macros for gcc
  86. # AS defines
  87. AS_DEFS =
  88. # C defines
  89. C_DEFS = \
  90. -DUSE_HAL_DRIVER \
  91. -DSTM32F103xB \
  92. -DVTOR_OFFSET=$(FS_OFF) \
  93. -DOFF_SEL=$(OFF_SEL)
  94. # AS includes
  95. AS_INCLUDES =
  96. # C includes
  97. C_INCLUDES = \
  98. -IDrivers/STM32F1xx_HAL_Driver/Inc \
  99. -IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
  100. -IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
  101. -IDrivers/CMSIS/Include \
  102. -Ihardware/hard_inc\
  103. -Isoftware/soft_inc\
  104. -IHelper_Func/help_inc\
  105. -IUser_Inc
  106. # compile gcc flags
  107. ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  108. CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections -DVTOR_OFFSET=$(FS_OFF) -DDOFF_SEL=$(OFF_SEL)
  109. ifeq ($(DEBUG), 1)
  110. CFLAGS += -g -gdwarf-2
  111. endif
  112. # Generate dependency information
  113. CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
  114. #######################################
  115. # LDFLAGS
  116. #######################################
  117. # link script
  118. FS_OFF1 = 0
  119. FS_OFF2 = 0x3400
  120. FS_OFF3 = 0x8400
  121. LDSCRIPT = STM32F103C8Tx_FLASH.ld
  122. # 默认使用FS_OFF1,可通过make参数选择
  123. ifeq ($(OFF_SEL),1)
  124. FS_OFF = $(FS_OFF2)
  125. else ifeq ($(OFF_SEL),2)
  126. FS_OFF = $(FS_OFF3)
  127. else ifeq ($(OFF_SEL),0)
  128. FS_OFF = $(FS_OFF1)
  129. else
  130. FS_OFF = $(FS_OFF3)
  131. endif
  132. # libraries
  133. LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) -Wl,--defsym=FS_OFFSET=$(FS_OFF) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
  134. LIBS = -lc -lm -lnosys
  135. LIBDIR =
  136. # default action: build all
  137. all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  138. #######################################
  139. # build the application
  140. #######################################
  141. # list of objects
  142. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  143. vpath %.c $(sort $(dir $(C_SOURCES)))
  144. # list of ASM program objects
  145. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
  146. vpath %.s $(sort $(dir $(ASM_SOURCES)))
  147. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  148. $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  149. $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
  150. $(AS) -c $(CFLAGS) $< -o $@
  151. $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
  152. $(CC) $(OBJECTS) $(LDFLAGS) -o $@
  153. $(SZ) $@
  154. $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  155. $(HEX) $< $@
  156. $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  157. $(BIN) $< $@
  158. $(BUILD_DIR):
  159. mkdir $@
  160. #######################################
  161. # clean up
  162. #######################################
  163. clean:
  164. -rm -fR $(BUILD_DIR)
  165. #######################################
  166. # dependencies
  167. #######################################
  168. -include $(wildcard $(BUILD_DIR)/*.d)
  169. # *** EOF ***