Make SBufWriteString write string without terminating zero
[betaflight.git] / Makefile
blob88f7221c99354cfdd66edf04e53bda9f5dad512a
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 betaflight 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 ?= NAZE
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 = betaflight
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 SPRACINGF4EVO STM32F3DISCOVERY
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)/CM4/CoreSupport:$(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F30x
280 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM4/CoreSupport/*.c \
281 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F30x/*.c))
283 INCLUDE_DIRS := $(INCLUDE_DIRS) \
284 $(STDPERIPH_DIR)/inc \
285 $(CMSIS_DIR)/CM4/CoreSupport \
286 $(CMSIS_DIR)/CM4/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/buttons.c \
676 drivers/display.c \
677 drivers/exti.c \
678 drivers/io.c \
679 drivers/light_led.c \
680 drivers/resource.c \
681 drivers/rcc.c \
682 drivers/serial.c \
683 drivers/serial_uart.c \
684 drivers/sound_beeper.c \
685 drivers/stack_check.c \
686 drivers/system.c \
687 drivers/timer.c \
688 drivers/transponder_ir.c \
689 fc/config.c \
690 fc/fc_dispatch.c \
691 fc/fc_hardfaults.c \
692 fc/fc_msp.c \
693 fc/fc_tasks.c \
694 fc/runtime_config.c \
695 io/beeper.c \
696 io/serial.c \
697 io/statusindicator.c \
698 io/transponder_ir.c \
699 msp/msp_serial.c \
700 scheduler/scheduler.c \
701 sensors/battery.c \
702 sensors/current.c \
703 sensors/voltage.c \
705 OSD_SLAVE_SRC = \
706 io/displayport_max7456.c \
707 osd_slave/osd_slave_init.c \
708 io/osd_slave.c
710 FC_SRC = \
711 fc/fc_init.c \
712 fc/controlrate_profile.c \
713 drivers/gyro_sync.c \
714 drivers/rx_nrf24l01.c \
715 drivers/rx_spi.c \
716 drivers/rx_xn297.c \
717 drivers/pwm_esc_detect.c \
718 drivers/pwm_output.c \
719 drivers/rx_pwm.c \
720 drivers/serial_softserial.c \
721 fc/fc_core.c \
722 fc/fc_rc.c \
723 fc/rc_adjustments.c \
724 fc/rc_controls.c \
725 fc/cli.c \
726 fc/settings.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_encoding.c \
761 blackbox/blackbox_io.c \
762 cms/cms.c \
763 cms/cms_menu_blackbox.c \
764 cms/cms_menu_builtin.c \
765 cms/cms_menu_imu.c \
766 cms/cms_menu_ledstrip.c \
767 cms/cms_menu_misc.c \
768 cms/cms_menu_osd.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 drivers/transponder_ir.c \
777 flight/navigation.c \
778 io/dashboard.c \
779 io/displayport_max7456.c \
780 io/displayport_msp.c \
781 io/displayport_oled.c \
782 io/gps.c \
783 io/ledstrip.c \
784 io/osd.c \
785 sensors/sonar.c \
786 sensors/barometer.c \
787 telemetry/telemetry.c \
788 telemetry/crsf.c \
789 telemetry/srxl.c \
790 telemetry/frsky.c \
791 telemetry/hott.c \
792 telemetry/smartport.c \
793 telemetry/ltm.c \
794 telemetry/mavlink.c \
795 telemetry/ibus.c \
796 telemetry/ibus_shared.c \
797 sensors/esc_sensor.c \
798 io/vtx_string.c \
799 io/vtx_rtc6705.c \
800 io/vtx_smartaudio.c \
801 io/vtx_tramp.c \
802 io/vtx_control.c
804 COMMON_DEVICE_SRC = \
805 $(CMSIS_SRC) \
806 $(DEVICE_STDPERIPH_SRC)
808 ifeq ($(OSD_SLAVE),yes)
809 TARGET_FLAGS := -DUSE_OSD_SLAVE $(TARGET_FLAGS)
810 COMMON_SRC := $(COMMON_SRC) $(OSD_SLAVE_SRC) $(COMMON_DEVICE_SRC)
811 else
812 COMMON_SRC := $(COMMON_SRC) $(FC_SRC) $(COMMON_DEVICE_SRC)
813 endif
816 SPEED_OPTIMISED_SRC := ""
817 SIZE_OPTIMISED_SRC := ""
819 ifneq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
820 SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
821 common/encoding.c \
822 common/filter.c \
823 common/maths.c \
824 common/typeconversion.c \
825 drivers/adc.c \
826 drivers/buf_writer.c \
827 drivers/bus_i2c_soft.c \
828 drivers/bus_spi.c \
829 drivers/bus_spi_soft.c \
830 drivers/exti.c \
831 drivers/gyro_sync.c \
832 drivers/io.c \
833 drivers/light_led.c \
834 drivers/resource.c \
835 drivers/rx_nrf24l01.c \
836 drivers/rx_spi.c \
837 drivers/rx_xn297.c \
838 drivers/pwm_output.c \
839 drivers/rcc.c \
840 drivers/rx_pwm.c \
841 drivers/serial.c \
842 drivers/serial_uart.c \
843 drivers/sound_beeper.c \
844 drivers/system.c \
845 drivers/timer.c \
846 fc/fc_core.c \
847 fc/fc_tasks.c \
848 fc/fc_rc.c \
849 fc/rc_controls.c \
850 fc/runtime_config.c \
851 flight/imu.c \
852 flight/mixer.c \
853 flight/pid.c \
854 flight/servos.c \
855 io/serial.c \
856 rx/ibus.c \
857 rx/jetiexbus.c \
858 rx/nrf24_cx10.c \
859 rx/nrf24_inav.c \
860 rx/nrf24_h8_3d.c \
861 rx/nrf24_syma.c \
862 rx/nrf24_v202.c \
863 rx/pwm.c \
864 rx/rx.c \
865 rx/rx_spi.c \
866 rx/crsf.c \
867 rx/sbus.c \
868 rx/spektrum.c \
869 rx/sumd.c \
870 rx/sumh.c \
871 rx/xbus.c \
872 scheduler/scheduler.c \
873 sensors/acceleration.c \
874 sensors/boardalignment.c \
875 sensors/gyro.c \
876 sensors/gyroanalyse.c \
877 $(CMSIS_SRC) \
878 $(DEVICE_STDPERIPH_SRC) \
879 drivers/display_ug2864hsweg01.c \
880 drivers/light_ws2811strip.c \
881 drivers/serial_softserial.c \
882 io/dashboard.c \
883 io/displayport_max7456.c \
884 io/osd.c \
885 io/osd_slave.c
887 SIZE_OPTIMISED_SRC := $(SIZE_OPTIMISED_SRC) \
888 drivers/serial_escserial.c \
889 drivers/vtx_common.c \
890 fc/fc_init.c \
891 fc/cli.c \
892 fc/settings.c \
893 config/config_eeprom.c \
894 config/feature.c \
895 config/parameter_group.c \
896 config/config_streamer.c \
897 io/serial_4way.c \
898 io/serial_4way_avrootloader.c \
899 io/serial_4way_stk500v2.c \
900 msp/msp_serial.c \
901 cms/cms.c \
902 cms/cms_menu_blackbox.c \
903 cms/cms_menu_builtin.c \
904 cms/cms_menu_imu.c \
905 cms/cms_menu_ledstrip.c \
906 cms/cms_menu_misc.c \
907 cms/cms_menu_osd.c \
908 io/vtx_rtc6705.c \
909 io/vtx_smartaudio.c \
910 io/vtx_tramp.c
911 endif #!F1
913 ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS)))
914 VCP_SRC = \
915 vcpf4/stm32f4xx_it.c \
916 vcpf4/usb_bsp.c \
917 vcpf4/usbd_desc.c \
918 vcpf4/usbd_usr.c \
919 vcpf4/usbd_cdc_vcp.c \
920 drivers/serial_usb_vcp.c \
921 drivers/usb_io.c
922 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
923 VCP_SRC = \
924 vcp_hal/usbd_desc.c \
925 vcp_hal/usbd_conf.c \
926 vcp_hal/usbd_cdc_interface.c \
927 drivers/serial_usb_vcp.c \
928 drivers/usb_io.c
929 else
930 VCP_SRC = \
931 vcp/hw_config.c \
932 vcp/stm32_it.c \
933 vcp/usb_desc.c \
934 vcp/usb_endp.c \
935 vcp/usb_istr.c \
936 vcp/usb_prop.c \
937 vcp/usb_pwr.c \
938 drivers/serial_usb_vcp.c \
939 drivers/usb_io.c
940 endif
942 STM32F10x_COMMON_SRC = \
943 drivers/adc_stm32f10x.c \
944 drivers/bus_i2c_stm32f10x.c \
945 drivers/dma.c \
946 drivers/gpio_stm32f10x.c \
947 drivers/inverter.c \
948 drivers/light_ws2811strip_stdperiph.c \
949 drivers/serial_uart_stm32f10x.c \
950 drivers/system_stm32f10x.c \
951 drivers/timer_stm32f10x.c
953 STM32F30x_COMMON_SRC = \
954 target/system_stm32f30x.c \
955 drivers/adc_stm32f30x.c \
956 drivers/bus_i2c_stm32f30x.c \
957 drivers/dma.c \
958 drivers/gpio_stm32f30x.c \
959 drivers/light_ws2811strip_stdperiph.c \
960 drivers/pwm_output_dshot.c \
961 drivers/serial_uart_stm32f30x.c \
962 drivers/system_stm32f30x.c \
963 drivers/timer_stm32f30x.c
965 STM32F4xx_COMMON_SRC = \
966 target/system_stm32f4xx.c \
967 drivers/accgyro/accgyro_mpu.c \
968 drivers/adc_stm32f4xx.c \
969 drivers/bus_i2c_stm32f10x.c \
970 drivers/dma_stm32f4xx.c \
971 drivers/gpio_stm32f4xx.c \
972 drivers/inverter.c \
973 drivers/light_ws2811strip_stdperiph.c \
974 drivers/pwm_output_dshot.c \
975 drivers/serial_uart_stm32f4xx.c \
976 drivers/system_stm32f4xx.c \
977 drivers/timer_stm32f4xx.c
979 STM32F7xx_COMMON_SRC = \
980 target/system_stm32f7xx.c \
981 drivers/accgyro/accgyro_mpu.c \
982 drivers/adc_stm32f7xx.c \
983 drivers/bus_i2c_hal.c \
984 drivers/dma_stm32f7xx.c \
985 drivers/gpio_stm32f7xx.c \
986 drivers/light_ws2811strip_hal.c \
987 drivers/bus_spi_hal.c \
988 drivers/pwm_output_dshot_hal.c \
989 drivers/timer_hal.c \
990 drivers/timer_stm32f7xx.c \
991 drivers/system_stm32f7xx.c \
992 drivers/serial_uart_stm32f7xx.c \
993 drivers/serial_uart_hal.c
995 F7EXCLUDES = drivers/bus_spi.c \
996 drivers/bus_i2c.c \
997 drivers/timer.c \
998 drivers/serial_uart.c
1000 SITLEXCLUDES = \
1001 drivers/adc.c \
1002 drivers/bus_spi.c \
1003 drivers/bus_i2c.c \
1004 drivers/dma.c \
1005 drivers/pwm_output.c \
1006 drivers/timer.c \
1007 drivers/light_led.c \
1008 drivers/system.c \
1009 drivers/rcc.c \
1010 drivers/serial_uart.c \
1011 drivers/rx_xn297.c \
1012 drivers/display_ug2864hsweg01.c \
1013 telemetry/crsf.c \
1014 telemetry/srxl.c \
1015 io/displayport_oled.c
1018 # check if target.mk supplied
1019 ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS)))
1020 SRC := $(STARTUP_SRC) $(STM32F4xx_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1021 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
1022 SRC := $(STARTUP_SRC) $(STM32F7xx_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1023 else ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
1024 SRC := $(STARTUP_SRC) $(STM32F30x_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1025 else ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
1026 SRC := $(STARTUP_SRC) $(STM32F10x_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1027 else ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1028 SRC := $(TARGET_SRC) $(SITL_SRC) $(VARIANT_SRC)
1029 endif
1031 ifneq ($(filter $(TARGET),$(F3_TARGETS) $(F4_TARGETS) $(F7_TARGETS)),)
1032 DSPLIB := $(ROOT)/lib/main/DSP_Lib
1033 DEVICE_FLAGS += -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1 -DUNALIGNED_SUPPORT_DISABLE
1035 ifneq ($(filter $(TARGET),$(F3_TARGETS)) $(F4_TARGETS)),)
1036 DEVICE_FLAGS += -DARM_MATH_CM4
1037 endif
1038 ifneq ($(filter $(TARGET),$(F7_TARGETS)),)
1039 DEVICE_FLAGS += -DARM_MATH_CM7
1040 endif
1042 INCLUDE_DIRS += $(DSPLIB)/Include
1044 SRC += $(DSPLIB)/Source/BasicMathFunctions/arm_mult_f32.c
1045 SRC += $(DSPLIB)/Source/TransformFunctions/arm_rfft_fast_f32.c
1046 SRC += $(DSPLIB)/Source/TransformFunctions/arm_cfft_f32.c
1047 SRC += $(DSPLIB)/Source/TransformFunctions/arm_rfft_fast_init_f32.c
1048 SRC += $(DSPLIB)/Source/TransformFunctions/arm_cfft_radix8_f32.c
1049 SRC += $(DSPLIB)/Source/CommonTables/arm_common_tables.c
1051 SRC += $(DSPLIB)/Source/ComplexMathFunctions/arm_cmplx_mag_f32.c
1052 SRC += $(DSPLIB)/Source/StatisticsFunctions/arm_max_f32.c
1054 SRC += $(wildcard $(DSPLIB)/Source/*/*.S)
1056 endif
1059 ifneq ($(filter ONBOARDFLASH,$(FEATURES)),)
1060 SRC += \
1061 drivers/flash_m25p16.c \
1062 io/flashfs.c
1063 endif
1065 SRC += $(COMMON_SRC)
1067 #excludes
1068 ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
1069 SRC := $(filter-out ${F7EXCLUDES}, $(SRC))
1070 endif
1072 #SITL excludes
1073 ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1074 SRC := $(filter-out ${SITLEXCLUDES}, $(SRC))
1075 endif
1077 ifneq ($(filter SDCARD,$(FEATURES)),)
1078 SRC += \
1079 drivers/sdcard.c \
1080 drivers/sdcard_standard.c \
1081 io/asyncfatfs/asyncfatfs.c \
1082 io/asyncfatfs/fat_standard.c
1083 endif
1085 ifneq ($(filter VCP,$(FEATURES)),)
1086 SRC += $(VCP_SRC)
1087 endif
1088 # end target specific make file checks
1091 # Search path and source files for the ST stdperiph library
1092 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
1094 ###############################################################################
1095 # Things that might need changing to use different tools
1098 # Find out if ccache is installed on the system
1099 CCACHE := ccache
1100 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
1101 ifneq ($(RESULT),0)
1102 CCACHE :=
1103 endif
1105 # Tool names
1106 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
1107 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
1108 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
1109 SIZE := $(ARM_SDK_PREFIX)size
1112 # Tool options.
1115 ifneq ($(DEBUG),GDB)
1116 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
1117 OPTIMISE_SPEED := ""
1118 OPTIMISE_SIZE := ""
1120 ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
1121 OPTIMISE_DEFAULT := -Os
1123 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
1125 else ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1126 OPTIMISE_DEFAULT := -Ofast
1127 OPTIMISE_SPEED := -Ofast
1128 OPTIMISE_SIZE := -Os
1130 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
1132 else
1133 OPTIMISE_DEFAULT := -O2
1134 OPTIMISE_SPEED := -Ofast
1135 OPTIMISE_SIZE := -Os
1137 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
1139 endif #TARGETS
1141 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
1142 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
1143 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
1145 else #DEBUG
1146 OPTIMISE_DEFAULT := -Og
1148 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
1150 LTO_FLAGS := $(OPTIMISE_DEFAULT)
1151 endif #DEBUG
1153 DEBUG_FLAGS = -ggdb3 -DDEBUG
1155 CFLAGS += $(ARCH_FLAGS) \
1156 $(addprefix -D,$(OPTIONS)) \
1157 $(addprefix -I,$(INCLUDE_DIRS)) \
1158 $(DEBUG_FLAGS) \
1159 -std=gnu99 \
1160 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
1161 -ffunction-sections \
1162 -fdata-sections \
1163 -pedantic \
1164 $(DEVICE_FLAGS) \
1165 -DUSE_STDPERIPH_DRIVER \
1166 -D$(TARGET) \
1167 $(TARGET_FLAGS) \
1168 -D'__FORKNAME__="$(FORKNAME)"' \
1169 -D'__TARGET__="$(TARGET)"' \
1170 -D'__REVISION__="$(REVISION)"' \
1171 -save-temps=obj \
1172 -MMD -MP \
1173 $(EXTRA_FLAGS)
1176 ASFLAGS = $(ARCH_FLAGS) \
1177 -x assembler-with-cpp \
1178 $(addprefix -I,$(INCLUDE_DIRS)) \
1179 -MMD -MP
1181 LDFLAGS = -lm \
1182 -nostartfiles \
1183 --specs=nano.specs \
1184 -lc \
1185 -lnosys \
1186 $(ARCH_FLAGS) \
1187 $(LTO_FLAGS) \
1188 $(DEBUG_FLAGS) \
1189 -static \
1190 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
1191 -Wl,-L$(LINKER_DIR) \
1192 -Wl,--cref \
1193 -Wl,--no-wchar-size-warning \
1194 -T$(LD_SCRIPT)
1196 #SITL compile
1197 ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1198 LDFLAGS = \
1199 -lm \
1200 -lpthread \
1201 -lc \
1202 -lrt \
1203 $(ARCH_FLAGS) \
1204 $(LTO_FLAGS) \
1205 $(DEBUG_FLAGS) \
1206 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
1207 -Wl,-L$(LINKER_DIR) \
1208 -Wl,--cref \
1209 -T$(LD_SCRIPT)
1211 ifneq ($(filter SITL_STATIC,$(OPTIONS)),)
1212 LDFLAGS += \
1213 -static \
1214 -static-libgcc
1215 endif
1216 endif
1218 ###############################################################################
1219 # No user-serviceable parts below
1220 ###############################################################################
1222 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
1223 --std=c99 --inline-suppr --quiet --force \
1224 $(addprefix -I,$(INCLUDE_DIRS)) \
1225 -I/usr/include -I/usr/include/linux
1228 # Things we will build
1230 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
1231 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
1232 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
1233 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
1234 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
1235 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
1238 CLEAN_ARTIFACTS := $(TARGET_BIN)
1239 CLEAN_ARTIFACTS += $(TARGET_HEX)
1240 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
1242 # Make sure build date and revision is updated on every incremental build
1243 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
1245 # List of buildable ELF files and their object dependencies.
1246 # It would be nice to compute these lists, but that seems to be just beyond make.
1248 $(TARGET_HEX): $(TARGET_ELF)
1249 $(V0) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
1251 $(TARGET_BIN): $(TARGET_ELF)
1252 $(V0) $(OBJCOPY) -O binary $< $@
1254 $(TARGET_ELF): $(TARGET_OBJS)
1255 $(V1) echo Linking $(TARGET)
1256 $(V1) $(CROSS_CC) -o $@ $^ $(LDFLAGS)
1257 $(V0) $(SIZE) $(TARGET_ELF)
1259 # Compile
1260 ifneq ($(DEBUG),GDB)
1261 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1262 $(V1) mkdir -p $(dir $@)
1263 $(V1) $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
1264 echo "%% (speed optimised) $(notdir $<)" "$(STDOUT)" && \
1265 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SPEED_OPTIMISATION) $<, \
1266 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
1267 echo "%% (size optimised) $(notdir $<)" "$(STDOUT)" && \
1268 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SIZE_OPTIMISATION) $<, \
1269 echo "%% $(notdir $<)" "$(STDOUT)" && \
1270 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEFAULT_OPTIMISATION) $<))
1271 else
1272 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1273 $(V1) mkdir -p $(dir $@)
1274 $(V1) echo "%% $(notdir $<)" "$(STDOUT)" && \
1275 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEBUG_OPTIMISATION) $<
1276 endif
1278 # Assemble
1279 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
1280 $(V1) mkdir -p $(dir $@)
1281 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1282 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1284 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
1285 $(V1) mkdir -p $(dir $@)
1286 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1287 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1290 ## all : Build all valid targets
1291 all: $(VALID_TARGETS)
1293 ## official : Build all official (travis) targets
1294 official: $(OFFICIAL_TARGETS)
1296 ## targets-group-1 : build some targets
1297 targets-group-1: $(GROUP_1_TARGETS)
1299 ## targets-group-2 : build some targets
1300 targets-group-2: $(GROUP_2_TARGETS)
1302 ## targets-group-3 : build some targets
1303 targets-group-3: $(GROUP_3_TARGETS)
1305 ## targets-group-3 : build some targets
1306 targets-group-4: $(GROUP_4_TARGETS)
1308 ## targets-group-rest: build the rest of the targets (not listed in group 1, 2 or 3)
1309 targets-group-rest: $(GROUP_OTHER_TARGETS)
1312 $(VALID_TARGETS):
1313 $(V0) echo "" && \
1314 echo "Building $@" && \
1315 time $(MAKE) binary hex TARGET=$@ && \
1316 echo "Building $@ succeeded."
1320 CLEAN_TARGETS = $(addprefix clean_,$(VALID_TARGETS) )
1321 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
1323 ## clean : clean up temporary / machine-generated files
1324 clean:
1325 $(V0) echo "Cleaning $(TARGET)"
1326 $(V0) rm -f $(CLEAN_ARTIFACTS)
1327 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
1328 $(V0) echo "Cleaning $(TARGET) succeeded."
1330 ## clean_test : clean up temporary / machine-generated files (tests)
1331 clean_test:
1332 $(V0) cd src/test && $(MAKE) clean || true
1334 ## clean_<TARGET> : clean up one specific target
1335 $(CLEAN_TARGETS) :
1336 $(V0) $(MAKE) -j TARGET=$(subst clean_,,$@) clean
1338 ## <TARGET>_clean : clean up one specific target (alias for above)
1339 $(TARGETS_CLEAN) :
1340 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
1342 ## clean_all : clean all valid targets
1343 clean_all:$(CLEAN_TARGETS)
1345 ## all_clean : clean all valid targets (alias for above)
1346 all_clean:$(TARGETS_CLEAN)
1349 flash_$(TARGET): $(TARGET_HEX)
1350 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1351 $(V0) echo -n 'R' >$(SERIAL_DEVICE)
1352 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1354 ## flash : flash firmware (.hex) onto flight controller
1355 flash: flash_$(TARGET)
1357 st-flash_$(TARGET): $(TARGET_BIN)
1358 $(V0) st-flash --reset write $< 0x08000000
1360 ## st-flash : flash firmware (.bin) onto flight controller
1361 st-flash: st-flash_$(TARGET)
1363 binary:
1364 $(V0) $(MAKE) -j $(TARGET_BIN)
1366 hex:
1367 $(V0) $(MAKE) -j $(TARGET_HEX)
1369 unbrick_$(TARGET): $(TARGET_HEX)
1370 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1371 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1373 ## unbrick : unbrick flight controller
1374 unbrick: unbrick_$(TARGET)
1376 ## cppcheck : run static analysis on C source code
1377 cppcheck: $(CSOURCES)
1378 $(V0) $(CPPCHECK)
1380 cppcheck-result.xml: $(CSOURCES)
1381 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
1383 # mkdirs
1384 $(DL_DIR):
1385 mkdir -p $@
1387 $(TOOLS_DIR):
1388 mkdir -p $@
1390 $(BUILD_DIR):
1391 mkdir -p $@
1393 ## version : print firmware version
1394 version:
1395 @echo $(FC_VER)
1397 ## help : print this help message and exit
1398 help: Makefile make/tools.mk
1399 $(V0) @echo ""
1400 $(V0) @echo "Makefile for the $(FORKNAME) firmware"
1401 $(V0) @echo ""
1402 $(V0) @echo "Usage:"
1403 $(V0) @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
1404 $(V0) @echo "Or:"
1405 $(V0) @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
1406 $(V0) @echo ""
1407 $(V0) @echo "Valid TARGET values are: $(VALID_TARGETS)"
1408 $(V0) @echo ""
1409 $(V0) @sed -n 's/^## //p' $?
1411 ## targets : print a list of all valid target platforms (for consumption by scripts)
1412 targets:
1413 $(V0) @echo "Valid targets: $(VALID_TARGETS)"
1414 $(V0) @echo "Target: $(TARGET)"
1415 $(V0) @echo "Base target: $(BASE_TARGET)"
1416 $(V0) @echo "targets-group-1: $(GROUP_1_TARGETS)"
1417 $(V0) @echo "targets-group-2: $(GROUP_2_TARGETS)"
1418 $(V0) @echo "targets-group-3: $(GROUP_3_TARGETS)"
1419 $(V0) @echo "targets-group-4: $(GROUP_4_TARGETS)"
1420 $(V0) @echo "targets-group-rest: $(GROUP_OTHER_TARGETS)"
1422 ## test : run the cleanflight test suite
1423 ## junittest : run the cleanflight test suite, producing Junit XML result files.
1424 test junittest:
1425 $(V0) cd src/test && $(MAKE) $@
1427 # rebuild everything when makefile changes
1428 $(TARGET_OBJS) : Makefile
1430 # include auto-generated dependencies
1431 -include $(TARGET_DEPS)