target.h updated for DYSF4PRO
[betaflight.git] / Makefile
blob9acab8ad24aa2480880ec6636ac71343989ff51b
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 CLRACINGF4 \
123 COLIBRI \
124 COLIBRI_OPBL \
125 COLIBRI_RACE \
126 DOGE \
127 ELLE0 \
128 F4BY \
129 FISHDRONEF4 \
130 FLIP32F3OSD \
131 FF_ACROWHOOPSP \
132 FF_FORTINIF4 \
133 FF_KOMBINI \
134 FF_PIKOBLX \
135 FF_PIKOF4 \
136 FF_RADIANCE \
137 FRSKYF3 \
138 FRSKYF4 \
139 FURYF3 \
140 FURYF4 \
141 FURYF7 \
142 IMPULSERCF3 \
143 IRCFUSIONF3 \
144 ISHAPEDF3
146 GROUP_3_TARGETS := \
147 KAKUTEF4 \
148 KISSCC \
149 KIWIF4 \
150 LUX_RACE \
151 LUXV2_RACE \
152 MICROSCISKY \
153 MOTOLAB \
154 MULTIFLITEPICO \
155 NAZE \
156 NERO \
157 NUCLEOF7 \
158 OMNIBUS \
159 OMNIBUSF4 \
160 OMNIBUSF4SD \
161 PLUMF4 \
162 PODIUMF4 \
163 DYSF4PRO
165 GROUP_4_TARGETS := \
166 RCEXPLORERF3 \
167 REVO \
168 REVO_OPBL \
169 REVOLT \
170 REVONANO \
171 RMDO \
172 SINGULARITY \
173 SIRINFPV \
174 SOULF4 \
175 SPARKY \
176 SPARKY2 \
177 SPRACINGF3 \
178 SPRACINGF3EVO \
179 SPRACINGF3MINI \
180 SPRACINGF3NEO \
181 SPRACINGF3OSD \
182 SPRACINGF4EVO \
183 SPRACINGF4NEO \
184 STM32F3DISCOVERY \
185 TINYBEEF3
187 GROUP_OTHER_TARGETS := $(filter-out $(GROUP_1_TARGETS) $(GROUP_2_TARGETS) $(GROUP_3_TARGETS) $(GROUP_4_TARGETS), $(VALID_TARGETS))
190 ifeq ($(filter $(TARGET),$(ALT_TARGETS)), $(TARGET))
191 BASE_TARGET := $(firstword $(subst /,, $(subst ./src/main/target/,, $(dir $(wildcard $(ROOT)/src/main/target/*/$(TARGET).mk)))))
192 -include $(ROOT)/src/main/target/$(BASE_TARGET)/$(TARGET).mk
193 else
194 BASE_TARGET := $(TARGET)
195 endif
197 ifeq ($(filter $(TARGET),$(OPBL_TARGETS)), $(TARGET))
198 OPBL = yes
199 endif
201 ifeq ($(filter $(TARGET),$(OSD_SLAVE_TARGETS)), $(TARGET))
202 # build an OSD SLAVE
203 OSD_SLAVE = yes
204 else
205 # build an FC
206 FC = yes
207 endif
210 # silently ignore if the file is not present. Allows for target specific.
211 -include $(ROOT)/src/main/target/$(BASE_TARGET)/target.mk
213 F4_TARGETS = $(F405_TARGETS) $(F411_TARGETS) $(F446_TARGETS)
214 F7_TARGETS = $(F7X2RE_TARGETS) $(F7X5XE_TARGETS) $(F7X5XG_TARGETS) $(F7X5XI_TARGETS) $(F7X6XG_TARGETS)
216 ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
217 $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS). Have you prepared a valid target.mk?)
218 endif
220 ifeq ($(filter $(TARGET),$(F1_TARGETS) $(F3_TARGETS) $(F4_TARGETS) $(F7_TARGETS) $(SITL_TARGETS)),)
221 $(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?)
222 endif
224 128K_TARGETS = $(F1_TARGETS)
225 256K_TARGETS = $(F3_TARGETS)
226 512K_TARGETS = $(F411_TARGETS) $(F446_TARGETS) $(F7X2RE_TARGETS) $(F7X5XE_TARGETS)
227 1024K_TARGETS = $(F405_TARGETS) $(F7X5XG_TARGETS) $(F7X6XG_TARGETS)
228 2048K_TARGETS = $(F7X5XI_TARGETS) $(SITL_TARGETS)
230 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
231 ifeq ($(FLASH_SIZE),)
232 ifeq ($(TARGET),$(filter $(TARGET),$(2048K_TARGETS)))
233 FLASH_SIZE = 2048
234 else ifeq ($(TARGET),$(filter $(TARGET),$(1024K_TARGETS)))
235 FLASH_SIZE = 1024
236 else ifeq ($(TARGET),$(filter $(TARGET),$(512K_TARGETS)))
237 FLASH_SIZE = 512
238 else ifeq ($(TARGET),$(filter $(TARGET),$(256K_TARGETS)))
239 FLASH_SIZE = 256
240 else ifeq ($(TARGET),$(filter $(TARGET),$(128K_TARGETS)))
241 FLASH_SIZE = 128
242 else
243 $(error FLASH_SIZE not configured for target $(TARGET))
244 endif
245 endif
247 # note that there is no hardfault debugging startup file assembly handler for other platforms
248 ifeq ($(DEBUG_HARDFAULTS),F3)
249 CFLAGS += -DDEBUG_HARDFAULTS
250 STM32F30x_COMMON_SRC = startup_stm32f3_debug_hardfault_handler.S
251 else
252 STM32F30x_COMMON_SRC = startup_stm32f30x_md_gcc.S
253 endif
255 ifeq ($(DEBUG_HARDFAULTS),F7)
256 CFLAGS += -DDEBUG_HARDFAULTS
257 endif
259 REVISION := $(shell git log -1 --format="%h")
261 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
262 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
263 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
265 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
267 # Search path for sources
268 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
269 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
270 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
271 FATFS_DIR = $(ROOT)/lib/main/FatFS
272 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
274 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
276 ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
277 # F3 TARGETS
279 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver
280 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
281 EXCLUDES = stm32f30x_crc.c \
282 stm32f30x_can.c
283 STARTUP_SRC = startup_stm32f30x_md_gcc.S
285 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
286 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
288 VPATH := $(VPATH):$(CMSIS_DIR)/CM4/CoreSupport:$(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F30x
289 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM4/CoreSupport/*.c \
290 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F30x/*.c))
292 INCLUDE_DIRS := $(INCLUDE_DIRS) \
293 $(STDPERIPH_DIR)/inc \
294 $(CMSIS_DIR)/CM4/CoreSupport \
295 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F30x
297 ifneq ($(filter VCP, $(FEATURES)),)
298 INCLUDE_DIRS := $(INCLUDE_DIRS) \
299 $(USBFS_DIR)/inc \
300 $(ROOT)/src/main/vcp
302 VPATH := $(VPATH):$(USBFS_DIR)/src
304 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC)\
305 $(USBPERIPH_SRC)
306 endif
308 ifneq ($(filter SDCARD, $(FEATURES)),)
309 INCLUDE_DIRS := $(INCLUDE_DIRS) \
310 $(FATFS_DIR) \
312 VPATH := $(VPATH):$(FATFS_DIR)
313 endif
315 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k.ld
317 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
318 DEVICE_FLAGS = -DSTM32F303xC -DSTM32F303
319 # End F3 targets
321 # Start F4 targets
322 else ifeq ($(TARGET),$(filter $(TARGET), $(F4_TARGETS)))
324 #STDPERIPH
325 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F4xx_StdPeriph_Driver
326 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
327 EXCLUDES = stm32f4xx_crc.c \
328 stm32f4xx_can.c \
329 stm32f4xx_fmc.c \
330 stm32f4xx_sai.c \
331 stm32f4xx_cec.c \
332 stm32f4xx_dsi.c \
333 stm32f4xx_flash_ramfunc.c \
334 stm32f4xx_fmpi2c.c \
335 stm32f4xx_lptim.c \
336 stm32f4xx_qspi.c \
337 stm32f4xx_spdifrx.c \
338 stm32f4xx_cryp.c \
339 stm32f4xx_cryp_aes.c \
340 stm32f4xx_hash_md5.c \
341 stm32f4xx_cryp_des.c \
342 stm32f4xx_rtc.c \
343 stm32f4xx_hash.c \
344 stm32f4xx_dbgmcu.c \
345 stm32f4xx_cryp_tdes.c \
346 stm32f4xx_hash_sha1.c
348 ifeq ($(TARGET),$(filter $(TARGET), $(F411_TARGETS)))
349 EXCLUDES += stm32f4xx_fsmc.c
350 endif
352 ifeq ($(TARGET),$(filter $(TARGET), $(F446_TARGETS)))
353 EXCLUDES += stm32f4xx_fsmc.c
354 endif
356 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
358 #USB
359 USBCORE_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Core
360 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/src/*.c))
361 USBOTG_DIR = $(ROOT)/lib/main/STM32_USB_OTG_Driver
362 USBOTG_SRC = $(notdir $(wildcard $(USBOTG_DIR)/src/*.c))
363 EXCLUDES = usb_bsp_template.c \
364 usb_conf_template.c \
365 usb_hcd_int.c \
366 usb_hcd.c \
367 usb_otg.c
369 USBOTG_SRC := $(filter-out ${EXCLUDES}, $(USBOTG_SRC))
370 USBCDC_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Class/cdc
371 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/src/*.c))
372 EXCLUDES = usbd_cdc_if_template.c
373 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
374 VPATH := $(VPATH):$(USBOTG_DIR)/src:$(USBCORE_DIR)/src:$(USBCDC_DIR)/src
376 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
377 $(USBOTG_SRC) \
378 $(USBCORE_SRC) \
379 $(USBCDC_SRC)
381 #CMSIS
382 VPATH := $(VPATH):$(CMSIS_DIR)/CM4/CoreSupport:$(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx
383 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM4/CoreSupport/*.c \
384 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx/*.c))
385 INCLUDE_DIRS := $(INCLUDE_DIRS) \
386 $(STDPERIPH_DIR)/inc \
387 $(USBOTG_DIR)/inc \
388 $(USBCORE_DIR)/inc \
389 $(USBCDC_DIR)/inc \
390 $(USBFS_DIR)/inc \
391 $(CMSIS_DIR)/CM4/CoreSupport \
392 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx \
393 $(ROOT)/src/main/vcpf4
395 ifneq ($(filter SDCARD,$(FEATURES)),)
396 INCLUDE_DIRS := $(INCLUDE_DIRS) \
397 $(FATFS_DIR)
398 VPATH := $(VPATH):$(FATFS_DIR)
399 endif
401 #Flags
402 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
404 ifeq ($(TARGET),$(filter $(TARGET),$(F411_TARGETS)))
405 DEVICE_FLAGS = -DSTM32F411xE
406 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411.ld
407 STARTUP_SRC = startup_stm32f411xe.s
408 else ifeq ($(TARGET),$(filter $(TARGET),$(F405_TARGETS)))
409 DEVICE_FLAGS = -DSTM32F40_41xxx
410 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405.ld
411 STARTUP_SRC = startup_stm32f40xx.s
412 else ifeq ($(TARGET),$(filter $(TARGET),$(F446_TARGETS)))
413 DEVICE_FLAGS = -DSTM32F446xx
414 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f446.ld
415 STARTUP_SRC = startup_stm32f446xx.s
416 else
417 $(error Unknown MCU for F4 target)
418 endif
419 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE)
421 # End F4 targets
423 # Start F7 targets
424 else ifeq ($(TARGET),$(filter $(TARGET), $(F7_TARGETS)))
426 #STDPERIPH
427 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F7xx_HAL_Driver
428 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/Src/*.c))
429 EXCLUDES = stm32f7xx_hal_can.c \
430 stm32f7xx_hal_cec.c \
431 stm32f7xx_hal_crc.c \
432 stm32f7xx_hal_crc_ex.c \
433 stm32f7xx_hal_cryp.c \
434 stm32f7xx_hal_cryp_ex.c \
435 stm32f7xx_hal_dac.c \
436 stm32f7xx_hal_dac_ex.c \
437 stm32f7xx_hal_dcmi.c \
438 stm32f7xx_hal_dcmi_ex.c \
439 stm32f7xx_hal_dfsdm.c \
440 stm32f7xx_hal_dma2d.c \
441 stm32f7xx_hal_dsi.c \
442 stm32f7xx_hal_eth.c \
443 stm32f7xx_hal_hash.c \
444 stm32f7xx_hal_hash_ex.c \
445 stm32f7xx_hal_hcd.c \
446 stm32f7xx_hal_i2s.c \
447 stm32f7xx_hal_irda.c \
448 stm32f7xx_hal_iwdg.c \
449 stm32f7xx_hal_jpeg.c \
450 stm32f7xx_hal_lptim.c \
451 stm32f7xx_hal_ltdc.c \
452 stm32f7xx_hal_ltdc_ex.c \
453 stm32f7xx_hal_mdios.c \
454 stm32f7xx_hal_mmc.c \
455 stm32f7xx_hal_msp_template.c \
456 stm32f7xx_hal_nand.c \
457 stm32f7xx_hal_nor.c \
458 stm32f7xx_hal_qspi.c \
459 stm32f7xx_hal_rng.c \
460 stm32f7xx_hal_rtc.c \
461 stm32f7xx_hal_rtc_ex.c \
462 stm32f7xx_hal_sai.c \
463 stm32f7xx_hal_sai_ex.c \
464 stm32f7xx_hal_sd.c \
465 stm32f7xx_hal_sdram.c \
466 stm32f7xx_hal_smartcard.c \
467 stm32f7xx_hal_smartcard_ex.c \
468 stm32f7xx_hal_smbus.c \
469 stm32f7xx_hal_spdifrx.c \
470 stm32f7xx_hal_sram.c \
471 stm32f7xx_hal_timebase_rtc_alarm_template.c \
472 stm32f7xx_hal_timebase_rtc_wakeup_template.c \
473 stm32f7xx_hal_timebase_tim_template.c \
474 stm32f7xx_hal_wwdg.c \
475 stm32f7xx_ll_adc.c \
476 stm32f7xx_ll_crc.c \
477 stm32f7xx_ll_dac.c \
478 stm32f7xx_ll_dma.c \
479 stm32f7xx_ll_dma2d.c \
480 stm32f7xx_ll_exti.c \
481 stm32f7xx_ll_fmc.c \
482 stm32f7xx_ll_gpio.c \
483 stm32f7xx_ll_i2c.c \
484 stm32f7xx_ll_lptim.c \
485 stm32f7xx_ll_pwr.c \
486 stm32f7xx_ll_rcc.c \
487 stm32f7xx_ll_rng.c \
488 stm32f7xx_ll_rtc.c \
489 stm32f7xx_ll_sdmmc.c \
490 stm32f7xx_ll_spi.c \
491 stm32f7xx_ll_tim.c \
492 stm32f7xx_ll_usart.c \
493 stm32f7xx_ll_utils.c
495 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
497 #USB
498 USBCORE_DIR = $(ROOT)/lib/main/Middlewares/ST/STM32_USB_Device_Library/Core
499 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/Src/*.c))
500 EXCLUDES = usbd_conf_template.c
501 USBCORE_SRC := $(filter-out ${EXCLUDES}, $(USBCORE_SRC))
503 USBCDC_DIR = $(ROOT)/lib/main/Middlewares/ST/STM32_USB_Device_Library/Class/CDC
504 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/Src/*.c))
505 EXCLUDES = usbd_cdc_if_template.c
506 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
508 VPATH := $(VPATH):$(USBCDC_DIR)/Src:$(USBCORE_DIR)/Src
510 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
511 $(USBCORE_SRC) \
512 $(USBCDC_SRC)
514 #CMSIS
515 VPATH := $(VPATH):$(CMSIS_DIR)/CM7/Include:$(CMSIS_DIR)/CM7/Device/ST/STM32F7xx
516 VPATH := $(VPATH):$(STDPERIPH_DIR)/Src
517 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM7/Include/*.c \
518 $(CMSIS_DIR)/CM7/Device/ST/STM32F7xx/*.c))
519 INCLUDE_DIRS := $(INCLUDE_DIRS) \
520 $(STDPERIPH_DIR)/Inc \
521 $(USBCORE_DIR)/Inc \
522 $(USBCDC_DIR)/Inc \
523 $(CMSIS_DIR)/CM7/Include \
524 $(CMSIS_DIR)/CM7/Device/ST/STM32F7xx/Include \
525 $(ROOT)/src/main/vcp_hal
527 ifneq ($(filter SDCARD,$(FEATURES)),)
528 INCLUDE_DIRS := $(INCLUDE_DIRS) \
529 $(FATFS_DIR)
530 VPATH := $(VPATH):$(FATFS_DIR)
531 endif
533 #Flags
534 ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsingle-precision-constant -Wdouble-promotion
536 ifeq ($(TARGET),$(filter $(TARGET),$(F7X5XG_TARGETS)))
537 DEVICE_FLAGS = -DSTM32F745xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
538 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f745.ld
539 STARTUP_SRC = startup_stm32f745xx.s
540 else ifeq ($(TARGET),$(filter $(TARGET),$(F7X6XG_TARGETS)))
541 DEVICE_FLAGS = -DSTM32F746xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
542 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f746.ld
543 STARTUP_SRC = startup_stm32f746xx.s
544 else ifeq ($(TARGET),$(filter $(TARGET),$(F7X2RE_TARGETS)))
545 DEVICE_FLAGS = -DSTM32F722xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
546 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f722.ld
547 STARTUP_SRC = startup_stm32f722xx.s
548 else
549 $(error Unknown MCU for F7 target)
550 endif
551 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE)
553 TARGET_FLAGS = -D$(TARGET)
555 # End F7 targets
557 # Start SITL targets
558 else ifeq ($(TARGET),$(filter $(TARGET), $(SITL_TARGETS)))
560 INCLUDE_DIRS := $(INCLUDE_DIRS) \
561 $(ROOT)/lib/main/dyad
563 SITL_SRC := $(ROOT)/lib/main/dyad/dyad.c
565 #Flags
566 ARCH_FLAGS =
567 DEVICE_FLAGS =
568 LD_SCRIPT = src/main/target/SITL/parameter_group.ld
569 STARTUP_SRC =
571 TARGET_FLAGS = -D$(TARGET)
573 ARM_SDK_PREFIX =
575 # End SITL targets
577 # Start F1 targets
578 else
580 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
581 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
582 EXCLUDES = stm32f10x_crc.c \
583 stm32f10x_cec.c \
584 stm32f10x_can.c
585 STARTUP_SRC = startup_stm32f10x_md_gcc.S
586 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
588 # Search path and source files for the CMSIS sources
589 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
590 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
591 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
593 INCLUDE_DIRS := $(INCLUDE_DIRS) \
594 $(STDPERIPH_DIR)/inc \
595 $(CMSIS_DIR)/CM3/CoreSupport \
596 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
598 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
600 ifneq ($(filter VCP, $(FEATURES)),)
601 INCLUDE_DIRS := $(INCLUDE_DIRS) \
602 $(USBFS_DIR)/inc \
603 $(ROOT)/src/main/vcp
605 VPATH := $(VPATH):$(USBFS_DIR)/src
607 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
608 $(USBPERIPH_SRC)
610 endif
612 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
613 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
615 ifeq ($(DEVICE_FLAGS),)
616 DEVICE_FLAGS = -DSTM32F10X_MD
617 endif
618 DEVICE_FLAGS += -DSTM32F10X
620 endif
622 # End F1 targets
624 ifneq ($(BASE_TARGET), $(TARGET))
625 TARGET_FLAGS := $(TARGET_FLAGS) -D$(BASE_TARGET)
626 endif
628 ifneq ($(FLASH_SIZE),)
629 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
630 endif
632 ifneq ($(HSE_VALUE),)
633 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
634 endif
636 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
637 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
639 ifeq ($(OPBL),yes)
640 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
641 ifeq ($(TARGET), $(filter $(TARGET),$(F405_TARGETS)))
642 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405_opbl.ld
643 else ifeq ($(TARGET), $(filter $(TARGET),$(F411_TARGETS)))
644 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411_opbl.ld
645 else ifeq ($(TARGET), $(filter $(TARGET),$(F3_TARGETS)))
646 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k_opbl.ld
647 else ifeq ($(TARGET), $(filter $(TARGET),$(F1_TARGETS)))
648 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k_opbl.ld
649 endif
650 .DEFAULT_GOAL := binary
651 else
652 .DEFAULT_GOAL := hex
653 endif
655 INCLUDE_DIRS := $(INCLUDE_DIRS) \
656 $(ROOT)/lib/main/MAVLink
658 INCLUDE_DIRS := $(INCLUDE_DIRS) \
659 $(TARGET_DIR)
661 VPATH := $(VPATH):$(TARGET_DIR)
663 COMMON_SRC = \
664 build/build_config.c \
665 build/debug.c \
666 build/version.c \
667 $(TARGET_DIR_SRC) \
668 main.c \
669 common/bitarray.c \
670 common/encoding.c \
671 common/filter.c \
672 common/maths.c \
673 common/printf.c \
674 common/streambuf.c \
675 common/typeconversion.c \
676 config/config_eeprom.c \
677 config/feature.c \
678 config/parameter_group.c \
679 config/config_streamer.c \
680 drivers/adc.c \
681 drivers/buf_writer.c \
682 drivers/bus_i2c_config.c \
683 drivers/bus_i2c_soft.c \
684 drivers/bus_spi.c \
685 drivers/bus_spi_config.c \
686 drivers/bus_spi_pinconfig.c \
687 drivers/bus_spi_soft.c \
688 drivers/buttons.c \
689 drivers/display.c \
690 drivers/exti.c \
691 drivers/io.c \
692 drivers/light_led.c \
693 drivers/resource.c \
694 drivers/rcc.c \
695 drivers/serial.c \
696 drivers/serial_pinconfig.c \
697 drivers/serial_uart.c \
698 drivers/serial_uart_pinconfig.c \
699 drivers/sound_beeper.c \
700 drivers/stack_check.c \
701 drivers/system.c \
702 drivers/timer.c \
703 drivers/transponder_ir.c \
704 drivers/transponder_ir_arcitimer.c \
705 drivers/transponder_ir_ilap.c \
706 drivers/transponder_ir_erlt.c \
707 fc/config.c \
708 fc/fc_dispatch.c \
709 fc/fc_hardfaults.c \
710 fc/fc_msp.c \
711 fc/fc_tasks.c \
712 fc/runtime_config.c \
713 io/beeper.c \
714 io/serial.c \
715 io/statusindicator.c \
716 io/transponder_ir.c \
717 io/rcsplit.c \
718 msp/msp_serial.c \
719 scheduler/scheduler.c \
720 sensors/battery.c \
721 sensors/current.c \
722 sensors/voltage.c \
724 OSD_SLAVE_SRC = \
725 io/displayport_max7456.c \
726 osd_slave/osd_slave_init.c \
727 io/osd_slave.c
729 FC_SRC = \
730 fc/fc_init.c \
731 fc/controlrate_profile.c \
732 drivers/gyro_sync.c \
733 drivers/rx_nrf24l01.c \
734 drivers/rx_spi.c \
735 drivers/rx_xn297.c \
736 drivers/pwm_esc_detect.c \
737 drivers/pwm_output.c \
738 drivers/rx_pwm.c \
739 drivers/serial_softserial.c \
740 fc/fc_core.c \
741 fc/fc_rc.c \
742 fc/rc_adjustments.c \
743 fc/rc_controls.c \
744 fc/rc_modes.c \
745 fc/cli.c \
746 fc/settings.c \
747 flight/altitude.c \
748 flight/failsafe.c \
749 flight/imu.c \
750 flight/mixer.c \
751 flight/pid.c \
752 flight/servos.c \
753 io/serial_4way.c \
754 io/serial_4way_avrootloader.c \
755 io/serial_4way_stk500v2.c \
756 rx/ibus.c \
757 rx/jetiexbus.c \
758 rx/msp.c \
759 rx/nrf24_cx10.c \
760 rx/nrf24_inav.c \
761 rx/nrf24_h8_3d.c \
762 rx/nrf24_syma.c \
763 rx/nrf24_v202.c \
764 rx/pwm.c \
765 rx/rx.c \
766 rx/rx_spi.c \
767 rx/crsf.c \
768 rx/sbus.c \
769 rx/spektrum.c \
770 rx/sumd.c \
771 rx/sumh.c \
772 rx/xbus.c \
773 sensors/acceleration.c \
774 sensors/boardalignment.c \
775 sensors/compass.c \
776 sensors/gyro.c \
777 sensors/gyroanalyse.c \
778 sensors/initialisation.c \
779 blackbox/blackbox.c \
780 blackbox/blackbox_encoding.c \
781 blackbox/blackbox_io.c \
782 cms/cms.c \
783 cms/cms_menu_blackbox.c \
784 cms/cms_menu_builtin.c \
785 cms/cms_menu_imu.c \
786 cms/cms_menu_ledstrip.c \
787 cms/cms_menu_misc.c \
788 cms/cms_menu_osd.c \
789 common/colorconversion.c \
790 common/gps_conversion.c \
791 drivers/display_ug2864hsweg01.c \
792 drivers/light_ws2811strip.c \
793 drivers/serial_escserial.c \
794 drivers/sonar_hcsr04.c \
795 drivers/vtx_common.c \
796 flight/navigation.c \
797 io/dashboard.c \
798 io/displayport_max7456.c \
799 io/displayport_msp.c \
800 io/displayport_oled.c \
801 io/gps.c \
802 io/ledstrip.c \
803 io/osd.c \
804 sensors/sonar.c \
805 sensors/barometer.c \
806 telemetry/telemetry.c \
807 telemetry/crsf.c \
808 telemetry/srxl.c \
809 telemetry/frsky.c \
810 telemetry/hott.c \
811 telemetry/smartport.c \
812 telemetry/ltm.c \
813 telemetry/mavlink.c \
814 telemetry/ibus.c \
815 telemetry/ibus_shared.c \
816 sensors/esc_sensor.c \
817 io/vtx_string.c \
818 io/vtx_rtc6705.c \
819 io/vtx_smartaudio.c \
820 io/vtx_tramp.c \
821 io/vtx_control.c
823 COMMON_DEVICE_SRC = \
824 $(CMSIS_SRC) \
825 $(DEVICE_STDPERIPH_SRC)
827 ifeq ($(OSD_SLAVE),yes)
828 TARGET_FLAGS := -DUSE_OSD_SLAVE $(TARGET_FLAGS)
829 COMMON_SRC := $(COMMON_SRC) $(OSD_SLAVE_SRC) $(COMMON_DEVICE_SRC)
830 else
831 COMMON_SRC := $(COMMON_SRC) $(FC_SRC) $(COMMON_DEVICE_SRC)
832 endif
835 SPEED_OPTIMISED_SRC := ""
836 SIZE_OPTIMISED_SRC := ""
838 ifneq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
839 SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
840 common/encoding.c \
841 common/filter.c \
842 common/maths.c \
843 common/typeconversion.c \
844 drivers/adc.c \
845 drivers/buf_writer.c \
846 drivers/bus_spi.c \
847 drivers/exti.c \
848 drivers/gyro_sync.c \
849 drivers/io.c \
850 drivers/pwm_output.c \
851 drivers/rcc.c \
852 drivers/serial.c \
853 drivers/serial_uart.c \
854 drivers/system.c \
855 drivers/timer.c \
856 fc/fc_core.c \
857 fc/fc_tasks.c \
858 fc/fc_rc.c \
859 fc/rc_controls.c \
860 fc/runtime_config.c \
861 flight/imu.c \
862 flight/mixer.c \
863 flight/pid.c \
864 io/serial.c \
865 rx/ibus.c \
866 rx/jetiexbus.c \
867 rx/rx.c \
868 rx/rx_spi.c \
869 rx/crsf.c \
870 rx/sbus.c \
871 rx/spektrum.c \
872 rx/sumd.c \
873 rx/sumh.c \
874 rx/xbus.c \
875 scheduler/scheduler.c \
876 sensors/acceleration.c \
877 sensors/boardalignment.c \
878 sensors/gyro.c \
879 sensors/gyroanalyse.c \
880 $(CMSIS_SRC) \
881 $(DEVICE_STDPERIPH_SRC) \
882 drivers/light_ws2811strip.c \
883 io/displayport_max7456.c \
884 io/osd.c \
885 io/osd_slave.c
887 SIZE_OPTIMISED_SRC := $(SIZE_OPTIMISED_SRC) \
888 drivers/bus_i2c_config.c \
889 drivers/bus_spi_config.c \
890 drivers/bus_spi_pinconfig.c \
891 drivers/serial_escserial.c \
892 drivers/serial_pinconfig.c \
893 drivers/serial_uart_init.c \
894 drivers/serial_uart_pinconfig.c \
895 drivers/vtx_rtc6705_soft_spi.c \
896 drivers/vtx_rtc6705.c \
897 drivers/vtx_common.c \
898 fc/fc_init.c \
899 fc/cli.c \
900 fc/settings.c \
901 config/config_eeprom.c \
902 config/feature.c \
903 config/parameter_group.c \
904 config/config_streamer.c \
905 io/serial_4way.c \
906 io/serial_4way_avrootloader.c \
907 io/serial_4way_stk500v2.c \
908 io/dashboard.c \
909 msp/msp_serial.c \
910 cms/cms.c \
911 cms/cms_menu_blackbox.c \
912 cms/cms_menu_builtin.c \
913 cms/cms_menu_imu.c \
914 cms/cms_menu_ledstrip.c \
915 cms/cms_menu_misc.c \
916 cms/cms_menu_osd.c \
917 io/vtx_string.c \
918 io/vtx_rtc6705.c \
919 io/vtx_smartaudio.c \
920 io/vtx_tramp.c \
921 io/vtx_control.c
922 endif #!F1
924 ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS)))
925 VCP_SRC = \
926 vcpf4/stm32f4xx_it.c \
927 vcpf4/usb_bsp.c \
928 vcpf4/usbd_desc.c \
929 vcpf4/usbd_usr.c \
930 vcpf4/usbd_cdc_vcp.c \
931 drivers/serial_usb_vcp.c \
932 drivers/usb_io.c
933 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
934 VCP_SRC = \
935 vcp_hal/usbd_desc.c \
936 vcp_hal/usbd_conf.c \
937 vcp_hal/usbd_cdc_interface.c \
938 drivers/serial_usb_vcp.c \
939 drivers/usb_io.c
940 else
941 VCP_SRC = \
942 vcp/hw_config.c \
943 vcp/stm32_it.c \
944 vcp/usb_desc.c \
945 vcp/usb_endp.c \
946 vcp/usb_istr.c \
947 vcp/usb_prop.c \
948 vcp/usb_pwr.c \
949 drivers/serial_usb_vcp.c \
950 drivers/usb_io.c
951 endif
953 STM32F10x_COMMON_SRC = \
954 drivers/adc_stm32f10x.c \
955 drivers/bus_i2c_stm32f10x.c \
956 drivers/dma.c \
957 drivers/gpio_stm32f10x.c \
958 drivers/inverter.c \
959 drivers/light_ws2811strip_stdperiph.c \
960 drivers/serial_uart_init.c \
961 drivers/serial_uart_stm32f10x.c \
962 drivers/system_stm32f10x.c \
963 drivers/timer_stm32f10x.c
965 STM32F30x_COMMON_SRC = \
966 target/system_stm32f30x.c \
967 drivers/adc_stm32f30x.c \
968 drivers/bus_i2c_stm32f30x.c \
969 drivers/dma.c \
970 drivers/gpio_stm32f30x.c \
971 drivers/light_ws2811strip_stdperiph.c \
972 drivers/pwm_output_dshot.c \
973 drivers/serial_uart_init.c \
974 drivers/serial_uart_stm32f30x.c \
975 drivers/system_stm32f30x.c \
976 drivers/timer_stm32f30x.c
978 STM32F4xx_COMMON_SRC = \
979 target/system_stm32f4xx.c \
980 drivers/accgyro/accgyro_mpu.c \
981 drivers/adc_stm32f4xx.c \
982 drivers/bus_i2c_stm32f10x.c \
983 drivers/dma_stm32f4xx.c \
984 drivers/gpio_stm32f4xx.c \
985 drivers/inverter.c \
986 drivers/light_ws2811strip_stdperiph.c \
987 drivers/pwm_output_dshot.c \
988 drivers/serial_uart_init.c \
989 drivers/serial_uart_stm32f4xx.c \
990 drivers/system_stm32f4xx.c \
991 drivers/timer_stm32f4xx.c
993 STM32F7xx_COMMON_SRC = \
994 target/system_stm32f7xx.c \
995 drivers/accgyro/accgyro_mpu.c \
996 drivers/adc_stm32f7xx.c \
997 drivers/bus_i2c_hal.c \
998 drivers/dma_stm32f7xx.c \
999 drivers/gpio_stm32f7xx.c \
1000 drivers/light_ws2811strip_hal.c \
1001 drivers/bus_spi_hal.c \
1002 drivers/pwm_output_dshot_hal.c \
1003 drivers/timer_hal.c \
1004 drivers/timer_stm32f7xx.c \
1005 drivers/system_stm32f7xx.c \
1006 drivers/serial_uart_stm32f7xx.c \
1007 drivers/serial_uart_hal.c
1009 F7EXCLUDES = \
1010 drivers/bus_spi.c \
1011 drivers/bus_i2c.c \
1012 drivers/timer.c \
1013 drivers/serial_uart.c
1015 SITLEXCLUDES = \
1016 drivers/adc.c \
1017 drivers/bus_i2c.c \
1018 drivers/bus_i2c_config.c \
1019 drivers/bus_spi.c \
1020 drivers/bus_spi_config.c \
1021 drivers/bus_spi_pinconfig.c \
1022 drivers/dma.c \
1023 drivers/pwm_output.c \
1024 drivers/timer.c \
1025 drivers/light_led.c \
1026 drivers/system.c \
1027 drivers/rcc.c \
1028 drivers/serial_escserial.c \
1029 drivers/serial_pinconfig.c \
1030 drivers/serial_uart.c \
1031 drivers/serial_uart_init.c \
1032 drivers/serial_uart_pinconfig.c \
1033 drivers/rx_xn297.c \
1034 drivers/display_ug2864hsweg01.c \
1035 telemetry/crsf.c \
1036 telemetry/srxl.c \
1037 io/displayport_oled.c
1040 # check if target.mk supplied
1041 ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS)))
1042 SRC := $(STARTUP_SRC) $(STM32F4xx_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1043 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
1044 SRC := $(STARTUP_SRC) $(STM32F7xx_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1045 else ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
1046 SRC := $(STARTUP_SRC) $(STM32F30x_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1047 else ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
1048 SRC := $(STARTUP_SRC) $(STM32F10x_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
1049 else ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1050 SRC := $(TARGET_SRC) $(SITL_SRC) $(VARIANT_SRC)
1051 endif
1053 ifneq ($(filter $(TARGET),$(F3_TARGETS) $(F4_TARGETS) $(F7_TARGETS)),)
1054 DSPLIB := $(ROOT)/lib/main/DSP_Lib
1055 DEVICE_FLAGS += -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1 -DUNALIGNED_SUPPORT_DISABLE
1057 ifneq ($(filter $(TARGET),$(F3_TARGETS)) $(F4_TARGETS)),)
1058 DEVICE_FLAGS += -DARM_MATH_CM4
1059 endif
1060 ifneq ($(filter $(TARGET),$(F7_TARGETS)),)
1061 DEVICE_FLAGS += -DARM_MATH_CM7
1062 endif
1064 INCLUDE_DIRS += $(DSPLIB)/Include
1066 SRC += $(DSPLIB)/Source/BasicMathFunctions/arm_mult_f32.c
1067 SRC += $(DSPLIB)/Source/TransformFunctions/arm_rfft_fast_f32.c
1068 SRC += $(DSPLIB)/Source/TransformFunctions/arm_cfft_f32.c
1069 SRC += $(DSPLIB)/Source/TransformFunctions/arm_rfft_fast_init_f32.c
1070 SRC += $(DSPLIB)/Source/TransformFunctions/arm_cfft_radix8_f32.c
1071 SRC += $(DSPLIB)/Source/CommonTables/arm_common_tables.c
1073 SRC += $(DSPLIB)/Source/ComplexMathFunctions/arm_cmplx_mag_f32.c
1074 SRC += $(DSPLIB)/Source/StatisticsFunctions/arm_max_f32.c
1076 SRC += $(wildcard $(DSPLIB)/Source/*/*.S)
1078 endif
1081 ifneq ($(filter ONBOARDFLASH,$(FEATURES)),)
1082 SRC += \
1083 drivers/flash_m25p16.c \
1084 io/flashfs.c
1085 endif
1087 SRC += $(COMMON_SRC)
1089 #excludes
1090 ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
1091 SRC := $(filter-out ${F7EXCLUDES}, $(SRC))
1092 endif
1094 #SITL excludes
1095 ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1096 SRC := $(filter-out ${SITLEXCLUDES}, $(SRC))
1097 endif
1099 ifneq ($(filter SDCARD,$(FEATURES)),)
1100 SRC += \
1101 drivers/sdcard.c \
1102 drivers/sdcard_standard.c \
1103 io/asyncfatfs/asyncfatfs.c \
1104 io/asyncfatfs/fat_standard.c
1105 endif
1107 ifneq ($(filter VCP,$(FEATURES)),)
1108 SRC += $(VCP_SRC)
1109 endif
1110 # end target specific make file checks
1113 # Search path and source files for the ST stdperiph library
1114 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
1116 ###############################################################################
1117 # Things that might need changing to use different tools
1120 # Find out if ccache is installed on the system
1121 CCACHE := ccache
1122 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
1123 ifneq ($(RESULT),0)
1124 CCACHE :=
1125 endif
1127 # Tool names
1128 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
1129 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
1130 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
1131 OBJDUMP := $(ARM_SDK_PREFIX)objdump
1132 SIZE := $(ARM_SDK_PREFIX)size
1135 # Tool options.
1138 ifneq ($(DEBUG),GDB)
1139 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
1140 OPTIMISE_SPEED :=
1141 OPTIMISE_SIZE :=
1143 ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
1144 OPTIMISE_DEFAULT := -Os
1146 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
1148 else ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1149 OPTIMISE_DEFAULT := -Ofast
1150 OPTIMISE_SPEED := -Ofast
1151 OPTIMISE_SIZE := -Os
1153 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
1155 else
1156 OPTIMISE_DEFAULT := -O2
1157 OPTIMISE_SPEED := -Ofast
1158 OPTIMISE_SIZE := -Os
1160 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
1162 endif #TARGETS
1164 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
1165 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
1166 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
1168 else #DEBUG
1169 OPTIMISE_DEFAULT := -Og
1171 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
1173 LTO_FLAGS := $(OPTIMISE_DEFAULT)
1174 endif #DEBUG
1176 DEBUG_FLAGS = -ggdb3 -DDEBUG
1178 CFLAGS += $(ARCH_FLAGS) \
1179 $(addprefix -D,$(OPTIONS)) \
1180 $(addprefix -I,$(INCLUDE_DIRS)) \
1181 $(DEBUG_FLAGS) \
1182 -std=gnu99 \
1183 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
1184 -ffunction-sections \
1185 -fdata-sections \
1186 -pedantic \
1187 $(DEVICE_FLAGS) \
1188 -DUSE_STDPERIPH_DRIVER \
1189 -D$(TARGET) \
1190 $(TARGET_FLAGS) \
1191 -D'__FORKNAME__="$(FORKNAME)"' \
1192 -D'__TARGET__="$(TARGET)"' \
1193 -D'__REVISION__="$(REVISION)"' \
1194 -save-temps=obj \
1195 -MMD -MP \
1196 $(EXTRA_FLAGS)
1199 ASFLAGS = $(ARCH_FLAGS) \
1200 -x assembler-with-cpp \
1201 $(addprefix -I,$(INCLUDE_DIRS)) \
1202 -MMD -MP
1204 LDFLAGS = -lm \
1205 -nostartfiles \
1206 --specs=nano.specs \
1207 -lc \
1208 -lnosys \
1209 $(ARCH_FLAGS) \
1210 $(LTO_FLAGS) \
1211 $(DEBUG_FLAGS) \
1212 -static \
1213 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
1214 -Wl,-L$(LINKER_DIR) \
1215 -Wl,--cref \
1216 -Wl,--no-wchar-size-warning \
1217 -T$(LD_SCRIPT)
1219 #SITL compile
1220 ifeq ($(TARGET),$(filter $(TARGET),$(SITL_TARGETS)))
1221 LDFLAGS = \
1222 -lm \
1223 -lpthread \
1224 -lc \
1225 -lrt \
1226 $(ARCH_FLAGS) \
1227 $(LTO_FLAGS) \
1228 $(DEBUG_FLAGS) \
1229 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
1230 -Wl,-L$(LINKER_DIR) \
1231 -Wl,--cref \
1232 -T$(LD_SCRIPT)
1234 ifneq ($(filter SITL_STATIC,$(OPTIONS)),)
1235 LDFLAGS += \
1236 -static \
1237 -static-libgcc
1238 endif
1239 endif
1241 ###############################################################################
1242 # No user-serviceable parts below
1243 ###############################################################################
1245 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
1246 --std=c99 --inline-suppr --quiet --force \
1247 $(addprefix -I,$(INCLUDE_DIRS)) \
1248 -I/usr/include -I/usr/include/linux
1251 # Things we will build
1253 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
1254 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
1255 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
1256 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
1257 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
1258 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
1259 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
1262 CLEAN_ARTIFACTS := $(TARGET_BIN)
1263 CLEAN_ARTIFACTS += $(TARGET_HEX)
1264 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
1265 CLEAN_ARTIFACTS += $(TARGET_LST)
1267 # Make sure build date and revision is updated on every incremental build
1268 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
1270 # List of buildable ELF files and their object dependencies.
1271 # It would be nice to compute these lists, but that seems to be just beyond make.
1273 $(TARGET_LST): $(TARGET_ELF)
1274 $(V0) $(OBJDUMP) -S --disassemble $< > $@
1276 $(TARGET_HEX): $(TARGET_ELF)
1277 $(V0) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
1279 $(TARGET_BIN): $(TARGET_ELF)
1280 $(V0) $(OBJCOPY) -O binary $< $@
1282 $(TARGET_ELF): $(TARGET_OBJS)
1283 $(V1) echo Linking $(TARGET)
1284 $(V1) $(CROSS_CC) -o $@ $^ $(LDFLAGS)
1285 $(V0) $(SIZE) $(TARGET_ELF)
1287 # Compile
1288 ifneq ($(DEBUG),GDB)
1289 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1290 $(V1) mkdir -p $(dir $@)
1291 $(V1) $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
1292 echo "%% (speed optimised) $(notdir $<)" "$(STDOUT)" && \
1293 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SPEED_OPTIMISATION) $<, \
1294 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
1295 echo "%% (size optimised) $(notdir $<)" "$(STDOUT)" && \
1296 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SIZE_OPTIMISATION) $<, \
1297 echo "%% $(notdir $<)" "$(STDOUT)" && \
1298 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEFAULT_OPTIMISATION) $<))
1299 else
1300 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1301 $(V1) mkdir -p $(dir $@)
1302 $(V1) echo "%% $(notdir $<)" "$(STDOUT)" && \
1303 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEBUG_OPTIMISATION) $<
1304 endif
1306 # Assemble
1307 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
1308 $(V1) mkdir -p $(dir $@)
1309 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1310 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1312 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
1313 $(V1) mkdir -p $(dir $@)
1314 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1315 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1318 ## all : Build all valid targets
1319 all: $(VALID_TARGETS)
1321 ## official : Build all official (travis) targets
1322 official: $(OFFICIAL_TARGETS)
1324 ## targets-group-1 : build some targets
1325 targets-group-1: $(GROUP_1_TARGETS)
1327 ## targets-group-2 : build some targets
1328 targets-group-2: $(GROUP_2_TARGETS)
1330 ## targets-group-3 : build some targets
1331 targets-group-3: $(GROUP_3_TARGETS)
1333 ## targets-group-3 : build some targets
1334 targets-group-4: $(GROUP_4_TARGETS)
1336 ## targets-group-rest: build the rest of the targets (not listed in group 1, 2 or 3)
1337 targets-group-rest: $(GROUP_OTHER_TARGETS)
1340 $(VALID_TARGETS):
1341 $(V0) @echo "" && \
1342 echo "Building $@" && \
1343 time $(MAKE) binary hex TARGET=$@ && \
1344 echo "Building $@ succeeded."
1346 CLEAN_TARGETS = $(addprefix clean_,$(VALID_TARGETS) )
1347 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
1349 ## clean : clean up temporary / machine-generated files
1350 clean:
1351 $(V0) @echo "Cleaning $(TARGET)"
1352 $(V0) rm -f $(CLEAN_ARTIFACTS)
1353 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
1354 $(V0) @echo "Cleaning $(TARGET) succeeded."
1356 ## clean_test : clean up temporary / machine-generated files (tests)
1357 clean_test:
1358 $(V0) cd src/test && $(MAKE) clean || true
1360 ## clean_<TARGET> : clean up one specific target
1361 $(CLEAN_TARGETS) :
1362 $(V0) $(MAKE) -j TARGET=$(subst clean_,,$@) clean
1364 ## <TARGET>_clean : clean up one specific target (alias for above)
1365 $(TARGETS_CLEAN) :
1366 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
1368 ## clean_all : clean all valid targets
1369 clean_all:$(CLEAN_TARGETS)
1371 ## all_clean : clean all valid targets (alias for above)
1372 all_clean:$(TARGETS_CLEAN)
1375 flash_$(TARGET): $(TARGET_HEX)
1376 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1377 $(V0) echo -n 'R' >$(SERIAL_DEVICE)
1378 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1380 ## flash : flash firmware (.hex) onto flight controller
1381 flash: flash_$(TARGET)
1383 st-flash_$(TARGET): $(TARGET_BIN)
1384 $(V0) st-flash --reset write $< 0x08000000
1386 ## st-flash : flash firmware (.bin) onto flight controller
1387 st-flash: st-flash_$(TARGET)
1389 binary:
1390 $(V0) $(MAKE) -j $(TARGET_BIN)
1392 hex:
1393 $(V0) $(MAKE) -j $(TARGET_HEX)
1395 unbrick_$(TARGET): $(TARGET_HEX)
1396 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1397 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1399 ## unbrick : unbrick flight controller
1400 unbrick: unbrick_$(TARGET)
1402 ## cppcheck : run static analysis on C source code
1403 cppcheck: $(CSOURCES)
1404 $(V0) $(CPPCHECK)
1406 cppcheck-result.xml: $(CSOURCES)
1407 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
1409 # mkdirs
1410 $(DL_DIR):
1411 mkdir -p $@
1413 $(TOOLS_DIR):
1414 mkdir -p $@
1416 $(BUILD_DIR):
1417 mkdir -p $@
1419 ## version : print firmware version
1420 version:
1421 @echo $(FC_VER)
1423 ## help : print this help message and exit
1424 help: Makefile make/tools.mk
1425 $(V0) @echo ""
1426 $(V0) @echo "Makefile for the $(FORKNAME) firmware"
1427 $(V0) @echo ""
1428 $(V0) @echo "Usage:"
1429 $(V0) @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
1430 $(V0) @echo "Or:"
1431 $(V0) @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
1432 $(V0) @echo ""
1433 $(V0) @echo "Valid TARGET values are: $(VALID_TARGETS)"
1434 $(V0) @echo ""
1435 $(V0) @sed -n 's/^## //p' $?
1437 ## targets : print a list of all valid target platforms (for consumption by scripts)
1438 targets:
1439 $(V0) @echo "Valid targets: $(VALID_TARGETS)"
1440 $(V0) @echo "Target: $(TARGET)"
1441 $(V0) @echo "Base target: $(BASE_TARGET)"
1442 $(V0) @echo "targets-group-1: $(GROUP_1_TARGETS)"
1443 $(V0) @echo "targets-group-2: $(GROUP_2_TARGETS)"
1444 $(V0) @echo "targets-group-3: $(GROUP_3_TARGETS)"
1445 $(V0) @echo "targets-group-4: $(GROUP_4_TARGETS)"
1446 $(V0) @echo "targets-group-rest: $(GROUP_OTHER_TARGETS)"
1448 ## test : run the cleanflight test suite
1449 ## junittest : run the cleanflight test suite, producing Junit XML result files.
1450 test junittest:
1451 $(V0) cd src/test && $(MAKE) $@
1453 # rebuild everything when makefile changes
1454 $(TARGET_OBJS) : Makefile
1456 # include auto-generated dependencies
1457 -include $(TARGET_DEPS)