-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
123 lines (89 loc) · 2.72 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
119
120
121
122
123
#######################################################################
# Makefile for STM32F0 Discovery board projects
OUTPATH = build
PROJECT = $(OUTPATH)/blank
OPENOCD_SCRIPT_DIR ?= /usr/share/openocd/scripts
HEAP_SIZE = 0x400
################
# Sources
SOURCES_S = core/startup_stm32f051x8.s
SOURCES_CORE = $(wildcard core/*.c)
SOURCES_PERIPH = $(wildcard plib/*.c)
SOURCES_LIB = $(wildcard lib/*.c)
SOURCES_SENSOR = $(wildcard lib/vl53l0x/*.c)
SOURCES_C = $(wildcard *.c)
SOURCES_C += $(SOURCES_CORE)
SOURCES_C += $(SOURCES_PERIPH)
SOURCES_C += $(SOURCES_LIB)
SOURCES_C += $(SOURCES_SENSOR)
SOURCES = $(SOURCES_S) $(SOURCES_C)
OBJS = $(SOURCES_S:.s=.o) $(SOURCES_C:.c=.o)
# Includes and Defines
INC_CORE = -Icore
INC_LIB = -Ilib
INC_PERIPH = -Iplib
INC_SENSOR = -Ilib/vl53l0x
INCLUDES += $(INC_CORE)
INCLUDES += $(INC_LIB)
INCLUDES += $(INC_PERIPH)
INCLUDES += $(INC_SENSOR)
DEFINES = -DSTM32 -DSTM32F0 -DSTM32F051x8 -DHEAP_SIZE=$(HEAP_SIZE)
# Compiler/Assembler/Linker/etc
PREFIX = arm-none-eabi
CC = $(PREFIX)-gcc
AS = $(PREFIX)-as
AR = $(PREFIX)-ar
LD = $(PREFIX)-gcc
NM = $(PREFIX)-nm
OBJCOPY = $(PREFIX)-objcopy
OBJDUMP = $(PREFIX)-objdump
READELF = $(PREFIX)-readelf
SIZE = $(PREFIX)-size
GDB = $(PREFIX)-gdb
RM = rm -f
OPENOCD=openocd
# Compiler options
MCUFLAGS = -mcpu=cortex-m0 -mlittle-endian -mfloat-abi=soft -mthumb \
-mno-unaligned-access
DEBUG_OPTIMIZE_FLAGS = -O0 -ggdb -gdwarf-2
CFLAGS = -Wall -Wextra --pedantic
CFLAGS_EXTRA = -nostartfiles -nodefaultlibs -nostdlib \
-fdata-sections -ffunction-sections
CFLAGS += $(DEFINES) $(MCUFLAGS) $(DEBUG_OPTIMIZE_FLAGS) $(CFLAGS_EXTRA) $(INCLUDES)
LDFLAGS = -static $(MCUFLAGS) -Wl,--start-group -lgcc -lc -lg -Wl,--end-group\
-Wl,--gc-sections -T core/stm32f051r8tx_mmap.ld
.PHONY: dirs all clean flash erase
all: dirs $(PROJECT).bin $(PROJECT).asm
dirs: ${OUTPATH}
${OUTPATH}:
mkdir -p ${OUTPATH}
clean:
$(RM) $(OBJS) $(PROJECT).elf $(PROJECT).bin $(PROJECT).asm
rm -rf ${OUTPATH}
# Hardware specific
flash: $(PROJECT).bin
st-flash write $(PROJECT).bin 0x08000000
erase:
st-flash erase
gdb-server-ocd:
$(OPENOCD) -f $(OPENOCD_SCRIPT_DIR)/interface/stlink-v2.cfg \
-f $(OPENOCD_SCRIPT_DIR)/target/stm32f0x.cfg
gdb-server-st:
st-util
OPENOCD_P=3333
gdb-openocd: $(PROJECT).elf
$(GDB) --eval-command="target extended-remote localhost:$(OPENOCD_P)"\
--eval-command="load" $(PROJECT).elf
GDB_P=4242
gdb-st-util: $(PROJECT).elf
$(GDB) --eval-command="target extended-remote localhost:$(GDB_P)"\
--eval-command="monitor halt" $(PROJECT).elf
# --eval-command="load" $(PROJECT).elf
$(PROJECT).elf: $(OBJS)
%.elf:
$(LD) $(OBJS) $(LDFLAGS) -o $@
$(SIZE) -A $@
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
%.asm: %.elf
$(OBJDUMP) -dwh $< > $@