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 iNav 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
21 # Compile-time options
24 # compile for OpenPilot BootLoader support
27 # Debugger optons, must be empty or GDB
30 # Insert the debugging hardfault debugger
31 # releases should not be built with this flag as it does not disable pwm output
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.
40 ## V : Set verbosity level based on the V= parameter
52 export STDOUT
:= "> /dev/null"
53 export MAKE
:= $(MAKE
) --no-print-directory
60 ###############################################################################
61 # Things that need to be maintained as the source changes
67 ROOT
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
68 SRC_DIR
= $(ROOT
)/src
/main
69 OBJECT_DIR
= $(ROOT
)/obj
/main
71 CMSIS_DIR
= $(ROOT
)/lib
/main
/CMSIS
72 INCLUDE_DIRS
= $(SRC_DIR
) \
73 $(ROOT
)/src
/main
/target
74 LINKER_DIR
= $(ROOT
)/src
/main
/target
/link
76 # default xtal value for F4 targets
79 # used for turning on features like VCP and SDCARD
82 ALT_TARGETS
= $(sort $(filter-out target
, $(basename $(notdir $(wildcard $(ROOT
)/src
/main
/target
/*/*.mk
)))))
83 OPBL_TARGETS
= $(filter %_OPBL
, $(ALT_TARGETS
))
85 VALID_TARGETS
= $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/target.mk
))
86 VALID_TARGETS
:= $(subst /,, $(subst .
/src
/main
/target
/,, $(VALID_TARGETS
)))
87 VALID_TARGETS
:= $(VALID_TARGETS
) $(ALT_TARGETS
)
88 VALID_TARGETS
:= $(sort $(VALID_TARGETS
))
90 CLEAN_TARGETS
= $(addprefix clean_
,$(VALID_TARGETS
) )
91 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
) )
93 ifeq ($(filter $(TARGET
),$(ALT_TARGETS
)), $(TARGET
))
94 BASE_TARGET
:= $(firstword $(subst /,, $(subst .
/src
/main
/target
/,, $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/$(TARGET
).mk
)))))
95 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/$(TARGET
).mk
97 BASE_TARGET
:= $(TARGET
)
100 ifeq ($(filter $(TARGET
),$(OPBL_TARGETS
)), $(TARGET
))
104 # silently ignore if the file is not present. Allows for target specific.
105 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/target.mk
107 F4_TARGETS
= $(F405_TARGETS
) $(F411_TARGETS
) $(F427_TARGETS
) $(F446_TARGETS
)
108 F7_TARGETS
= $(F7X2RE_TARGETS
) $(F7X5XE_TARGETS
) $(F7X5XG_TARGETS
) $(F7X5XI_TARGETS
) $(F7X6XG_TARGETS
)
110 ifeq ($(filter $(TARGET
),$(VALID_TARGETS
)),)
111 $(error Target
'$(TARGET)' is not valid
, must be one of
$(VALID_TARGETS
). Have you prepared a valid target.mk?
)
114 ifeq ($(filter $(TARGET
),$(F1_TARGETS
) $(F3_TARGETS
) $(F4_TARGETS
) $(F7_TARGETS
)),)
115 $(error Target
'$(TARGET)' has not specified a valid STM group
, must be one of F1
, F3
, F405
, F411
, F427 or F7x. Have you prepared a valid target.mk?
)
118 128K_TARGETS
= $(F1_TARGETS
)
119 256K_TARGETS
= $(F3_TARGETS
)
120 512K_TARGETS
= $(F411_TARGETS
) $(F446_TARGETS
) $(F7X2RE_TARGETS
) $(F7X5XE_TARGETS
)
121 1024K_TARGETS
= $(F405_TARGETS
) $(F7X5XG_TARGETS
) $(F7X6XG_TARGETS
)
122 2048K_TARGETS
= $(F427_TARGETS
) $(F7X5XI_TARGETS
)
124 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
125 ifeq ($(FLASH_SIZE
),)
126 ifeq ($(TARGET
),$(filter $(TARGET
),$(2048K_TARGETS
)))
128 else ifeq ($(TARGET
),$(filter $(TARGET
),$(1024K_TARGETS
)))
130 else ifeq ($(TARGET
),$(filter $(TARGET
),$(512K_TARGETS
)))
132 else ifeq ($(TARGET
),$(filter $(TARGET
),$(256K_TARGETS
)))
134 else ifeq ($(TARGET
),$(filter $(TARGET
),$(128K_TARGETS
)))
137 $(error FLASH_SIZE not configured for target
$(TARGET
))
141 GROUP_1_TARGETS
:= AIRHEROF3 AIRHEROF3_QUAD COLIBRI_RACE LUX_RACE SPARKY REVO SPARKY2 COLIBRI FALCORE PIKOBLX
142 GROUP_2_TARGETS
:= SPRACINGF3 SPRACINGF3EVO SPRACINGF3EVO_1SS SPRACINGF3MINI SPRACINGF3NEO SPRACINGF4EVO
143 GROUP_3_TARGETS
:= OMNIBUS AIRBOTF4 BLUEJAYF4 OMNIBUSF4 OMNIBUSF4PRO OMNIBUSF4V3 SPARKY2 MATEKF405 OMNIBUSF7 DYSF4PRO MATEKF405OSD MATEKF405_SERVOS6
144 GROUP_4_TARGETS
:= ANYFC ANYFCF7 ANYFCF7_EXTERNAL_BARO ANYFCM7 ALIENFLIGHTNGF7 PIXRACER
145 GROUP_OTHER_TARGETS
:= $(filter-out $(GROUP_1_TARGETS
) $(GROUP_2_TARGETS
) $(GROUP_3_TARGETS
) $(GROUP_4_TARGETS
), $(VALID_TARGETS
))
147 # note that there is no hardfault debugging startup file assembly handler for other platforms
148 ifeq ($(DEBUG_HARDFAULTS
),F3
)
149 CFLAGS
+= -DDEBUG_HARDFAULTS
150 STM32F30x_COMMON_SRC
= startup_stm32f3_debug_hardfault_handler.S
152 STM32F30x_COMMON_SRC
= startup_stm32f30x_md_gcc.S
155 ifeq ($(DEBUG_HARDFAULTS
),F7
)
156 CFLAGS
+= -DDEBUG_HARDFAULTS
159 REVISION
= $(shell git log
-1 --format
="%h")
161 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
162 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
163 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
165 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
167 # Search path for sources
168 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
169 USBFS_DIR
= $(ROOT
)/lib
/main
/STM32_USB-FS-Device_Driver
170 USBPERIPH_SRC
= $(notdir $(wildcard $(USBFS_DIR
)/src
/*.c
))
171 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
172 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
174 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
176 ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
179 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F30x_StdPeriph_Driver
180 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
181 EXCLUDES
= stm32f30x_crc.c \
184 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
185 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
187 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM1
/CoreSupport
:$(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
188 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM1
/CoreSupport
/*.c \
189 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
/*.c
))
191 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
192 $(STDPERIPH_DIR
)/inc \
193 $(CMSIS_DIR
)/CM1
/CoreSupport \
194 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
196 ifneq ($(filter VCP
, $(FEATURES
)),)
197 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
201 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
203 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
)\
207 ifneq ($(filter SDCARD
, $(FEATURES
)),)
208 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
211 VPATH
:= $(VPATH
):$(FATFS_DIR
)
214 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k.
ld
216 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
217 DEVICE_FLAGS
= -DSTM32F303xC
-DSTM32F303
218 TARGET_FLAGS
= -D
$(TARGET
)
222 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F4_TARGETS
)))
225 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F4xx_StdPeriph_Driver
226 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
227 EXCLUDES
= stm32f4xx_crc.c \
233 stm32f4xx_flash_ramfunc.c \
237 stm32f4xx_spdifrx.c \
239 stm32f4xx_cryp_aes.c \
240 stm32f4xx_hash_md5.c \
241 stm32f4xx_cryp_des.c \
245 stm32f4xx_cryp_tdes.c \
246 stm32f4xx_hash_sha1.c
248 ifeq ($(TARGET
),$(filter $(TARGET
), $(F411_TARGETS
)))
249 EXCLUDES
+= stm32f4xx_fsmc.c
252 ifeq ($(TARGET
),$(filter $(TARGET
), $(F427_TARGETS
)))
253 EXCLUDES
+= stm32f4xx_fsmc.c
256 ifeq ($(TARGET
),$(filter $(TARGET
), $(F446_TARGETS
)))
257 EXCLUDES
+= stm32f4xx_fsmc.c
260 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
263 USBCORE_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Core
264 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/src
/*.c
))
265 USBOTG_DIR
= $(ROOT
)/lib
/main
/STM32_USB_OTG_Driver
266 USBOTG_SRC
= $(notdir $(wildcard $(USBOTG_DIR
)/src
/*.c
))
267 EXCLUDES
= usb_bsp_template.c \
268 usb_conf_template.c \
273 USBOTG_SRC
:= $(filter-out ${EXCLUDES}, $(USBOTG_SRC
))
274 USBCDC_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Class
/cdc
275 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/src
/*.c
))
276 EXCLUDES
= usbd_cdc_if_template.c
277 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
278 VPATH
:= $(VPATH
):$(USBOTG_DIR
)/src
:$(USBCORE_DIR
)/src
:$(USBCDC_DIR
)/src
280 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
286 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM4
/CoreSupport
:$(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
287 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM4
/CoreSupport
/*.c \
288 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
/*.c
))
289 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
290 $(STDPERIPH_DIR
)/inc \
295 $(CMSIS_DIR
)/CM4
/CoreSupport \
296 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx \
297 $(ROOT
)/src
/main
/vcpf4
299 ifneq ($(filter SDCARD
,$(FEATURES
)),)
300 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
302 VPATH
:= $(VPATH
):$(FATFS_DIR
)
306 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-march
=armv7e-m
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
308 ifeq ($(TARGET
),$(filter $(TARGET
),$(F411_TARGETS
)))
309 DEVICE_FLAGS
= -DSTM32F411xE
310 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411.
ld
311 STARTUP_SRC
= startup_stm32f411xe.s
312 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F405_TARGETS
)))
313 DEVICE_FLAGS
= -DSTM32F40_41xxx
314 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405.
ld
315 STARTUP_SRC
= startup_stm32f40xx.s
316 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F446_TARGETS
)))
317 DEVICE_FLAGS
= -DSTM32F446xx
318 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f446.
ld
319 STARTUP_SRC
= startup_stm32f446xx.s
320 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F427_TARGETS
)))
321 DEVICE_FLAGS
= -DSTM32F427_437xx
322 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f427.
ld
323 STARTUP_SRC
= startup_stm32f427xx.s
325 $(error Unknown MCU for F4 target
)
328 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
330 TARGET_FLAGS
= -D
$(TARGET
)
334 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F7_TARGETS
)))
337 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F7xx_HAL_Driver
338 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/Src
/*.c
))
339 EXCLUDES
= stm32f7xx_hal_can.c \
340 stm32f7xx_hal_cec.c \
341 stm32f7xx_hal_crc.c \
342 stm32f7xx_hal_crc_ex.c \
343 stm32f7xx_hal_cryp.c \
344 stm32f7xx_hal_cryp_ex.c \
345 stm32f7xx_hal_dac.c \
346 stm32f7xx_hal_dac_ex.c \
347 stm32f7xx_hal_dcmi.c \
348 stm32f7xx_hal_dcmi_ex.c \
349 stm32f7xx_hal_dfsdm.c \
350 stm32f7xx_hal_dma2d.c \
351 stm32f7xx_hal_dsi.c \
352 stm32f7xx_hal_eth.c \
353 stm32f7xx_hal_hash.c \
354 stm32f7xx_hal_hash_ex.c \
355 stm32f7xx_hal_hcd.c \
356 stm32f7xx_hal_i2s.c \
357 stm32f7xx_hal_irda.c \
358 stm32f7xx_hal_iwdg.c \
359 stm32f7xx_hal_jpeg.c \
360 stm32f7xx_hal_lptim.c \
361 stm32f7xx_hal_ltdc.c \
362 stm32f7xx_hal_ltdc_ex.c \
363 stm32f7xx_hal_mdios.c \
364 stm32f7xx_hal_mmc.c \
365 stm32f7xx_hal_msp_template.c \
366 stm32f7xx_hal_nand.c \
367 stm32f7xx_hal_nor.c \
368 stm32f7xx_hal_qspi.c \
369 stm32f7xx_hal_rng.c \
370 stm32f7xx_hal_rtc.c \
371 stm32f7xx_hal_rtc_ex.c \
372 stm32f7xx_hal_sai.c \
373 stm32f7xx_hal_sai_ex.c \
375 stm32f7xx_hal_sdram.c \
376 stm32f7xx_hal_smartcard.c \
377 stm32f7xx_hal_smartcard_ex.c \
378 stm32f7xx_hal_smbus.c \
379 stm32f7xx_hal_spdifrx.c \
380 stm32f7xx_hal_sram.c \
381 stm32f7xx_hal_timebase_rtc_alarm_template.c \
382 stm32f7xx_hal_timebase_rtc_wakeup_template.c \
383 stm32f7xx_hal_timebase_tim_template.c \
384 stm32f7xx_hal_wwdg.c \
389 stm32f7xx_ll_dma2d.c \
390 stm32f7xx_ll_exti.c \
392 stm32f7xx_ll_gpio.c \
394 stm32f7xx_ll_lptim.c \
399 stm32f7xx_ll_sdmmc.c \
402 stm32f7xx_ll_usart.c \
405 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
408 USBCORE_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Core
409 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/Src
/*.c
))
410 EXCLUDES
= usbd_conf_template.c
411 USBCORE_SRC
:= $(filter-out ${EXCLUDES}, $(USBCORE_SRC
))
413 USBCDC_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Class
/CDC
414 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/Src
/*.c
))
415 EXCLUDES
= usbd_cdc_if_template.c
416 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
418 VPATH
:= $(VPATH
):$(USBCDC_DIR
)/Src
:$(USBCORE_DIR
)/Src
420 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
425 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM7
/Include
:$(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
426 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/Src
427 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM7
/Include
/*.c \
428 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/*.c
))
429 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
430 $(STDPERIPH_DIR
)/Inc \
433 $(CMSIS_DIR
)/CM7
/Include \
434 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/Include \
435 $(ROOT
)/src
/main
/vcp_hal
437 ifneq ($(filter SDCARD
,$(FEATURES
)),)
438 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
440 VPATH
:= $(VPATH
):$(FATFS_DIR
)
444 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m7
-mfloat-abi
=hard
-mfpu
=fpv5-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
446 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X5XG_TARGETS
)))
447 DEVICE_FLAGS
= -DSTM32F745xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
448 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f745.
ld
449 STARTUP_SRC
= startup_stm32f745xx.s
450 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X6XG_TARGETS
)))
451 DEVICE_FLAGS
= -DSTM32F746xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
452 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f746.
ld
453 STARTUP_SRC
= startup_stm32f746xx.s
454 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X2RE_TARGETS
)))
455 DEVICE_FLAGS
= -DSTM32F722xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
456 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f722.
ld
457 STARTUP_SRC
= startup_stm32f722xx.s
459 $(error Unknown MCU for F7 target
)
461 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
463 TARGET_FLAGS
= -D
$(TARGET
)
470 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F10x_StdPeriph_Driver
471 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
472 EXCLUDES
= stm32f10x_crc.c \
476 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
478 # Search path and source files for the CMSIS sources
479 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM3
/CoreSupport
:$(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
480 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM3
/CoreSupport
/*.c \
481 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
/*.c
))
483 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
484 $(STDPERIPH_DIR
)/inc \
485 $(CMSIS_DIR
)/CM3
/CoreSupport \
486 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x \
488 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
490 ifneq ($(filter VCP
, $(FEATURES
)),)
491 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
495 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
497 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
) \
502 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k.
ld
503 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m3
504 TARGET_FLAGS
:= -D
$(TARGET
) -pedantic
$(TARGET_FLAGS
)
506 ifeq ($(DEVICE_FLAGS
),)
507 DEVICE_FLAGS
= -DSTM32F10X_MD
509 DEVICE_FLAGS
+= -DSTM32F10X
515 ifneq ($(BASE_TARGET
), $(TARGET
))
516 TARGET_FLAGS
:= $(TARGET_FLAGS
) -D
$(BASE_TARGET
)
519 ifneq ($(FLASH_SIZE
),)
520 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFLASH_SIZE
=$(FLASH_SIZE
)
523 ifneq ($(HSE_VALUE
),)
524 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
527 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)
528 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
531 TARGET_FLAGS
:= -DOPBL
$(TARGET_FLAGS
)
532 ifeq ($(TARGET
), $(filter $(TARGET
),$(F405_TARGETS
)))
533 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405_opbl.
ld
534 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F411_TARGETS
)))
535 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411_opbl.
ld
536 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F3_TARGETS
)))
537 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k_opbl.
ld
538 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F1_TARGETS
)))
539 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k_opbl.
ld
541 .DEFAULT_GOAL
:= binary
546 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
547 $(ROOT
)/lib
/main
/MAVLink
549 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
552 VPATH
:= $(VPATH
):$(TARGET_DIR
)
557 target
/common_hardware.c \
559 build
/build_config.c \
571 common
/typeconversion.c \
572 common
/string_light.c \
573 config
/config_eeprom.c \
574 config
/config_streamer.c \
576 config
/parameter_group.c \
578 drivers
/buf_writer.c \
580 drivers
/bus_busdev_i2c.c \
581 drivers
/bus_busdev_spi.c \
582 drivers
/bus_i2c_soft.c \
586 drivers
/gps_i2cnav.c \
588 drivers
/io_pca9685.c \
589 drivers
/light_led.c \
592 drivers
/rx_nrf24l01.c \
595 drivers
/pitotmeter_adc.c \
596 drivers
/pwm_esc_detect.c \
597 drivers
/pwm_mapping.c \
598 drivers
/pwm_output.c \
602 drivers
/serial_uart.c \
603 drivers
/sound_beeper.c \
604 drivers
/stack_check.c \
607 drivers
/lights_io.c \
610 fc/controlrate_profile.c \
617 fc/rc_adjustments.c \
621 fc/runtime_config.c \
629 flight
/pid_autotune.c \
636 io
/serial_4way_avrootloader.c \
637 io
/serial_4way_stk500v2.c \
638 io
/statusindicator.c \
663 scheduler
/scheduler.c \
664 sensors
/acceleration.c \
666 sensors
/temperature.c \
667 sensors
/boardalignment.c \
669 sensors
/diagnostics.c \
671 sensors
/initialisation.c \
672 uav_interconnect
/uav_interconnect_bus.c \
673 uav_interconnect
/uav_interconnect_rangefinder.c \
675 $(DEVICE_STDPERIPH_SRC
)
678 blackbox
/blackbox.c \
679 blackbox
/blackbox_encoding.c \
680 blackbox
/blackbox_io.c \
682 cms
/cms_menu_blackbox.c \
683 cms
/cms_menu_builtin.c \
685 cms
/cms_menu_ledstrip.c \
686 cms
/cms_menu_misc.c \
687 cms
/cms_menu_navigation.c \
689 cms
/cms_menu_vtx_smartaudio.c \
690 cms
/cms_menu_vtx_tramp.c \
691 common
/colorconversion.c \
692 common
/gps_conversion.c \
693 drivers
/display_ug2864hsweg01.c \
694 drivers
/rangefinder
/rangefinder_hcsr04.c \
695 drivers
/rangefinder
/rangefinder_hcsr04_i2c.c \
696 drivers
/rangefinder
/rangefinder_srf10.c \
697 drivers
/rangefinder
/rangefinder_vl53l0x.c \
698 drivers
/opflow
/opflow_fake.c \
699 drivers
/opflow
/opflow_virtual.c \
700 drivers
/vtx_common.c \
703 io
/displayport_max7456.c \
704 io
/displayport_msp.c \
705 io
/displayport_oled.c \
713 navigation
/navigation.c \
714 navigation
/navigation_fixedwing.c \
715 navigation
/navigation_fw_launch.c \
716 navigation
/navigation_geo.c \
717 navigation
/navigation_multicopter.c \
718 navigation
/navigation_pos_estimator.c \
719 sensors
/barometer.c \
720 sensors
/pitotmeter.c \
721 sensors
/rangefinder.c \
726 telemetry
/ibus_shared.c \
729 telemetry
/mavlink.c \
730 telemetry
/msp_shared.c \
731 telemetry
/smartport.c \
732 telemetry
/telemetry.c \
734 io
/vtx_smartaudio.c \
738 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
740 vcpf4
/stm32f4xx_it.c \
744 vcpf4
/usbd_cdc_vcp.c \
745 drivers
/serial_usb_vcp.c \
747 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
749 vcp_hal
/usbd_desc.c \
750 vcp_hal
/usbd_conf.c \
751 vcp_hal
/usbd_cdc_interface.c \
752 drivers
/serial_usb_vcp.c \
763 drivers
/serial_usb_vcp.c \
767 STM32F10x_COMMON_SRC
= \
768 startup_stm32f10x_md_gcc.S \
769 drivers
/accgyro
/accgyro.c \
770 drivers
/adc_stm32f10x.c \
771 drivers
/bus_i2c_stm32f10x.c \
773 drivers
/gpio_stm32f10x.c \
775 drivers
/serial_softserial.c \
776 drivers
/serial_uart_stm32f10x.c \
777 drivers
/system_stm32f10x.c \
778 drivers
/timer_stm32f10x.c
780 STM32F30x_COMMON_SRC
= \
781 startup_stm32f30x_md_gcc.S \
782 target
/system_stm32f30x.c \
783 drivers
/accgyro
/accgyro.c \
784 drivers
/adc_stm32f30x.c \
785 drivers
/bus_i2c_stm32f30x.c \
787 drivers
/gpio_stm32f30x.c \
788 drivers
/serial_uart_stm32f30x.c \
789 drivers
/system_stm32f30x.c \
790 drivers
/timer_stm32f30x.c
792 STM32F4xx_COMMON_SRC
= \
793 target
/system_stm32f4xx.c \
794 drivers
/accgyro
/accgyro.c \
795 drivers
/accgyro
/accgyro_mpu.c \
796 drivers
/adc_stm32f4xx.c \
797 drivers
/adc_stm32f4xx.c \
798 drivers
/bus_i2c_stm32f10x.c \
799 drivers
/gpio_stm32f4xx.c \
801 drivers
/serial_softserial.c \
802 drivers
/serial_uart_stm32f4xx.c \
803 drivers
/system_stm32f4xx.c \
804 drivers
/timer_stm32f4xx.c \
805 drivers
/dma_stm32f4xx.c
807 STM32F7xx_COMMON_SRC
= \
808 target
/system_stm32f7xx.c \
809 drivers
/accgyro
/accgyro.c \
810 drivers
/accgyro
/accgyro_mpu.c \
811 drivers
/adc_stm32f7xx.c \
812 drivers
/bus_i2c_hal.c \
813 drivers
/dma_stm32f7xx.c \
814 drivers
/gpio_stm32f7xx.c \
816 drivers
/bus_spi_hal.c \
817 drivers
/timer_hal.c \
818 drivers
/timer_stm32f7xx.c \
819 drivers
/system_stm32f7xx.c \
820 drivers
/serial_uart_stm32f7xx.c \
821 drivers
/serial_uart_hal.c
823 F7EXCLUDES
= drivers
/bus_spi.c \
826 drivers
/serial_uart.c
828 # check if target.mk supplied
829 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
830 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F4xx_COMMON_SRC
) $(TARGET_SRC
)
831 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
832 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F7xx_COMMON_SRC
) $(TARGET_SRC
)
833 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
834 TARGET_SRC
:= $(STM32F30x_COMMON_SRC
) $(TARGET_SRC
)
835 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F1_TARGETS
)))
836 TARGET_SRC
:= $(STM32F10x_COMMON_SRC
) $(TARGET_SRC
)
839 ifneq ($(filter ONBOARDFLASH
,$(FEATURES
)),)
841 drivers
/flash_m25p16.c \
845 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
) $(F4_TARGETS
) $(F3_TARGETS
)))
846 TARGET_SRC
+= $(HIGHEND_SRC
)
847 else ifneq ($(filter HIGHEND
,$(FEATURES
)),)
848 TARGET_SRC
+= $(HIGHEND_SRC
)
851 TARGET_SRC
+= $(COMMON_SRC
)
853 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
854 TARGET_SRC
:= $(filter-out ${F7EXCLUDES}, $(TARGET_SRC
))
857 ifneq ($(filter SDCARD
,$(FEATURES
)),)
860 drivers
/sdcard_standard.c \
861 io
/asyncfatfs
/asyncfatfs.c \
862 io
/asyncfatfs
/fat_standard.c
865 ifneq ($(filter VCP
,$(FEATURES
)),)
866 TARGET_SRC
+= $(VCP_SRC
)
868 # end target specific make file checks
870 # Search path and source files for the ST stdperiph library
871 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/src
873 ###############################################################################
874 # Things that might need changing to use different tools
878 ifneq ($(TOOLCHAINPATH
),)
879 CROSS_CC
= $(TOOLCHAINPATH
)/arm-none-eabi-gcc
880 OBJCOPY
= $(TOOLCHAINPATH
)/arm-none-eabi-objcopy
881 SIZE
= $(TOOLCHAINPATH
)/arm-none-eabi-size
883 CROSS_CC
= arm-none-eabi-gcc
884 OBJCOPY
= arm-none-eabi-objcopy
885 SIZE
= arm-none-eabi-size
894 LTO_FLAGS
= $(OPTIMIZE
)
897 LTO_FLAGS
= -flto
-fuse-linker-plugin
$(OPTIMIZE
)
900 DEBUG_FLAGS
= -ggdb3
-DDEBUG
902 CFLAGS
+= $(ARCH_FLAGS
) \
904 $(addprefix -D
,$(OPTIONS
)) \
905 $(addprefix -I
,$(INCLUDE_DIRS
)) \
908 -Wall
-Wextra
-Wunsafe-loop-optimizations
-Wdouble-promotion \
910 -ffunction-sections \
913 -DUSE_STDPERIPH_DRIVER \
915 -D
'__FORKNAME__="$(FORKNAME)"' \
916 -D
'__TARGET__="$(TARGET)"' \
917 -D
'__REVISION__="$(REVISION)"' \
921 ASFLAGS
= $(ARCH_FLAGS
) \
922 -x assembler-with-cpp \
923 $(addprefix -I
,$(INCLUDE_DIRS
)) \
936 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
937 -Wl
,-L
$(LINKER_DIR
) \
939 -Wl
,--no-wchar-size-warning \
942 ###############################################################################
943 # No user-serviceable parts below
944 ###############################################################################
946 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
947 --std
=c99
--inline-suppr
--quiet
--force \
948 $(addprefix -I
,$(INCLUDE_DIRS
)) \
949 -I
/usr
/include -I
/usr
/include/linux
952 # Things we will build
954 TARGET_BIN
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).bin
955 TARGET_HEX
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).hex
956 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
957 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
958 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
959 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
962 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
963 CLEAN_ARTIFACTS
+= $(TARGET_HEX
)
964 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
966 # Make sure build date and revision is updated on every incremental build
967 $(OBJECT_DIR
)/$(TARGET
)/build
/version.o
: $(TARGET_SRC
)
970 .PHONY
: .FORCE settings clean-settings
971 UTILS_DIR
= $(ROOT
)/src
/utils
972 SETTINGS_GENERATOR
= $(UTILS_DIR
)/settings.rb
973 BUILD_STAMP
= $(UTILS_DIR
)/build_stamp.rb
974 STAMP
= $(BIN_DIR
)/build.stamp
976 GENERATED_SETTINGS
= $(SRC_DIR
)/fc/settings_generated.h
$(SRC_DIR
)/fc/settings_generated.c
977 SETTINGS_FILE
= $(SRC_DIR
)/fc/settings.yaml
978 GENERATED_FILES
= $(GENERATED_SETTINGS
)
979 $(GENERATED_SETTINGS
): $(SETTINGS_GENERATOR
) $(SETTINGS_FILE
) $(STAMP
)
982 $(V1
) CFLAGS
="$(CFLAGS)" TARGET
=$(TARGET
) ruby
$(BUILD_STAMP
) $(SETTINGS_FILE
) $(STAMP
)
984 # Use a pattern rule, since they're different than normal rules.
985 # See https://www.gnu.org/software/make/manual/make.html#Pattern-Examples
986 %generated.h
%generated.c
:
987 $(V1
) echo
"settings.yaml -> settings_generated.h, settings_generated.c" "$(STDOUT)"
988 $(V1
) CFLAGS
="$(CFLAGS)" TARGET
=$(TARGET
) ruby
$(SETTINGS_GENERATOR
) .
$(SETTINGS_FILE
)
991 $(V0
) CFLAGS
="$(CFLAGS)" TARGET
=$(TARGET
) ruby
$(SETTINGS_GENERATOR
) .
$(SETTINGS_FILE
) --json settings.json
994 $(V1
) $(RM
) $(GENERATED_SETTINGS
)
996 # List of buildable ELF files and their object dependencies.
997 # It would be nice to compute these lists, but that seems to be just beyond make.
999 $(TARGET_HEX
): $(TARGET_ELF
)
1000 $(V0
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
1002 $(TARGET_BIN
): $(TARGET_ELF
)
1003 $(V0
) $(OBJCOPY
) -O binary
$< $@
1005 $(TARGET_ELF
): $(TARGET_OBJS
)
1006 $(V1
) echo Linking
$(TARGET
)
1007 $(V1
) $(CROSS_CC
) -o
$@
$(filter %.o
, $^
) $(LDFLAGS
)
1008 $(V0
) $(SIZE
) $(TARGET_ELF
)
1011 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
1012 $(V1
) mkdir
-p
$(dir $@
)
1013 $(V1
) echo
%% $(notdir $<) "$(STDOUT)"
1014 $(V1
) $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $<
1017 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
1018 $(V1
) mkdir
-p
$(dir $@
)
1019 $(V1
) echo
%% $(notdir $<) "$(STDOUT)"
1020 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
1022 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
1023 $(V1
) mkdir
-p
$(dir $@
)
1024 $(V1
) echo
%% $(notdir $<) "$(STDOUT)"
1025 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
1028 ## all : Build all valid targets
1029 all: $(VALID_TARGETS
)
1031 ## targets-group-1 : build some targets
1032 targets-group-1
: $(GROUP_1_TARGETS
)
1034 ## targets-group-2 : build some targets
1035 targets-group-2
: $(GROUP_2_TARGETS
)
1037 ## targets-group-3 : build some targets
1038 targets-group-3
: $(GROUP_3_TARGETS
)
1040 ## targets-group-3 : build some targets
1041 targets-group-4
: $(GROUP_4_TARGETS
)
1043 ## targets-group-rest: build the rest of the targets (not listed in group 1, 2 or 3)
1044 targets-group-rest
: $(GROUP_OTHER_TARGETS
)
1048 echo
"Building $@" && \
1049 $(MAKE
) -j
8 TARGET
=$@
&& \
1050 echo
"Building $@ succeeded."
1052 ## clean : clean up all temporary / machine-generated files
1054 $(V0
) echo
"Cleaning $(TARGET)"
1055 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
1056 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
1057 $(V0
) rm -f
$(GENERATED_SETTINGS
)
1058 $(V0
) echo
"Cleaning $(TARGET) succeeded."
1060 ## clean_test : clean up all temporary / machine-generated files (tests)
1062 $(V0
) cd src
/test && $(MAKE
) clean || true
1064 ## clean_<TARGET> : clean up one specific target
1066 $(V0
) $(MAKE
) -j
8 TARGET
=$(subst clean_
,,$@
) clean
1068 ## <TARGET>_clean : clean up one specific target (alias for above)
1070 $(V0
) $(MAKE
) -j
8 TARGET
=$(subst _clean
,,$@
) clean
1072 ## clean_all : clean all valid targets
1073 clean_all
:$(CLEAN_TARGETS
)
1075 ## all_clean : clean all valid targets (alias for above)
1076 all_clean
:$(TARGETS_CLEAN
)
1078 flash_
$(TARGET
): $(TARGET_HEX
)
1079 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
1080 $(V0
) echo
-n
'R' >$(SERIAL_DEVICE
)
1081 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
1083 ## flash : flash firmware (.hex) onto flight controller
1084 flash
: flash_
$(TARGET
)
1086 st-flash_
$(TARGET
): $(TARGET_BIN
)
1087 $(V0
) st-flash
--reset write
$< 0x08000000
1089 ## st-flash : flash firmware (.bin) onto flight controller
1090 st-flash
: st-flash_
$(TARGET
)
1092 binary
: $(TARGET_BIN
)
1095 unbrick_
$(TARGET
): $(TARGET_HEX
)
1096 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
1097 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
1099 ## unbrick : unbrick flight controller
1100 unbrick
: unbrick_
$(TARGET
)
1102 ## cppcheck : run static analysis on C source code
1103 cppcheck
: $(CSOURCES
)
1106 cppcheck-result.xml
: $(CSOURCES
)
1107 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
1109 ## help : print this help message and exit
1112 $(V0
) @echo
"Makefile for the $(FORKNAME) firmware"
1114 $(V0
) @echo
"Usage:"
1115 $(V0
) @echo
" make [TARGET=<target>] [OPTIONS=\"<options>\"]"
1117 $(V0
) @echo
" make <target> [OPTIONS=\"<options>\"]"
1119 $(V0
) @echo
"Valid TARGET values are: $(VALID_TARGETS)"
1121 $(V0
) @sed
-n
's/^## //p' $<
1123 ## targets : print a list of all valid target platforms (for consumption by scripts)
1125 $(V0
) @echo
"Valid targets: $(VALID_TARGETS)"
1126 $(V0
) @echo
"Target: $(TARGET)"
1127 $(V0
) @echo
"Base target: $(BASE_TARGET)"
1128 $(V0
) @echo
"targets-group-1: $(GROUP_1_TARGETS)"
1129 $(V0
) @echo
"targets-group-2: $(GROUP_2_TARGETS)"
1130 $(V0
) @echo
"targets-group-3: $(GROUP_3_TARGETS)"
1131 $(V0
) @echo
"targets-group-4: $(GROUP_4_TARGETS)"
1132 $(V0
) @echo
"targets-group-rest: $(GROUP_OTHER_TARGETS)"
1134 ## test : run the cleanflight test suite
1136 $(V0
) cd src
/test && $(MAKE
) test || true
1138 # rebuild everything when makefile changes
1139 # Make the generated files and the build stamp order only prerequisites,
1140 # so they will be generated before TARGET_OBJS but regenerating them
1141 # won't cause all TARGET_OBJS to be rebuilt.
1142 $(TARGET_OBJS
) : Makefile |
$(GENERATED_FILES
) $(STAMP
)
1144 # include auto-generated dependencies
1145 -include $(TARGET_DEPS
)