-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
79 lines (61 loc) · 2.1 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# General Target Settings
TARGET = stm32f1-template-project
SRCS = main.c
# Toolchain & Utils
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size
STFLASH = st-flash
STUTIL = st-util
CPPCHECK = cppcheck
# STM32Cube Path
STM32CUBE = ${STM32CUBE_PATH}
STM32_STARTUP = $(STM32CUBE)/Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103xb.s
STM32_SYSINIT = $(STM32CUBE)/Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c
STM32_LDSCRIPT = $(STM32CUBE)/Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/linker/STM32F103XB_FLASH.ld
STM32_INCLUDES += -I$(STM32CUBE)/Drivers/CMSIS/Core/Include
STM32_INCLUDES += -I$(STM32CUBE)/Drivers/CMSIS/Core_A/Include
STM32_INCLUDES += -I$(STM32CUBE)/Drivers/CMSIS/Device/ST/STM32F1xx/Include
DEFINES = -DSTM32F103xB
CPUFLAGS = -mthumb -mcpu=cortex-m3
WARNINGS = -Wall -pedantic
OPTIMIZATION = -O3
DEBUG = -ggdb
CFLAGS = $(DEFINES) $(STM32_INCLUDES) $(CPUFLAGS) $(WARNINGS) $(OPTIMIZATION) $(DEBUG)
LDFLAGS = $(CPUFLAGS) -T$(STM32_LDSCRIPT) --specs=nosys.specs
DEPFLAGS = -MT $@ -MMD -MP -MF $(BUILD_DIR)/$*.d
CHKREPORT = cppcheck-report.txt
CHKFLAGS = --enable=all --error-exitcode=1 --suppress=missingIncludeSystem:nofile -D__GNUC__
BUILD_DIR = build
OBJS += $(SRCS:%.c=$(BUILD_DIR)/%.o)
OBJS += $(STM32_SYSINIT:%.c=$(BUILD_DIR)/%.o)
STARTUP += $(STM32_STARTUP:%.s=$(BUILD_DIR)/%.o)
.PHONY: all
all: $(TARGET).hex size
$(TARGET).hex: $(TARGET).elf
$(OBJCOPY) -Oihex $(TARGET).elf $(TARGET).hex
$(TARGET).elf: $(OBJS) $(STARTUP)
$(CC) $(LDFLAGS) $^ -o $@
$(BUILD_DIR)/%.o: %.c
mkdir -p $(@D)
$(CC) $(DEPFLAGS) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o: %.s
mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
DEPFILES := $(OBJS:%.o=%.d)
$(DEPFILES):
-include $(DEPFILES)
cppcheck: $(SRCS)
$(CPPCHECK) $(CHKFLAGS) $(STM32_INCLUDES) $(DEFINES) --output-file=$(CHKREPORT) $^
.PHONY: flash
flash: all
$(STFLASH) --format ihex write $(TARGET).hex
.PHONY: size
size:
$(SIZE) $(TARGET).elf
.PHONY: clean
clean:
rm -rf $(BUILD_DIR) $(CHKREPORT)
.PHONY: distclean
distclean: clean
rm -rf $(TARGET).elf $(TARGET).hex