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
84 TOOLS_DIR
:= $(ROOT
)/tools
85 BUILD_DIR
:= $(ROOT
)/build
86 DL_DIR
:= $(ROOT
)/downloads
90 # import macros that are OS specific
91 include $(ROOT
)/make
/$(OSFAMILY
).mk
93 # include the tools makefile
94 include $(ROOT
)/make
/tools.mk
96 # default xtal value for F4 targets
99 # used for turning on features like VCP and SDCARD
102 SAMPLE_TARGETS
= ALIENFLIGHTF3 ALIENFLIGHTF4 ANYFCF7 BETAFLIGHTF3 BLUEJAYF4 CC3D FURYF4 NAZE REVO SIRINFPV SPARKY SPRACINGF3 SPRACINGF3EVO STM32F3DISCOVERY
103 ALT_TARGETS
= $(sort $(filter-out target
, $(basename $(notdir $(wildcard $(ROOT
)/src
/main
/target
/*/*.mk
)))))
104 OPBL_TARGETS
= $(filter %_OPBL
, $(ALT_TARGETS
))
106 VALID_TARGETS
= $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/target.mk
))
107 VALID_TARGETS
:= $(subst /,, $(subst .
/src
/main
/target
/,, $(VALID_TARGETS
)))
108 VALID_TARGETS
:= $(VALID_TARGETS
) $(ALT_TARGETS
)
109 VALID_TARGETS
:= $(sort $(VALID_TARGETS
))
111 ifeq ($(filter $(TARGET
),$(ALT_TARGETS
)), $(TARGET
))
112 BASE_TARGET
:= $(firstword $(subst /,, $(subst .
/src
/main
/target
/,, $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/$(TARGET
).mk
)))))
113 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/$(TARGET
).mk
115 BASE_TARGET
:= $(TARGET
)
118 ifeq ($(filter $(TARGET
),$(OPBL_TARGETS
)), $(TARGET
))
122 # silently ignore if the file is not present. Allows for target specific.
123 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/target.mk
125 F4_TARGETS
= $(F405_TARGETS
) $(F411_TARGETS
)
126 F7_TARGETS
= $(F7X2RE_TARGETS
) $(F7X5XE_TARGETS
) $(F7X5XG_TARGETS
) $(F7X5XI_TARGETS
) $(F7X6XG_TARGETS
)
128 ifeq ($(filter $(TARGET
),$(VALID_TARGETS
)),)
129 $(error Target
'$(TARGET)' is not valid
, must be one of
$(VALID_TARGETS
). Have you prepared a valid target.mk?
)
132 ifeq ($(filter $(TARGET
),$(F1_TARGETS
) $(F3_TARGETS
) $(F4_TARGETS
) $(F7_TARGETS
)),)
133 $(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?
)
136 128K_TARGETS
= $(F1_TARGETS
)
137 256K_TARGETS
= $(F3_TARGETS
)
138 512K_TARGETS
= $(F411_TARGETS
) $(F7X2RE_TARGETS
) $(F7X5XE_TARGETS
)
139 1024K_TARGETS
= $(F405_TARGETS
) $(F7X5XG_TARGETS
) $(F7X6XG_TARGETS
)
140 2048K_TARGETS
= $(F7X5XI_TARGETS
)
142 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
143 ifeq ($(FLASH_SIZE
),)
144 ifeq ($(TARGET
),$(filter $(TARGET
),$(2048K_TARGETS
)))
146 else ifeq ($(TARGET
),$(filter $(TARGET
),$(1024K_TARGETS
)))
148 else ifeq ($(TARGET
),$(filter $(TARGET
),$(512K_TARGETS
)))
150 else ifeq ($(TARGET
),$(filter $(TARGET
),$(256K_TARGETS
)))
152 else ifeq ($(TARGET
),$(filter $(TARGET
),$(128K_TARGETS
)))
155 $(error FLASH_SIZE not configured for target
$(TARGET
))
159 # note that there is no hardfault debugging startup file assembly handler for other platforms
160 ifeq ($(DEBUG_HARDFAULTS
),F3
)
161 CFLAGS
+= -DDEBUG_HARDFAULTS
162 STM32F30x_COMMON_SRC
= startup_stm32f3_debug_hardfault_handler.S
164 STM32F30x_COMMON_SRC
= startup_stm32f30x_md_gcc.S
167 ifeq ($(DEBUG_HARDFAULTS
),F7
)
168 CFLAGS
+= -DDEBUG_HARDFAULTS
171 REVISION
:= $(shell git log
-1 --format
="%h")
173 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
174 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
175 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
177 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
179 # Search path for sources
180 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
181 USBFS_DIR
= $(ROOT
)/lib
/main
/STM32_USB-FS-Device_Driver
182 USBPERIPH_SRC
= $(notdir $(wildcard $(USBFS_DIR
)/src
/*.c
))
183 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
184 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
186 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
188 ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
191 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F30x_StdPeriph_Driver
192 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
193 EXCLUDES
= stm32f30x_crc.c \
195 STARTUP_SRC
= startup_stm32f30x_md_gcc.S
197 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
198 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
200 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM1
/CoreSupport
:$(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
201 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM1
/CoreSupport
/*.c \
202 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
/*.c
))
204 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
205 $(STDPERIPH_DIR
)/inc \
206 $(CMSIS_DIR
)/CM1
/CoreSupport \
207 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
209 ifneq ($(filter VCP
, $(FEATURES
)),)
210 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
214 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
216 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
)\
220 ifneq ($(filter SDCARD
, $(FEATURES
)),)
221 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
224 VPATH
:= $(VPATH
):$(FATFS_DIR
)
227 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k.
ld
229 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
230 DEVICE_FLAGS
= -DSTM32F303xC
-DSTM32F303
234 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F4_TARGETS
)))
237 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F4xx_StdPeriph_Driver
238 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
239 EXCLUDES
= stm32f4xx_crc.c \
245 stm32f4xx_flash_ramfunc.c \
249 stm32f4xx_spdifrx.c \
251 stm32f4xx_cryp_aes.c \
252 stm32f4xx_hash_md5.c \
253 stm32f4xx_cryp_des.c \
257 stm32f4xx_cryp_tdes.c \
258 stm32f4xx_hash_sha1.c
260 ifeq ($(TARGET
),$(filter $(TARGET
), $(F411_TARGETS
)))
261 EXCLUDES
+= stm32f4xx_fsmc.c
264 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
267 USBCORE_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Core
268 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/src
/*.c
))
269 USBOTG_DIR
= $(ROOT
)/lib
/main
/STM32_USB_OTG_Driver
270 USBOTG_SRC
= $(notdir $(wildcard $(USBOTG_DIR
)/src
/*.c
))
271 EXCLUDES
= usb_bsp_template.c \
272 usb_conf_template.c \
277 USBOTG_SRC
:= $(filter-out ${EXCLUDES}, $(USBOTG_SRC
))
278 USBCDC_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Class
/cdc
279 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/src
/*.c
))
280 EXCLUDES
= usbd_cdc_if_template.c
281 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
282 VPATH
:= $(VPATH
):$(USBOTG_DIR
)/src
:$(USBCORE_DIR
)/src
:$(USBCDC_DIR
)/src
284 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
290 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM4
/CoreSupport
:$(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
291 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM4
/CoreSupport
/*.c \
292 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
/*.c
))
293 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
294 $(STDPERIPH_DIR
)/inc \
299 $(CMSIS_DIR
)/CM4
/CoreSupport \
300 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx \
301 $(ROOT
)/src
/main
/vcpf4
303 ifneq ($(filter SDCARD
,$(FEATURES
)),)
304 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
306 VPATH
:= $(VPATH
):$(FATFS_DIR
)
310 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-march
=armv7e-m
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
312 ifeq ($(TARGET
),$(filter $(TARGET
),$(F411_TARGETS
)))
313 DEVICE_FLAGS
= -DSTM32F411xE
314 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411.
ld
315 STARTUP_SRC
= startup_stm32f411xe.s
316 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F405_TARGETS
)))
317 DEVICE_FLAGS
= -DSTM32F40_41xxx
318 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405.
ld
319 STARTUP_SRC
= startup_stm32f40xx.s
321 $(error Unknown MCU for F4 target
)
323 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
328 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F7_TARGETS
)))
331 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F7xx_HAL_Driver
332 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/Src
/*.c
))
333 EXCLUDES
= stm32f7xx_hal_timebase_rtc_wakeup_template.c \
334 stm32f7xx_hal_timebase_rtc_alarm_template.c \
335 stm32f7xx_hal_timebase_tim_template.c
337 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
340 USBCORE_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Core
341 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/Src
/*.c
))
342 EXCLUDES
= usbd_conf_template.c
343 USBCORE_SRC
:= $(filter-out ${EXCLUDES}, $(USBCORE_SRC
))
345 USBCDC_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Class
/CDC
346 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/Src
/*.c
))
347 EXCLUDES
= usbd_cdc_if_template.c
348 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
350 VPATH
:= $(VPATH
):$(USBCDC_DIR
)/Src
:$(USBCORE_DIR
)/Src
352 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
357 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM7
/Include
:$(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
358 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/Src
359 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM7
/Include
/*.c \
360 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/*.c
))
361 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
362 $(STDPERIPH_DIR
)/Inc \
365 $(CMSIS_DIR
)/CM7
/Include \
366 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/Include \
367 $(ROOT
)/src
/main
/vcp_hal
369 ifneq ($(filter SDCARD
,$(FEATURES
)),)
370 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
372 VPATH
:= $(VPATH
):$(FATFS_DIR
)
376 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m7
-mfloat-abi
=hard
-mfpu
=fpv5-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
378 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X5XG_TARGETS
)))
379 DEVICE_FLAGS
= -DSTM32F745xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
380 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f745.
ld
381 STARTUP_SRC
= startup_stm32f745xx.s
382 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X6XG_TARGETS
)))
383 DEVICE_FLAGS
= -DSTM32F746xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
384 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f746.
ld
385 STARTUP_SRC
= startup_stm32f746xx.s
386 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X2RE_TARGETS
)))
387 DEVICE_FLAGS
= -DSTM32F722xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
388 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f722.
ld
389 STARTUP_SRC
= startup_stm32f722xx.s
391 $(error Unknown MCU for F7 target
)
393 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
395 TARGET_FLAGS
= -D
$(TARGET
)
402 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F10x_StdPeriph_Driver
403 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
404 EXCLUDES
= stm32f10x_crc.c \
407 STARTUP_SRC
= startup_stm32f10x_md_gcc.S
408 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
410 # Search path and source files for the CMSIS sources
411 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM3
/CoreSupport
:$(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
412 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM3
/CoreSupport
/*.c \
413 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
/*.c
))
415 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
416 $(STDPERIPH_DIR
)/inc \
417 $(CMSIS_DIR
)/CM3
/CoreSupport \
418 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
420 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
422 ifneq ($(filter VCP
, $(FEATURES
)),)
423 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
427 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
429 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
) \
434 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k.
ld
435 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m3
437 ifeq ($(DEVICE_FLAGS
),)
438 DEVICE_FLAGS
= -DSTM32F10X_MD
440 DEVICE_FLAGS
+= -DSTM32F10X
446 ifneq ($(BASE_TARGET
), $(TARGET
))
447 TARGET_FLAGS
:= $(TARGET_FLAGS
) -D
$(BASE_TARGET
)
450 ifneq ($(FLASH_SIZE
),)
451 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFLASH_SIZE
=$(FLASH_SIZE
)
454 ifneq ($(HSE_VALUE
),)
455 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
458 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)
459 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
462 TARGET_FLAGS
:= -DOPBL
$(TARGET_FLAGS
)
463 ifeq ($(TARGET
), $(filter $(TARGET
),$(F405_TARGETS
)))
464 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405_opbl.
ld
465 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F411_TARGETS
)))
466 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411_opbl.
ld
467 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F3_TARGETS
)))
468 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k_opbl.
ld
469 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F1_TARGETS
)))
470 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k_opbl.
ld
472 .DEFAULT_GOAL
:= binary
477 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
478 $(ROOT
)/lib
/main
/MAVLink
480 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
483 VPATH
:= $(VPATH
):$(TARGET_DIR
)
486 build
/build_config.c \
496 common
/typeconversion.c \
497 config
/config_eeprom.c \
499 config
/parameter_group.c \
501 drivers
/buf_writer.c \
502 drivers
/bus_i2c_soft.c \
504 drivers
/bus_spi_soft.c \
507 drivers
/gyro_sync.c \
509 drivers
/light_led.c \
511 drivers
/rx_nrf24l01.c \
514 drivers
/pwm_esc_detect.c \
515 drivers
/pwm_output.c \
519 drivers
/serial_uart.c \
520 drivers
/sound_beeper.c \
521 drivers
/stack_check.c \
533 fc/runtime_config.c \
535 flight
/altitudehold.c \
544 io
/serial_4way_avrootloader.c \
545 io
/serial_4way_stk500v2.c \
546 io
/statusindicator.c \
565 scheduler
/scheduler.c \
566 sensors
/acceleration.c \
568 sensors
/boardalignment.c \
571 sensors
/initialisation.c \
573 $(DEVICE_STDPERIPH_SRC
)
576 blackbox
/blackbox.c \
577 blackbox
/blackbox_io.c \
579 cms
/cms_menu_blackbox.c \
580 cms
/cms_menu_builtin.c \
582 cms
/cms_menu_ledstrip.c \
583 cms
/cms_menu_misc.c \
586 common
/colorconversion.c \
587 drivers
/display_ug2864hsweg01.c \
588 drivers
/light_ws2811strip.c \
589 drivers
/serial_escserial.c \
590 drivers
/serial_softserial.c \
591 drivers
/sonar_hcsr04.c \
592 flight
/navigation.c \
593 flight
/gps_conversion.c \
595 io
/displayport_max7456.c \
596 io
/displayport_msp.c \
597 io
/displayport_oled.c \
602 sensors
/barometer.c \
603 telemetry
/telemetry.c \
608 telemetry
/smartport.c \
610 telemetry
/mavlink.c \
612 sensors
/esc_sensor.c \
615 SPEED_OPTIMISED_SRC
:= ""
616 SIZE_OPTIMISED_SRC
:= ""
618 ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
619 SPEED_OPTIMISED_SRC
:= $(SPEED_OPTIMISED_SRC
) \
623 common
/typeconversion.c \
625 drivers
/buf_writer.c \
626 drivers
/bus_i2c_soft.c \
628 drivers
/bus_spi_soft.c \
630 drivers
/gyro_sync.c \
632 drivers
/light_led.c \
634 drivers
/rx_nrf24l01.c \
637 drivers
/pwm_output.c \
641 drivers
/serial_uart.c \
642 drivers
/sound_beeper.c \
643 drivers
/stack_check.c \
650 fc/runtime_config.c \
651 flight
/altitudehold.c \
659 io
/statusindicator.c \
677 scheduler
/scheduler.c \
678 sensors
/acceleration.c \
679 sensors
/boardalignment.c \
682 $(DEVICE_STDPERIPH_SRC
) \
683 blackbox
/blackbox.c \
684 blackbox
/blackbox_io.c \
685 drivers
/display_ug2864hsweg01.c \
686 drivers
/light_ws2811strip.c \
687 drivers
/serial_softserial.c \
689 io
/displayport_max7456.c \
690 io
/displayport_msp.c \
691 io
/displayport_oled.c \
694 telemetry
/telemetry.c \
698 telemetry
/smartport.c \
700 telemetry
/mavlink.c \
701 telemetry
/esc_telemetry.c \
703 SIZE_OPTIMISED_SRC
:= $(SIZE_OPTIMISED_SRC
) \
704 drivers
/serial_escserial.c \
707 io
/serial_4way_avrootloader.c \
708 io
/serial_4way_stk500v2.c \
711 cms
/cms_menu_blackbox.c \
712 cms
/cms_menu_builtin.c \
714 cms
/cms_menu_ledstrip.c \
715 cms
/cms_menu_misc.c \
721 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
723 vcpf4
/stm32f4xx_it.c \
727 vcpf4
/usbd_cdc_vcp.c \
728 drivers
/serial_usb_vcp.c
729 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
731 vcp_hal
/usbd_desc.c \
732 vcp_hal
/usbd_conf.c \
733 vcp_hal
/usbd_cdc_interface.c \
734 drivers
/serial_usb_vcp.c
744 drivers
/serial_usb_vcp.c \
748 STM32F10x_COMMON_SRC
= \
749 drivers
/adc_stm32f10x.c \
750 drivers
/bus_i2c_stm32f10x.c \
752 drivers
/gpio_stm32f10x.c \
754 drivers
/light_ws2811strip_stm32f10x.c \
755 drivers
/serial_uart_stm32f10x.c \
756 drivers
/system_stm32f10x.c \
757 drivers
/timer_stm32f10x.c
759 STM32F30x_COMMON_SRC
= \
760 target
/system_stm32f30x.c \
761 drivers
/adc_stm32f30x.c \
762 drivers
/bus_i2c_stm32f30x.c \
764 drivers
/gpio_stm32f30x.c \
765 drivers
/light_ws2811strip_stm32f30x.c \
766 drivers
/pwm_output_stm32f3xx.c \
767 drivers
/serial_uart_stm32f30x.c \
768 drivers
/system_stm32f30x.c \
769 drivers
/timer_stm32f30x.c
771 STM32F4xx_COMMON_SRC
= \
772 target
/system_stm32f4xx.c \
773 drivers
/accgyro_mpu.c \
774 drivers
/adc_stm32f4xx.c \
775 drivers
/bus_i2c_stm32f10x.c \
776 drivers
/dma_stm32f4xx.c \
777 drivers
/gpio_stm32f4xx.c \
779 drivers
/light_ws2811strip_stm32f4xx.c \
780 drivers
/pwm_output_stm32f4xx.c \
781 drivers
/serial_uart_stm32f4xx.c \
782 drivers
/system_stm32f4xx.c \
783 drivers
/timer_stm32f4xx.c
785 STM32F7xx_COMMON_SRC
= \
786 target
/system_stm32f7xx.c \
787 drivers
/accgyro_mpu.c \
788 drivers
/adc_stm32f7xx.c \
789 drivers
/bus_i2c_hal.c \
790 drivers
/dma_stm32f7xx.c \
791 drivers
/gpio_stm32f7xx.c \
793 drivers
/bus_spi_hal.c \
794 drivers
/pwm_output_stm32f7xx.c \
795 drivers
/timer_hal.c \
796 drivers
/timer_stm32f7xx.c \
797 drivers
/system_stm32f7xx.c \
798 drivers
/serial_uart_stm32f7xx.c \
799 drivers
/serial_uart_hal.c
801 F7EXCLUDES
= drivers
/bus_spi.c \
804 drivers
/serial_uart.c
806 # check if target.mk supplied
807 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
808 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F4xx_COMMON_SRC
) $(TARGET_SRC
)
809 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
810 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F7xx_COMMON_SRC
) $(TARGET_SRC
)
811 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
812 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F30x_COMMON_SRC
) $(TARGET_SRC
)
813 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F1_TARGETS
)))
814 TARGET_SRC
:= $(STARTUP_SRC
) $(STM32F10x_COMMON_SRC
) $(TARGET_SRC
)
817 ifneq ($(filter ONBOARDFLASH
,$(FEATURES
)),)
819 drivers
/flash_m25p16.c \
823 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
) $(F4_TARGETS
) $(F3_TARGETS
)))
824 TARGET_SRC
+= $(HIGHEND_SRC
)
825 else ifneq ($(filter HIGHEND
,$(FEATURES
)),)
826 TARGET_SRC
+= $(HIGHEND_SRC
)
829 TARGET_SRC
+= $(COMMON_SRC
)
831 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
832 TARGET_SRC
:= $(filter-out ${F7EXCLUDES}, $(TARGET_SRC
))
835 ifneq ($(filter SDCARD
,$(FEATURES
)),)
838 drivers
/sdcard_standard.c \
839 io
/asyncfatfs
/asyncfatfs.c \
840 io
/asyncfatfs
/fat_standard.c
843 ifneq ($(filter VCP
,$(FEATURES
)),)
844 TARGET_SRC
+= $(VCP_SRC
)
846 # end target specific make file checks
849 # Search path and source files for the ST stdperiph library
850 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/src
852 ###############################################################################
853 # Things that might need changing to use different tools
856 # Find out if ccache is installed on the system
858 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
864 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
865 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
866 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
867 SIZE
:= $(ARM_SDK_PREFIX
)size
874 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
878 ifeq ($(TARGET
),$(filter $(TARGET
),$(F1_TARGETS
)))
879 OPTIMISE_DEFAULT
:= -Os
881 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
883 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
884 OPTIMISE_DEFAULT
:= -O2
885 OPTIMISE_SPEED
:= -Ofast
888 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
891 OPTIMISE_DEFAULT
:= -Ofast
893 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
897 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
898 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
899 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
902 OPTIMISE_DEFAULT
:= -O0
904 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
906 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
909 DEBUG_FLAGS
= -ggdb3
-DDEBUG
911 CFLAGS
+= $(ARCH_FLAGS
) \
912 $(addprefix -D
,$(OPTIONS
)) \
913 $(addprefix -I
,$(INCLUDE_DIRS
)) \
916 -Wall
-Wextra
-Wunsafe-loop-optimizations
-Wdouble-promotion \
917 -ffunction-sections \
921 -DUSE_STDPERIPH_DRIVER \
924 -D
'__FORKNAME__="$(FORKNAME)"' \
925 -D
'__TARGET__="$(TARGET)"' \
926 -D
'__REVISION__="$(REVISION)"' \
930 ASFLAGS
= $(ARCH_FLAGS
) \
931 -x assembler-with-cpp \
932 $(addprefix -I
,$(INCLUDE_DIRS
)) \
944 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
945 -Wl
,-L
$(LINKER_DIR
) \
947 -Wl
,--no-wchar-size-warning \
950 ###############################################################################
951 # No user-serviceable parts below
952 ###############################################################################
954 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
955 --std
=c99
--inline-suppr
--quiet
--force \
956 $(addprefix -I
,$(INCLUDE_DIRS
)) \
957 -I
/usr
/include -I
/usr
/include/linux
960 # Things we will build
962 TARGET_BIN
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).bin
963 TARGET_HEX
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).hex
964 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
965 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
966 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
967 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
970 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
971 CLEAN_ARTIFACTS
+= $(TARGET_HEX
)
972 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
974 # Make sure build date and revision is updated on every incremental build
975 $(OBJECT_DIR
)/$(TARGET
)/build
/version.o
: $(TARGET_SRC
)
977 # List of buildable ELF files and their object dependencies.
978 # It would be nice to compute these lists, but that seems to be just beyond make.
980 $(TARGET_HEX
): $(TARGET_ELF
)
981 $(V0
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
983 $(TARGET_BIN
): $(TARGET_ELF
)
984 $(V0
) $(OBJCOPY
) -O binary
$< $@
986 $(TARGET_ELF
): $(TARGET_OBJS
)
987 $(V1
) echo Linking
$(TARGET
)
988 $(V1
) $(CROSS_CC
) -o
$@
$^
$(LDFLAGS
)
989 $(V0
) $(SIZE
) $(TARGET_ELF
)
993 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
994 $(V1
) mkdir
-p
$(dir $@
)
995 $(V1
) $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
996 echo
"%% (speed optimised) $(notdir $<)" "$(STDOUT)" && \
997 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_SPEED_OPTIMISATION
) $<, \
998 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
999 echo
"%% (size optimised) $(notdir $<)" "$(STDOUT)" && \
1000 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_SIZE_OPTIMISATION
) $<, \
1001 echo
"%% $(notdir $<)" "$(STDOUT)" && \
1002 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_DEFAULT_OPTIMISATION
) $<))
1004 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
1005 $(V1
) mkdir
-p
$(dir $@
)
1006 $(V1
) echo
"%% $(notdir $<)" "$(STDOUT)" && \
1007 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_DEBUG_OPTIMISATION
) $<
1011 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
1012 $(V1
) mkdir
-p
$(dir $@
)
1013 $(V1
) echo
"%% $(notdir $<)" "$(STDOUT)"
1014 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
1016 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
1017 $(V1
) mkdir
-p
$(dir $@
)
1018 $(V1
) echo
"%% $(notdir $<)" "$(STDOUT)"
1019 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
1021 ## sample : Build all sample (travis) targets
1022 sample
: $(SAMPLE_TARGETS
)
1024 ## all : Build all valid targets
1025 all: $(VALID_TARGETS
)
1029 echo
"Building $@" && \
1030 $(MAKE
) binary hex TARGET
=$@
&& \
1031 echo
"Building $@ succeeded."
1035 CLEAN_TARGETS
= $(addprefix clean_
,$(VALID_TARGETS
) )
1036 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
) )
1038 ## clean : clean up temporary / machine-generated files
1040 $(V0
) echo
"Cleaning $(TARGET)"
1041 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
1042 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
1043 $(V0
) echo
"Cleaning $(TARGET) succeeded."
1045 ## clean_test : clean up temporary / machine-generated files (tests)
1047 $(V0
) cd src
/test && $(MAKE
) clean || true
1049 ## clean_<TARGET> : clean up one specific target
1051 $(V0
) $(MAKE
) -j TARGET
=$(subst clean_
,,$@
) clean
1053 ## <TARGET>_clean : clean up one specific target (alias for above)
1055 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
1057 ## clean_all : clean all valid targets
1058 clean_all
:$(CLEAN_TARGETS
)
1060 ## all_clean : clean all valid targets (alias for above)
1061 all_clean
:$(TARGETS_CLEAN
)
1064 flash_
$(TARGET
): $(TARGET_HEX
)
1065 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
1066 $(V0
) echo
-n
'R' >$(SERIAL_DEVICE
)
1067 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
1069 ## flash : flash firmware (.hex) onto flight controller
1070 flash
: flash_
$(TARGET
)
1072 st-flash_
$(TARGET
): $(TARGET_BIN
)
1073 $(V0
) st-flash
--reset write
$< 0x08000000
1075 ## st-flash : flash firmware (.bin) onto flight controller
1076 st-flash
: st-flash_
$(TARGET
)
1079 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
1082 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
1084 unbrick_
$(TARGET
): $(TARGET_HEX
)
1085 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
1086 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
1088 ## unbrick : unbrick flight controller
1089 unbrick
: unbrick_
$(TARGET
)
1091 ## cppcheck : run static analysis on C source code
1092 cppcheck
: $(CSOURCES
)
1095 cppcheck-result.xml
: $(CSOURCES
)
1096 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
1108 ## help : print this help message and exit
1109 help
: Makefile make
/tools.mk
1111 $(V0
) @echo
"Makefile for the $(FORKNAME) firmware"
1113 $(V0
) @echo
"Usage:"
1114 $(V0
) @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
1116 $(V0
) @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
1118 $(V0
) @echo
"Valid TARGET values are: $(VALID_TARGETS)"
1120 $(V0
) @sed
-n
's/^## //p' $?
1122 ## targets : print a list of all valid target platforms (for consumption by scripts)
1124 $(V0
) @echo
"Valid targets: $(VALID_TARGETS)"
1125 $(V0
) @echo
"Target: $(TARGET)"
1126 $(V0
) @echo
"Base target: $(BASE_TARGET)"
1128 ## test : run the cleanflight test suite
1129 ## junittest : run the cleanflight test suite, producing Junit XML result files.
1131 $(V0
) cd src
/test && $(MAKE
) $@
1133 # rebuild everything when makefile changes
1134 $(TARGET_OBJS
) : Makefile
1136 # include auto-generated dependencies
1137 -include $(TARGET_DEPS
)