-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
238 lines (173 loc) · 7.23 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Ross Baehr
# R@M 2017
# ross.baehr@gmail.com
# FreeRTOS and src objects are put into obj/
# Tivaware objects are built in drivers/ and symlinked into obj/
LINKER_SCRIPT = $(SRC)tiva.ld
ELF_IMAGE = image.elf
TARGET = image.bin
# You shouldn't need to edit anything below here
#########################################################################
# FLAGS #
#########################################################################
TOOLCHAIN = arm-none-eabi-
CC = $(TOOLCHAIN)gcc
CXX = $(TOOLCHAIN)g++
AS = $(TOOLCHAIN)as
LD = $(TOOLCHAIN)ld
OBJCOPY = $(TOOLCHAIN)objcopy
AR = $(TOOLCHAIN)gcc-ar
# GCC flags
#
CFLAG = -c
OFLAG = -o
INCLUDEFLAG = -I
CFLAGS = -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS +=-Os -ffunction-sections -fdata-sections -MD -std=c99
CFLAGS += -pedantic -DPART_TM4C123GH6PM -c
CFLAGS += -DTARGET_IS_TM4C123_RB2
CFLAGS += -Dgcc
#CFLAGS = -mcpu=cortex-m4 -march=armv7e-m -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -Dgcc -DPART_TM4C123GH6PM -DTARGET_IS_TM4C123_RB1 -ffunction-sections -fdata-sections -g -gdwarf-3 -gstrict-dwarf -specs="nosys.specs" -MD -std=c99 -I$(TC_PATH)arm-none-eabi/include/
LTO_PLUGIN = $(shell arm-none-eabi-gcc --print-file-name=liblto_plugin.so)
LDFLAGS = -T $(LINKER_SCRIPT) --entry ResetISR --gc-sections
# Default debug off unless ran with make debug
DEBUG = OFF
##########################################################################
# LOCATIONS #
##########################################################################
# Directory with HW drivers' source files
DRIVERS_SRC = drivers/
# Directory with demo specific source (and header) files
SRC = src/
# Subdir of src
TASKDIR = tasks/
# subdir of src for interrupts
INTERRUPTS = interrupts/
# Intermediate directory for all *.o and other files:
OBJDIR = obj/
USB = usb/
# These objects are needed for linking
LIBGCC = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LIBC = $(shell $(CC) $(CFLAGS) -print-file-name=libc.a)
LIBM = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
# Additional C compiler flags to produce debugging symbols
DEB_FLAG = -g -DDEBUG
# Compiler/target path in FreeRTOS/Source/portable
PORT_COMP_TARG = GCC/ARM_CM4F/
# FreeRTOS source base directory
FREERTOS_SRC = FreeRTOS/Source/
# Directory with memory management source files
FREERTOS_MEMMANG_SRC = $(FREERTOS_SRC)portable/MemMang/
# Directory with platform specific source files
FREERTOS_PORT_SRC = $(FREERTOS_SRC)portable/$(PORT_COMP_TARG)
# Qubobus src files
QUBOBUS_SRC = qubobus/src/
##########################################################################
# OBJECTS #
##########################################################################
# Object files for FreeRTOS
FREERTOS_OBJS = queue.o list.o tasks.o stream_buffer.o
# The following o. files are only necessary if
# certain options are enabled in FreeRTOSConfig.h
#FREERTOS_OBJS += timers.o
#FREERTOS_OBJS += croutine.o
#FREERTOS_OBJS += event_groups.o
# Only one memory management .o file must be uncommented!
#FREERTOS_MEMMANG_OBJS = heap_1.o
#FREERTOS_MEMMANG_OBJS = heap_2.o
#FREERTOS_MEMMANG_OBJS = heap_3.o
FREERTOS_MEMMANG_OBJS = heap_4.o
#FREERTOS_MEMMANG_OBJS = heap_5.o
FREERTOS_PORT_OBJS = port.o
# Driver object lists to tivaware libs
DRIVERLIB_OBJS = $(wildcard $(OBJDIR)driverlib/*.o)
DRIVERLIB_OBJS := $(DRIVERLIB_OBJS) $(wildcard $(OBJDIR)driverlib/*.a)
UTILS_OBJS = $(wildcard $(OBJDIR)utils/*.o)
USBLIB_OBJS = $(wildcard $(OBJDIR)usblib/*.o)
TIVA_DRIVER_OBJS = $(DRIVERLIB_OBJS)
# List of source file objects. Adds any c file in $(SRC) and $(SRC)$(TASKDIR)
SRC_C_FILES = $(wildcard $(SRC)*.c) $(wildcard $(SRC)$(TASKDIR)*.c) $(wildcard $(SRC)lib/*.c) \
$(wildcard $(SRC)$(INTERRUPTS)*.c) $(wildcard $(SRC)$(USB)*.c)
SRC_OBJS := $(SRC_C_FILES:$(SRC)%=%)
SRC_OBJS := $(SRC_OBJS:.c=.o)
QUBOBUS_OBJECTS = io.o protocol.o embedded.o safety.o battery.o power.o thruster.o pneumatics.o depth.o debug.o
# All object files specified above are prefixed the object directory
OBJS = $(addprefix $(OBJDIR), $(FREERTOS_OBJS) $(FREERTOS_MEMMANG_OBJS) $(FREERTOS_PORT_OBJS) \
$(SRC_OBJS) $(QUBOBUS_OBJECTS))
OBJS += $(USBLIB_OBJS)
OBJS += $(DRIVERLIB_OBJS)
##########################################################################
# INCLUDES #
##########################################################################
# FreeRTOS core include files
INC_FREERTOS = $(FREERTOS_SRC)include/
INC_QUBOBUS = qubobus/include/
# Complete include flags to be passed to $(CC) where necessary
INC_FLAGS = $(addprefix $(INCLUDEFLAG), $(INC_FREERTOS) $(FREERTOS_PORT_SRC) $(DRIVERS_SRC) $(SRC) $(INC_QUBOBUS))
DEP_FRTOS_CONFIG = $(SRC)FreeRTOSConfig.h
##########################################################################
# RULES #
##########################################################################
all : $(TARGET)
debug: clean debug_flag all
debug_flag: tiva
$(eval DEBUG := ON)
$(eval CFLAGS += $(DEB_FLAG))
tiva:
bash -c "cd drivers;./symlink_objs &> /dev/null"
rebuild : clean
setenv:
source setenv.sh
dbgrun:
./start_openocd.sh
dbg:
arm-none-eabi-gdb $(ELF_IMAGE)
$(TARGET) : $(OBJDIR) $(ELF_IMAGE)
$(OBJCOPY) -O binary $(word 2,$^) $@ && ./utils/static_usage.bash image.elf
$(OBJDIR) :
mkdir -p $@ $(OBJDIR)$(TASKDIR) $(OBJDIR)lib/ $(OBJDIR)$(INTERRUPTS) $(OBJDIR)usb/
$(ELF_IMAGE) : $(OBJS) $(LIBC) $(LIBM) $(LIBGCC)
@if [ $(DEBUG) = "ON" ]; then \
echo "_____________________________________________________________";\
echo "Debug on";\
echo "$(LD) $(OFLAG) $@ $^ $(UTILS_OBJS) $(LDFLAGS)";\
$(LD) $(OFLAG) $@ $^ $(UTILS_OBJS) $(LDFLAGS);\
else \
echo "_____________________________________________________________";\
echo "Debug off";\
echo "$(LD) $(OFLAG) $@ $^ $(LDFLAGS)";\
$(LD) $(OFLAG) $@ $^ $(LDFLAGS);\
fi
# Objects for files in $(SRC) and $(SRC)$(TASKDIR)
$(OBJDIR)%.o: $(SRC)%.c $(SRC)include/* $(OBJDIR)
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $< $(OFLAG) $@
# Make objects for the FreeRTOS Files
$(OBJDIR)%.o: $(FREERTOS_SRC)%.c $(INC_FREERTOS)* $(DEP_FRTOS_CONFIG)
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $< $(OFLAG) $@
$(OBJDIR)%.o: $(FREERTOS_MEMMANG_SRC)%.c $(DEP_FRTOS_CONFIG)
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $< $(OFLAG) $@
$(OBJDIR)%.o: $(FREERTOS_PORT_SRC)%.c $(DEP_FRTOS_CONFIG)
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $< $(OFLAG) $@
$(OBJDIR)%.o: $(QUBOBUS_SRC)%.c $(INC_QUBOBUS)*
$(CC) $(CFLAG) $(CFLAGS) $(INC_FLAGS) $< $(OFLAG) $@
usage:
./utils/static_usage.bash image.elf
drivers:
cd drivers && make
# Cleanup directives:
clean_obj :
$(RM) $(OBJDIR)*.o $(OBJDIR)*.d
$(RM) $(OBJDIR)$(TASKDIR)*.o $(OBJDIR)$(TASKDIR)*.d
$(RM) $(OBJDIR)lib/*.o $(RM) $(OBJDIR)lib/*.d
$(RM) $(OBJDIR)$(INTERRUPTS)*.o $(OBJDIR)$(INTERRUPTS)*.d
clean_intermediate : clean_obj
$(RM) *.elf
$(RM) *.img
clean : clean_intermediate
$(RM) *.bin
# Rule for flashing
flash:
sudo /opt/lm4tools/lm4flash/lm4flash ./image.bin
# Short help instructions:
print-% : ; @echo $* = $($*)
.PHONY : all rebuild clean clean_intermediate clean_obj debug debug_rebuild _debug_flags help dbgrun dbg setenv