1 | #/*
|
2 | # FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.
|
3 | #
|
4 | # ***************************************************************************
|
5 | # * *
|
6 | # * If you are: *
|
7 | # * *
|
8 | # * + New to FreeRTOS, *
|
9 | # * + Wanting to learn FreeRTOS or multitasking in general quickly *
|
10 | # * + Looking for basic training, *
|
11 | # * + Wanting to improve your FreeRTOS skills and productivity *
|
12 | # * *
|
13 | # * then take a look at the FreeRTOS books - available as PDF or paperback *
|
14 | # * *
|
15 | # * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
|
16 | # * http://www.FreeRTOS.org/Documentation *
|
17 | # * *
|
18 | # * A pdf reference manual is also available. Both are usually delivered *
|
19 | # * to your inbox within 20 minutes to two hours when purchased between 8am *
|
20 | # * and 8pm GMT (although please allow up to 24 hours in case of *
|
21 | # * exceptional circumstances). Thank you for your support! *
|
22 | # * *
|
23 | # ***************************************************************************
|
24 | #
|
25 | # This file is part of the FreeRTOS distribution.
|
26 | #
|
27 | # FreeRTOS is free software; you can redistribute it and/or modify it under
|
28 | # the terms of the GNU General Public License (version 2) as published by the
|
29 | # Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
30 | # ***NOTE*** The exception to the GPL is included to allow you to distribute
|
31 | # a combined work that includes FreeRTOS without being obliged to provide the
|
32 | # source code for proprietary components outside of the FreeRTOS kernel.
|
33 | # FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
|
34 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
35 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
36 | # more details. You should have received a copy of the GNU General Public
|
37 | # License and the FreeRTOS license exception along with FreeRTOS; if not it
|
38 | # can be viewed here: http://www.freertos.org/a00114.html and also obtained
|
39 | # by writing to Richard Barry, contact details for whom are available on the
|
40 | # FreeRTOS WEB site.
|
41 | #
|
42 | # 1 tab == 4 spaces!
|
43 | #
|
44 | # http://www.FreeRTOS.org - Documentation, latest information, license and
|
45 | # contact details.
|
46 | #
|
47 | # http://www.SafeRTOS.com - A version that is certified for use in safety
|
48 | # critical systems.
|
49 | #
|
50 | # http://www.OpenRTOS.com - Commercial support, development, porting,
|
51 | # licensing and training services.
|
52 | #*/
|
53 |
|
54 |
|
55 | #/*************************************************************************
|
56 | # * Please ensure to read http://www.freertos.org/portLM3Sxxxx_Eclipse.html
|
57 | # * which provides information on configuring and running this demo for the
|
58 | # * various Luminary Micro EKs.
|
59 | # *************************************************************************/
|
60 |
|
61 | #+---------------------------------------------------------------------------
|
62 | #
|
63 | # Copyright (c) 2010 Anton Gusev aka AHTOXA (HTTP://AHTOXA.NET)
|
64 | #
|
65 | # File: makefile
|
66 | #
|
67 | # Contents: makefile to build arm Cortex-M3 software with gcc
|
68 | #
|
69 | #----------------------------------------------------------------------------
|
70 |
|
71 | ############# program name
|
72 | TARGET = main
|
73 |
|
74 | # program version
|
75 | VER_MAJOR = 0
|
76 | VER_MINOR = 1
|
77 |
|
78 | TOOL = arm-none-eabi-
|
79 | # TOOL = arm-kgp-eabi-
|
80 |
|
81 | OPTIMIZE = -O2
|
82 | USE_LTO = NO
|
83 |
|
84 | # compile options
|
85 | # MCU = cortex-m3
|
86 | # Select family
|
87 | # STM32F10X_LD : STM32 Low density devices
|
88 | # STM32F10X_LD_VL : STM32 Low density Value Line devices
|
89 | # CHIP = STM32F10X_MD #: STM32 Medium density devices
|
90 | # STM32F10X_MD_VL : STM32 Medium density Value Line devices
|
91 | # STM32F10X_HD : STM32 High density devices
|
92 | # STM32F10X_HD_VL : STM32 XL-density devices
|
93 | # STM32F10X_CL : STM32 Connectivity line devices
|
94 | # STM32F10X_XL : STM32 XL-density devices
|
95 | # CHIP = STM32F10X_MD
|
96 |
|
97 | MCU = cortex-m4
|
98 | CHIP = STM32F407VG
|
99 |
|
100 | #STARTUP = startup_stm32f10x_md.S
|
101 | STARTUP = startup_$(CHIP)
|
102 |
|
103 | RTOS_ROOT=../FreeRTOSV7.1.1
|
104 | CMSIS_DRIVER_DIR=../STM32F4xx_DSP_StdPeriph_Lib_V1.0.0/Libraries/CMSIS/Include
|
105 |
|
106 |
|
107 | #defines
|
108 | DEFS = -D$(CHIP)
|
109 | DEFS += -DVER_MAJOR=$(VER_MAJOR)
|
110 | DEFS += -DVER_MINOR=$(VER_MINOR)
|
111 |
|
112 | ###########################################################
|
113 | # common part for all my cortex-m3 projects
|
114 | ###########################################################
|
115 |
|
116 | BASE = .
|
117 | CC = $(TOOL)gcc
|
118 | CXX = $(TOOL)g++
|
119 | LD = $(TOOL)g++
|
120 | AS = $(CC) -x assembler-with-cpp
|
121 | OBJCOPY = $(TOOL)objcopy
|
122 | OBJDUMP = $(TOOL)objdump
|
123 | SIZE = $(TOOL)size -d
|
124 | FLASHER = openocd
|
125 | RM = rm -f
|
126 | CP = cp
|
127 | MD = mkdir
|
128 |
|
129 |
|
130 | # dirs
|
131 | SRCDIR = $(BASE)/src
|
132 | OBJDIR = $(BASE)/obj
|
133 | EXEDIR = $(BASE)/exe
|
134 | LSTDIR = $(BASE)/lst
|
135 | PRJDIR = $(BASE)/prj
|
136 | BAKDIR = $(BASE)/bak
|
137 |
|
138 | #files
|
139 | HEX = $(EXEDIR)/$(TARGET).hex
|
140 | BIN = $(EXEDIR)/$(TARGET).bin
|
141 | AXF = $(EXEDIR)/$(TARGET).axf
|
142 | ELF = $(EXEDIR)/$(TARGET).elf
|
143 | MAP = $(LSTDIR)/$(TARGET).map
|
144 | LSS = $(LSTDIR)/$(TARGET).lss
|
145 | OK = $(EXEDIR)/$(TARGET).ok
|
146 |
|
147 | # linker script (chip dependent)
|
148 | LD_SCRIPT = $(SRCDIR)/$(CHIP).ld
|
149 |
|
150 | # scmRTOS dir
|
151 | # SCMDIR = ../scmRTOS
|
152 | # COMMON = ../SamplesCommon
|
153 |
|
154 | # source directories (all *.c, *.cpp and *.s files included)
|
155 | DIRS := $(SRCDIR)
|
156 | # DIRS += $(COMMON)
|
157 | DIRS += $(RTOS_ROOT)/Source
|
158 | DIRS += $(RTOS_ROOT)/Source/portable/GCC/ARM_CM4F
|
159 | DIRS += $(RTOS_ROOT)/Source/include
|
160 | # DIRS += ../MyARMLib/STM32/STM32F103_Pinboard_II
|
161 | # DIRS += $(RTOS_ROOT)/Demo/Common/Minimal
|
162 | DIRS += $(RTOS_ROOT)/Demo/Common/include
|
163 | # DIRS += $(RTOS_ROOT)/Demo/Common/ethernet/uIP/uip-1.0/uip
|
164 | # DIRS += $(RTOS_ROOT)/Source/portable/GCC/ARM_CM3_MPU
|
165 |
|
166 | #STM32F1_DISCOVERY_DRIVER_DIR=../MyARMLib/STM32/STM32F4_discovery
|
167 | DIRS += $(CMSIS_DRIVER_DIR)
|
168 | DIRS += ../STM32F4xx_DSP_StdPeriph_Lib_V1.0.0/Libraries/CMSIS/Include
|
169 | # DIRS += ../MyARMLib/STM32/STM32F10x/include
|
170 | # DIRS += ../MyARMLib/STM32/STM32F10x_StdPeriph_Driver/inc
|
171 | # DIRS += ../MyARMLib/STM32/STM32F10x_StdPeriph_Driver/src
|
172 | DIRS += ../STM32F4xx_DSP_StdPeriph_Lib_V1.0.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include
|
173 | # DIRS += ../STM32F4xx_DSP_StdPeriph_Lib_V1.0.0/Libraries/STM32/STM32F4_discovery
|
174 | DIRS += ../stm32f4-discovery/Utilities/STM32F4-Discovery
|
175 | DIRS += ../STM32F4xx_DSP_StdPeriph_Lib_V1.0.0/Libraries/STM32F4xx_StdPeriph_Driver/src
|
176 | DIRS += ../STM32F4xx_DSP_StdPeriph_Lib_V1.0.0/Libraries/STM32F4xx_StdPeriph_Driver/inc
|
177 |
|
178 |
|
179 | # DIRS += ../MyARMLib/FreeRTOS
|
180 |
|
181 | # includes
|
182 | INCS := $(patsubst %, -I "%", $(DIRS))
|
183 |
|
184 | # individual source files
|
185 | SRCS :=
|
186 |
|
187 | #calc obj files list
|
188 | OBJS := $(SRCS)
|
189 | OBJS += $(wildcard $(addsuffix /*.cpp, $(DIRS)))
|
190 | OBJS += $(wildcard $(addsuffix /*.c, $(DIRS)))
|
191 | OBJS += $(wildcard $(addsuffix /*.S, $(DIRS)))
|
192 |
|
193 | #OBJS += $(RTOS_ROOT)/Source/tasks.c
|
194 | #/port.c
|
195 |
|
196 | # OBJS += ../MyARMLib/STM32/STM32F10x_StdPeriph_Driver/src/stm32f10x_gpio.c
|
197 | # OBJS += ../MyARMLib/STM32/STM32F10x_StdPeriph_Driver/src/stm32f10x_rcc.c
|
198 | # OBJS += $(RTOS_ROOT)/Source/tasks.c
|
199 | # OBJS += $(RTOS_ROOT)/Source/list.c
|
200 | # OBJS += $(RTOS_ROOT)/Source/timers.c
|
201 | # OBJS += $(RTOS_ROOT)/Source/queue.c
|
202 | # OBJS += $(RTOS_ROOT)/Source/tasks.c
|
203 | # OBJS += $(RTOS_ROOT)/Source/portable/GCC/ARM_CM3/port.c
|
204 | # OBJS += $(RTOS_ROOT)/Source/portable/MemMang/heap_2.c
|
205 | OBJS := $(notdir $(OBJS))
|
206 | OBJS := $(OBJS:.cpp=.o)
|
207 | OBJS := $(OBJS:.c=.o)
|
208 | OBJS := $(OBJS:.S=.o)
|
209 | OBJS := $(patsubst %, $(OBJDIR)/%, $(OBJS))
|
210 |
|
211 | #files to archive
|
212 | ARCFILES = \
|
213 | $(SRCDIR) \
|
214 | $(PRJDIR) \
|
215 | $(SCMDIR) \
|
216 | $(BASE)/makefile \
|
217 | $(BASE)/.cproject \
|
218 | $(BASE)/.project
|
219 |
|
220 | # flags
|
221 | FLAGS = -mcpu=$(MCU) -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp
|
222 | FLAGS += $(INCS)
|
223 | FLAGS += -MD
|
224 | #-DGCC_ARMCM3
|
225 | FLAGS += $(DEFS) -DUSE_STDPERIPH_DRIVER
|
226 | FLAGS += -Wa,-adhlns=$(addprefix $(LSTDIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
|
227 |
|
228 | AFLAGS = $(FLAGS)
|
229 |
|
230 | CFLAGS = $(FLAGS)
|
231 | CFLAGS += $(OPTIMIZE)
|
232 | CFLAGS += -std=gnu99
|
233 | CFLAGS += -D GCC_ARMCM3
|
234 | CFLAGS += -g
|
235 | CFLAGS += -ffunction-sections -fdata-sections
|
236 | # CFLAGS += -Wall -Wextra
|
237 | # CFLAGS += -Wimplicit -Wcast-align -Wpointer-arith -Wredundant-decls
|
238 | # CFLAGS += -Wshadow -Wcast-qual -Wcast-align -Wnested-externs -pedantic
|
239 |
|
240 | CXXFLAGS = $(FLAGS)
|
241 | CXXFLAGS += $(OPTIMIZE)
|
242 | CXXFLAGS += -g
|
243 | CXXFLAGS += -fno-exceptions -fno-rtti
|
244 | CXXFLAGS += -ffunction-sections -fdata-sections
|
245 | CXXFLAGS += -fno-threadsafe-statics
|
246 | CXXFLAGS += -funsigned-bitfields -fshort-enums
|
247 | CXXFLAGS += -Wall -Wextra
|
248 | CXXFLAGS += -Winline
|
249 | CXXFLAGS += -Wpointer-arith -Wredundant-decls
|
250 | CXXFLAGS += -Wshadow -Wcast-qual -Wcast-align -pedantic
|
251 |
|
252 | LD_FLAGS = -mcpu=$(MCU)
|
253 | LD_FLAGS += -mthumb
|
254 | LD_FLAGS += -nostartfiles
|
255 | LD_FLAGS += -Wl,-Map="$(MAP)",--cref
|
256 | LD_FLAGS += -Wl,--gc-sections
|
257 | LD_FLAGS += -T$(LD_SCRIPT)
|
258 |
|
259 | ifeq ($(USE_LTO),YES)
|
260 | CFLAGS += -flto
|
261 | CXXFLAGS += -flto
|
262 | LD_FLAGS += -flto $(OPTIMIZE)
|
263 | endif
|
264 |
|
265 | #openocd command-line
|
266 |
|
267 | # debug level (d0..d3)
|
268 | oocd_params = -d3
|
269 | # interface and board/target settings (using the OOCD target-library here)
|
270 | # oocd_params += -c "fast enable"
|
271 | oocd_params += -f interface/arm-usb-ocd.cfg
|
272 | oocd_params += -f board/stm32f10x_128k_eval.cfg
|
273 | oocd_params += -c init -c targets
|
274 | oocd_params_program = $(oocd_params)
|
275 | # commands to prepare flash-write
|
276 | oocd_params_program += -c "halt"
|
277 | # flash-write and -verify
|
278 | oocd_params_program += -c "flash write_image erase $(ELF)"
|
279 | oocd_params_program += -c "verify_image $(ELF)"
|
280 | # reset target
|
281 | oocd_params_program += -c "reset run"
|
282 | # terminate OOCD after programming
|
283 | oocd_params_program += -c shutdown
|
284 |
|
285 | oocd_params_reset = $(oocd_params)
|
286 | oocd_params_reset += -c "reset run"
|
287 | oocd_params_reset += -c shutdown
|
288 |
|
289 | .SILENT :
|
290 |
|
291 | .PHONY: all start dirs build clean program reset archive
|
292 |
|
293 | ############# targets
|
294 |
|
295 | all : start dirs $(AXF) $(ELF) $(HEX) $(BIN) $(LSS) $(OK)
|
296 |
|
297 | build: clean all
|
298 |
|
299 | start:
|
300 | @echo --- building $(TARGET) $(OBJS)
|
301 |
|
302 | $(LSS): $(ELF) makefile
|
303 | @echo --- making asm-lst...
|
304 | # @$(OBJDUMP) -dStC $(ELF) > $(LSS)
|
305 | @$(OBJDUMP) -dC $(ELF) > $(LSS)
|
306 |
|
307 | $(OK): $(ELF)
|
308 | @$(SIZE) $(ELF)
|
309 | @echo "Errors: none"
|
310 |
|
311 | $(AXF): $(OBJS) $(STARTUP).o makefile
|
312 | @echo --- linking... axf
|
313 | $(LD) $(OBJS) $(STARTUP).o $(LIBS) $(LD_FLAGS) -o "$(AXF)"
|
314 |
|
315 | $(ELF): $(OBJS) makefile
|
316 | @echo --- linking...
|
317 | $(LD) $(OBJS) $(LIBS) $(LD_FLAGS) -o "$(ELF)"
|
318 |
|
319 | $(HEX): $(ELF)
|
320 | @echo --- make hex...
|
321 | @$(OBJCOPY) -O ihex $(ELF) $(HEX)
|
322 |
|
323 | $(BIN): $(ELF)
|
324 | @echo --- make binary...
|
325 | @$(OBJCOPY) -O binary $(ELF) $(BIN)
|
326 |
|
327 | program: $(ELF)
|
328 | @echo "Programming with OPENOCD"
|
329 | $(FLASHER) $(oocd_params_program)
|
330 |
|
331 | reset:
|
332 | @echo Resetting device
|
333 | $(FLASHER) $(oocd_params_reset)
|
334 |
|
335 | VPATH := $(DIRS)
|
336 |
|
337 | $(OBJDIR)/%.o: %.cpp makefile
|
338 | @echo --- compiling $<...
|
339 | $(CXX) -c $(CXXFLAGS) -o $@ $<
|
340 |
|
341 | $(OBJDIR)/%.o: %.c makefile
|
342 | @echo --- compiling $<...
|
343 | $(CC) -c $(CFLAGS) -o $@ $<
|
344 |
|
345 | $(OBJDIR)/%.o: %.S makefile
|
346 | @echo --- assembling $<...
|
347 | $(AS) -c $(AFLAGS) -o $@ $<
|
348 |
|
349 | $(OBJDIR)/%.o: %.s makefile
|
350 | @echo --- assembling $<...
|
351 | $(AS) -c $(AFLAGS) -o $@ $<
|
352 |
|
353 |
|
354 | dirs: $(OBJDIR) $(EXEDIR) $(LSTDIR) $(BAKDIR)
|
355 |
|
356 | $(OBJDIR):
|
357 | -@$(MD) $(OBJDIR)
|
358 |
|
359 | $(EXEDIR):
|
360 | -@$(MD) $(EXEDIR)
|
361 |
|
362 | $(LSTDIR):
|
363 | -@$(MD) $(LSTDIR)
|
364 |
|
365 | $(BAKDIR):
|
366 | -@$(MD) $(BAKDIR)
|
367 |
|
368 | clean:
|
369 | -@$(RM) $(OBJDIR)/*.d 2>/dev/null
|
370 | -@$(RM) $(OBJDIR)/*.o 2>/dev/null
|
371 | -@$(RM) $(LSTDIR)/*.lst 2>/dev/null
|
372 | -@$(RM) $(ELF)
|
373 | -@$(RM) $(HEX)
|
374 | -@$(RM) $(LSS)
|
375 | -@$(RM) $(MAP)
|
376 |
|
377 | archive:
|
378 | @echo --- archiving...
|
379 | 7z a $(BAKDIR)/$(TARGET)_`date +%Y-%m-%d,%H-%M-%S` $(ARCFILES)
|
380 | @echo --- done!
|
381 |
|
382 | # dependencies
|
383 | ifeq (,$(findstring build,$(MAKECMDGOALS)))
|
384 | ifeq (,$(findstring clean,$(MAKECMDGOALS)))
|
385 | ifeq (,$(findstring dirs,$(MAKECMDGOALS)))
|
386 | -include $(wildcard $(OBJDIR)/*.d)
|
387 | endif
|
388 | endif
|
389 | endif
|