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
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 # Build tools, so we all share the same versions
77 # import macros common to all supported build systems
78 include $(ROOT
)/make
/system-id.mk
80 # developer preferences, edit these at will, they'll be gitignored
81 -include $(ROOT
)/make
/local.mk
83 # configure some directories that are relative to wherever ROOT_DIR is located
85 TOOLS_DIR
:= $(ROOT
)/tools
87 BUILD_DIR
:= $(ROOT
)/build
88 DL_DIR
:= $(ROOT
)/downloads
92 # import macros that are OS specific
93 include $(ROOT
)/make
/$(OSFAMILY
).mk
95 # include the tools makefile
96 include $(ROOT
)/make
/tools.mk
98 # default xtal value for F4 targets
101 # used for turning on features like VCP and SDCARD
104 SAMPLE_TARGETS
= ALIENFLIGHTF3 ALIENFLIGHTF4 ANYFCF7 BETAFLIGHTF3 BLUEJAYF4 CC3D FURYF4 NAZE REVO SIRINFPV SPARKY SPRACINGF3 SPRACINGF3EVO SPRACINGF3NEO STM32F3DISCOVERY
105 ALT_TARGETS
= $(sort $(filter-out target
, $(basename $(notdir $(wildcard $(ROOT
)/src
/main
/target
/*/*.mk
)))))
106 OPBL_TARGETS
= $(filter %_OPBL
, $(ALT_TARGETS
))
108 VALID_TARGETS
= $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/target.mk
))
109 VALID_TARGETS
:= $(subst /,, $(subst .
/src
/main
/target
/,, $(VALID_TARGETS
)))
110 VALID_TARGETS
:= $(VALID_TARGETS
) $(ALT_TARGETS
)
111 VALID_TARGETS
:= $(sort $(VALID_TARGETS
))
113 ifeq ($(filter $(TARGET
),$(ALT_TARGETS
)), $(TARGET
))
114 BASE_TARGET
:= $(firstword $(subst /,, $(subst .
/src
/main
/target
/,, $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/$(TARGET
).mk
)))))
115 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/$(TARGET
).mk
117 BASE_TARGET
:= $(TARGET
)
120 ifeq ($(filter $(TARGET
),$(OPBL_TARGETS
)), $(TARGET
))
124 # silently ignore if the file is not present. Allows for target specific.
125 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/target.mk
127 F4_TARGETS
= $(F405_TARGETS
) $(F411_TARGETS
)
128 F7_TARGETS
= $(F7X2RE_TARGETS
) $(F7X5XE_TARGETS
) $(F7X5XG_TARGETS
) $(F7X5XI_TARGETS
) $(F7X6XG_TARGETS
)
130 ifeq ($(filter $(TARGET
),$(VALID_TARGETS
)),)
131 $(error Target
'$(TARGET)' is not valid
, must be one of
$(VALID_TARGETS
). Have you prepared a valid target.mk?
)
134 ifeq ($(filter $(TARGET
),$(F1_TARGETS
) $(F3_TARGETS
) $(F4_TARGETS
) $(F7_TARGETS
)),)
135 $(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?
)
138 128K_TARGETS
= $(F1_TARGETS
)
139 256K_TARGETS
= $(F3_TARGETS
)
140 512K_TARGETS
= $(F411_TARGETS
) $(F7X2RE_TARGETS
) $(F7X5XE_TARGETS
)
141 1024K_TARGETS
= $(F405_TARGETS
) $(F7X5XG_TARGETS
) $(F7X6XG_TARGETS
)
142 2048K_TARGETS
= $(F7X5XI_TARGETS
)
144 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
145 ifeq ($(FLASH_SIZE
),)
146 ifeq ($(TARGET
),$(filter $(TARGET
),$(2048K_TARGETS
)))
148 else ifeq ($(TARGET
),$(filter $(TARGET
),$(1024K_TARGETS
)))
150 else ifeq ($(TARGET
),$(filter $(TARGET
),$(512K_TARGETS
)))
152 else ifeq ($(TARGET
),$(filter $(TARGET
),$(256K_TARGETS
)))
154 else ifeq ($(TARGET
),$(filter $(TARGET
),$(128K_TARGETS
)))
157 $(error FLASH_SIZE not configured for target
$(TARGET
))
161 # note that there is no hardfault debugging startup file assembly handler for other platforms
162 ifeq ($(DEBUG_HARDFAULTS
),F3
)
163 CFLAGS
+= -DDEBUG_HARDFAULTS
164 STM32F30x_COMMON_SRC
= startup_stm32f3_debug_hardfault_handler.S
166 STM32F30x_COMMON_SRC
= startup_stm32f30x_md_gcc.S
169 ifeq ($(DEBUG_HARDFAULTS
),F7
)
170 CFLAGS
+= -DDEBUG_HARDFAULTS
173 REVISION
:= $(shell git log
-1 --format
="%h")
175 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
176 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
177 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
179 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
181 # Search path for sources
182 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
183 USBFS_DIR
= $(ROOT
)/lib
/main
/STM32_USB-FS-Device_Driver
184 USBPERIPH_SRC
= $(notdir $(wildcard $(USBFS_DIR
)/src
/*.c
))
185 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
186 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
188 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
190 ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
193 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F30x_StdPeriph_Driver
194 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
195 EXCLUDES
= stm32f30x_crc.c \
197 STARTUP_SRC
= startup_stm32f30x_md_gcc.S
199 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
200 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
202 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM1
/CoreSupport
:$(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
203 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM1
/CoreSupport
/*.c \
204 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
/*.c
))
206 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
207 $(STDPERIPH_DIR
)/inc \
208 $(CMSIS_DIR
)/CM1
/CoreSupport \
209 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
211 ifneq ($(filter VCP
, $(FEATURES
)),)
212 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
216 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
218 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
)\
222 ifneq ($(filter SDCARD
, $(FEATURES
)),)
223 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
226 VPATH
:= $(VPATH
):$(FATFS_DIR
)
229 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k.
ld
231 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
232 DEVICE_FLAGS
= -DSTM32F303xC
-DSTM32F303
236 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F4_TARGETS
)))
239 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F4xx_StdPeriph_Driver
240 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
241 EXCLUDES
= stm32f4xx_crc.c \
247 stm32f4xx_flash_ramfunc.c \
251 stm32f4xx_spdifrx.c \
253 stm32f4xx_cryp_aes.c \
254 stm32f4xx_hash_md5.c \
255 stm32f4xx_cryp_des.c \
259 stm32f4xx_cryp_tdes.c \
260 stm32f4xx_hash_sha1.c
262 ifeq ($(TARGET
),$(filter $(TARGET
), $(F411_TARGETS
)))
263 EXCLUDES
+= stm32f4xx_fsmc.c
266 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
269 USBCORE_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Core
270 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/src
/*.c
))
271 USBOTG_DIR
= $(ROOT
)/lib
/main
/STM32_USB_OTG_Driver
272 USBOTG_SRC
= $(notdir $(wildcard $(USBOTG_DIR
)/src
/*.c
))
273 EXCLUDES
= usb_bsp_template.c \
274 usb_conf_template.c \
279 USBOTG_SRC
:= $(filter-out ${EXCLUDES}, $(USBOTG_SRC
))
280 USBCDC_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Class
/cdc
281 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/src
/*.c
))
282 EXCLUDES
= usbd_cdc_if_template.c
283 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
284 VPATH
:= $(VPATH
):$(USBOTG_DIR
)/src
:$(USBCORE_DIR
)/src
:$(USBCDC_DIR
)/src
286 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
292 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM4
/CoreSupport
:$(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
293 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM4
/CoreSupport
/*.c \
294 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
/*.c
))
295 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
296 $(STDPERIPH_DIR
)/inc \
301 $(CMSIS_DIR
)/CM4
/CoreSupport \
302 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx \
303 $(ROOT
)/src
/main
/vcpf4
305 ifneq ($(filter SDCARD
,$(FEATURES
)),)
306 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
308 VPATH
:= $(VPATH
):$(FATFS_DIR
)
312 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-march
=armv7e-m
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
314 ifeq ($(TARGET
),$(filter $(TARGET
),$(F411_TARGETS
)))
315 DEVICE_FLAGS
= -DSTM32F411xE
316 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411.
ld
317 STARTUP_SRC
= startup_stm32f411xe.s
318 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F405_TARGETS
)))
319 DEVICE_FLAGS
= -DSTM32F40_41xxx
320 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405.
ld
321 STARTUP_SRC
= startup_stm32f40xx.s
323 $(error Unknown MCU for F4 target
)
325 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
330 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F7_TARGETS
)))
333 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F7xx_HAL_Driver
334 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/Src
/*.c
))
335 EXCLUDES
= stm32f7xx_hal_can.c \
336 stm32f7xx_hal_cec.c \
337 stm32f7xx_hal_crc.c \
338 stm32f7xx_hal_crc_ex.c \
339 stm32f7xx_hal_cryp.c \
340 stm32f7xx_hal_cryp_ex.c \
341 stm32f7xx_hal_dac.c \
342 stm32f7xx_hal_dac_ex.c \
343 stm32f7xx_hal_dcmi.c \
344 stm32f7xx_hal_dcmi_ex.c \
345 stm32f7xx_hal_dfsdm.c \
346 stm32f7xx_hal_dma2d.c \
347 stm32f7xx_hal_dsi.c \
348 stm32f7xx_hal_eth.c \
349 stm32f7xx_hal_hash.c \
350 stm32f7xx_hal_hash_ex.c \
351 stm32f7xx_hal_hcd.c \
352 stm32f7xx_hal_i2s.c \
353 stm32f7xx_hal_irda.c \
354 stm32f7xx_hal_iwdg.c \
355 stm32f7xx_hal_jpeg.c \
356 stm32f7xx_hal_lptim.c \
357 stm32f7xx_hal_ltdc.c \
358 stm32f7xx_hal_ltdc_ex.c \
359 stm32f7xx_hal_mdios.c \
360 stm32f7xx_hal_mmc.c \
361 stm32f7xx_hal_msp_template.c \
362 stm32f7xx_hal_nand.c \
363 stm32f7xx_hal_nor.c \
364 stm32f7xx_hal_qspi.c \
365 stm32f7xx_hal_rng.c \
366 stm32f7xx_hal_rtc.c \
367 stm32f7xx_hal_rtc_ex.c \
368 stm32f7xx_hal_sai.c \
369 stm32f7xx_hal_sai_ex.c \
371 stm32f7xx_hal_sdram.c \
372 stm32f7xx_hal_smartcard.c \
373 stm32f7xx_hal_smartcard_ex.c \
374 stm32f7xx_hal_smbus.c \
375 stm32f7xx_hal_spdifrx.c \
376 stm32f7xx_hal_sram.c \
377 stm32f7xx_hal_timebase_rtc_alarm_template.c \
378 stm32f7xx_hal_timebase_rtc_wakeup_template.c \
379 stm32f7xx_hal_timebase_tim_template.c \
380 stm32f7xx_hal_wwdg.c \
385 stm32f7xx_ll_dma2d.c \
386 stm32f7xx_ll_exti.c \
388 stm32f7xx_ll_gpio.c \
390 stm32f7xx_ll_lptim.c \
395 stm32f7xx_ll_sdmmc.c \
398 stm32f7xx_ll_usart.c \
401 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
404 USBCORE_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Core
405 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/Src
/*.c
))
406 EXCLUDES
= usbd_conf_template.c
407 USBCORE_SRC
:= $(filter-out ${EXCLUDES}, $(USBCORE_SRC
))
409 USBCDC_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Class
/CDC
410 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/Src
/*.c
))
411 EXCLUDES
= usbd_cdc_if_template.c
412 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
414 VPATH
:= $(VPATH
):$(USBCDC_DIR
)/Src
:$(USBCORE_DIR
)/Src
416 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
421 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM7
/Include
:$(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
422 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/Src
423 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM7
/Include
/*.c \
424 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/*.c
))
425 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
426 $(STDPERIPH_DIR
)/Inc \
429 $(CMSIS_DIR
)/CM7
/Include \
430 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/Include \
431 $(ROOT
)/src
/main
/vcp_hal
433 ifneq ($(filter SDCARD
,$(FEATURES
)),)
434 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
436 VPATH
:= $(VPATH
):$(FATFS_DIR
)
440 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m7
-mfloat-abi
=hard
-mfpu
=fpv5-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
442 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X5XG_TARGETS
)))
443 DEVICE_FLAGS
= -DSTM32F745xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
444 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f745.
ld
445 STARTUP_SRC
= startup_stm32f745xx.s
446 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X6XG_TARGETS
)))
447 DEVICE_FLAGS
= -DSTM32F746xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
448 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f746.
ld
449 STARTUP_SRC
= startup_stm32f746xx.s
450 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X2RE_TARGETS
)))
451 DEVICE_FLAGS
= -DSTM32F722xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
452 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f722.
ld
453 STARTUP_SRC
= startup_stm32f722xx.s
455 $(error Unknown MCU for F7 target
)
457 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
459 TARGET_FLAGS
= -D
$(TARGET
)
466 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F10x_StdPeriph_Driver
467 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
468 EXCLUDES
= stm32f10x_crc.c \
471 STARTUP_SRC
= startup_stm32f10x_md_gcc.S
472 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
474 # Search path and source files for the CMSIS sources
475 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM3
/CoreSupport
:$(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
476 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM3
/CoreSupport
/*.c \
477 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
/*.c
))
479 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
480 $(STDPERIPH_DIR
)/inc \
481 $(CMSIS_DIR
)/CM3
/CoreSupport \
482 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
484 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
486 ifneq ($(filter VCP
, $(FEATURES
)),)
487 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
491 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
493 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
) \
498 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k.
ld
499 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m3
501 ifeq ($(DEVICE_FLAGS
),)
502 DEVICE_FLAGS
= -DSTM32F10X_MD
504 DEVICE_FLAGS
+= -DSTM32F10X
510 ifneq ($(BASE_TARGET
), $(TARGET
))
511 TARGET_FLAGS
:= $(TARGET_FLAGS
) -D
$(BASE_TARGET
)
514 ifneq ($(FLASH_SIZE
),)
515 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFLASH_SIZE
=$(FLASH_SIZE
)
518 ifneq ($(HSE_VALUE
),)
519 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
522 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)
523 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
526 TARGET_FLAGS
:= -DOPBL
$(TARGET_FLAGS
)
527 ifeq ($(TARGET
), $(filter $(TARGET
),$(F405_TARGETS
)))
528 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405_opbl.
ld
529 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F411_TARGETS
)))
530 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411_opbl.
ld
531 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F3_TARGETS
)))
532 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k_opbl.
ld
533 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F1_TARGETS
)))
534 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k_opbl.
ld
536 .DEFAULT_GOAL
:= binary
541 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
542 $(ROOT
)/lib
/main
/MAVLink
544 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
547 VPATH
:= $(VPATH
):$(TARGET_DIR
)
550 build
/build_config.c \
560 common
/typeconversion.c \
561 config
/config_eeprom.c \
563 config
/parameter_group.c \
565 drivers
/buf_writer.c \
566 drivers
/bus_i2c_soft.c \
568 drivers
/bus_spi_soft.c \
571 drivers
/gyro_sync.c \
573 drivers
/light_led.c \
575 drivers
/rx_nrf24l01.c \
578 drivers
/pwm_esc_detect.c \
579 drivers
/pwm_output.c \
583 drivers
/serial_uart.c \
584 drivers
/serial_softserial.c \
585 drivers
/sound_beeper.c \
586 drivers
/stack_check.c \
598 fc/runtime_config.c \
600 flight
/altitudehold.c \
609 io
/serial_4way_avrootloader.c \
610 io
/serial_4way_stk500v2.c \
611 io
/statusindicator.c \
630 scheduler
/scheduler.c \
631 sensors
/acceleration.c \
633 sensors
/boardalignment.c \
636 sensors
/initialisation.c \
638 $(DEVICE_STDPERIPH_SRC
)
641 blackbox
/blackbox.c \
642 blackbox
/blackbox_io.c \
644 cms
/cms_menu_blackbox.c \
645 cms
/cms_menu_builtin.c \
647 cms
/cms_menu_ledstrip.c \
648 cms
/cms_menu_misc.c \
651 common
/colorconversion.c \
652 drivers
/display_ug2864hsweg01.c \
653 drivers
/light_ws2811strip.c \
654 drivers
/serial_escserial.c \
655 drivers
/sonar_hcsr04.c \
656 drivers
/vtx_common.c \
657 flight
/navigation.c \
658 flight
/gps_conversion.c \
660 io
/displayport_max7456.c \
661 io
/displayport_msp.c \
662 io
/displayport_oled.c \
667 sensors
/barometer.c \
668 telemetry
/telemetry.c \
673 telemetry
/smartport.c \
675 telemetry
/mavlink.c \
677 sensors
/esc_sensor.c \
679 io
/vtx_smartaudio.c \
682 SPEED_OPTIMISED_SRC
:= ""
683 SIZE_OPTIMISED_SRC
:= ""
685 ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
686 SPEED_OPTIMISED_SRC
:= $(SPEED_OPTIMISED_SRC
) \
690 common
/typeconversion.c \
692 drivers
/buf_writer.c \
693 drivers
/bus_i2c_soft.c \
695 drivers
/bus_spi_soft.c \
697 drivers
/gyro_sync.c \
699 drivers
/light_led.c \
701 drivers
/rx_nrf24l01.c \
704 drivers
/pwm_output.c \
708 drivers
/serial_uart.c \
709 drivers
/sound_beeper.c \
710 drivers
/stack_check.c \
716 fc/runtime_config.c \
717 flight
/altitudehold.c \
725 io
/statusindicator.c \
743 scheduler
/scheduler.c \
744 sensors
/acceleration.c \
745 sensors
/boardalignment.c \
748 $(DEVICE_STDPERIPH_SRC
) \
749 blackbox
/blackbox.c \
750 blackbox
/blackbox_io.c \
751 drivers
/display_ug2864hsweg01.c \
752 drivers
/light_ws2811strip.c \
753 drivers
/serial_softserial.c \
755 io
/displayport_max7456.c \
756 io
/displayport_msp.c \
757 io
/displayport_oled.c \
760 telemetry
/telemetry.c \
764 telemetry
/smartport.c \
766 telemetry
/mavlink.c \
767 telemetry
/esc_telemetry.c \
769 SIZE_OPTIMISED_SRC
:= $(SIZE_OPTIMISED_SRC
) \
770 drivers
/serial_escserial.c \
771 drivers
/vtx_common.c \
774 io
/serial_4way_avrootloader.c \
775 io
/serial_4way_stk500v2.c \
778 cms
/cms_menu_blackbox.c \
779 cms
/cms_menu_builtin.c \
781 cms
/cms_menu_ledstrip.c \
782 cms
/cms_menu_misc.c \
785 io
/vtx_smartaudio.c \
789 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
791 vcpf4
/stm32f4xx_it.c \
795 vcpf4
/usbd_cdc_vcp.c \
796 drivers
/serial_usb_vcp.c
797 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
799 vcp_hal
/usbd_desc.c \
800 vcp_hal
/usbd_conf.c \
801 vcp_hal
/usbd_cdc_interface.c \
802 drivers
/serial_usb_vcp.c
812 drivers
/serial_usb_vcp.c \
816 STM32F10x_COMMON_SRC
= \
817 drivers
/adc_stm32f10x.c \
818 drivers
/bus_i2c_stm32f10x.c \
820 drivers
/gpio_stm32f10x.c \
822 drivers
/light_ws2811strip_stm32f10x.c \
823 drivers
/serial_uart_stm32f10x.c \
824 drivers
/system_stm32f10x.c \
825 drivers
/timer_stm32f10x.c
827 STM32F30x_COMMON_SRC
= \
828 target
/system_stm32f30x.c \
829 drivers
/adc_stm32f30x.c \
830 drivers
/bus_i2c_stm32f30x.c \
832 drivers
/gpio_stm32f30x.c \
833 drivers
/light_ws2811strip_stm32f30x.c \
834 drivers
/pwm_output_stm32f3xx.c \
835 drivers
/serial_uart_stm32f30x.c \
836 drivers
/system_stm32f30x.c \
837 drivers
/timer_stm32f30x.c
839 STM32F4xx_COMMON_SRC
= \
840 target
/system_stm32f4xx.c \
841 drivers
/accgyro_mpu.c \
842 drivers
/adc_stm32f4xx.c \
843 drivers
/bus_i2c_stm32f10x.c \
844 drivers
/dma_stm32f4xx.c \
845 drivers
/gpio_stm32f4xx.c \
847 drivers
/light_ws2811strip_stm32f4xx.c \
848 drivers
/pwm_output_stm32f4xx.c \
849 drivers
/serial_uart_stm32f4xx.c \
850 drivers
/system_stm32f4xx.c \
851 drivers
/timer_stm32f4xx.c
853 STM32F7xx_COMMON_SRC
= \
854 target
/system_stm32f7xx.c \
855 drivers
/accgyro_mpu.c \
856 drivers
/adc_stm32f7xx.c \
857 drivers
/bus_i2c_hal.c \
858 drivers
/dma_stm32f7xx.c \
859 drivers
/gpio_stm32f7xx.c \
861 drivers
/bus_spi_hal.c \
862 drivers
/pwm_output_stm32f7xx.c \
863 drivers
/timer_hal.c \
864 drivers
/timer_stm32f7xx.c \
865 drivers
/system_stm32f7xx.c \
866 drivers
/serial_uart_stm32f7xx.c \
867 drivers
/serial_uart_hal.c
869 F7EXCLUDES
= drivers
/bus_spi.c \
872 drivers
/serial_uart.c
874 # check if target.mk supplied
875 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
876 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F4xx_COMMON_SRC
) $(TARGET_SRC
)
877 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
878 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F7xx_COMMON_SRC
) $(TARGET_SRC
)
879 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
880 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F30x_COMMON_SRC
) $(TARGET_SRC
)
881 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F1_TARGETS
)))
882 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F10x_COMMON_SRC
) $(TARGET_SRC
)
885 ifneq ($(filter ONBOARDFLASH
,$(FEATURES
)),)
887 drivers
/flash_m25p16.c \
891 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
) $(F4_TARGETS
) $(F3_TARGETS
)))
892 TARGET_SRC
+= $(HIGHEND_SRC
)
893 else ifneq ($(filter HIGHEND
,$(FEATURES
)),)
894 TARGET_SRC
+= $(HIGHEND_SRC
)
897 TARGET_SRC
+= $(COMMON_SRC
)
899 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
900 TARGET_SRC
:= $(filter-out ${F7EXCLUDES}, $(TARGET_SRC
))
903 ifneq ($(filter SDCARD
,$(FEATURES
)),)
906 drivers
/sdcard_standard.c \
907 io
/asyncfatfs
/asyncfatfs.c \
908 io
/asyncfatfs
/fat_standard.c
911 ifneq ($(filter VCP
,$(FEATURES
)),)
912 TARGET_SRC
+= $(VCP_SRC
)
914 # end target specific make file checks
917 # Search path and source files for the ST stdperiph library
918 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/src
920 ###############################################################################
921 # Things that might need changing to use different tools
924 # Find out if ccache is installed on the system
926 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
932 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
933 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
934 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
935 SIZE
:= $(ARM_SDK_PREFIX
)size
942 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
946 ifeq ($(TARGET
),$(filter $(TARGET
),$(F1_TARGETS
)))
947 OPTIMISE_DEFAULT
:= -Os
949 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
951 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
952 OPTIMISE_DEFAULT
:= -O2
953 OPTIMISE_SPEED
:= -Ofast
956 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
959 OPTIMISE_DEFAULT
:= -Ofast
961 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
965 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
966 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
967 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
970 OPTIMISE_DEFAULT
:= -O0
972 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
974 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
977 DEBUG_FLAGS
= -ggdb3
-DDEBUG
979 CFLAGS
+= $(ARCH_FLAGS
) \
980 $(addprefix -D
,$(OPTIONS
)) \
981 $(addprefix -I
,$(INCLUDE_DIRS
)) \
984 -Wall
-Wextra
-Wunsafe-loop-optimizations
-Wdouble-promotion \
985 -ffunction-sections \
989 -DUSE_STDPERIPH_DRIVER \
992 -D
'__FORKNAME__="$(FORKNAME)"' \
993 -D
'__TARGET__="$(TARGET)"' \
994 -D
'__REVISION__="$(REVISION)"' \
998 ASFLAGS
= $(ARCH_FLAGS
) \
999 -x assembler-with-cpp \
1000 $(addprefix -I
,$(INCLUDE_DIRS
)) \
1005 --specs
=nano.specs \
1012 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
1013 -Wl
,-L
$(LINKER_DIR
) \
1015 -Wl
,--no-wchar-size-warning \
1018 ###############################################################################
1019 # No user-serviceable parts below
1020 ###############################################################################
1022 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
1023 --std
=c99
--inline-suppr
--quiet
--force \
1024 $(addprefix -I
,$(INCLUDE_DIRS
)) \
1025 -I
/usr
/include -I
/usr
/include/linux
1028 # Things we will build
1030 TARGET_BIN
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).bin
1031 TARGET_HEX
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).hex
1032 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
1033 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
1034 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
1035 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
1038 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
1039 CLEAN_ARTIFACTS
+= $(TARGET_HEX
)
1040 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
1042 # Make sure build date and revision is updated on every incremental build
1043 $(OBJECT_DIR
)/$(TARGET
)/build
/version.o
: $(TARGET_SRC
)
1045 # List of buildable ELF files and their object dependencies.
1046 # It would be nice to compute these lists, but that seems to be just beyond make.
1048 $(TARGET_HEX
): $(TARGET_ELF
)
1049 $(V0
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
1051 $(TARGET_BIN
): $(TARGET_ELF
)
1052 $(V0
) $(OBJCOPY
) -O binary
$< $@
1054 $(TARGET_ELF
): $(TARGET_OBJS
)
1055 $(V1
) echo Linking
$(TARGET
)
1056 $(V1
) $(CROSS_CC
) -o
$@
$^
$(LDFLAGS
)
1057 $(V0
) $(SIZE
) $(TARGET_ELF
)
1060 ifneq ($(DEBUG
),GDB
)
1061 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
1062 $(V1
) mkdir
-p
$(dir $@
)
1063 $(V1
) $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
1064 echo
"%% (speed optimised) $(notdir $<)" "$(STDOUT)" && \
1065 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_SPEED_OPTIMISATION
) $<, \
1066 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
1067 echo
"%% (size optimised) $(notdir $<)" "$(STDOUT)" && \
1068 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_SIZE_OPTIMISATION
) $<, \
1069 echo
"%% $(notdir $<)" "$(STDOUT)" && \
1070 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_DEFAULT_OPTIMISATION
) $<))
1072 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
1073 $(V1
) mkdir
-p
$(dir $@
)
1074 $(V1
) echo
"%% $(notdir $<)" "$(STDOUT)" && \
1075 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_DEBUG_OPTIMISATION
) $<
1079 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
1080 $(V1
) mkdir
-p
$(dir $@
)
1081 $(V1
) echo
"%% $(notdir $<)" "$(STDOUT)"
1082 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
1084 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
1085 $(V1
) mkdir
-p
$(dir $@
)
1086 $(V1
) echo
"%% $(notdir $<)" "$(STDOUT)"
1087 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
1089 ## sample : Build all sample (travis) targets
1090 sample
: $(SAMPLE_TARGETS
)
1092 ## all : Build all valid targets
1093 all: $(VALID_TARGETS
)
1097 echo
"Building $@" && \
1098 $(MAKE
) binary hex TARGET
=$@
&& \
1099 echo
"Building $@ succeeded."
1103 CLEAN_TARGETS
= $(addprefix clean_
,$(VALID_TARGETS
) )
1104 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
) )
1106 ## clean : clean up temporary / machine-generated files
1108 $(V0
) echo
"Cleaning $(TARGET)"
1109 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
1110 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
1111 $(V0
) echo
"Cleaning $(TARGET) succeeded."
1113 ## clean_test : clean up temporary / machine-generated files (tests)
1115 $(V0
) cd src
/test && $(MAKE
) clean || true
1117 ## clean_<TARGET> : clean up one specific target
1119 $(V0
) $(MAKE
) -j TARGET
=$(subst clean_
,,$@
) clean
1121 ## <TARGET>_clean : clean up one specific target (alias for above)
1123 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
1125 ## clean_all : clean all valid targets
1126 clean_all
:$(CLEAN_TARGETS
)
1128 ## all_clean : clean all valid targets (alias for above)
1129 all_clean
:$(TARGETS_CLEAN
)
1132 flash_
$(TARGET
): $(TARGET_HEX
)
1133 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
1134 $(V0
) echo
-n
'R' >$(SERIAL_DEVICE
)
1135 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
1137 ## flash : flash firmware (.hex) onto flight controller
1138 flash
: flash_
$(TARGET
)
1140 st-flash_
$(TARGET
): $(TARGET_BIN
)
1141 $(V0
) st-flash
--reset write
$< 0x08000000
1143 ## st-flash : flash firmware (.bin) onto flight controller
1144 st-flash
: st-flash_
$(TARGET
)
1147 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
1150 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
1152 unbrick_
$(TARGET
): $(TARGET_HEX
)
1153 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
1154 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
1156 ## unbrick : unbrick flight controller
1157 unbrick
: unbrick_
$(TARGET
)
1159 ## cppcheck : run static analysis on C source code
1160 cppcheck
: $(CSOURCES
)
1163 cppcheck-result.xml
: $(CSOURCES
)
1164 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
1176 ## help : print this help message and exit
1177 help
: Makefile make
/tools.mk
1179 $(V0
) @echo
"Makefile for the $(FORKNAME) firmware"
1181 $(V0
) @echo
"Usage:"
1182 $(V0
) @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
1184 $(V0
) @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
1186 $(V0
) @echo
"Valid TARGET values are: $(VALID_TARGETS)"
1188 $(V0
) @sed
-n
's/^## //p' $?
1190 ## targets : print a list of all valid target platforms (for consumption by scripts)
1192 $(V0
) @echo
"Valid targets: $(VALID_TARGETS)"
1193 $(V0
) @echo
"Target: $(TARGET)"
1194 $(V0
) @echo
"Base target: $(BASE_TARGET)"
1196 ## test : run the cleanflight test suite
1197 ## junittest : run the cleanflight test suite, producing Junit XML result files.
1199 $(V0
) cd src
/test && $(MAKE
) $@
1201 # rebuild everything when makefile changes
1202 $(TARGET_OBJS
) : Makefile
1204 # include auto-generated dependencies
1205 -include $(TARGET_DEPS
)