|
楼主 |
发表于 2024-9-25 19:20:30
|
显示全部楼层
算是跑起来了
贴一下makefile
- include Makefile.Cfg.mk
- # include Makefile.Cfg.ARMCLANG.mk
- .PHONY: test echo prestage endsatge
- # default action: build all
- all: prestage buildstage endsatge
- build: buildstage FORCE
- buildstage: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
- prestage:
- @echo -e "$(OK_COLOR)::::::::::: prestage build :::::::::::$(NO_COLOR) "
- @mkdir -p $(BUILD_DIR)
- @mkdir -p $(OBJ_DIR)
- endsatge:
- @echo -e "$(OK_COLOR)::::::::::: COMPLETE BUILDING :::::::::::$(NO_COLOR) "
-
- #######################################
- # build the application
- #######################################
- # list of objects
- OBJECTS = $(addprefix $(OBJ_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
- vpath %.c $(sort $(dir $(C_SOURCES)))
- OBJECTS += $(addprefix $(OBJ_DIR)/,$(notdir $(CXX_SOURCES:.cpp=.o)))
- vpath %.cpp $(sort $(dir $(CXX_SOURCES)))
- # list of ASM program objects
- OBJECTS += $(addprefix $(OBJ_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
- vpath %.s $(sort $(dir $(ASM_SOURCES)))
- $(OBJ_DIR)/%.o: %.c Makefile | $(OBJ_DIR)
- @echo -e "$(OK_COLOR) $< ===>>> $@ $(NO_COLOR) "
- $(CC) -c $(CFLAGS) $(C_INCLUDES) $< -o $@
- # C++ 生成OBJECTS中的.o 依赖同名的 %.cpp 文件
- $(OBJ_DIR)/%.o: %.cpp Makefile | $(OBJ_DIR)
- @echo -e "$(CC_COLOR) CC ==== $< $@ $(NO_COLOR) "
- $(CXX) -c $(CXX_FLAGS) -Wa,-a,-ad,-alms=$(OBJ_DIR)/$(notdir $(<:.cpp=.lst)) $< -o $@
- $(OBJ_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
- # $(AS) $(ASFLAGS) -o $(OBJ_DIR)/$(notdir $@) $(C_INCLUDES) $<
- $(CC) -c -o $(OBJ_DIR)/$(notdir $@) $(CFLAGS) $(C_INCLUDES) $<
- $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
- @echo -e "$(OK_COLOR) LINK TO ELF : $@ $(NO_COLOR) "
- $(LD) -o $@ $(LDFLAGS) $(OBJECTS)
- @echo -e "$(CC_COLOR) "
- $(SZ) $@
- # $(CC) $(OBJECTS) $(LDFLAGS) -o $@
- $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
- $(OBJCOPY) -O ihex $< $@
- $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
- $(OBJCOPY) -O binary $< $@
- @echo -e "$(NO_COLOR)"
- # $(BUILD_DIR):
- # mkdir $@
-
- test:
- @$(info === test ===)
- @echo -e "$(CC_COLOR) ===== "
- @echo ${C_SOURCES}
- @echo -e "$(CC_COLOR) ===== "
- @echo ${C_INCLUDES}
- @echo -e "$(CC_COLOR) ===== "
- @echo ${OBJECTS}
- @echo -e "$(NO_COLOR)"
- echo:
- @$(info === echo info ===)
- @echo ${STDPD_SOURCES2} ${adddd}
- clean:
- rm -rf $(BUILD)/*
- #######################################
- # upload cmsis-dap.cfg stlink.cfg
- #######################################
- upload:
- # @openocd -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg -c init -c halt -c "flash write_image erase $(BUILD_DIR)/$(TARGET).bin 0x08000000" -c reset -c shutdown
- # @openocd -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg -c init -c halt -c "program $(BUILD_DIR)/$(TARGET).bin exit 0x08000000" -c reset -c shutdown
- # @openocd -f interface/cmsis-dap.cfg -f target/stm32f4x.cfg -c init -c halt -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit" -c reset -c shutdown
- @openocd -f cmsis-dap.cfg -f swm341.cfg \
- -c init -c reset -c halt \
- -c "program $(BUILD_DIR)/$(TARGET).bin exit 0x00000000" \
- -c reset -c shutdown
复制代码
Makefile.Cfg.ARMCLANG.mk
- #######################################
- # TARGET
- #######################################
- # GCC ARMGCC ARMCLANG
- TARGET ?= 00_template
- BUILD ?= out
- BUILD_DIR ?= out
- OBJ_DIR ?= ${BUILD_DIR}/obj
- WORKSPACE_DIR = ../../../
- #######################################
- # CROSS_COMPILE
- #######################################
- # GCC ARMGCC ARMCLANG
- COMPILER = ARMCLANG
- PREFIX = arm-none-eabi-
- ifeq ($(COMPILER),GCC)
- CC = $(PREFIX)gcc
- AR = $(PREFIX)ar
- AS = $(PREFIX)gcc -x assembler-with-cpp
- OBJCOPY = $(PREFIX)objcopy
- OBJDUMP = $(PREFIX)armclang
- SZ = $(PREFIX)size
- CXX = $(PREFIX)g++
- LD = $(PREFIX)g++
- endif
- ifeq ($(COMPILER),ARMCLANG)
- PREFIX = C:/Keil_v5/ARM/ARMCLANG/bin/
- CC = $(PREFIX)armclang
- AR = $(PREFIX)armar
- AS = $(PREFIX)armasm
- SZ = $(PREFIX)size
- CXX = $(PREFIX)armclang
- LD = $(PREFIX)armlink
- endif
- #######################################
- # CFLAGS -mthumb -mcpu=cortex-m33 -mfloat-abi=soft -std=c99 -Wpointer-arith
- #######################################
- # C_DEFS ?= -D__UVISION_VERSION="532" -D__TARGET_FPU_VFP -D__ARM_MATH_CM4 -D__FPU_PRSENT=1
- C_DEFS ?=
- DEBUG = 1
- ifeq ($(DEBUG),1)
- CFLAGS += -O0 -g
- else
- CFLAGS += -O2
- endif
- CPU = -mcpu=cortex-m33
- # fpu
- FPU = -mfpu=fpv5-sp-d16
- # float-abi
- # FLOAT-ABI = -mfloat-abi=soft
- FLOAT-ABI = -mfloat-abi=hard
- # mcu
- MCU = --target=arm-arm-none-eabi $(CPU) $(FPU) $(FLOAT-ABI)
- CC_FLAGS = $(MCU)
- CC_FLAGS += -fno-rtti -funsigned-char -fshort-enums -fshort-wchar
- # CC_FLAGS += -gdwarf-3 -O3 -ffunction-sections
- CC_FLAGS += -D__MICROLIB -D__UVISION_VERSION="532" -gdwarf-3 -O3 -ffunction-sections
- CC_FLAGS += -Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes -Wno-missing-noreturn -Wno-sign-conversion
- CC_FLAGS += -Wno-nonportable-include-path -Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command -Wno-documentation -Wno-license-management -Wno-parentheses-equality
- CC_FLAGS += -Wno-nonportable-include-path -Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command -Wno-documentation -Wno-license-management -Wno-parentheses-equality
- CFLAGS = $(CC_FLAGS) -xc -std=c99
- CXX_FLAGS = $(CC_FLAGS) -xc++ -fno-rtti -fno-exceptions -lstdc++ -std=c++11
- DEBUG = 1
- ifeq ($(DEBUG),1)
- CFLAGS += -O0 -g
- else
- CFLAGS += -O2
- endif
- ASFLAGS = --cpu=Cortex-M33 --fpu=FPv5-SP -g --pd "__MICROLIB SETA 1"
- ASFLAGS += $(C_INCLUDES)
- ASFLAGS += --pd "__UVISION_VERSION SETA 532" --xref
- # ASFLAGS = --cpu=Cortex-M33 -gdwarf-3 -Wa,armasm,--pd,"__MICROLIB SETA 1"
- # LINKER_SCRIPT = swm341.ld
- LINKER_SCRIPT = swm341.sct
- # LIBS = -llibswm34lib
- # LIBDIR = --libpath lib
- # LDFLAGS = --cpu=Cortex-M33 --strict --scatter $(LINKER_SCRIPT)
- # LDFLAGS = --cpu=Cortex-M33 $(LIBDIR) $(LIBS) --strict --scatter $(LINKER_SCRIPT) --libpath C:\\Keil_v5\\ARM\\ARMCLANG\\lib
- LDFLAGS = --cpu=Cortex-M33 $(LIBDIR) $(LIBS) --strict --scatter $(LINKER_SCRIPT) --library_type=microlib
- # --cpu Cortex-M3 --library_type=microlib --strict
- LDFLAGS += --summary_stderr --info summarysizes --map --load_addr_map_info --xref --callgraph --symbols
- LDFLAGS += --info sizes --info totals --info unused --info veneers
- LDFLAGS += --list "$(BUILD_DIR)SWM341.map"
- # LDFLAGS = -Wl,--gc-sections -Wl,-Map=$@.map -T $(LINKER_SCRIPT) $(MCU) -specs=nano.specs -u _printf_float
- ASM_SOURCES ?=
- ASM_SOURCES += $(WORKSPACE_DIR)startup/arm/startup_SWM341.s
- C_SOURCES ?=
- C_INCLUDES ?=
- C_INCLUDES += -I ${WORKSPACE_DIR}CSL/CMSIS/CoreSupport/
- C_INCLUDES += -I ${WORKSPACE_DIR}CSL/CMSIS/DeviceSupport/
- C_INCLUDES += -I ${WORKSPACE_DIR}CSL/SWM341_StdPeriph_Driver/
- # SWM341_StdPeriph_Driver
- STD_PD_ITEM ?= adc can cordic crc dac div dma dma2d exti flash
- STD_PD_ITEM += gpio i2c jpeg lcd port pwm rtc sdio sdram sfc
- STD_PD_ITEM += sleep spi timr uart usbd usbh wdt
- STD_PD_ITEM_FILTEROUT = can sleep usbd usbh dac cordic
- STD_PD_ITEM_FILTER = uart port gpio sfc sdram sdio
- STDPD_SOURCES += $(WORKSPACE_DIR)CSL/CMSIS/DeviceSupport/system_SWM341.c
- STDPD_SOURCES += $(shell find $(WORKSPACE_DIR)CSL/SWM341_StdPeriph_Driver -name *.c )
- #过滤一些 STD_PD_ITEM_FILTEROUT $(addsuffix names...) $(addprefix -I,$( ) ))
- C_SOURCES += ${STDPD_SOURCES}
- # C_SOURCES += $(filter $(addsuffix .c,$(addprefix %,$(STD_PD_ITEM_FILTER) )), $(STDPD_SOURCES))
- # C_SOURCES += $(filter-out $(addsuffix .c,$(addprefix %,$(STD_PD_ITEM_FILTEROUT) )), $(STDPD_SOURCES))
- # C_SOURCES =
- ############ Freertos
- C_SOURCES += $(wildcard *.c $(WORKSPACE_DIR)FreeRTOS/*.c)
- C_INCLUDES += -I$(WORKSPACE_DIR)FreeRTOS/include/
- C_INCLUDES += -I$(WORKSPACE_DIR)FreeRTOS/
- # C_SOURCES += $(wildcard *.c $(WORKSPACE_DIR)FreeRTOS/portable/GCC/ARM_CM4F/*.c)
- # C_INCLUDES += -I$(WORKSPACE_DIR)FreeRTOS/portable/GCC/ARM_CM4F
- C_SOURCES += $(wildcard *.c $(WORKSPACE_DIR)FreeRTOS/portable/GCC/ARM_CM33_NTZ/non_secure/*.c)
- C_INCLUDES += -I$(WORKSPACE_DIR)FreeRTOS/portable/GCC/ARM_CM33_NTZ/non_secure
- C_SOURCES += $(wildcard *.c $(WORKSPACE_DIR)FreeRTOS/CMSIS_RTOS_V2/*.c)
- C_INCLUDES += -I$(WORKSPACE_DIR)FreeRTOS/CMSIS_RTOS_V2
- C_SOURCES += $(wildcard *.c $(WORKSPACE_DIR)FreeRTOS/portable/MemMang/heap_4.c)
- ############ Easylooger
- C_SOURCES += $(wildcard *.c $(WORKSPACE_DIR)EasyLogger/src/*.c)
- C_INCLUDES += -I$(WORKSPACE_DIR)EasyLogger/inc/
-
- C_SOURCES += $(wildcard *.c APP/*.c)
- C_INCLUDES += $(addprefix -I,$(sort $(dir $(subst \,/,$(shell find ./APP -type f -name *.h))) ))
- C_SOURCES += $(wildcard *.c BSP/*.c)
- C_INCLUDES += $(addprefix -I,$(sort $(dir $(subst \,/,$(shell find ./BSP -type f -name *.h))) ))
- C_SOURCES += $(wildcard *.c Core/*.c)
- C_INCLUDES += $(addprefix -I,$(sort $(dir $(subst \,/,$(shell find ./Core -type f -name *.h))) ))
-
- # OBJS = $(addprefix $(BUILD)/, $(APP_SRC:.c=.o) $(CSL_SRC:.c=.o) $(CSL_SRS:.s=.o) $(BSP_SRC:.c=.o))
- # CXX_SOURCES += $(wildcard *.c APP/*.cpp)
- # color
- NO_COLOR = \033[0;01m
- OK_COLOR = \033[35;01m
- ERROR_COLOR = \033[31;01m
- DONE_COLOR = \033[31;01m
- CC_COLOR = \033[34;01m
复制代码 |
|