-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile
executable file
·312 lines (267 loc) · 10 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#
# @author iota square [i2]
# <pre>
# ██╗ ██████╗ ████████╗ █████╗ ██████╗
# ██║██╔═══██╗╚══██╔══╝██╔══██╗╚════██╗
# ██║██║ ██║ ██║ ███████║ █████╔╝
# ██║██║ ██║ ██║ ██╔══██║██╔═══╝
# ██║╚██████╔╝ ██║ ██║ ██║███████╗
# ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝
# </pre>
#
# @date 07-09-2019
# @file makefile
# @brief Makefile for IOTA2 HUB application.
#
# @copyright GNU GPU v3
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Free Software, Hell Yeah!
#
NAME := IOTA2_HUB
GLOBAL_DEFINES := $(NAME)
GLOBAL_DEFINES += STM32F40XX
export GLOBAL_DEFINES
TOOLS_ROOT := $(CURDIR)/tools
TOOLCHAIN_PREFIX := arm-none-eabi-
TOOLCHAIN_PATH := $(TOOLS_ROOT)/ARM_GNU/Linux64/bin/
# MAP file parser
MAP_FILE_PARSER := $(TOOLS_ROOT)/utilities/map_parser.pl
# Default disable make verbose level
VERBOSE_LEVEL ?= 0
ifeq ($(VERBOSE_LEVEL),2)
GLOBAL_DEFINES += VERBOSE_LEVEL=2
else ifeq ($(VERBOSE_LEVEL),1)
GLOBAL_DEFINES += VERBOSE_LEVEL=1
else ifeq ($(VERBOSE_LEVEL),0)
GLOBAL_DEFINES += VERBOSE_LEVEL=0
.SILENT:
endif
# ------------------------------------------------------------------------------
# Compiler Paths
# ------------------------------------------------------------------------------
export CC := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)gcc
export CCDEP := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)gcc
export LD := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)gcc
export AR := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)ar
export AS := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)gcc
export OBJCOPY := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)objcopy
export OBJDUMP := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)objdump
export GDB := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)gdb
export GCOV := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)gcov
export SIZE := $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)size
OUTPUT_ROOT = build
ifeq ($(RELEASE), yes)
OUTPUT = $(OUTPUT_ROOT)/$(NAME)/release
else
OUTPUT = $(OUTPUT_ROOT)/$(NAME)/debug
endif
# ------------------------------------------------------------------------------
# Executables
# ------------------------------------------------------------------------------
ELF = $(OUTPUT)/$(NAME).elf
BIN = $(OUTPUT)/$(NAME).bin
HEX = $(OUTPUT)/$(NAME).hex
LST = $(OUTPUT)/$(NAME).list
MAP = $(OUTPUT)/$(NAME).map
COV = $(OUTPUT)/GCOV/
GIT_HASH := $(shell git describe --dirty --always --abbrev=0)
CPU = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard
STM32_OPT = -DSTM32F407xx -DSTM32F407xx -DENABLE_RTOS_AWARE_HAL
STM32_OPT += -DUSE_FULL_ASSERT -DENABLE_ASSERT
OTHER_OPT = "-D__weak=__attribute__((weak))"
OTHER_OPT += "-D__packed=__attribute__((__packed__))"
LDSCRIPT = ./STM32F407IGTx_FLASH.ld
DRV_DIR := ./drivers
MDL_DIR := ./middleware
LIBINC := -Iapp/inc
LIBINC += -Iiota2/i2_Interface_Driver/inc
LIBINC += -Iiota2/i2_STM32F4xx_HAL_Driver/inc
LIBINC += -I$(DRV_DIR)/CMSIS/Include
LIBINC += -I$(DRV_DIR)/CMSIS/RTOS/Template
LIBINC += -I$(DRV_DIR)/CMSIS/Device/ST/STM32F4xx/Include
LIBINC += -I$(DRV_DIR)/STM32F4xx_HAL_Driver/Inc
LIBINC += -I$(MDL_DIR)/FreeRTOSv10.2.1/FreeRTOS/Source/include
LIBINC += -I$(MDL_DIR)/FreeRTOSv10.2.1/FreeRTOS/Source/portable/GCC/ARM_CM4F
LIBS := ./$(DRV_DIR)/STM32F4xx_HAL_Driver/lib_stm32f4xx_hal.a
LIBS += ./$(MDL_DIR)/FreeRTOSv10.2.1/FreeRTOS/lib_freertos_v10_2_1.a
INCLUDES = $(LIBINC)
CFLAGS += $(CPU) $(STM32_OPT) $(OTHER_OPT)
CFLAGS += -fno-common -fno-short-enums
CFLAGS += $(INCLUDES) -std=gnu99 -DGIT_VERSION=\"$(GIT_HASH)\"
CFLAGS += -Wall -Werror -Wfatal-errors
ASFLAGS = $(CFLAGS) -x assembler-with-cpp
LDFLAGS = -Wl,--gc-sections,-Map=$(MAP),-cref -fno-short-enums
LDFLAGS += -Wl,--no-enum-size-warning -T $(LDSCRIPT) $(CPU) -coverage
ARFLAGS = cr
OBJFLAGS_C = -Obinary
OBJFLAGS_D = -S
# ------------------------------------------------------------------------------
# Build Type Modifiers
# ------------------------------------------------------------------------------
ifeq ($(RELEASE), yes)
CFLAGS += -Os
LDFLAGS += --specs=nosys.specs
else
xSTM32_OPT += -DENABLE_DEBUG
CFLAGS += -ggdb -g3 -Og
LDFLAGS += --specs=rdimon.specs -Og
endif
export CFLAGS
export ARFLAGS
# ------------------------------------------------------------------------------
# Code Coverage Computation
# Adding -coverage to both CFLAGS and LDFLAGS
# - This will enable both -fprofile-arcs and -ftest-coverage flags
# ------------------------------------------------------------------------------
ifeq ($(CODE_COV), yes)
COVERAGE += -coverage
GCOV_PREFIX = $(COV)
GCOV_PREFIX_STRIP = 1
endif
VPATH = app/src:
VPATH += iota2/i2_Interface_Driver/src:
VPATH += iota2/i2_STM32F4xx_HAL_Driver/src:
VPATH += $(DRV_DIR)/CMSIS/Device/ST/STM32F4xx/Source/Templates:
VPATH += $(DRV_DIR)/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc:
ASMS = $(DRV_DIR)/CMSIS/Device/ST/STM32F4xx/Source/ \
Templates/gcc/startup_stm32f407xx.s
SRCS = $(DRV_DIR)/CMSIS/Device/ST/STM32F4xx/Source/ \
Templates/system_stm32f4xx.c
SRCS += app/src/main.c
SRCS += app/src/stm32f4xx_it.c
SRCS += iota2/i2_STM32F4xx_HAL_Driver/i2_assert.c
SRCS += iota2/i2_STM32F4xx_HAL_Driver/i2_stm32f4xx_hal_common.c
SRCS += iota2/i2_STM32F4xx_HAL_Driver/i2_stm32f4xx_hal_clock.c
SRCS += iota2/i2_STM32F4xx_HAL_Driver/i2_stm32f4xx_hal_gpio.c
SRCS += iota2/i2_STM32F4xx_HAL_Driver/i2_stm32f4xx_hal_rtc.c
SRCS += iota2/i2_STM32F4xx_HAL_Driver/i2_stm32f4xx_hal_uart.c
SRCS += iota2/i2_STM32F4xx_HAL_Driver/i2_stm32f4xx_hal_spi.c
SRCS += iota2/i2_Interface_Driver/src/i2_fifo.c
SRCS += iota2/i2_Interface_Driver/src/i2_led.c
SRCS += iota2/i2_Interface_Driver/src/i2_font5x7.c
SRCS += iota2/i2_Interface_Driver/src/i2_oled_ssd1306.c
ASMS_TEMP := $(notdir $(ASMS))
SRCS_TEMP := $(notdir $(SRCS))
AOBJS := $(patsubst %.s, $(OUTPUT_ROOT)/%.o, $(ASMS_TEMP) )
OBJS := $(patsubst %.c, $(OUTPUT_ROOT)/%.o, $(SRCS_TEMP) )
DEPS = $(AOBJS:.o=.d)
DEPS += $(OBJS:.o=.d)
all: $(OUTPUT) $(ELF) $(BIN) $(HEX)
$(OBJDUMP) $(OBJFLAGS_D) $(ELF) > $(LST)
$(SIZE) $(ELF)
@echo "\n"
$(MAP_FILE_PARSER) -w $(MAP)
@echo HEAD GIT HASH : $(GIT_HASH)
@echo Make finished
flash: $(BIN)
@echo "Starting Flashing Target..."
st-flash --format binary write $< 0x8000000
erase:
@echo "Erasing Target..."
st-flash erase
$(OUTPUT):
ifeq ($(RELEASE), yes)
@echo "Initiating RELEASE build..."
else
@echo "Initiating DEBUG build..."
endif
mkdir -p $(OUTPUT)
mkdir -p $(COV)
$(ELF): $(LIBS) $(AOBJS) $(OBJS)
$(CC) $(AOBJS) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
$(HEX): $(ELF)
$(OBJCOPY) -O ihex $< $@
$(BIN): $(ELF)
$(OBJCOPY) -O binary -S $< $@
$(LIBS): libs
libs:
@echo Building libraries...
@$(MAKE) -C $(DRV_DIR)
@$(MAKE) -C $(MDL_DIR)
libclean: clean
@echo Cleaning libraries...
@$(MAKE) -C $(DRV_DIR) clean
@$(MAKE) -C $(MDL_DIR) clean
get_mem_map:
@echo "Detailed Memory Mapping:"
$(SIZE) $(AOBJS) $(OBJS) $(LIBS)
@echo "\n\nExecutables:"
$(SIZE) $(ELF) $(HEX)
$(MAP_FILE_PARSER) -w $(MAP)
clean:
@echo Removing executables...
rm -fr $(OUTPUT_ROOT)
@$(MAKE) -C $(DRV_DIR) clean
@$(MAKE) -C $(MDL_DIR) clean
$(OUTPUT_ROOT)/%.o: %.c
ifeq ($(VERBOSE_LEVEL),1)
@echo cc $<
endif
@$(CC) $(CFLAGS) $(COVERAGE) -c $< -o $@ -MMD -MF $(@:.o=.d)
$(OUTPUT_ROOT)/%.o: %.s
ifeq ($(VERBOSE_LEVEL),1)
@echo as $<
endif
@$(AS) $(ASFLAGS) $(COVERAGE) -c -o $@ $<
get_code_cov:
@echo "#################################"
@echo "# Computing code coverage... "
@echo "#################################"
$(GCOV) -k -c -d **/*.gcno
test: $(AOBJS) $(OBJS)
@echo ----- ASM -----
@echo $(ASMS)
@echo ----- SRC -----
@echo $(SRCS)
@echo ---- AOBJ -----
@echo $(AOBJS)
@echo ----- OBJ -----
@echo $(OBJS)
@echo ----- DEP -----
@echo $(DEPS)
gcc_path:
@echo "Set paths for toolchain:"
@echo "\tCC: $(CC)"
@echo "\tCCDEP: $(CCDEP)"
@echo "\tLD: $(LD)"
@echo "\tAR: $(AR)"
@echo "\tAS: $(AS)"
@echo "\tOBJCOPY: $(OBJCOPY)"
@echo "\tOBJDUMP: $(OBJDUMP)"
@echo "\tGDB: $(GDB)"
@echo "\tGCOV: $(GCOV)"
@echo "\tSIZE: $(SIZE)"
help:
@echo "==== $(NAME) ===="
@echo "Make Options:"
@echo "[all] make complete project"
@echo "[libs] make libraries again"
@echo "[get_mem_map] Get Detailed memory profiling"
@echo "[clean] Clean complete project"
@echo "[libclean] Clean all libraries"
@echo "[test] Test complete project by test making all targets"
@echo "[gcc_path] Display all configured GCC paths"
@echo "[flash] Flash build to target"
@echo "[erase] Erase target"
@echo "[get_code_cov] Compute code coverage reports"
@echo "\nMake Configurations:"
@echo "[VERBOSE_LEVEL]"
@echo " Define the make verbose level to print debug messages"
@echo " 0 : No make debug message will be printed <default>"
@echo " 1 : Only additional make messages will be printed"
@echo " 2 : All debug messages of make will be printed"
@echo "[RELEASE]"
@echo " yes : Make Release build, else Debug build will be made"
@echo "[CODE_COV]"
@echo " yes : Compile with code coverage flags"
# *********************** (C) COPYRIGHT iota2 ***[i2]******END OF FILE**********