-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
192 lines (148 loc) · 6.13 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
# Copyright (c) 2022 Nestor D. Pereira Neto
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# This makefile was written based on the
# https://github.com/jkovacic/FreeRTOS-GCC-tm4c123glx/blob/master/Makefile
TOOLCHAIN = arm-none-eabi-
CC = $(TOOLCHAIN)gcc
CXX = $(TOOLCHAIN)g++
AS = $(TOOLCHAIN)as
LD = $(TOOLCHAIN)ld
OBJCOPY = $(TOOLCHAIN)objcopy
AR = $(TOOLCHAIN)ar
# GCC flags
#--------------------
CPUFLAG = -mthumb -mcpu=cortex-m4
WFLAG = -Wall
WFLAG +=-Wextra
FPUFLAG +=-mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS = $(CPUFLAG)
CFLAGS += $(WFLAG)
CFLAGS += $(FPUFLAG)
CFLAGS += -std=c99
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -DPART_TM4C123GH6PM
DEB_FLAG = -g -DDEBUG
# Directories variables
#---------------------
PORT_TARGET = GCC/ARM_CM4F/
OBJ_DIR = obj/
DRIVERS_DIR = drivers/
SRC_DIR = src/
FREERTOS_SRC_DIR = FreeRTOS/Source/
FREERTOS_MEMMANG_DIR = $(FREERTOS_SRC_DIR)portable/MemMang/
FREERTOS_PORT_DIR = $(FREERTOS_SRC_DIR)portable/$(PORT_TARGET)
# Object files
#---------------------
FREERTOS_OBJS = queue.o list.o tasks.o
FREERTOS_OBJS += timers.o
FREERTOS_OBJS += croutine.o
FREERTOS_OBJS += event_groups.o
FREERTOS_OBJS += stream_buffer.o
#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
FREERTOS_PORT_SOURCE= $(shell ls $(FREERTOS_PORT_DIR)*.c)
DRIVERS_SOURCES = $(shell ls $(DRIVERS_DIR)*.c)
SRC_SOURCES = $(shell ls $(SRC_DIR)*.c)
FREERTOS_PORT_OBJS = $(patsubst $(FREERTOS_PORT_DIR)%,$(OBJ_DIR)%,$(FREERTOS_PORT_SOURCE:.c=.o))
DRIVERS_OBJS = $(patsubst $(DRIVERS_DIR)%,$(OBJ_DIR)%,$(DRIVERS_SOURCES:.c=.o))
SRC_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(SRC_SOURCES:.c=.o))
OBJS = $(addprefix $(OBJ_DIR), $(FREERTOS_OBJS))
OBJS += $(addprefix $(OBJ_DIR), $(FREERTOS_MEMMANG_OBJS))
OBJS += $(FREERTOS_PORT_OBJS)
OBJS += $(DRIVERS_OBJS)
OBJS += $(SRC_OBJS)
# Get the location of libgcc.a, libc.a and libm.a from the GCC front-end.
#---------------------
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}
# Include paths to be passed to $(CC) where necessary
#---------------------
INC_DIR = include/
INC_FREERTOS = $(FREERTOS_SRC_DIR)include/
INC_TIVAWARE = $(TIVAWARE_DIR)/
INC_FLAGS = -I $(INC_FREERTOS) -I $(SRC_DIR) -I $(FREERTOS_PORT_DIR) -I $(INC_DIR) -I $(INC_TIVAWARE)
# Dependency on HW specific settings
#---------------------
DEP_BSP = $(INC_DIR)drivers/bsp.h
DEP_FRTOS_CONFIG = $(SRC_DIR)FreeRTOSConfig.h
DEP_SETTINGS = $(DEP_FRTOS_CONFIG)
# Definition of the linker script and final targets
#---------------------
LINKER_SCRIPT = $(addprefix , tm4c123gh6pm.lds)
ELF_IMAGE = image.elf
TARGET_IMAGE = image.bin
# Make rules:
#---------------------
print-% : ; @echo $* = $($*)
all : $(TARGET_IMAGE)
rebuild : clean all
$(TARGET_IMAGE) : $(OBJ_DIR) $(ELF_IMAGE)
$(OBJCOPY) -O binary $(word 2,$^) $@
$(OBJ_DIR) :
mkdir -p $@
# Linker
$(ELF_IMAGE) : $(OBJS) $(LINKER_SCRIPT)
$(LD) -L $(OBJ_DIR) -L$(TIVAWARE_DIR)/driverlib/gcc -T $(LINKER_SCRIPT) $(OBJS) -o $@ -ldriver '$(LIBGCC)' '$(LIBC)' '$(LIBM)'
debug : _debug_flags all
debug_rebuild : _debug_flags rebuild
_debug_flags :
$(eval CFLAGS += $(DEB_FLAG))
# FreeRTOS core
$(OBJ_DIR)%.o: $(FREERTOS_SRC_DIR)%.c $(DEP_FRTOS_CONFIG) $(DEP_SETTINGS)
$(CC) $(CFLAGS) $(INC_FLAGS) -c $< -o $@
# HW specific part, in FreeRTOS/Source/portable/$(PORT_TARGETET)
$(OBJ_DIR)port.o : $(FREERTOS_PORT_DIR)port.c $(DEP_FRTOS_CONFIG)
$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
# Rules for all MemMang implementations are provided
$(OBJ_DIR)%.o : $(FREERTOS_MEMMANG_DIR)%.c $(DEP_FRTOS_CONFIG)
$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
# Drivers
$(OBJ_DIR)%.o : $(DRIVERS_DIR)%.c
$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
# Main Code
$(OBJ_DIR)%.o : $(SRC_DIR)%.c $(DEP_SETTINGS)
$(CC) -c $(CFLAGS) $(INC_FLAGS) $< -o $@
# Cleanup directives:
#---------------------
clean_obj :
$(RM) -r $(OBJ_DIR)
clean_intermediate : clean_obj
$(RM) *.elf
$(RM) *.img
clean : clean_intermediate
$(RM) *.bin
# Short help instructions:
#---------------------
help :
@echo
@echo Valid targets:
@echo - all: builds missing dependencies and creates the target image \'$(TARGET_IMAGE)\'.
@echo - rebuild: rebuilds all dependencies and creates the target image \'$(TARGET_IMAGE)\'.
@echo - debug: same as \'all\', also includes debugging symbols to \'$(ELF_IMAGE)\'.
@echo - debug_rebuild: same as \'rebuild\', also includes debugging symbols to \'$(ELF_IMAGE)\'.
@echo - clean_obj: deletes all object files, only keeps \'$(ELF_IMAGE)\' and \'$(TARGET_IMAGE)\'.
@echo - clean_intermediate: deletes all intermediate binaries, only keeps the target image \'$(TARGET_IMAGE)\'.
@echo - clean: deletes all intermediate binaries, incl. the target image \'$(TARGET_IMAGE)\'.
@echo - help: displays these help instructions.
@echo
.PHONY : all rebuild clean clean_intermediate clean_obj debug debug_rebuild _debug_flags help