您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

155 行
4.0 KiB

################################################################################
#
################################################################################
VERBOSE=@
HELP=''
STM_MCU_FAMILY=STM32F0
STM_MCU_SUB_FAMILY=72
STM_MCU_PIN_COUNT=C
STM_MCU_CODE_SIZE=8
STM_MCU_PACKAGE=T
STM_MCU=$(STM_MCU_FAMILY)$(STM_MCU_SUB_FAMILY)$(STM_MCU_PIN_COUNT)$(STM_MCU_CODE_SIZE)
STM_MCU_FAMILY_LOWER=$(shell echo $(STM_MCU_FAMILY) | tr A-Z a-z)
STM_MCU_CODE_SIZE_LOWER=$(shell echo $(STM_MCU_CODE_SIZE) | tr A-Z a-z)
ifeq ($(VARIANT),)
VARIANT = debug
endif
OS := $(shell uname)
ifeq ($(OS),Linux)
TOOLCHAIN := /usr/bin
else
TOOLCHAIN :=
endif
TOOLCHAIN_PREFIX := arm-none-eabi-
CC := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)gcc
GDB := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)gdb
AS := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)as
LD := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)gcc
OBJCOPY := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)objcopy
SIZE := $(TOOLCHAIN)/$(TOOLCHAIN_PREFIX)size
ECHO := echo
MKDIR := mkdir -p
RM := rm -rf
OUT = out/$(VARIANT)
ELF = $(OUT)/stm.elf
CFLAGS += -g
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb
CFLAGS += -mfloat-abi=soft
#CFLAGS += -mfpu=fpv5-sp-d16
CFLAGS += '-D__weak=__attribute__((weak))'
CFLAGS += '-D__packed="__attribute__((__packed__))"'
CFLAGS += -DUSE_HAL_DRIVER
ifeq ($(STM_MCU),STM32F072C8)
CFLAGS += -D$(STM_MCU_FAMILY)$(STM_MCU_SUB_FAMILY)xB
else
CFLAGS += -D$(STM_MCU_FAMILY)$(STM_MCU_SUB_FAMILY)x$(STM_MCU_CODE_SIZE)
endif
CFLAGS += -Wall
CFLAGS += -Werror
CFLAGS += -fmessage-length=0
CFLAGS += -ffunction-sections
CFLAGS += -c
CFLAGS += -fmessage-length=0
#CFLAGS += -MMD
#CFLAGS += -MP
CFLAGS += -Icubemx/Inc
CFLAGS += -Icubemx/Drivers/$(STM_MCU_FAMILY)xx_HAL_Driver/Inc
CFLAGS += -Icubemx/Drivers/$(STM_MCU_FAMILY)xx_HAL_Driver/Inc/Legacy
CFLAGS += -Icubemx/Drivers/CMSIS/Device/ST/$(STM_MCU_FAMILY)xx/Include
CFLAGS += -Icubemx/Drivers/CMSIS/Include
CFLAGS += -Icubemx/Middlewares/Third_Party/FreeRTOS/Source
CFLAGS += -Icubemx/Middlewares/Third_Party/FreeRTOS/Source/include
CFLAGS += -Icubemx/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
CFLAGS += -Icubemx/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM0
CFLAGS += -Icubemx/Middlewares/ST/STM32_USB_Device_Library/Core/Inc
CFLAGS += -Icubemx/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
ifeq ($(VARIANT),debug)
CFLAGS_PROJECT += -O0
CFLAGS_PROJECT += -DDEBUG_LEVEL=5
else ifeq ($(VARIANT),release)
CFLAGS_PROJECT += -O3
CFLAGS_PROJECT += -DDEBUG_LEVEL=0
CFLAGS_PROJECT += -DNDEBUG
endif
CFLAGS_OPUS += -O3
CFLAGS_OPUS += -DDEBUG_LEVEL=0
CFLAGS_OPUS += -DNDEBUG
LDFLAGS =
LDFLAGS += -mcpu=cortex-m0
LDFLAGS += -mthumb
LDFLAGS += -mfloat-abi=soft
#LDFLAGS += -mfpu=fpv5-sp-d16
LDFLAGS += -specs=nosys.specs
LDFLAGS += -specs=nano.specs
LDFLAGS += -T"cubemx/$(STM_MCU)$(STM_MCU_PACKAGE)x_FLASH.ld"
LDFLAGS += -Wl,-Map=$(OUT)/output.map
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -lm
# All Target
HELP += 'all'
all: $(ELF)
# All of the sources participating in the build are defined here
SOURCE =
include gcc/freertos.mk
include gcc/stm32.mk
include gcc/middleware_usb.mk
include gcc/middleware_usb_class.mk
include gcc/drivers.mk
include gcc/startup.mk
include gcc/project.mk
include openocd/openocd.mk
include openocd/flash.mk
ifneq ($(MAKECMDGOALS),clean)
-include $(addprefix $(OUT)/,$(SOURCE:.c=.d))
endif
OBJC = $(SOURCE:.c=.o)
OBJS = $(subst ../,,$(addprefix $(OUT)/,$(OBJC:.s=.o)))
$(OUT):
$(VERBOSE)$(MKDIR) $@
# Tool invocations
$(ELF): $(OBJS) $(OBJA) cubemx/$(STM_MCU)$(STM_MCU_PACKAGE)x_FLASH.ld | $(OUT)
$(VERBOSE)$(ECHO) '[LD] $@'
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(OBJA) $(LIBS)
$(MAKE) --no-print-directory post-build
# Other Targets
HELP += 'clean'
clean:
-$(VERBOSE)$(ECHO) '[RM] out'
-$(VERBOSE)$(RM) $(OUT)
post-build:
-$(VERBOSE)$(ECHO) 'Generating binary and Printing size information:'
$(VERBOSE)$(OBJCOPY) -O binary $(ELF) $(ELF:.elf=.bin)
$(VERBOSE)$(OBJCOPY) -O binary $(ELF) $(ELF:.elf=.hex)
$(VERBOSE)$(SIZE) $(ELF)
-$(VERBOSE)$(ECHO) ' '
.PHONY: all clean dependents help
.SECONDARY: post-build
help:
-$(VERBOSE)$(ECHO) 'targets: $(HELP)'