修改,传入必须的宏定义,比如stm32型号等:
#工程名称
TARGET = OSAL_example
#设置编译器
CC = arm-none-eabi-gcc
#CC = /opt/arm-none-gcc-5.4/bin/arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
#OBJCOPY = /opt/arm-none-gcc-5.4/bin/arm-none-eabi-objcopy
ARMSIZE = arm-none-eabi-size
#获取当前工作目录
TOP=.
#设置源文件后缀,c或cpp
EXT = c
#设置自定义源文件目录
# APP_DIR = $(TOP)/APP
HARD_DIR = $(TOP)/HARDWARE
PORT_STM32F4_DIR = $(TOP)/LWIP/port
SYS_DIR = $(TOP)/SYSTEM
FREERTOS_DIR = $(TOP)/FreeRTOS
#设置源文件搜索路径
VPATH += $(TOP)/Cpu/Core
VPATH += $(TOP)/firmware
VPATH += $(TOP)/FreeRTOS
VPATH += $(FREERTOS_DIR)/portable/RVDS/ARM_CM4_MPU
VPATH += $(TOP)/FWLIB/src
VPATH += $(TOP)/IAP:$(TOP)/LWIP:$(TOP)/HARDWARE
VPATH += $(HARD_DIR)/ADC:$(HARD_DIR)/CAN:$(HARD_DIR)/DIN:$(HARD_DIR)/DMA:$(HARD_DIR)/DOUT:$(HARD_DIR)/DS1302:$(HARD_DIR)/FLASH:$(HARD_DIR)/GPRS:$(HARD_DIR)/KEY:$(HARD_DIR)/TIMER:$(HARD_DIR)/USART2:$(HARD_DIR)/WDG
VPATH += $(TOP)/LWIP/app:$(TOP)/LWIP/cfg:$(TOP)/LWIP/drv
VPATH += $(PORT_STM32F4_DIR)/FreeRTOS:$(PORT_STM32F4_DIR)/Standalone
VPATH += $(SYS_DIR)/delay:$(SYS_DIR)/sys:$(SYS_DIR)/usart
VPATH += $(TOP)/Task
VPATH += $(TOP)/USER
VPATH += $(TOP)/Main
#设置中间目标文件目录
OBJ_DIR = $(TOP)/OBJ
#设定头文件包含目录
INC_FLAGS += -I $(TOP)/FreeRTOS/include
INC_FLAGS += -I $(TOP)/Cpu/Core
INC_FLAGS += -I $(TOP)/firmware
INC_FLAGS += -I $(FREERTOS_DIR)/include
INC_FLAGS += -I $(FREERTOS_DIR)/portable/RVDS/ARM_CM4_MPU
INC_FLAGS += -I $(TOP)/FWLIB/inc
INC_FLAGS += -I $(HARD_DIR)
INC_FLAGS += -I $(HARD_DIR)/ADC
INC_FLAGS += -I $(HARD_DIR)/CAN
INC_FLAGS += -I $(HARD_DIR)/DIN
INC_FLAGS += -I $(HARD_DIR)/DMA
INC_FLAGS += -I $(HARD_DIR)/DOUT
INC_FLAGS += -I $(HARD_DIR)/DS1302
INC_FLAGS += -I $(HARD_DIR)/FLASH
INC_FLAGS += -I $(HARD_DIR)/GPRS
INC_FLAGS += -I $(HARD_DIR)/KEY
INC_FLAGS += -I $(HARD_DIR)/TIMER
INC_FLAGS += -I $(HARD_DIR)/USART2
INC_FLAGS += -I $(HARD_DIR)/WDG
INC_FLAGS += -I $(TOP)/IAP
INC_FLAGS += -I $(TOP)/LWIP/app
INC_FLAGS += -I $(TOP)/LWIP/cfg$(TOP)/LWIP/drv
INC_FLAGS += -I $(TOP)/LWIP
INC_FLAGS += -I $(PORT_STM32F4_DIR)/FreeRTOS
INC_FLAGS += -I $(PORT_STM32F4_DIR)/Standalone
INC_FLAGS += -I $(PORT_STM32F4_DIR)/arch
INC_FLAGS += -I $(TOP)/Main
INC_FLAGS += -I $(SYS_DIR)/delay
INC_FLAGS += -I $(SYS_DIR)/sys
INC_FLAGS += -I $(SYS_DIR)/usart
INC_FLAGS += -I $(TOP)/Task
INC_FLAGS += -I $(TOP)/USER
INC_FLAGS += -I $(TOP)/LWIP/drv
#编译选项
CFLAGS += -W -Wall -g -mcpu=cortex-m3 -mthumb -O2 -std=gnu11
CFLAGS += -D STM32F10X_HD -D USE_STDPERIPH_DRIVER
CFLAGS += -DSTM32F40XX
CFLAGS += -D__TARGET_FPU_VFP
#链接选项
LFLAGS += -mthumb -mcpu=cortex-m3 -Wl,--start-group -lc -lm -Wl,--end-group -specs=nano.specs
LFLAGS += -specs=nosys.specs -static -Wl,-cref,-u,Reset_Handler -Wl,-Map=Project.map -Wl,--gc-sections
LFLAGS += -Wl,--defsym=malloc_getpagesize_P=0x80
#链接启动文件和链接脚本
LFLAGS += $(TOP)/CORE/startup_stm32f10x_hd.s
LFLAGS += -T $(TOP)/CORE/stm32_flash.ld
#固定源文件添加
C_SRC += $(shell find $(TOP)/Cpu/Core -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/firmware -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -maxdepth 1 -name '*.$(EXT)')
C_SRC += $(shell find $(FREERTOS_DIR)/portable/RVDS/ARM_CM4_MPU -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FWLIB/src -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(shell find $(TOP)/FreeRTOS -name '*.$(EXT)')
C_SRC += $(FREERTOS_DIR)/MemMang/heap_4.c
#中间目标文件
#C_OBJ += $(C_SRC:%.$(EXT)=%.o)
C_SRC_NODIR = $(notdir $(C_SRC))
C_OBJ = $(patsubst %.$(EXT), $(OBJ_DIR)/%.o,$(C_SRC_NODIR))
#依赖文件
C_DEP = $(patsubst %.$(EXT), $(OBJ_DIR)/%.d,$(C_SRC_NODIR))
.PHONY: all clean rebuild upload test ctags
all:$(C_OBJ)
@echo "linking object to $(TARGET).elf"
@$(CC) $(C_OBJ) -o $(TARGET).elf $(LFLAGS)
@$(ARMSIZE) $(TARGET).elf
@echo "create $(TARGET).hex from $(TARGET).elf"
@$(OBJCOPY) $(TARGET).elf $(TARGET).hex -Oihex
@$(ARMSIZE) $(TARGET).hex
#$(OBJCOPY) $(TARGET).elf $(TARGET).bin -Obinary
#静态模式
#$(C_OBJ):%.o:%.$(EXT)
# $(CC) -c $(CFLAGS) -o $@ [ DISCUZ_CODE_0 ]lt;
$(OBJ_DIR)/%.o:%.$(EXT)
@mkdir -p OBJ
@echo "building [ DISCUZ_CODE_0 ]lt;"
@$(CC) -c $(CFLAGS) $(INC_FLAGS) -o $@ [ DISCUZ_CODE_0 ]lt;
-include $(C_DEP)
$(OBJ_DIR)/%.d:%.$(EXT)
@mkdir -p OBJ
@echo "making $@"
@set -e;rm -f $@;$(CC) -MM $(CFLAGS) $(INC_FLAGS) [ DISCUZ_CODE_0 ]lt; > $@.$;sed 's,\($*\)\.o[ :]*,$(OBJ_DIR)/\1.o $(OBJ_DIR)/\1.d:,g' < $@.$ > $@;rm -f $@.$
clean:
-rm -f $(OBJ_DIR)/*
-rm -f $(shell find ./ -name '*.map')
-rm -f $(shell find ./ -name '*.elf')
-rm -f $(shell find ./ -name '*.bin')
-rm -f $(shell find ./ -name '*.hex')
rebuild: clean all
test:
@echo "Test !"
@echo "cflags:$(CFLAGS) ========= inc flags:$(INC_FLAGS)"
ctags:
@ctags -R *
upload:
#openocd -f /usr/local/share/openocd/scripts/interface/jlink.cfg -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg -c init -c "reset halt" -c "flash write_image erase $(TOP)/$(TARGET).hex" -c reset -c shutdown
openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg -c init -c "reset halt" -c "flash write_image erase $(TOP)/$(TARGET).hex" -c reset -c shutdown
|