-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
118 lines (92 loc) · 2.81 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
OCD_CFG = /home/tim/stm32f0raspberry.cfg
# TODO add path of CMSIS and HAL base directory
CMSIS = /home/tim/STM32CubeF0/Drivers/CMSIS
HAL = /home/tim/STM32CubeF0/Drivers/STM32F0xx_HAL_Driver
BUILDDIR = $(PWD)/build
SRCDIR = $(PWD)/src
INCDIR = $(PWD)/include
TRGT = arm-none-eabi-
CC = $(TRGT)gcc
CPPC = $(TRGT)g++
# Enable loading with g++ only if you need C++ runtime support.
# NOTE: You can use C++ even without C++ support if you are careful. C++
# runtime support makes code size explode.
LD = $(TRGT)gcc
#LD = $(TRGT)g++
CP = $(TRGT)objcopy
AS = $(TRGT)gcc -x assembler-with-cpp
AR = $(TRGT)ar
OD = $(TRGT)objdump
SZ = $(TRGT)size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary
INCLUDE = -I$(CMSIS)/Include
INCLUDE += -I$(CMSIS)/Device/ST/STM32F0xx/Include
INCLUDE += -I$(HAL)/Inc
INCLUDE += -I$(INCDIR)
# Flags - Overall Options
CPPFLAGS += -specs=nosys.specs
# Flags - C Language Options
# CFLAGS += -ffreestanding
# Flags - C++ Language Options
CXXFLAGS += -fno-threadsafe-statics
CXXFLAGS += -fno-rtti
CXXFLAGS += -fno-exceptions
CXXFLAGS += -fno-unwind-tables
# CXXFLAGS += -std=gnu++11
# Flags - Warning Options
CPPFLAGS += -Wall
CPPFLAGS += -Wextra
CPPFLAGS += -Wundef
# Flags - Debugging Options
# CPPFLAGS += -g
CPPFLAGS += -ggdb
# Flags - Optimization Options
CPPFLAGS += -ffunction-sections
CPPFLAGS += -fdata-sections
CPPFLAGS += -fno-common
CPPFLAGS += -O2
CPPFLAGS += -fomit-frame-pointer
# CPPFLAGS += -falign-functions=16
# Be careful, link time optimizations might cause problems...
# CPPFLAGS += -flto
# Flags - Preprocessor options
CPPFLAGS += -DSTM32F030xC
# Flags - Machine-dependant options
CPPFLAGS += -mcpu=cortex-m0
CPPFLAGS += -mlittle-endian
CPPFLAGS += -mthumb
CPPFLAGS += -mfloat-abi=soft
CPPFLAGS += -masm-syntax-unified
# Flags - Linker Options
# CPPFLAGS += -nostdlib
LDFLAGS += -Tlinker/STM32F030xC_FLASH.ld -nostartfiles -nostdlib
# LDFLAGS += --gc-sections
CFLAGS += $(CPPFLAGS) $(CXXFLAGS)
AFLAGS += $(CFLAGS)
CSRC = $(shell find $(SRCDIR) -name "*.c")
CSRC += $(CMSIS)/Device/ST/STM32F0xx/Source/Templates/system_stm32f0xx.c
HAL_SRC := $(shell find $(HAL)/Src/*.c ! -name '*_template.c')
CSRC += $(HAL_SRC)
ASRC = startup/startup_stm32f030xc.s
ELFFILE = main.elf
COBJS = $(patsubst %, $(BUILDDIR)%,$(CSRC:.c=.o))
AOBJS = $(patsubst %, $(BUILDDIR)/%,$(ASRC:.s=.o))
all: setup build
setup:
@mkdir -p $(BUILDDIR)
build: setup $(COBJS) $(AOBJS)
$(LD) $(CFLAGS) $(LDFLAGS) -o $(ELFFILE) $(COBJS) $(AOBJS)
$(COBJS): $(BUILDDIR)%.o : %.c
mkdir -p $(dir $@)
$(CPPC) $(INCLUDE) $(CFLAGS) -c $< -o $@
$(AOBJS): $(BUILDDIR)/%.o : %.s
mkdir -p $(dir $@)
$(CPPC) $(INCLUDE) $(AFLAGS) -c $< -o $@
clean:
rm -rf $(BUILDDIR)
flash: build
openocd -f $(OCD_CFG) -c "program $(ELFFILE) verify reset exit"
reset:
openocd -f $(OCD_CFG) -c "reset run; exit"
.PHONY: all setup build clean flash