OP-1156: Added new (stub template) pathFollower Module as well as builkd environment...
[librepilot.git] / flight / targets / boards / simposix / firmware / Makefile
blobd8af95e4a1c5192927935891f987df47b13cac3d
1 #####
3 # TODO: This file should be reworked. It will be done as a part of sim target refactoring.
5 # The OpenPilot Team, http://www.openpilot.org, Copyright (C) 2009.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc.,
20 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #####
23 override ARM_SDK_PREFIX :=
24 override THUMB :=
26 include ../board-info.mk
27 include $(ROOT_DIR)/make/firmware-defs.mk
29 # Set developer code and compile options
30 # Set to YES for debugging
31 DEBUG ?= YES
33 # List of modules to include
34 MODULES = ManualControl Stabilization GPS
35 MODULES += PathPlanner
36 MODULES += PathFollower
37 MODULES += CameraStab
38 MODULES += Telemetry
39 MODULES += Logging
40 MODULES += FirmwareIAP
41 MODULES += StateEstimation
42 #MODULES += Sensors/simulated/Sensors
43 MODULES += Airspeed
44 #MODULES += AltitudeHold # now integrated in Stabilization
45 #MODULES += OveroSync
47 SRC += $(FLIGHTLIB)/notification.c
49 # Paths
50 OPSYSTEM = .
51 BOARDINC = ..
52 OPSYSTEMINC = $(OPSYSTEM)/inc
53 OPUAVTALK = ../../../../uavtalk
54 OPUAVTALKINC = $(OPUAVTALK)/inc
55 OPUAVOBJ = ../../../../uavobjects
56 OPUAVOBJINC = $(OPUAVOBJ)/inc
57 PIOSINC = $(PIOS)/inc
58 OPMODULEDIR = ../../../../modules
59 FLIGHTLIB = ../../../../libraries
60 FLIGHTLIBINC = $(FLIGHTLIB)/inc
61 MATHLIB = $(FLIGHTLIB)/math
62 MATHLIBINC = $(FLIGHTLIB)/math
63 PIOSPOSIX = $(PIOS)/posix
64 PIOSCOMMON = $(PIOS)/posix
65 PIOSCORECOMMON = $(PIOS)/common
66 PIOSCOMMONLIB = $(PIOS)/common/libraries
67 BOOT =
68 BOOTINC =
69 UAVOBJSYNTHDIR = $(OUTDIR)/../uavobject-synthetics/flight
71 # optional component libraries
72 include $(PIOS)/common/libraries/FreeRTOS/library.mk
73 #include $(FLIGHTLIB)/PyMite/pymite.mk
75 # List C source files here. (C dependencies are automatically generated.)
76 # use file-extension c for "c-only"-files
78 ## MODULES
79 SRC += ${foreach MOD, ${MODULES}, ${wildcard ${OPMODULEDIR}/${MOD}/*.c}}
80 SRC += ${OUTDIR}/InitMods.c
81 ## OPENPILOT CORE:
82 SRC += ${OPMODULEDIR}/System/systemmod.c
83 SRC += $(OPSYSTEM)/simposix.c
84 SRC += $(OPSYSTEM)/pios_board.c
85 SRC += $(FLIGHTLIB)/alarms.c
86 SRC += $(OPUAVTALK)/uavtalk.c
87 SRC += $(OPUAVOBJ)/uavobjectmanager.c
88 SRC += $(OPUAVOBJ)/eventdispatcher.c
89 SRC += $(UAVOBJSYNTHDIR)/uavobjectsinit.c
91 SRC += $(FLIGHTLIB)/CoordinateConversions.c
92 SRC += $(FLIGHTLIB)/fifo_buffer.c
93 SRC += $(FLIGHTLIB)/WorldMagModel.c
94 SRC += $(FLIGHTLIB)/insgps13state.c
95 SRC += $(FLIGHTLIB)/paths.c
96 SRC += $(FLIGHTLIB)/plans.c
97 SRC += $(FLIGHTLIB)/sanitycheck.c
99 SRC += $(MATHLIB)/sin_lookup.c
100 SRC += $(MATHLIB)/pid.c
101 SRC += $(MATHLIB)/mathmisc.c
103 SRC += $(PIOSCORECOMMON)/pios_task_monitor.c
104 SRC += $(PIOSCORECOMMON)/pios_dosfs_logfs.c
105 SRC += $(PIOSCORECOMMON)/pios_debuglog.c
106 SRC += $(PIOSCORECOMMON)/pios_callbackscheduler.c
107 SRC += $(PIOSCORECOMMON)/pios_deltatime.c
108 SRC += $(PIOSCORECOMMON)/pios_notify.c
109 SRC += $(PIOSCORECOMMON)/pios_mem.c
111 ## PIOS Hardware
112 include $(PIOS)/posix/library.mk
114 include ./UAVObjects.inc
115 SRC += $(UAVOBJSRC)
117 # List any extra directories to look for include files here.
118 # Each directory must be seperated by a space.
119 EXTRAINCDIRS += $(PIOS)
120 EXTRAINCDIRS += $(PIOSINC)
121 EXTRAINCDIRS += $(BOARDINC)
122 EXTRAINCDIRS += $(OPSYSTEMINC)
123 EXTRAINCDIRS += $(OPUAVTALK)
124 EXTRAINCDIRS += $(OPUAVTALKINC)
125 EXTRAINCDIRS += $(OPUAVOBJ)
126 EXTRAINCDIRS += $(OPUAVOBJINC)
127 EXTRAINCDIRS += $(UAVOBJSYNTHDIR)
128 EXTRAINCDIRS += $(FLIGHTLIBINC)
129 EXTRAINCDIRS += $(MATHLIBINC)
130 EXTRAINCDIRS += $(PIOSCOMMON)
131 EXTRAINCDIRS += $(CMSISDIR)
132 EXTRAINCDIRS += $(OPUAVSYNTHDIR)
133 EXTRAINCDIRS += $(BOOTINC)
135 EXTRAINCDIRS += ${foreach MOD, ${MODULES}, $(OPMODULEDIR)/${MOD}/inc} ${OPMODULEDIR}/System/inc
137 BLONLY_CDEFS += -DBOARD_TYPE=$(BOARD_TYPE)
138 BLONLY_CDEFS += -DBOARD_REVISION=$(BOARD_REVISION)
139 BLONLY_CDEFS += -DHW_TYPE=$(HW_TYPE)
140 BLONLY_CDEFS += -DBOOTLOADER_VERSION=$(BOOTLOADER_VERSION)
141 BLONLY_CDEFS += -DFW_BANK_BASE=$(FW_BANK_BASE)
142 BLONLY_CDEFS += -DFW_BANK_SIZE=$(FW_BANK_SIZE)
143 BLONLY_CDEFS += -DFW_DESC_SIZE=$(FW_DESC_SIZE)
145 # Since we are simulating all this firmware the code needs to know what the BL would
146 # normally contain
147 CFLAGS += $(BLONLY_CDEFS)
149 ifeq ($(DEBUG),YES)
150 CFLAGS += -O0
151 CFLAGS += -DGENERAL_COV
152 CFLAGS += -finstrument-functions -ffixed-r10
153 else
154 CFLAGS += -Os
155 endif
157 # common architecture-specific flags from the device-specific library makefile
158 CFLAGS += $(ARCHFLAGS)
160 CFLAGS += $(UAVOBJDEFINE)
162 CFLAGS += -DDIAG_STACK
163 CFLAGS += -DDIA_MIXERSTATUS
164 CFLAGS += -DDIAG_RATEDESIRED
165 CFLAGS += -DDIAG_I2C_WDG_STATS
166 CFLAGS += -DDIAG_TASKS
167 # Or all of above:
168 #CFLAGS += -DDIAG_ALL
170 # This is not the best place for these. Really should abstract out
171 # to the board file or something
172 #CFLAGS += -DSTM32F4XX
173 CFLAGS += -DMEM_SIZE=1024000000
175 # Output format. (can be ihex or binary or both)
176 # binary to create a load-image in raw-binary format i.e. for SAM-BA,
177 # ihex to create a load-image in Intel hex format
178 #LOADFORMAT = ihex
179 #LOADFORMAT = binary
180 LOADFORMAT = both
182 # Debugging format.
183 DEBUGF = dwarf-2
185 # Place project-specific -D (define) and/or
186 # -U options for C here.
187 CDEFS += -DHSE_VALUE=$(OSCILLATOR_FREQ)
188 CDEFS += -DSYSCLK_FREQ=$(SYSCLK_FREQ)
189 CDEFS += -DUSE_STDPERIPH_DRIVER
190 CDEFS += -DUSE_$(BOARD)
192 # Place project-specific -D and/or -U options for
193 # Assembler with preprocessor here.
194 #ADEFS = -DUSE_IRQ_ASM_WRAPPER
195 ADEFS = -D__ASSEMBLY__
197 # Compiler flag to set the C Standard level.
198 # c89 - "ANSI" C
199 # gnu89 - c89 plus GCC extensions
200 # c99 - ISO C99 standard (not yet fully implemented)
201 # gnu99 - c99 plus GCC extensions
202 CSTANDARD = -std=gnu99
204 #-----
206 # Compiler flags.
208 # -g*: generate debugging information
209 # -O*: optimization level
210 # -f...: tuning, see GCC manual and avr-libc documentation
211 # -Wall...: warning level
212 # -Wa,...: tell GCC to pass this to the assembler.
213 # -adhlns...: create assembler listing
215 # Flags for C and C++ (arm-elf-gcc/arm-elf-g++)
217 CFLAGS += -g$(DEBUGF)
219 CFLAGS += -ffast-math
221 #CFLAGS += -mcpu=$(MCU)
222 CFLAGS += $(CDEFS)
223 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I.
225 #CFLAGS += -mapcs-frame
226 CFLAGS += -fomit-frame-pointer
227 ifeq ($(CODE_SOURCERY), YES)
228 CFLAGS += -fpromote-loop-indices
229 endif
231 CFLAGS += -Wall
232 #CFLAGS += -Werror
233 CFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
234 # Compiler flags to generate dependency files:
235 CFLAGS += -MD -MP -MF $(OUTDIR)/dep/$(@F).d
237 # flags only for C
238 #CONLYFLAGS += -Wnested-externs
239 CONLYFLAGS += $(CSTANDARD)
241 # Assembler flags.
242 # -Wa,...: tell GCC to pass this to the assembler.
243 # -ahlns: create listing
244 ASFLAGS = $(ARCHFLAGS) -I. -x assembler-with-cpp
245 ASFLAGS += $(ADEFS)
246 ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
247 ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
249 MATH_LIB = -lm
251 # Linker flags.
252 # -Wl,...: tell GCC to pass this to linker.
253 # -Map: create map file
254 # --cref: add cross reference to map file
255 #LDFLAGS = -nostartfiles -Wl,-Map=$(OUTDIR)/$(TARGET).map,--cref,--gc-sections
256 LDFLAGS = -Wl,-Map=$(OUTDIR)/$(TARGET).map,--cref,--gc-sections
257 LDFLAGS += $(patsubst %,-L%,$(EXTRA_LIBDIRS))
258 LDFLAGS += -lc
259 LDFLAGS += $(patsubst %,-l%,$(EXTRA_LIBS))
260 LDFLAGS += $(MATH_LIB)
261 LDFLAGS += -lc -lgcc -lpthread -lrt
263 #Linker scripts
264 LDFLAGS += $(addprefix -T,$(LINKER_SCRIPTS_APP))
267 # Define programs and commands.
268 REMOVE = $(RM) -f
270 # List of all source files.
271 ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC)
272 # List of all source files without directory and file-extension.
273 ALLSRCBASE = $(notdir $(basename $(ALLSRC)))
275 # Define all object files.
276 ALLOBJ = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE) uavobjectsinit.o.firmware_info ))
278 # Define all listing files (used for make clean).
279 LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE)))
280 # Define all depedency-files (used for make clean).
281 DEPFILES = $(addprefix $(OUTDIR)/dep/, $(addsuffix .o.d, $(ALLSRCBASE)))
283 # Default target.
284 all: gccversion build
286 ifeq ($(LOADFORMAT),ihex)
287 build: elf hex lss sym
288 else
289 ifeq ($(LOADFORMAT),binary)
290 build: elf bin lss sym
291 else
292 ifeq ($(LOADFORMAT),both)
293 build: elf hex bin lss sym
294 else
295 $(error "$(MSG_FORMATERROR) $(FORMAT)")
296 endif
297 endif
298 endif
301 # Link: create ELF output file from object files.
302 $(eval $(call LINK_TEMPLATE, $(OUTDIR)/$(TARGET).elf, $(ALLOBJ)))
304 # Assemble: create object files from assembler source files.
305 $(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src))))
307 # Assemble: create object files from assembler source files. ARM-only
308 $(foreach src, $(ASRCARM), $(eval $(call ASSEMBLE_ARM_TEMPLATE, $(src))))
310 # Compile: create object files from C source files.
311 $(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src))))
313 # Compile: create object files from C source files. ARM-only
314 $(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src))))
316 # Compile: create object files from C++ source files.
317 $(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src))))
319 # Compile: create object files from C++ source files. ARM-only
320 $(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src))))
322 # Compile: create assembler files from C source files. ARM/Thumb
323 $(eval $(call PARTIAL_COMPILE_TEMPLATE, SRC))
325 # Compile: create assembler files from C source files. ARM only
326 $(eval $(call PARTIAL_COMPILE_ARM_TEMPLATE, SRCARM))
328 $(OUTDIR)/$(TARGET).bin.o: $(OUTDIR)/$(TARGET).bin
330 $(eval $(call OPFW_TEMPLATE,$(OUTDIR)/$(TARGET).bin,$(BOARD_TYPE),$(BOARD_REVISION)))
332 $(eval $(call OPFW_TEMPLATE,$(OUTDIR)/uavobjectsinit.o,$(BOARD_TYPE),$(BOARD_REVISION)))
334 # Add jtag targets (program and wipe)
335 $(eval $(call JTAG_TEMPLATE,$(OUTDIR)/$(TARGET).bin,$(FW_BANK_BASE),$(FW_BANK_SIZE),$(OPENOCD_JTAG_CONFIG),$(OPENOCD_CONFIG)))
337 .PHONY: elf lss sym hex bin bino opfw
338 elf: $(OUTDIR)/$(TARGET).elf
339 lss: $(OUTDIR)/$(TARGET).lss
340 sym: $(OUTDIR)/$(TARGET).sym
341 hex: $(OUTDIR)/$(TARGET).hex
342 bin: $(OUTDIR)/$(TARGET).bin
343 bino: $(OUTDIR)/$(TARGET).bin.o
344 opfw: $(OUTDIR)/$(TARGET).opfw
346 # Display sizes of sections.
347 $(eval $(call SIZE_TEMPLATE, $(OUTDIR)/$(TARGET).elf))
349 # Install: install binary file with prefix/suffix into install directory
350 install: $(OUTDIR)/$(TARGET).opfw
351 ifneq ($(INSTALL_DIR),)
352 @echo $(MSG_INSTALLING) $(call toprel, $<)
353 $(V1) mkdir -p $(INSTALL_DIR)
354 $(V1) $(INSTALL) $< $(INSTALL_DIR)/$(INSTALL_PFX)$(TARGET)$(INSTALL_SFX).opfw
355 else
356 $(error INSTALL_DIR must be specified for $@)
357 endif
359 # Target: clean project.
360 clean: clean_list
362 clean_list :
363 @echo $(MSG_CLEANING)
364 $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).map
365 $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).elf
366 $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).hex
367 $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).bin
368 $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).sym
369 $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).lss
370 $(V1) $(REMOVE) $(OUTDIR)/$(TARGET).bin.o
371 $(V1) $(REMOVE) $(ALLOBJ)
372 $(V1) $(REMOVE) $(LSTFILES)
373 $(V1) $(REMOVE) $(DEPFILES)
374 $(V1) $(REMOVE) $(SRC:.c=.s)
375 $(V1) $(REMOVE) $(SRCARM:.c=.s)
376 $(V1) $(REMOVE) $(CPPSRC:.cpp=.s)
377 $(V1) $(REMOVE) $(CPPSRCARM:.cpp=.s)
379 # Create output files directory
380 # all known MS Windows OS define the ComSpec environment variable
381 ifdef ComSpec
382 $(shell md $(subst /,\\,$(OUTDIR)) 2>NUL)
383 else
384 $(shell mkdir -p $(OUTDIR) 2>/dev/null)
385 endif
387 # Include the dependency files.
388 ifdef ComSpec
389 -include $(shell md $(subst /,\\,$(OUTDIR))\dep 2>NUL) $(wildcard $(OUTDIR)/dep/*)
390 else
391 -include $(shell mkdir $(OUTDIR) 2>/dev/null) $(shell mkdir $(OUTDIR)/dep 2>/dev/null) $(wildcard $(OUTDIR)/dep/*)
392 endif
394 #create compile-time module auto-initialisation
395 MODNAMES = ${notdir $(subst /revolution,,$(MODULES))}
397 # Generate intermediate code
398 gencode: ${OUTDIR}/InitMods.c ${OUTDIR}/pmlib_img.c ${OUTDIR}/pmlib_nat.c ${OUTDIR}/pmlibusr_img.c ${OUTDIR}/pmlibusr_nat.c ${OUTDIR}/pmfeatures.h
400 # Generate code for module initialization
401 ${OUTDIR}/InitMods.c: Makefile
402 $(V1) $(ECHO) $(MSG_MODINIT $(call toprel, $@))
403 $(V1) $(ECHO) $(QUOTE)// Autogenerated file$(QUOTE) > ${OUTDIR}/InitMods.c
404 $(V1) $(ECHO) $(QUOTE)${foreach MOD, ${MODNAMES}, extern unsigned int ${MOD}Initialize(void);}$(QUOTE) >> ${OUTDIR}/InitMods.c
405 $(V1) $(ECHO) $(QUOTE)${foreach MOD, ${MODNAMES}, extern unsigned int ${MOD}Start(void);}$(QUOTE) >> ${OUTDIR}/InitMods.c
406 $(V1) $(ECHO) $(QUOTE)void InitModules() {$(QUOTE) >> ${OUTDIR}/InitMods.c
407 $(V1) $(ECHO) $(QUOTE)${foreach MOD, ${MODNAMES}, ${MOD}Initialize();}$(QUOTE) >> ${OUTDIR}/InitMods.c
408 $(V1) $(ECHO) $(QUOTE)}$(QUOTE) >> ${OUTDIR}/InitMods.c
409 $(V1) $(ECHO) $(QUOTE)void StartModules() {$(QUOTE) >> ${OUTDIR}/InitMods.c
410 $(V1) $(ECHO) $(QUOTE)${foreach MOD, ${MODNAMES}, ${MOD}Start();}$(QUOTE) >> ${OUTDIR}/InitMods.c
411 $(V1) $(ECHO) $(QUOTE)}$(QUOTE) >> ${OUTDIR}/InitMods.c
413 # Listing of phony targets.
414 .PHONY : all build clean clean_list install