-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
156 lines (119 loc) · 2.93 KB
/
Copy pathMakefile
File metadata and controls
156 lines (119 loc) · 2.93 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
default: all
Makefile_path := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Toolchain = /usr/bin/arm-none-eabi-
CC = $(Toolchain)gcc
CFlags =
CXX= $(Toolchain)g++
CXXFlags =
LD = $(Toolchain)ld
LFlags =
GDB=$(Toolchain)gdb
ifeq (, $(shell which ccache))
else
CC := ccache $(CC)
CXX:= ccache $(CXX)
endif
# Generic flags
CFlags += \
-Os \
-std=gnu11 \
-fdiagnostics-color=always \
-Wall \
-Wextra \
-g \
# -ffunction-sections \
# -fdata-sections \
# -fno-common \
# -fno-exceptions \
# --static
CXXFlags += \
-std=gnu++14
LFlags += \
-Wl,--gc-sections \
-nostartfiles \
-lm \
-lstdc++_nano \
-lc \
-lg \
-lrdimon
# MCU specific flags (stm32f401re)
LINKER_SCRIPTS_DIR = $(Makefile_path)/hal_common/linker_scripts
CFlags += \
-mcpu=cortex-m4 \
-mthumb \
-mfloat-abi=hard \
-mfpu=fpv4-sp-d16 \
-specs=nano.specs
# Use LibOpenCm3
LIBOPENCM3_DIR = $(Makefile_path)/hal_common/libopencm3
CFlags += -I $(LIBOPENCM3_DIR)/include -DSTM32F4
LFlags += -L $(LIBOPENCM3_DIR)/lib -lopencm3_stm32f4
libopencm3:
$(MAKE) -C $(LIBOPENCM3_DIR) -j
# Openocd configuration
OPENOCD_CFG = /usr/share/openocd/scripts/board/st_nucleo_f4.cfg
LFlags += -T $(LINKER_SCRIPTS_DIR)/stm32f401.ld
#include our directories with .h files
#add directories separated by whitespaces in INCPATHS
#a reparer
INCPATHS=lowlevel/include #$(DIR2) ...
INC_PARAMS=$(foreach d, $(INCPATHS), -I $d)
CFlags += $(INC_PARAMS)
all: mainTest.flash
%.o: %.cpp Makefile
@$(CXX) $(CFlags) $(CXXFlags) $< -o $@ -c
@echo CXX $<
%.o: %.c Makefile
$(CC) $(CFlags) $< -o $@ -c
@echo CC $<
pathMainTest = lowlevel
srcMainTest = $(foreach d, $(pathMainTest), $(wildcard $d/*.c))
objMainTest = $(foreach d, $(srcMainTest) , $(d:.c=.o) )
depsMainTest := $(objMainTest:.o=.d)
mainTest.elf: $(objMainTest) \
mainTest.c
#debug
#@echo $(objMainTest)
#
$(CC) $(CFlags) $^ $(LFlags) -o $@
@echo LINK $@
-include $(depsMainTest)
%.d: %.c
@$(CC) $(CFlags) $< -MM -MT $(@:.d=.o) >$@
#compiled version to be uploaded on the chip
%.hex: %.elf
@arm-none-eabi-objcopy -Oihex $^ $@
@echo OBJCOPY $@
#please do not put sudo before openocd, please run
#sudo usermod -a -G uucp <user> for serial monitor
#for udev rule:
#nano /etc/udev/rules.d/70-st-link.rules
# #NUCLEO ST-LINK/V2.1
# ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b",TAG+="uaccess"
#to find theses values lsusb
#then udevadm control --reload-rules
#unplug and plug st-link
install_udev:
@echo "Installing udev rules…"
@sudo ./install_udev.sh
@echo "Now, unplug and re-plug the st-link."
%.flash: %.hex
openocd -f $(OPENOCD_CFG) \
-c "init" \
-c "reset init" \
-c "flash write_image erase $^" \
-c "reset" \
-c "shutdown"
#feedback
#NOTE: the files in the gdb dir must correspond to your MCU
%.debug: %.elf
$(GDB) $^ --command=gdb/attach.gdb
clean:
find . \
\( -not -path "./hal_common*" \) \
\( -name "*.o" \
-o -name "*.a" \
-o -name "*.d" \
-o -name "*.hex" \
-o -name "*.elf" \
\) -delete