Merge branch 'master' of ../betaflight into betaflight-master
[betaflight.git] / Makefile
blob77b58d09203feb7dbf2628cac0722a6c4b4feca0
1 ###############################################################################
2 # "THE BEER-WARE LICENSE" (Revision 42):
3 # <msmith@FreeBSD.ORG> wrote this file. As long as you retain this notice you
4 # can do whatever you want with this stuff. If we meet some day, and you think
5 # this stuff is worth it, you can buy me a beer in return
6 ###############################################################################
8 # Makefile for building the cleanflight firmware.
10 # Invoke this with 'make help' to see the list of supported targets.
12 ###############################################################################
15 # Things that the user might override on the commandline
18 # The target to build, see VALID_TARGETS below
19 TARGET ?= SPRACINGF3NEO
21 # Compile-time options
22 OPTIONS ?=
24 # compile for OpenPilot BootLoader support
25 OPBL ?= no
27 # Debugger optons, must be empty or GDB
28 DEBUG ?=
30 # Insert the debugging hardfault debugger
31 # releases should not be built with this flag as it does not disable pwm output
32 DEBUG_HARDFAULTS ?=
34 # Serial port/Device for flashing
35 SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyUSB*) no-port-found)
37 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
38 FLASH_SIZE ?=
41 ###############################################################################
42 # Things that need to be maintained as the source changes
45 FORKNAME = cleanflight
47 # Working directories
48 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
49 SRC_DIR = $(ROOT)/src/main
50 OBJECT_DIR = $(ROOT)/obj/main
51 BIN_DIR = $(ROOT)/obj
52 CMSIS_DIR = $(ROOT)/lib/main/CMSIS
53 INCLUDE_DIRS = $(SRC_DIR) \
54 $(ROOT)/src/main/target
55 LINKER_DIR = $(ROOT)/src/main/target/link
57 ## V : Set verbosity level based on the V= parameter
58 ## V=0 Low
59 ## V=1 High
60 include $(ROOT)/make/build_verbosity.mk
62 # Build tools, so we all share the same versions
63 # import macros common to all supported build systems
64 include $(ROOT)/make/system-id.mk
66 # developer preferences, edit these at will, they'll be gitignored
67 -include $(ROOT)/make/local.mk
69 # configure some directories that are relative to wherever ROOT_DIR is located
70 ifndef TOOLS_DIR
71 TOOLS_DIR := $(ROOT)/tools
72 endif
73 BUILD_DIR := $(ROOT)/build
74 DL_DIR := $(ROOT)/downloads
76 export RM := rm
78 # import macros that are OS specific
79 include $(ROOT)/make/$(OSFAMILY).mk
81 # include the tools makefile
82 include $(ROOT)/make/tools.mk
84 # default xtal value for F4 targets
85 HSE_VALUE ?= 8000000
87 # used for turning on features like VCP and SDCARD
88 FEATURES =
90 OFFICIAL_TARGETS = ALIENFLIGHTF3 ALIENFLIGHTF4 ANYFCF7 BETAFLIGHTF3 BLUEJAYF4 CC3D FURYF4 NAZE REVO SIRINFPV SPARKY SPRACINGF3 SPRACINGF3EVO SPRACINGF3NEO SPRACINGF3MINI STM32F3DISCOVERY SPRACINGF4EVO
91 ALT_TARGETS = $(sort $(filter-out target, $(basename $(notdir $(wildcard $(ROOT)/src/main/target/*/*.mk)))))
92 OPBL_TARGETS = $(filter %_OPBL, $(ALT_TARGETS))
93 OSD_SLAVE_TARGETS = SPRACINGF3OSD
95 VALID_TARGETS = $(dir $(wildcard $(ROOT)/src/main/target/*/target.mk))
96 VALID_TARGETS := $(subst /,, $(subst ./src/main/target/,, $(VALID_TARGETS)))
97 VALID_TARGETS := $(VALID_TARGETS) $(ALT_TARGETS)
98 VALID_TARGETS := $(sort $(VALID_TARGETS))
100 GROUP_1_TARGETS := \
101 AFROMINI \
102 AIORACERF3 \
103 AIR32 \
104 AIRBOTF4 \
105 AIRBOTF4SD \
106 AIRHEROF3 \
107 ALIENFLIGHTF1 \
108 ALIENFLIGHTF3 \
109 ALIENFLIGHTF4 \
110 ALIENFLIGHTNGF7 \
111 ANYFCF7 \
112 BEEBRAIN \
113 BEEROTORF4 \
114 BETAFLIGHTF3 \
115 BLUEJAYF4 \
116 CC3D \
117 CC3D_OPBL \
119 GROUP_2_TARGETS := \
120 CHEBUZZF3 \
121 CJMCU \
122 CL_RACINGF4 \
123 COLIBRI \
124 COLIBRI_OPBL \
125 COLIBRI_RACE \
126 DOGE \
127 ELLE0 \
128 F4BY \
129 FISHDRONEF4 \
130 FLIP32F3OSD \
131 FURYF3 \
132 FURYF4 \
133 FURYF7 \
134 IMPULSERCF3 \
135 IRCFUSIONF3 \
136 ISHAPEDF3 \
138 GROUP_3_TARGETS := \
139 KAKUTEF4 \
140 KISSCC \
141 KIWIF4 \
142 LUX_RACE \
143 LUXV2_RACE \
144 MICROSCISKY \
145 MOTOLAB \
146 MULTIFLITEPICO \
147 NAZE \
148 NERO \
149 NUCLEOF7 \
150 OMNIBUS \
151 OMNIBUSF4 \
152 OMNIBUSF4SD \
153 PIKOBLX \
154 PLUMF4 \
155 PODIUMF4 \
157 GROUP_4_TARGETS := \
158 RCEXPLORERF3 \
159 REVO \
160 REVO_OPBL \
161 REVOLT \
162 REVONANO \
163 RMDO \
164 SINGULARITY \
165 SIRINFPV \
166 SOULF4 \
167 SPARKY \
168 SPARKY2 \
169 SPRACINGF3 \
170 SPRACINGF3EVO \
171 SPRACINGF3MINI \
172 SPRACINGF3NEO \
173 SPRACINGF3OSD \
174 SPRACINGF4EVO \
175 STM32F3DISCOVERY \
176 TINYBEEF3 \
178 GROUP_OTHER_TARGETS := $(filter-out $(GROUP_1_TARGETS) $(GROUP_2_TARGETS) $(GROUP_3_TARGETS) $(GROUP_4_TARGETS), $(VALID_TARGETS))
181 ifeq ($(filter $(TARGET),$(ALT_TARGETS)), $(TARGET))
182 BASE_TARGET := $(firstword $(subst /,, $(subst ./src/main/target/,, $(dir $(wildcard $(ROOT)/src/main/target/*/$(TARGET).mk)))))
183 -include $(ROOT)/src/main/target/$(BASE_TARGET)/$(TARGET).mk
184 else
185 BASE_TARGET := $(TARGET)
186 endif
188 ifeq ($(filter $(TARGET),$(OPBL_TARGETS)), $(TARGET))
189 OPBL = yes
190 endif
192 ifeq ($(filter $(TARGET),$(OSD_SLAVE_TARGETS)), $(TARGET))
193 # build an OSD SLAVE
194 OSD_SLAVE = yes
195 else
196 # build an FC
197 FC = yes
198 endif
201 # silently ignore if the file is not present. Allows for target specific.
202 -include $(ROOT)/src/main/target/$(BASE_TARGET)/target.mk
204 F4_TARGETS = $(F405_TARGETS) $(F411_TARGETS) $(F446_TARGETS)
205 F7_TARGETS = $(F7X2RE_TARGETS) $(F7X5XE_TARGETS) $(F7X5XG_TARGETS) $(F7X5XI_TARGETS) $(F7X6XG_TARGETS)
207 ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
208 $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS). Have you prepared a valid target.mk?)
209 endif
211 ifeq ($(filter $(TARGET),$(F1_TARGETS) $(F3_TARGETS) $(F4_TARGETS) $(F7_TARGETS) $(SITL_TARGETS)),)
212 $(error Target '$(TARGET)' has not specified a valid STM group, must be one of F1, F3, F405, F411 or F7x5. Have you prepared a valid target.mk?)
213 endif
215 128K_TARGETS = $(F1_TARGETS)
216 256K_TARGETS = $(F3_TARGETS)
217 512K_TARGETS = $(F411_TARGETS) $(F446_TARGETS) $(F7X2RE_TARGETS) $(F7X5XE_TARGETS)
218 1024K_TARGETS = $(F405_TARGETS) $(F7X5XG_TARGETS) $(F7X6XG_TARGETS)
219 2048K_TARGETS = $(F7X5XI_TARGETS) $(SITL_TARGETS)
221 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
222 ifeq ($(FLASH_SIZE),)
223 ifeq ($(TARGET),$(filter $(TARGET),$(2048K_TARGETS)))
224 FLASH_SIZE = 2048
225 else ifeq ($(TARGET),$(filter $(TARGET),$(1024K_TARGETS)))
226 FLASH_SIZE = 1024
227 else ifeq ($(TARGET),$(filter $(TARGET),$(512K_TARGETS)))
228 FLASH_SIZE = 512
229 else ifeq ($(TARGET),$(filter $(TARGET),$(256K_TARGETS)))
230 FLASH_SIZE = 256
231 else ifeq ($(TARGET),$(filter $(TARGET),$(128K_TARGETS)))
232 FLASH_SIZE = 128
233 else
234 $(error FLASH_SIZE not configured for target $(TARGET))
235 endif
236 endif
238 # note that there is no hardfault debugging startup file assembly handler for other platforms
239 ifeq ($(DEBUG_HARDFAULTS),F3)
240 CFLAGS += -DDEBUG_HARDFAULTS
241 STM32F30x_COMMON_SRC = startup_stm32f3_debug_hardfault_handler.S
242 else
243 STM32F30x_COMMON_SRC = startup_stm32f30x_md_gcc.S
244 endif
246 ifeq ($(DEBUG_HARDFAULTS),F7)
247 CFLAGS += -DDEBUG_HARDFAULTS
248 endif
250 REVISION := $(shell git log -1 --format="%h")
252 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
253 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
254 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
256 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
258 # Search path for sources
259 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
260 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
261 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
262 FATFS_DIR = $(ROOT)/lib/main/FatFS
263 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
265 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
267 ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
268 # F3 TARGETS
270 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver
271 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
272 EXCLUDES = stm32f30x_crc.c \
273 stm32f30x_can.c
274 STARTUP_SRC = startup_stm32f30x_md_gcc.S
276 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
277 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
279 VPATH := $(VPATH):$(CMSIS_DIR)/CM1/CoreSupport:$(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
280 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM1/CoreSupport/*.c \
281 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x/*.c))
283 INCLUDE_DIRS := $(INCLUDE_DIRS) \
284 $(STDPERIPH_DIR)/inc \
285 $(CMSIS_DIR)/CM1/CoreSupport \
286 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
288 ifneq ($(filter VCP, $(FEATURES)),)
289 INCLUDE_DIRS := $(INCLUDE_DIRS) \
290 $(USBFS_DIR)/inc \
291 $(ROOT)/src/main/vcp
293 VPATH := $(VPATH):$(USBFS_DIR)/src
295 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC)\
296 $(USBPERIPH_SRC)
297 endif
299 ifneq ($(filter SDCARD, $(FEATURES)),)
300 INCLUDE_DIRS := $(INCLUDE_DIRS) \
301 $(FATFS_DIR) \
303 VPATH := $(VPATH):$(FATFS_DIR)
304 endif
306 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k.ld
308 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
309 DEVICE_FLAGS = -DSTM32F303xC -DSTM32F303
310 # End F3 targets
312 # Start F4 targets
313 else ifeq ($(TARGET),$(filter $(TARGET), $(F4_TARGETS)))
315 #STDPERIPH
316 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F4xx_StdPeriph_Driver
317 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
318 EXCLUDES = stm32f4xx_crc.c \
319 stm32f4xx_can.c \
320 stm32f4xx_fmc.c \
321 stm32f4xx_sai.c \
322 stm32f4xx_cec.c \
323 stm32f4xx_dsi.c \
324 stm32f4xx_flash_ramfunc.c \
325 stm32f4xx_fmpi2c.c \
326 stm32f4xx_lptim.c \
327 stm32f4xx_qspi.c \
328 stm32f4xx_spdifrx.c \
329 stm32f4xx_cryp.c \
330 stm32f4xx_cryp_aes.c \
331 stm32f4xx_hash_md5.c \
332 stm32f4xx_cryp_des.c \
333 stm32f4xx_rtc.c \
334 stm32f4xx_hash.c \
335 stm32f4xx_dbgmcu.c \
336 stm32f4xx_cryp_tdes.c \
337 stm32f4xx_hash_sha1.c
339 ifeq ($(TARGET),$(filter $(TARGET), $(F411_TARGETS)))
340 EXCLUDES += stm32f4xx_fsmc.c
341 endif
343 ifeq ($(TARGET),$(filter $(TARGET), $(F446_TARGETS)))
344 EXCLUDES += stm32f4xx_fsmc.c
345 endif
347 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
349 #USB
350 USBCORE_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Core
351 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/src/*.c))
352 USBOTG_DIR = $(ROOT)/lib/main/STM32_USB_OTG_Driver
353 USBOTG_SRC = $(notdir $(wildcard $(USBOTG_DIR)/src/*.c))
354 EXCLUDES = usb_bsp_template.c \
355 usb_conf_template.c \
356 usb_hcd_int.c \
357 usb_hcd.c \
358 usb_otg.c
360 USBOTG_SRC := $(filter-out ${EXCLUDES}, $(USBOTG_SRC))
361 USBCDC_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Class/cdc
362 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/src/*.c))
363 EXCLUDES = usbd_cdc_if_template.c
364 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
365 VPATH := $(VPATH):$(USBOTG_DIR)/src:$(USBCORE_DIR)/src:$(USBCDC_DIR)/src
367 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
368 $(USBOTG_SRC) \
369 $(USBCORE_SRC) \
370 $(USBCDC_SRC)
372 #CMSIS
373 VPATH := $(VPATH):$(CMSIS_DIR)/CM4/CoreSupport:$(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx
374 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM4/CoreSupport/*.c \
375 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx/*.c))
376 INCLUDE_DIRS := $(INCLUDE_DIRS) \
377 $(STDPERIPH_DIR)/inc \
378 $(USBOTG_DIR)/inc \
379 $(USBCORE_DIR)/inc \
380 $(USBCDC_DIR)/inc \
381 $(USBFS_DIR)/inc \
382 $(CMSIS_DIR)/CM4/CoreSupport \
383 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx \
384 $(ROOT)/src/main/vcpf4
386 ifneq ($(filter SDCARD,$(FEATURES)),)
387 INCLUDE_DIRS := $(INCLUDE_DIRS) \
388 $(FATFS_DIR)
389 VPATH := $(VPATH):$(FATFS_DIR)
390 endif
392 #Flags
393 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
395 ifeq ($(TARGET),$(filter $(TARGET),$(F411_TARGETS)))
396 DEVICE_FLAGS = -DSTM32F411xE
397 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411.ld
398 STARTUP_SRC = startup_stm32f411xe.s
399 else ifeq ($(TARGET),$(filter $(TARGET),$(F405_TARGETS)))
400 DEVICE_FLAGS = -DSTM32F40_41xxx
401 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405.ld
402 STARTUP_SRC = startup_stm32f40xx.s
403 else ifeq ($(TARGET),$(filter $(TARGET),$(F446_TARGETS)))
404 DEVICE_FLAGS = -DSTM32F446xx
405 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f446.ld
406 STARTUP_SRC = startup_stm32f446xx.s
407 else
408 $(error Unknown MCU for F4 target)
409 endif
410 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE)
412 # End F4 targets
414 # Start F7 targets
415 else ifeq ($(TARGET),$(filter $(TARGET), $(F7_TARGETS)))
417 #STDPERIPH
418 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F7xx_HAL_Driver
419 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/Src/*.c))
420 EXCLUDES = stm32f7xx_hal_can.c \
421 stm32f7xx_hal_cec.c \
422 stm32f7xx_hal_crc.c \
423 stm32f7xx_hal_crc_ex.c \
424 stm32f7xx_hal_cryp.c \
425 stm32f7xx_hal_cryp_ex.c \
426 stm32f7xx_hal_dac.c \
427 stm32f7xx_hal_dac_ex.c \
428 stm32f7xx_hal_dcmi.c \
429 stm32f7xx_hal_dcmi_ex.c \
430 stm32f7xx_hal_dfsdm.c \
431 stm32f7xx_hal_dma2d.c \
432 stm32f7xx_hal_dsi.c \
433 stm32f7xx_hal_eth.c \
434 stm32f7xx_hal_hash.c \
435 stm32f7xx_hal_hash_ex.c \
436 stm32f7xx_hal_hcd.c \
437 stm32f7xx_hal_i2s.c \
438 stm32f7xx_hal_irda.c \
439 stm32f7xx_hal_iwdg.c \
440 stm32f7xx_hal_jpeg.c \
441 stm32f7xx_hal_lptim.c \
442 stm32f7xx_hal_ltdc.c \
443 stm32f7xx_hal_ltdc_ex.c \
444 stm32f7xx_hal_mdios.c \
445 stm32f7xx_hal_mmc.c \
446 stm32f7xx_hal_msp_template.c \
447 stm32f7xx_hal_nand.c \
448 stm32f7xx_hal_nor.c \
449 stm32f7xx_hal_qspi.c \
450 stm32f7xx_hal_rng.c \
451 stm32f7xx_hal_rtc.c \
452 stm32f7xx_hal_rtc_ex.c \
453 stm32f7xx_hal_sai.c \
454 stm32f7xx_hal_sai_ex.c \
455 stm32f7xx_hal_sd.c \
456 stm32f7xx_hal_sdram.c \
457 stm32f7xx_hal_smartcard.c \
458 stm32f7xx_hal_smartcard_ex.c \
459 stm32f7xx_hal_smbus.c \
460 stm32f7xx_hal_spdifrx.c \
461 stm32f7xx_hal_sram.c \
462 stm32f7xx_hal_timebase_rtc_alarm_template.c \
463 stm32f7xx_hal_timebase_rtc_wakeup_template.c \
464 stm32f7xx_hal_timebase_tim_template.c \
465 stm32f7xx_hal_wwdg.c \
466 stm32f7xx_ll_adc.c \
467 stm32f7xx_ll_crc.c \
468 stm32f7xx_ll_dac.c \
469 stm32f7xx_ll_dma.c \
470 stm32f7xx_ll_dma2d.c \
471 stm32f7xx_ll_exti.c \
472 stm32f7xx_ll_fmc.c \
473 stm32f7xx_ll_gpio.c \
474 stm32f7xx_ll_i2c.c \
475 stm32f7xx_ll_lptim.c \
476 stm32f7xx_ll_pwr.c \
477 stm32f7xx_ll_rcc.c \
478 stm32f7xx_ll_rng.c \
479 stm32f7xx_ll_rtc.c \
480 stm32f7xx_ll_sdmmc.c \
481 stm32f7xx_ll_spi.c \
482 stm32f7xx_ll_tim.c \
483 stm32f7xx_ll_usart.c \
484 stm32f7xx_ll_utils.c
486 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
488 #USB
489 USBCORE_DIR = $(ROOT)/lib/main/Middlewares/ST/STM32_USB_Device_Library/Core
490 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/Src/*.c))
491 EXCLUDES = usbd_conf_template.c
492 USBCORE_SRC := $(filter-out ${EXCLUDES}, $(USBCORE_SRC))
494 USBCDC_DIR = $(ROOT)/lib/main/Middlewares/ST/STM32_USB_Device_Library/Class/CDC
495 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/Src/*.c))
496 EXCLUDES = usbd_cdc_if_template.c
497 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
499 VPATH := $(VPATH):$(USBCDC_DIR)/Src:$(USBCORE_DIR)/Src
501 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
502 $(USBCORE_SRC) \
503 $(USBCDC_SRC)
505 #CMSIS
506 VPATH := $(VPATH):$(CMSIS_DIR)/CM7/Include:$(CMSIS_DIR)/CM7/Device/ST/STM32F7xx
507 VPATH := $(VPATH):$(STDPERIPH_DIR)/Src
508 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM7/Include/*.c \
509 $(CMSIS_DIR)/CM7/Device/ST/STM32F7xx/*.c))
510 INCLUDE_DIRS := $(INCLUDE_DIRS) \
511 $(STDPERIPH_DIR)/Inc \
512 $(USBCORE_DIR)/Inc \
513 $(USBCDC_DIR)/Inc \
514 $(CMSIS_DIR)/CM7/Include \
515 $(CMSIS_DIR)/CM7/Device/ST/STM32F7xx/Include \
516 $(ROOT)/src/main/vcp_hal
518 ifneq ($(filter SDCARD,$(FEATURES)),)
519 INCLUDE_DIRS := $(INCLUDE_DIRS) \
520 $(FATFS_DIR)
521 VPATH := $(VPATH):$(FATFS_DIR)
522 endif
524 #Flags
525 ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsingle-precision-constant -Wdouble-promotion
527 ifeq ($(TARGET),$(filter $(TARGET),$(F7X5XG_TARGETS)))
528 DEVICE_FLAGS = -DSTM32F745xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
529 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f745.ld
530 STARTUP_SRC = startup_stm32f745xx.s
531 else ifeq ($(TARGET),$(filter $(TARGET),$(F7X6XG_TARGETS)))
532 DEVICE_FLAGS = -DSTM32F746xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
533 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f746.ld
534 STARTUP_SRC = startup_stm32f746xx.s
535 else ifeq ($(TARGET),$(filter $(TARGET),$(F7X2RE_TARGETS)))
536 DEVICE_FLAGS = -DSTM32F722xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
537 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f722.ld
538 STARTUP_SRC = startup_stm32f722xx.s
539 else
540 $(error Unknown MCU for F7 target)
541 endif
542 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE)
544 TARGET_FLAGS = -D$(TARGET)
546 # End F7 targets
548 # Start SITL targets
549 else ifeq ($(TARGET),$(filter $(TARGET), $(SITL_TARGETS)))
551 INCLUDE_DIRS := $(INCLUDE_DIRS) \
552 $(ROOT)/lib/main/dyad
554 SITL_SRC := $(ROOT)/lib/main/dyad/dyad.c
556 #Flags
557 ARCH_FLAGS =
558 DEVICE_FLAGS =
559 LD_SCRIPT = src/main/target/SITL/parameter_group.ld
560 STARTUP_SRC =
562 TARGET_FLAGS = -D$(TARGET)
564 ARM_SDK_PREFIX =
566 # End SITL targets
568 # Start F1 targets
569 else
571 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
572 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
573 EXCLUDES = stm32f10x_crc.c \
574 stm32f10x_cec.c \
575 stm32f10x_can.c
576 STARTUP_SRC = startup_stm32f10x_md_gcc.S
577 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
579 # Search path and source files for the CMSIS sources
580 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
581 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
582 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
584 INCLUDE_DIRS := $(INCLUDE_DIRS) \
585 $(STDPERIPH_DIR)/inc \
586 $(CMSIS_DIR)/CM3/CoreSupport \
587 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
589 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
591 ifneq ($(filter VCP, $(FEATURES)),)
592 INCLUDE_DIRS := $(INCLUDE_DIRS) \
593 $(USBFS_DIR)/inc \
594 $(ROOT)/src/main/vcp
596 VPATH := $(VPATH):$(USBFS_DIR)/src
598 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
599 $(USBPERIPH_SRC)
601 endif
603 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
604 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
606 ifeq ($(DEVICE_FLAGS),)
607 DEVICE_FLAGS = -DSTM32F10X_MD
608 endif
609 DEVICE_FLAGS += -DSTM32F10X
611 endif
613 # End F1 targets
615 ifneq ($(BASE_TARGET), $(TARGET))
616 TARGET_FLAGS := $(TARGET_FLAGS) -D$(BASE_TARGET)
617 endif
619 ifneq ($(FLASH_SIZE),)
620 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
621 endif
623 ifneq ($(HSE_VALUE),)
624 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
625 endif
627 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
628 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
630 ifeq ($(OPBL),yes)
631 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
632 ifeq ($(TARGET), $(filter $(TARGET),$(F405_TARGETS)))
633 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405_opbl.ld
634 else ifeq ($(TARGET), $(filter $(TARGET),$(F411_TARGETS)))
635 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411_opbl.ld
636 else ifeq ($(TARGET), $(filter $(TARGET),$(F3_TARGETS)))
637 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k_opbl.ld
638 else ifeq ($(TARGET), $(filter $(TARGET),$(F1_TARGETS)))
639 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k_opbl.ld
640 endif
641 .DEFAULT_GOAL := binary
642 else
643 .DEFAULT_GOAL := hex
644 endif
646 INCLUDE_DIRS := $(INCLUDE_DIRS) \
647 $(ROOT)/lib/main/MAVLink
649 INCLUDE_DIRS := $(INCLUDE_DIRS) \
650 $(TARGET_DIR)
652 VPATH := $(VPATH):$(TARGET_DIR)
654 COMMON_SRC = \
655 build/build_config.c \
656 build/debug.c \
657 build/version.c \
658 $(TARGET_DIR_SRC) \
659 main.c \
660 common/encoding.c \
661 common/filter.c \
662 common/maths.c \
663 common/printf.c \
664 common/streambuf.c \
665 common/typeconversion.c \
666 config/config_eeprom.c \
667 config/feature.c \
668 config/parameter_group.c \
669 config/config_streamer.c \
670 drivers/adc.c \
671 drivers/buf_writer.c \
672 drivers/bus_i2c_soft.c \
673 drivers/bus_spi.c \
674 drivers/bus_spi_soft.c \
675 drivers/display.c \
676 drivers/exti.c \
677 drivers/io.c \
678 drivers/light_led.c \
679 drivers/resource.c \
680 drivers/rcc.c \
681 drivers/serial.c \
682 drivers/serial_uart.c \
683 drivers/sound_beeper.c \
684 drivers/stack_check.c \
685 drivers/system.c \
686 drivers/timer.c \
687 drivers/transponder_ir.c \
688 drivers/transponder_ir_arcitimer.c \
689 drivers/transponder_ir_ilap.c \
690 fc/config.c \
691 fc/fc_dispatch.c \
692 fc/fc_hardfaults.c \
693 fc/fc_msp.c \
694 fc/fc_tasks.c \
695 fc/runtime_config.c \
696 io/beeper.c \
697 io/serial.c \
698 io/statusindicator.c \
699 io/transponder_ir.c \
700 msp/msp_serial.c \
701 scheduler/scheduler.c \
702 sensors/battery.c \
703 sensors/current.c \
704 sensors/voltage.c \
706 OSD_SLAVE_SRC = \
707 io/displayport_max7456.c \
708 osd_slave/osd_slave_init.c \
709 io/osd_slave.c
711 FC_SRC = \
712 fc/fc_init.c \
713 fc/controlrate_profile.c \
714 drivers/gyro_sync.c \
715 drivers/rx_nrf24l01.c \
716 drivers/rx_spi.c \
717 drivers/rx_xn297.c \
718 drivers/pwm_esc_detect.c \
719 drivers/pwm_output.c \
720 drivers/rx_pwm.c \
721 drivers/serial_softserial.c \
722 fc/fc_core.c \
723 fc/fc_rc.c \
724 fc/rc_adjustments.c \
725 fc/rc_controls.c \
726 fc/cli.c \
727 flight/altitude.c \
728 flight/failsafe.c \
729 flight/imu.c \
730 flight/mixer.c \
731 flight/pid.c \
732 flight/servos.c \
733 io/serial_4way.c \
734 io/serial_4way_avrootloader.c \
735 io/serial_4way_stk500v2.c \
736 rx/ibus.c \
737 rx/jetiexbus.c \
738 rx/msp.c \
739 rx/nrf24_cx10.c \
740 rx/nrf24_inav.c \
741 rx/nrf24_h8_3d.c \
742 rx/nrf24_syma.c \
743 rx/nrf24_v202.c \
744 rx/pwm.c \
745 rx/rx.c \
746 rx/rx_spi.c \
747 rx/crsf.c \
748 rx/sbus.c \
749 rx/spektrum.c \
750 rx/sumd.c \
751 rx/sumh.c \
752 rx/xbus.c \
753 sensors/acceleration.c \
754 sensors/boardalignment.c \
755 sensors/compass.c \
756 sensors/gyro.c \
757 sensors/gyroanalyse.c \
758 sensors/initialisation.c \
759 blackbox/blackbox.c \
760 blackbox/blackbox_io.c \
761 cms/cms.c \
762 cms/cms_menu_blackbox.c \
763 cms/cms_menu_builtin.c \
764 cms/cms_menu_imu.c \
765 cms/cms_menu_ledstrip.c \
766 cms/cms_menu_misc.c \
767 cms/cms_menu_osd.c \
768 cms/cms_menu_vtx.c \
769 common/colorconversion.c \
770 common/gps_conversion.c \
771 drivers/display_ug2864hsweg01.c \
772 drivers/light_ws2811strip.c \
773 drivers/serial_escserial.c \
774 drivers/sonar_hcsr04.c \
775 drivers/vtx_common.c \
776 flight/navigation.c \
777 io/dashboard.c \
778 io/displayport_max7456.c \
779 io/displayport_msp.c \
780 io/displayport_oled.c \
781 io/gps.c \
782 io/ledstrip.c \
783 io/osd.c \
784 sensors/sonar.c \
785 sensors/barometer.c \
786 telemetry/telemetry.c \
787 telemetry/crsf.c \
788 telemetry/srxl.c \
789 telemetry/frsky.c \
790 telemetry/hott.c \
791 telemetry/smartport.c \
792 telemetry/ltm.c \
793 telemetry/mavlink.c \
794 telemetry/ibus.c \
795 telemetry/ibus_shared.c \
796 sensors/esc_sensor.c \
797 io/vtx_string.c \
798 io/vtx_smartaudio.c \
799 io/vtx_tramp.c \
800 io/vtx.c
802 COMMON_DEVICE_SRC = \
803 $(CMSIS_SRC) \
804 $(DEVICE_STDPERIPH_SRC)
806 ifeq ($(OSD_SLAVE),yes)
807 TARGET_FLAGS := -DUSE_OSD_SLAVE $(TARGET_FLAGS)
808 COMMON_SRC := $(COMMON_SRC) $(OSD_SLAVE_SRC) $(COMMON_DEVICE_SRC)
809 else
810 COMMON_SRC := $(COMMON_SRC) $(FC_SRC) $(COMMON_DEVICE_SRC)
811 endif
814 SPEED_OPTIMISED_SRC := ""
815 SIZE_OPTIMISED_SRC := ""
817 ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
818 SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
819 common/encoding.c \
820 common/filter.c \
821 common/maths.c \
822 common/typeconversion.c \
823 drivers/adc.c \
824 drivers/buf_writer.c \
825 drivers/bus_i2c_soft.c \
826 drivers/bus_spi.c \
827 drivers/bus_spi_soft.c \
828 drivers/exti.c \
829 drivers/gyro_sync.c \
830 drivers/io.c \
831 drivers/light_led.c \
832 drivers/resource.c \
833 drivers/rx_nrf24l01.c \
834 drivers/rx_spi.c \
835 drivers/rx_xn297.c \
836 drivers/pwm_output.c \
837 drivers/rcc.c \
838 drivers/rx_pwm.c \
839 drivers/serial.c \
840 drivers/serial_uart.c \
841 drivers/sound_beeper.c \
842 drivers/system.c \
843 drivers/timer.c \
844 fc/fc_core.c \
845 fc/fc_tasks.c \
846 fc/fc_rc.c \
847 fc/rc_controls.c \
848 fc/runtime_config.c \
849 flight/imu.c \
850 flight/mixer.c \
851 flight/pid.c \
852 flight/servos.c \
853 io/serial.c \
854 rx/ibus.c \
855 rx/jetiexbus.c \
856 rx/nrf24_cx10.c \
857 rx/nrf24_inav.c \
858 rx/nrf24_h8_3d.c \
859 rx/nrf24_syma.c \
860 rx/nrf24_v202.c \
861 rx/pwm.c \
862 rx/rx.c \
863 rx/rx_spi.c \
864 rx/crsf.c \
865 rx/sbus.c \
866 rx/spektrum.c \
867 rx/sumd.c \
868 rx/sumh.c \
869 rx/xbus.c \
870 scheduler/scheduler.c \
871 sensors/acceleration.c \
872 sensors/boardalignment.c \
873 sensors/gyro.c \
874 sensors/gyroanalyse.c \
875 $(CMSIS_SRC) \
876 $(DEVICE_STDPERIPH_SRC) \
877 drivers/display_ug2864hsweg01.c \
878 drivers/light_ws2811strip.c \
879 drivers/serial_softserial.c \
880 io/dashboard.c \
881 io/displayport_max7456.c \
882 io/osd.c \
883 io/osd_slave.c
885 SIZE_OPTIMISED_SRC := $(SIZE_OPTIMISED_SRC) \
886 drivers/serial_escserial.c \
887 drivers/vtx_common.c \
888 io/cli.c \
889 io/serial_4way.c \
890 io/serial_4way_avrootloader.c \
891 io/serial_4way_stk500v2.c \
892 msp/msp_serial.c \
893 cms/cms.c \
894 cms/cms_menu_blackbox.c \
895 cms/cms_menu_builtin.c \
896 cms/cms_menu_imu.c \
897 cms/cms_menu_ledstrip.c \
898 cms/cms_menu_misc.c \
899 cms/cms_menu_osd.c \
900 cms/cms_menu_vtx.c \
901 io/vtx_smartaudio.c \
902 io/vtx_tramp.c
903 endif #F3
905 ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS)))
906 VCP_SRC = \
907 vcpf4/stm32f4xx_it.c \
908 vcpf4/usb_bsp.c \
909 vcpf4/usbd_desc.c \
910 vcpf4/usbd_usr.c \
911 vcpf4/usbd_cdc_vcp.c \
912 drivers/serial_usb_vcp.c \
913 drivers/usb_io.c
914 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
915 VCP_SRC = \
916 vcp_hal/usbd_desc.c \
917 vcp_hal/usbd_conf.c \
918 vcp_hal/usbd_cdc_interface.c \
919 drivers/serial_usb_vcp.c \
920 drivers/usb_io.c
921 else
922 VCP_SRC = \
923 vcp/hw_config.c \
924 vcp/stm32_it.c \
925 vcp/usb_desc.c \
926 vcp/usb_endp.c \
927 vcp/usb_istr.c \
928 vcp/usb_prop.c \
929 vcp/usb_pwr.c \
930 drivers/serial_usb_vcp.c \
931 drivers/usb_io.c
932 endif
934 STM32F10x_COMMON_SRC = \
935 drivers/adc_stm32f10x.c \
936 drivers/bus_i2c_stm32f10x.c \
937 drivers/dma.c \
938 drivers/gpio_stm32f10x.c \
939 drivers/inverter.c \
940 drivers/light_ws2811strip_stdperiph.c \
941 drivers/serial_uart_stm32f10x.c \
942 drivers/system_stm32f10x.c \
943 drivers/timer_stm32f10x.c
945 STM32F30x_COMMON_SRC = \
946 target/system_stm32f30x.c \
947 drivers/adc_stm32f30x.c \
948 drivers/bus_i2c_stm32f30x.c \
949 drivers/dma.c \
950 drivers/gpio_stm32f30x.c \
951 drivers/light_ws2811strip_stdperiph.c \
952 drivers/pwm_output_dshot.c \
953 drivers/serial_uart_stm32f30x.c \
954 drivers/system_stm32f30x.c \
955 drivers/timer_stm32f30x.c
957 STM32F4xx_COMMON_SRC = \
958 target/system_stm32f4xx.c \
959 drivers/accgyro_mpu.c \
960 drivers/adc_stm32f4xx.c \
961 drivers/bus_i2c_stm32f10x.c \
962 drivers/dma_stm32f4xx.c \
963 drivers/gpio_stm32f4xx.c \
964 drivers/inverter.c \
965 drivers/light_ws2811strip_stdperiph.c \
966 drivers/pwm_output_dshot.c \
967 drivers/serial_uart_stm32f4xx.c \
968 drivers/system_stm32f4xx.c \
969 drivers/timer_stm32f4xx.c
971 STM32F7xx_COMMON_SRC = \
972 target/system_stm32f7xx.c \
973 drivers/accgyro_mpu.c \
974 drivers/adc_stm32f7xx.c \
975 drivers/bus_i2c_hal.c \
976 drivers/dma_stm32f7xx.c \
977 drivers/gpio_stm32f7xx.c \
978 drivers/inverter.c \
979 drivers/bus_spi_hal.c \
980 drivers/pwm_output_stm32f7xx.c \
981 drivers/timer_hal.c \
982 drivers/timer_stm32f7xx.c \
983 drivers/system_stm32f7xx.c \
984 drivers/serial_uart_stm32f7xx.c \
985 drivers/serial_uart_hal.c
987 F7EXCLUDES = drivers/bus_spi.c \
988 drivers/bus_i2c.c \
989 drivers/timer.c \
990 drivers/serial_uart.c
992 SITLEXCLUDES = \
993 drivers/adc.c \
994 drivers/bus_spi.c \
995 drivers/bus_i2c.c \
996 drivers/dma.c \
997 drivers/pwm_output.c \
998 drivers/timer.c \
999 drivers/light_led.c \
1000 drivers/system.c \
1001 drivers/rcc.c \
1002 drivers/serial_uart.c \
1005 # check if target.mk supplied
1006 ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS)))
1007 SRC := $(STARTUP_SRC) $(STM32F4xx_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1008 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
1009 SRC := $(STARTUP_SRC) $(STM32F7xx_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1010 else ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
1011 SRC := $(STARTUP_SRC) $(STM32F30x_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1012 else ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
1013 SRC := $(STARTUP_SRC) $(STM32F10x_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1014 else ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1015 SRC := $(TARGET_SRC) $(SITL_SRC) $(VARIANT_SRC)
1016 endif
1018 ifneq ($(filter $(TARGET),$(F4_TARGETS) $(F7_TARGETS)),)
1019 DSPLIB := $(ROOT)/lib/main/DSP_Lib
1020 DEVICE_FLAGS += -DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1 -DUNALIGNED_SUPPORT_DISABLE
1022 INCLUDE_DIRS += $(DSPLIB)/Include
1024 SRC += $(DSPLIB)/Source/TransformFunctions/arm_rfft_fast_f32.c
1025 SRC += $(DSPLIB)/Source/TransformFunctions/arm_cfft_f32.c
1026 SRC += $(DSPLIB)/Source/TransformFunctions/arm_rfft_fast_init_f32.c
1027 SRC += $(DSPLIB)/Source/TransformFunctions/arm_cfft_radix8_f32.c
1028 SRC += $(DSPLIB)/Source/CommonTables/arm_common_tables.c
1030 SRC += $(DSPLIB)/Source/ComplexMathFunctions/arm_cmplx_mag_f32.c
1031 SRC += $(DSPLIB)/Source/StatisticsFunctions/arm_max_f32.c
1033 SRC += $(wildcard $(DSPLIB)/Source/*/*.S)
1034 endif
1037 ifneq ($(filter ONBOARDFLASH,$(FEATURES)),)
1038 SRC += \
1039 drivers/flash_m25p16.c \
1040 io/flashfs.c
1041 endif
1043 SRC += $(COMMON_SRC)
1045 #excludes
1046 ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
1047 SRC := $(filter-out ${F7EXCLUDES}, $(SRC))
1048 endif
1050 #SITL excludes
1051 ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1052 SRC := $(filter-out ${SITLEXCLUDES}, $(SRC))
1053 endif
1055 ifneq ($(filter SDCARD,$(FEATURES)),)
1056 SRC += \
1057 drivers/sdcard.c \
1058 drivers/sdcard_standard.c \
1059 io/asyncfatfs/asyncfatfs.c \
1060 io/asyncfatfs/fat_standard.c
1061 endif
1063 ifneq ($(filter VCP,$(FEATURES)),)
1064 SRC += $(VCP_SRC)
1065 endif
1066 # end target specific make file checks
1069 # Search path and source files for the ST stdperiph library
1070 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
1072 ###############################################################################
1073 # Things that might need changing to use different tools
1076 # Find out if ccache is installed on the system
1077 CCACHE := ccache
1078 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
1079 ifneq ($(RESULT),0)
1080 CCACHE :=
1081 endif
1083 # Tool names
1084 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
1085 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
1086 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
1087 SIZE := $(ARM_SDK_PREFIX)size
1090 # Tool options.
1093 ifneq ($(DEBUG),GDB)
1094 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
1095 OPTIMISE_SPEED := ""
1096 OPTIMISE_SIZE := ""
1098 ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
1099 OPTIMISE_DEFAULT := -Os
1101 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
1103 else ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
1104 OPTIMISE_DEFAULT := -O2
1105 OPTIMISE_SPEED := -Ofast
1106 OPTIMISE_SIZE := -Os
1108 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
1110 else ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1111 OPTIMISE_DEFAULT := -Ofast
1112 OPTIMISE_SPEED := -Ofast
1113 OPTIMISE_SIZE := -Os
1115 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
1117 else
1118 OPTIMISE_DEFAULT := -Ofast
1120 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
1122 endif #TARGETS
1124 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
1125 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
1126 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
1128 else #DEBUG
1129 OPTIMISE_DEFAULT := -O0
1131 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
1133 LTO_FLAGS := $(OPTIMISE_DEFAULT)
1134 endif #DEBUG
1136 DEBUG_FLAGS = -ggdb3 -DDEBUG
1138 CFLAGS += $(ARCH_FLAGS) \
1139 $(addprefix -D,$(OPTIONS)) \
1140 $(addprefix -I,$(INCLUDE_DIRS)) \
1141 $(DEBUG_FLAGS) \
1142 -std=gnu99 \
1143 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
1144 -ffunction-sections \
1145 -fdata-sections \
1146 -pedantic \
1147 $(DEVICE_FLAGS) \
1148 -DUSE_STDPERIPH_DRIVER \
1149 -D$(TARGET) \
1150 $(TARGET_FLAGS) \
1151 -D'__FORKNAME__="$(FORKNAME)"' \
1152 -D'__TARGET__="$(TARGET)"' \
1153 -D'__REVISION__="$(REVISION)"' \
1154 -save-temps=obj \
1155 -MMD -MP
1157 ASFLAGS = $(ARCH_FLAGS) \
1158 -x assembler-with-cpp \
1159 $(addprefix -I,$(INCLUDE_DIRS)) \
1160 -MMD -MP
1162 LDFLAGS = -lm \
1163 -nostartfiles \
1164 --specs=nano.specs \
1165 -lc \
1166 -lnosys \
1167 $(ARCH_FLAGS) \
1168 $(LTO_FLAGS) \
1169 $(DEBUG_FLAGS) \
1170 -static \
1171 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
1172 -Wl,-L$(LINKER_DIR) \
1173 -Wl,--cref \
1174 -Wl,--no-wchar-size-warning \
1175 -T$(LD_SCRIPT)
1177 #SITL compile
1178 ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1179 LDFLAGS = \
1180 -lm \
1181 -lpthread \
1182 -lc \
1183 -lrt \
1184 $(ARCH_FLAGS) \
1185 $(LTO_FLAGS) \
1186 $(DEBUG_FLAGS) \
1187 -static \
1188 -static-libgcc \
1189 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
1190 -Wl,-L$(LINKER_DIR) \
1191 -Wl,--cref \
1192 -T$(LD_SCRIPT)
1193 endif
1195 ###############################################################################
1196 # No user-serviceable parts below
1197 ###############################################################################
1199 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
1200 --std=c99 --inline-suppr --quiet --force \
1201 $(addprefix -I,$(INCLUDE_DIRS)) \
1202 -I/usr/include -I/usr/include/linux
1205 # Things we will build
1207 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
1208 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
1209 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
1210 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
1211 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
1212 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
1215 CLEAN_ARTIFACTS := $(TARGET_BIN)
1216 CLEAN_ARTIFACTS += $(TARGET_HEX)
1217 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
1219 # Make sure build date and revision is updated on every incremental build
1220 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
1222 # List of buildable ELF files and their object dependencies.
1223 # It would be nice to compute these lists, but that seems to be just beyond make.
1225 $(TARGET_HEX): $(TARGET_ELF)
1226 $(V0) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
1228 $(TARGET_BIN): $(TARGET_ELF)
1229 $(V0) $(OBJCOPY) -O binary $< $@
1231 $(TARGET_ELF): $(TARGET_OBJS)
1232 $(V1) echo Linking $(TARGET)
1233 $(V1) $(CROSS_CC) -o $@ $^ $(LDFLAGS)
1234 $(V0) $(SIZE) $(TARGET_ELF)
1236 # Compile
1237 ifneq ($(DEBUG),GDB)
1238 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1239 $(V1) mkdir -p $(dir $@)
1240 $(V1) $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
1241 echo "%% (speed optimised) $(notdir $<)" "$(STDOUT)" && \
1242 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SPEED_OPTIMISATION) $<, \
1243 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
1244 echo "%% (size optimised) $(notdir $<)" "$(STDOUT)" && \
1245 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SIZE_OPTIMISATION) $<, \
1246 echo "%% $(notdir $<)" "$(STDOUT)" && \
1247 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEFAULT_OPTIMISATION) $<))
1248 else
1249 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1250 $(V1) mkdir -p $(dir $@)
1251 $(V1) echo "%% $(notdir $<)" "$(STDOUT)" && \
1252 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEBUG_OPTIMISATION) $<
1253 endif
1255 # Assemble
1256 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
1257 $(V1) mkdir -p $(dir $@)
1258 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1259 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1261 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
1262 $(V1) mkdir -p $(dir $@)
1263 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1264 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1267 ## all : Build all valid targets
1268 all: $(VALID_TARGETS)
1270 ## official : Build all official (travis) targets
1271 official: $(OFFICIAL_TARGETS)
1273 ## targets-group-1 : build some targets
1274 targets-group-1: $(GROUP_1_TARGETS)
1276 ## targets-group-2 : build some targets
1277 targets-group-2: $(GROUP_2_TARGETS)
1279 ## targets-group-3 : build some targets
1280 targets-group-3: $(GROUP_3_TARGETS)
1282 ## targets-group-3 : build some targets
1283 targets-group-4: $(GROUP_4_TARGETS)
1285 ## targets-group-rest: build the rest of the targets (not listed in group 1, 2 or 3)
1286 targets-group-rest: $(GROUP_OTHER_TARGETS)
1289 $(VALID_TARGETS):
1290 $(V0) echo "" && \
1291 echo "Building $@" && \
1292 time $(MAKE) binary hex TARGET=$@ && \
1293 echo "Building $@ succeeded."
1297 CLEAN_TARGETS = $(addprefix clean_,$(VALID_TARGETS) )
1298 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
1300 ## clean : clean up temporary / machine-generated files
1301 clean:
1302 $(V0) echo "Cleaning $(TARGET)"
1303 $(V0) rm -f $(CLEAN_ARTIFACTS)
1304 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
1305 $(V0) echo "Cleaning $(TARGET) succeeded."
1307 ## clean_test : clean up temporary / machine-generated files (tests)
1308 clean_test:
1309 $(V0) cd src/test && $(MAKE) clean || true
1311 ## clean_<TARGET> : clean up one specific target
1312 $(CLEAN_TARGETS) :
1313 $(V0) $(MAKE) -j TARGET=$(subst clean_,,$@) clean
1315 ## <TARGET>_clean : clean up one specific target (alias for above)
1316 $(TARGETS_CLEAN) :
1317 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
1319 ## clean_all : clean all valid targets
1320 clean_all:$(CLEAN_TARGETS)
1322 ## all_clean : clean all valid targets (alias for above)
1323 all_clean:$(TARGETS_CLEAN)
1326 flash_$(TARGET): $(TARGET_HEX)
1327 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1328 $(V0) echo -n 'R' >$(SERIAL_DEVICE)
1329 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1331 ## flash : flash firmware (.hex) onto flight controller
1332 flash: flash_$(TARGET)
1334 st-flash_$(TARGET): $(TARGET_BIN)
1335 $(V0) st-flash --reset write $< 0x08000000
1337 ## st-flash : flash firmware (.bin) onto flight controller
1338 st-flash: st-flash_$(TARGET)
1340 binary:
1341 $(V0) $(MAKE) -j $(TARGET_BIN)
1343 hex:
1344 $(V0) $(MAKE) -j $(TARGET_HEX)
1346 unbrick_$(TARGET): $(TARGET_HEX)
1347 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1348 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1350 ## unbrick : unbrick flight controller
1351 unbrick: unbrick_$(TARGET)
1353 ## cppcheck : run static analysis on C source code
1354 cppcheck: $(CSOURCES)
1355 $(V0) $(CPPCHECK)
1357 cppcheck-result.xml: $(CSOURCES)
1358 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
1360 # mkdirs
1361 $(DL_DIR):
1362 mkdir -p $@
1364 $(TOOLS_DIR):
1365 mkdir -p $@
1367 $(BUILD_DIR):
1368 mkdir -p $@
1370 ## version : print firmware version
1371 version:
1372 @echo $(FC_VER)
1374 ## help : print this help message and exit
1375 help: Makefile make/tools.mk
1376 $(V0) @echo ""
1377 $(V0) @echo "Makefile for the $(FORKNAME) firmware"
1378 $(V0) @echo ""
1379 $(V0) @echo "Usage:"
1380 $(V0) @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
1381 $(V0) @echo "Or:"
1382 $(V0) @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
1383 $(V0) @echo ""
1384 $(V0) @echo "Valid TARGET values are: $(VALID_TARGETS)"
1385 $(V0) @echo ""
1386 $(V0) @sed -n 's/^## //p' $?
1388 ## targets : print a list of all valid target platforms (for consumption by scripts)
1389 targets:
1390 $(V0) @echo "Valid targets: $(VALID_TARGETS)"
1391 $(V0) @echo "Target: $(TARGET)"
1392 $(V0) @echo "Base target: $(BASE_TARGET)"
1393 $(V0) @echo "Official targets: $(OFFICIAL_TARGETS)"
1394 $(V0) @echo "targets-group-1: $(GROUP_1_TARGETS)"
1395 $(V0) @echo "targets-group-2: $(GROUP_2_TARGETS)"
1396 $(V0) @echo "targets-group-3: $(GROUP_3_TARGETS)"
1397 $(V0) @echo "targets-group-4: $(GROUP_4_TARGETS)"
1398 $(V0) @echo "targets-group-rest: $(GROUP_OTHER_TARGETS)"
1400 ## test : run the cleanflight test suite
1401 ## junittest : run the cleanflight test suite, producing Junit XML result files.
1402 test junittest:
1403 $(V0) cd src/test && $(MAKE) $@
1405 # rebuild everything when makefile changes
1406 $(TARGET_OBJS) : Makefile
1408 # include auto-generated dependencies
1409 -include $(TARGET_DEPS)