Makefile 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. ##########################################################################################################################
  2. # File automatically-generated by tool: [projectgenerator] version: [4.3.0-B58] date: [Sun Jul 13 18:11:51 CST 2025]
  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 = ctrl_board
  15. APPVER = V010
  16. # 在文件顶部添加操作系统检测
  17. ifeq ($(OS),Windows_NT)
  18. MKDIR = cmd.exe /c if not exist $(1) mkdir $(1)
  19. CP = cmd.exe /c copy $(subst /,\,$(1)) $(subst /,\,$(2))
  20. RM = cmd.exe /c del /Q $(subst /,\,$(1))
  21. RMDIR = cmd.exe /c rmdir /S /Q $(subst /,\,$(1))
  22. else
  23. MKDIR = mkdir -p $(1)
  24. CP = cp $(1) $(2)
  25. RM = rm -f $(1)
  26. RMDIR = rm -rf $(1)
  27. endif
  28. # 改为 Windows 兼容格式:
  29. ifeq ($(OS),Windows_NT)
  30. # Windows
  31. BUILD_TIME := $(shell powershell -command "Get-Date -Format 'yyMMddHHmm'")
  32. else
  33. # Linux/Mac
  34. BUILD_TIME := $(shell date +%y%m%d%H%M)
  35. endif
  36. ######################################
  37. # building variables
  38. ######################################
  39. # debug build?
  40. DEBUG = 0
  41. # optimization
  42. OPT = -O0 -g
  43. #######################################
  44. # paths
  45. #######################################
  46. # Build path
  47. BUILD_DIR = build
  48. ######################################
  49. # source
  50. ######################################
  51. # C sources
  52. C_SOURCES = \
  53. Core/Src/main.c \
  54. Core/Src/gpio.c \
  55. Core/Src/adc.c \
  56. Core/Src/iwdg.c \
  57. Core/Src/rtc.c \
  58. Core/Src/spi.c \
  59. Core/Src/usart.c \
  60. Core/Src/stm32g0xx_it.c \
  61. Core/Src/stm32g0xx_hal_msp.c \
  62. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_adc.c \
  63. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_adc_ex.c \
  64. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_adc.c \
  65. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_rcc.c \
  66. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_rcc_ex.c \
  67. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_rcc.c \
  68. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_flash.c \
  69. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_flash_ex.c \
  70. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_gpio.c \
  71. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_dma.c \
  72. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_dma_ex.c \
  73. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_dma.c \
  74. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_pwr.c \
  75. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_pwr_ex.c \
  76. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_cortex.c \
  77. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal.c \
  78. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_exti.c \
  79. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_iwdg.c \
  80. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_rtc.c \
  81. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_rtc_ex.c \
  82. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_spi.c \
  83. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_spi_ex.c \
  84. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_tim.c \
  85. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_tim_ex.c \
  86. Core/Src/system_stm32g0xx.c \
  87. Core/Src/sysmem.c \
  88. Core/Src/syscalls.c \
  89. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_utils.c \
  90. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_exti.c \
  91. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_usart.c \
  92. Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_gpio.c \
  93. $(wildcard User/*.c) \
  94. $(wildcard User/w25qxx/*.c) \
  95. Core/Src/dma.c
  96. # ASM sources
  97. ASM_SOURCES = \
  98. startup_stm32g070xx.s
  99. # ASM sources
  100. ASMM_SOURCES =
  101. #######################################
  102. # binaries
  103. #######################################
  104. PREFIX = arm-none-eabi-
  105. # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
  106. # either it can be added to the PATH environment variable.
  107. ifdef GCC_PATH
  108. CC = $(GCC_PATH)/$(PREFIX)gcc
  109. AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
  110. OBJCOPY = $(GCC_PATH)/$(PREFIX)objcopy
  111. SZ = $(GCC_PATH)/$(PREFIX)size
  112. else
  113. CC = $(PREFIX)gcc
  114. AS = $(PREFIX)gcc -x assembler-with-cpp
  115. OBJCOPY = $(PREFIX)objcopy
  116. SZ = $(PREFIX)size
  117. endif
  118. HEX = $(OBJCOPY) -O ihex
  119. BIN = $(OBJCOPY) -O binary -S
  120. #######################################
  121. # CFLAGS
  122. #######################################
  123. # cpu
  124. CPU = -mcpu=cortex-m0plus
  125. # fpu
  126. # NONE for Cortex-M0/M0+/M3
  127. # float-abi
  128. # mcu
  129. MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
  130. # macros for gcc
  131. # AS defines
  132. AS_DEFS =
  133. # C defines
  134. C_DEFS = \
  135. -DUSE_HAL_DRIVER \
  136. -DSTM32G070xx \
  137. -DUSE_FULL_LL_DRIVER \
  138. -DSYS_VER="\"$(APPVER)\""
  139. # AS includes
  140. AS_INCLUDES =
  141. # C includes
  142. C_INCLUDES = \
  143. -ICore/Inc \
  144. -IDrivers/STM32G0xx_HAL_Driver/Inc \
  145. -IDrivers/STM32G0xx_HAL_Driver/Inc/Legacy \
  146. -IDrivers/CMSIS/Device/ST/STM32G0xx/Include \
  147. -IDrivers/CMSIS/Include \
  148. -IUser \
  149. -IUser/w25qxx
  150. # compile gcc flags
  151. ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  152. CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  153. ifeq ($(DEBUG), 1)
  154. CFLAGS += -g -gdwarf-2
  155. C_DEFS += -D__debug__
  156. else
  157. TARGET:= $(TARGET)_$(APPVER)_$(BUILD_TIME)
  158. endif
  159. # Generate dependency information
  160. CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
  161. #######################################
  162. # LDFLAGS
  163. #######################################
  164. # link script
  165. LDSCRIPT = STM32G070CBTx_FLASH.ld
  166. # libraries
  167. LIBS = -lc -lm -lnosys
  168. LIBDIR =
  169. LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
  170. # default action: build all
  171. ifeq ($(DEBUG), 1)
  172. all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  173. else
  174. all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin INSTALL
  175. endif
  176. #######################################
  177. # build the application
  178. #######################################
  179. # list of objects
  180. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  181. vpath %.c $(sort $(dir $(C_SOURCES)))
  182. # list of ASM program objects
  183. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
  184. vpath %.s $(sort $(dir $(ASM_SOURCES)))
  185. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASMM_SOURCES:.S=.o)))
  186. vpath %.S $(sort $(dir $(ASMM_SOURCES)))
  187. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  188. @echo "CC" $(<:.c=.o) "..."
  189. @$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  190. $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
  191. @echo "CC" $(<:.s=.o) "..."
  192. @$(AS) -c $(CFLAGS) $< -o $@
  193. $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
  194. @$(CC) $(OBJECTS) $(LDFLAGS) -o $@
  195. $(SZ) $@
  196. $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  197. $(HEX) $< $@
  198. $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  199. $(BIN) $< $@
  200. # 然后修改 INSTALL 目标:
  201. INSTALL:$(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  202. $(call CP,$(BUILD_DIR)/$(TARGET).hex,hex/)
  203. $(call CP,$(BUILD_DIR)/$(TARGET).bin,hex/)
  204. $(BUILD_DIR):
  205. mkdir $@
  206. #######################################
  207. # clean up
  208. #######################################
  209. clean:
  210. -rm -fR $(BUILD_DIR)
  211. #######################################
  212. # dependencies
  213. #######################################
  214. -include $(wildcard $(BUILD_DIR)/*.d)
  215. # *** EOF ***