-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile
387 lines (321 loc) · 11.4 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
#/*
# FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.
#
# ***************************************************************************
# * *
# * If you are: *
# * *
# * + New to FreeRTOS, *
# * + Wanting to learn FreeRTOS or multitasking in general quickly *
# * + Looking for basic training, *
# * + Wanting to improve your FreeRTOS skills and productivity *
# * *
# * then take a look at the FreeRTOS books - available as PDF or paperback *
# * *
# * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
# * http://www.FreeRTOS.org/Documentation *
# * *
# * A pdf reference manual is also available. Both are usually delivered *
# * to your inbox within 20 minutes to two hours when purchased between 8am *
# * and 8pm GMT (although please allow up to 24 hours in case of *
# * exceptional circumstances). Thank you for your support! *
# * *
# ***************************************************************************
#
# This file is part of the FreeRTOS distribution.
#
# FreeRTOS is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License (version 2) as published by the
# Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
# ***NOTE*** The exception to the GPL is included to allow you to distribute
# a combined work that includes FreeRTOS without being obliged to provide the
# source code for proprietary components outside of the FreeRTOS kernel.
# FreeRTOS 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. You should have received a copy of the GNU General Public
# License and the FreeRTOS license exception along with FreeRTOS; if not it
# can be viewed here: http://www.freertos.org/a00114.html and also obtained
# by writing to Richard Barry, contact details for whom are available on the
# FreeRTOS WEB site.
#
# 1 tab == 4 spaces!
#
# http://www.FreeRTOS.org - Documentation, latest information, license and
# contact details.
#
# http://www.SafeRTOS.com - A version that is certified for use in safety
# critical systems.
#
# http://www.OpenRTOS.com - Commercial support, development, porting,
# licensing and training services.
#*/
#/*************************************************************************
# * Please ensure to read http://www.freertos.org/portLM3Sxxxx_Eclipse.html
# * which provides information on configuring and running this demo for the
# * various Luminary Micro EKs.
# *************************************************************************/
#+---------------------------------------------------------------------------
#
# Copyright (c) 2010 Anton Gusev aka AHTOXA (HTTP://AHTOXA.NET)
#
# File: makefile
#
# Contents: makefile to build arm Cortex-M3 software with gcc
#
#----------------------------------------------------------------------------
############# program name
TARGET = main
# program version
VER_MAJOR = 0
VER_MINOR = 1
TOOL = arm-none-eabi-
# TOOL = arm-kgp-eabi-
OPTIMIZE = -O2
USE_LTO = NO
# compile options
# MCU = cortex-m3
# Select family
# STM32F10X_LD : STM32 Low density devices
# STM32F10X_LD_VL : STM32 Low density Value Line devices
# CHIP = STM32F10X_MD #: STM32 Medium density devices
# STM32F10X_MD_VL : STM32 Medium density Value Line devices
# STM32F10X_HD : STM32 High density devices
# STM32F10X_HD_VL : STM32 XL-density devices
# STM32F10X_CL : STM32 Connectivity line devices
# STM32F10X_XL : STM32 XL-density devices
# CHIP = STM32F10X_MD
MCU = cortex-m4
CHIP = STM32F407VG
#STARTUP = startup_stm32f10x_md.S
STARTUP = startup_$(CHIP)
RTOS_ROOT=../FreeRTOS
CMSIS_DRIVER_DIR=../MyARMLib/CMSIS/include
#defines
DEFS = -D$(CHIP)
DEFS += -DVER_MAJOR=$(VER_MAJOR)
DEFS += -DVER_MINOR=$(VER_MINOR)
###########################################################
# common part for all my cortex-m3 projects
###########################################################
BASE = .
CC = $(TOOL)gcc
CXX = $(TOOL)g++
LD = $(TOOL)g++
AS = $(CC) -x assembler-with-cpp
OBJCOPY = $(TOOL)objcopy
OBJDUMP = $(TOOL)objdump
SIZE = $(TOOL)size -d
FLASHER = openocd
RM = rm -f
CP = cp
MD = mkdir
# dirs
SRCDIR = $(BASE)/src
OBJDIR = $(BASE)/obj
EXEDIR = $(BASE)/exe
LSTDIR = $(BASE)/lst
PRJDIR = $(BASE)/prj
BAKDIR = $(BASE)/bak
#files
HEX = $(EXEDIR)/$(TARGET).hex
BIN = $(EXEDIR)/$(TARGET).bin
AXF = $(EXEDIR)/$(TARGET).axf
ELF = $(EXEDIR)/$(TARGET).elf
MAP = $(LSTDIR)/$(TARGET).map
LSS = $(LSTDIR)/$(TARGET).lss
OK = $(EXEDIR)/$(TARGET).ok
# linker script (chip dependent)
LD_SCRIPT = $(SRCDIR)/$(CHIP).ld
# scmRTOS dir
# SCMDIR = ../scmRTOS
# COMMON = ../SamplesCommon
# source directories (all *.c, *.cpp and *.s files included)
DIRS := $(SRCDIR)
# DIRS += $(COMMON)
DIRS += $(RTOS_ROOT)/Source
DIRS += $(RTOS_ROOT)/Source/portable/GCC/ARM_CM3
DIRS += $(RTOS_ROOT)/Source/include
# DIRS += ../MyARMLib/STM32/STM32F103_Pinboard_II
# DIRS += $(RTOS_ROOT)/Demo/Common/Minimal
DIRS += $(RTOS_ROOT)/Demo/Common/include
# DIRS += $(RTOS_ROOT)/Demo/Common/ethernet/uIP/uip-1.0/uip
# DIRS += $(RTOS_ROOT)/Source/portable/GCC/ARM_CM3_MPU
#STM32F1_DISCOVERY_DRIVER_DIR=../MyARMLib/STM32/STM32F4_discovery
DIRS += $(CMSIS_DRIVER_DIR)
DIRS += ../MyARMLib/CMSIS/include
# DIRS += ../MyARMLib/STM32/STM32F10x/include
# DIRS += ../MyARMLib/STM32/STM32F10x_StdPeriph_Driver/inc
# DIRS += ../MyARMLib/STM32/STM32F10x_StdPeriph_Driver/src
DIRS += ../MyARMLib/STM32/STM32F4xx/include
DIRS += ../MyARMLib/STM32/STM32F4_discovery
DIRS += ../MyARMLib/STM32/STM32F4xx_StdPeriph_Driver/src
DIRS += ../MyARMLib/STM32/STM32F4xx_StdPeriph_Driver/inc
# DIRS += ../MyARMLib/FreeRTOS
# includes
INCS := $(patsubst %, -I "%", $(DIRS))
# individual source files
SRCS :=
#calc obj files list
OBJS := $(SRCS)
OBJS += $(wildcard $(addsuffix /*.cpp, $(DIRS)))
OBJS += $(wildcard $(addsuffix /*.c, $(DIRS)))
OBJS += $(wildcard $(addsuffix /*.S, $(DIRS)))
#OBJS += $(RTOS_ROOT)/Source/tasks.c
#/port.c
# OBJS += ../MyARMLib/STM32/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.c
# OBJS += ../MyARMLib/STM32/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c
# OBJS += $(RTOS_ROOT)/Source/tasks.c
# OBJS += $(RTOS_ROOT)/Source/list.c
# OBJS += $(RTOS_ROOT)/Source/timers.c
# OBJS += $(RTOS_ROOT)/Source/queue.c
# OBJS += $(RTOS_ROOT)/Source/tasks.c
# OBJS += $(RTOS_ROOT)/Source/portable/GCC/ARM_CM3/port.c
# OBJS += $(RTOS_ROOT)/Source/portable/MemMang/heap_2.c
OBJS := $(notdir $(OBJS))
OBJS := $(OBJS:.cpp=.o)
OBJS := $(OBJS:.c=.o)
OBJS := $(OBJS:.S=.o)
OBJS := $(patsubst %, $(OBJDIR)/%, $(OBJS))
#files to archive
ARCFILES = \
$(SRCDIR) \
$(PRJDIR) \
$(SCMDIR) \
$(BASE)/makefile \
$(BASE)/.cproject \
$(BASE)/.project
# flags
FLAGS = -mcpu=$(MCU) -mthumb
FLAGS += $(INCS)
FLAGS += -MD
#-DGCC_ARMCM3
FLAGS += $(DEFS) -DUSE_STDPERIPH_DRIVER
FLAGS += -Wa,-adhlns=$(addprefix $(LSTDIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
AFLAGS = $(FLAGS)
CFLAGS = $(FLAGS)
CFLAGS += $(OPTIMIZE)
CFLAGS += -std=gnu99
CFLAGS += -D GCC_ARMCM3
CFLAGS += -g
CFLAGS += -ffunction-sections -fdata-sections
# CFLAGS += -Wall -Wextra
# CFLAGS += -Wimplicit -Wcast-align -Wpointer-arith -Wredundant-decls
# CFLAGS += -Wshadow -Wcast-qual -Wcast-align -Wnested-externs -pedantic
CXXFLAGS = $(FLAGS)
CXXFLAGS += $(OPTIMIZE)
CXXFLAGS += -g
CXXFLAGS += -fno-exceptions -fno-rtti
CXXFLAGS += -ffunction-sections -fdata-sections
CXXFLAGS += -fno-threadsafe-statics
CXXFLAGS += -funsigned-bitfields -fshort-enums
CXXFLAGS += -Wall -Wextra
CXXFLAGS += -Winline
CXXFLAGS += -Wpointer-arith -Wredundant-decls
CXXFLAGS += -Wshadow -Wcast-qual -Wcast-align -pedantic
LD_FLAGS = -mcpu=$(MCU)
LD_FLAGS += -mthumb
LD_FLAGS += -nostartfiles
LD_FLAGS += -Wl,-Map="$(MAP)",--cref
LD_FLAGS += -Wl,--gc-sections
LD_FLAGS += -T$(LD_SCRIPT)
ifeq ($(USE_LTO),YES)
CFLAGS += -flto
CXXFLAGS += -flto
LD_FLAGS += -flto $(OPTIMIZE)
endif
#openocd command-line
# debug level (d0..d3)
oocd_params = -d3
# interface and board/target settings (using the OOCD target-library here)
# oocd_params += -c "fast enable"
oocd_params += -f interface/arm-usb-ocd.cfg
oocd_params += -f board/stm32f10x_128k_eval.cfg
oocd_params += -c init -c targets
oocd_params_program = $(oocd_params)
# commands to prepare flash-write
oocd_params_program += -c "halt"
# flash-write and -verify
oocd_params_program += -c "flash write_image erase $(ELF)"
oocd_params_program += -c "verify_image $(ELF)"
# reset target
oocd_params_program += -c "reset run"
# terminate OOCD after programming
oocd_params_program += -c shutdown
oocd_params_reset = $(oocd_params)
oocd_params_reset += -c "reset run"
oocd_params_reset += -c shutdown
.SILENT :
.PHONY: all start dirs build clean program reset archive
############# targets
all : start dirs $(AXF) $(ELF) $(HEX) $(BIN) $(LSS) $(OK)
build: clean all
start:
@echo --- building $(TARGET) $(OBJS)
$(LSS): $(ELF) makefile
@echo --- making asm-lst...
# @$(OBJDUMP) -dStC $(ELF) > $(LSS)
@$(OBJDUMP) -dC $(ELF) > $(LSS)
$(OK): $(ELF)
@$(SIZE) $(ELF)
@echo "Errors: none"
$(AXF): $(OBJS) $(STARTUP).o makefile
@echo --- linking... axf
$(LD) $(OBJS) $(STARTUP).o $(LIBS) $(LD_FLAGS) -o "$(AXF)"
$(ELF): $(OBJS) makefile
@echo --- linking...
$(LD) $(OBJS) $(LIBS) $(LD_FLAGS) -o "$(ELF)"
$(HEX): $(ELF)
@echo --- make hex...
@$(OBJCOPY) -O ihex $(ELF) $(HEX)
$(BIN): $(ELF)
@echo --- make binary...
@$(OBJCOPY) -O binary $(ELF) $(BIN)
program: $(ELF)
@echo "Programming with OPENOCD"
$(FLASHER) $(oocd_params_program)
reset:
@echo Resetting device
$(FLASHER) $(oocd_params_reset)
VPATH := $(DIRS)
$(OBJDIR)/%.o: %.cpp makefile
@echo --- compiling $<...
$(CXX) -c $(CXXFLAGS) -o $@ $<
$(OBJDIR)/%.o: %.c makefile
@echo --- compiling $<...
$(CC) -c $(CFLAGS) -o $@ $<
$(OBJDIR)/%.o: %.S makefile
@echo --- assembling $<...
$(AS) -c $(AFLAGS) -o $@ $<
$(OBJDIR)/%.o: %.s makefile
@echo --- assembling $<...
$(AS) -c $(AFLAGS) -o $@ $<
dirs: $(OBJDIR) $(EXEDIR) $(LSTDIR) $(BAKDIR)
$(OBJDIR):
-@$(MD) $(OBJDIR)
$(EXEDIR):
-@$(MD) $(EXEDIR)
$(LSTDIR):
-@$(MD) $(LSTDIR)
$(BAKDIR):
-@$(MD) $(BAKDIR)
clean:
-@$(RM) $(OBJDIR)/*.d 2>/dev/null
-@$(RM) $(OBJDIR)/*.o 2>/dev/null
-@$(RM) $(LSTDIR)/*.lst 2>/dev/null
-@$(RM) $(ELF)
-@$(RM) $(HEX)
-@$(RM) $(LSS)
-@$(RM) $(MAP)
archive:
@echo --- archiving...
7z a $(BAKDIR)/$(TARGET)_`date +%Y-%m-%d,%H-%M-%S` $(ARCFILES)
@echo --- done!
# dependencies
ifeq (,$(findstring build,$(MAKECMDGOALS)))
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring dirs,$(MAKECMDGOALS)))
-include $(wildcard $(OBJDIR)/*.d)
endif
endif
endif