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
79 # developer preferences, edit these at will, they'll be gitignored
80 include $(ROOT
)/make
/local.mk
82 # configure some directories that are relative to wherever ROOT_DIR is located
83 TOOLS_DIR
:= $(ROOT
)/tools
84 BUILD_DIR
:= $(ROOT
)/build
85 DL_DIR
:= $(ROOT
)/downloads
89 # import macros that are OS specific
90 include $(ROOT
)/make
/$(OSFAMILY
).mk
92 # include the tools makefile
93 include $(ROOT
)/make
/tools.mk
95 # default xtal value for F4 targets
98 # used for turning on features like VCP and SDCARD
101 SAMPLE_TARGETS
= ALIENFLIGHTF3 ALIENFLIGHTF4 ANYFCF7 BETAFLIGHTF3 BLUEJAYF4 CC3D FURYF4 NAZE REVO SIRINFPV SPARKY SPRACINGF3 SPRACINGF3EVO STM32F3DISCOVERY
102 ALT_TARGETS
= $(sort $(filter-out target
, $(basename $(notdir $(wildcard $(ROOT
)/src
/main
/target
/*/*.mk
)))))
103 OPBL_TARGETS
= $(filter %_OPBL
, $(ALT_TARGETS
))
105 #VALID_TARGETS = $(F1_TARGETS) $(F3_TARGETS) $(F4_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
= $(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
) $(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 \
196 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
197 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
199 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM1
/CoreSupport
:$(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
200 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM1
/CoreSupport
/*.c \
201 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
/*.c
))
203 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
204 $(STDPERIPH_DIR
)/inc \
205 $(CMSIS_DIR
)/CM1
/CoreSupport \
206 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
208 ifneq ($(filter VCP
, $(FEATURES
)),)
209 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
213 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
215 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
)\
219 ifneq ($(filter SDCARD
, $(FEATURES
)),)
220 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
223 VPATH
:= $(VPATH
):$(FATFS_DIR
)
226 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k.
ld
228 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
229 DEVICE_FLAGS
= -DSTM32F303xC
-DSTM32F303
233 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F4_TARGETS
)))
236 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F4xx_StdPeriph_Driver
237 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
238 EXCLUDES
= stm32f4xx_crc.c \
244 stm32f4xx_flash_ramfunc.c \
248 stm32f4xx_spdifrx.c \
250 stm32f4xx_cryp_aes.c \
251 stm32f4xx_hash_md5.c \
252 stm32f4xx_cryp_des.c \
256 stm32f4xx_cryp_tdes.c \
257 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 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F405_TARGETS
)))
316 DEVICE_FLAGS
= -DSTM32F40_41xxx
317 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405.
ld
319 $(error Unknown MCU for F4 target
)
321 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
326 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F7_TARGETS
)))
329 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F7xx_HAL_Driver
330 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/Src
/*.c
))
331 EXCLUDES
= stm32f7xx_hal_timebase_rtc_wakeup_template.c \
332 stm32f7xx_hal_timebase_rtc_alarm_template.c \
333 stm32f7xx_hal_timebase_tim_template.c
335 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
338 USBCORE_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Core
339 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/Src
/*.c
))
340 EXCLUDES
= usbd_conf_template.c
341 USBCORE_SRC
:= $(filter-out ${EXCLUDES}, $(USBCORE_SRC
))
343 USBCDC_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Class
/CDC
344 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/Src
/*.c
))
345 EXCLUDES
= usbd_cdc_if_template.c
346 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
348 VPATH
:= $(VPATH
):$(USBCDC_DIR
)/Src
:$(USBCORE_DIR
)/Src
350 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
355 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM7
/Include
:$(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
356 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/Src
357 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM7
/Include
/*.c \
358 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/*.c
))
359 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
360 $(STDPERIPH_DIR
)/Inc \
363 $(CMSIS_DIR
)/CM7
/Include \
364 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/Include \
365 $(ROOT
)/src
/main
/vcp_hal
367 ifneq ($(filter SDCARD
,$(FEATURES
)),)
368 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
370 VPATH
:= $(VPATH
):$(FATFS_DIR
)
374 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m7
-mfloat-abi
=hard
-mfpu
=fpv5-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
376 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X5XG_TARGETS
)))
377 DEVICE_FLAGS
= -DSTM32F745xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
378 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f745.
ld
379 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X6XG_TARGETS
)))
380 DEVICE_FLAGS
= -DSTM32F746xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
381 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f746.
ld
383 $(error Unknown MCU for F7 target
)
385 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
387 TARGET_FLAGS
= -D
$(TARGET
)
394 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F10x_StdPeriph_Driver
395 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
396 EXCLUDES
= stm32f10x_crc.c \
400 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
402 # Search path and source files for the CMSIS sources
403 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM3
/CoreSupport
:$(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
404 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM3
/CoreSupport
/*.c \
405 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
/*.c
))
407 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
408 $(STDPERIPH_DIR
)/inc \
409 $(CMSIS_DIR
)/CM3
/CoreSupport \
410 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x \
412 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
414 ifneq ($(filter VCP
, $(FEATURES
)),)
415 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
419 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
421 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
) \
426 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k.
ld
427 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m3
429 ifeq ($(DEVICE_FLAGS
),)
430 DEVICE_FLAGS
= -DSTM32F10X_MD
432 DEVICE_FLAGS
+= -DSTM32F10X
438 ifneq ($(BASE_TARGET
), $(TARGET
))
439 TARGET_FLAGS
:= $(TARGET_FLAGS
) -D
$(BASE_TARGET
)
442 ifneq ($(FLASH_SIZE
),)
443 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFLASH_SIZE
=$(FLASH_SIZE
)
446 ifneq ($(HSE_VALUE
),)
447 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
450 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)
451 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
454 TARGET_FLAGS
:= -DOPBL
$(TARGET_FLAGS
)
455 ifeq ($(TARGET
), $(filter $(TARGET
),$(F405_TARGETS
)))
456 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405_opbl.
ld
457 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F411_TARGETS
)))
458 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411_opbl.
ld
459 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F3_TARGETS
)))
460 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k_opbl.
ld
461 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F1_TARGETS
)))
462 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k_opbl.
ld
464 .DEFAULT_GOAL
:= binary
469 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
470 $(ROOT
)/lib
/main
/MAVLink
472 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
475 VPATH
:= $(VPATH
):$(TARGET_DIR
)
478 build
/build_config.c \
488 common
/typeconversion.c \
489 config
/config_eeprom.c \
491 config
/parameter_group.c \
493 drivers
/buf_writer.c \
494 drivers
/bus_i2c_soft.c \
496 drivers
/bus_spi_soft.c \
499 drivers
/gyro_sync.c \
501 drivers
/light_led.c \
503 drivers
/rx_nrf24l01.c \
506 drivers
/pwm_esc_detect.c \
507 drivers
/pwm_output.c \
511 drivers
/serial_uart.c \
512 drivers
/sound_beeper.c \
513 drivers
/stack_check.c \
522 fc/runtime_config.c \
523 flight
/altitudehold.c \
532 io
/serial_4way_avrootloader.c \
533 io
/serial_4way_stk500v2.c \
535 io
/statusindicator.c \
554 scheduler
/scheduler.c \
555 sensors
/acceleration.c \
557 sensors
/boardalignment.c \
560 sensors
/initialisation.c \
562 $(DEVICE_STDPERIPH_SRC
)
565 blackbox
/blackbox.c \
566 blackbox
/blackbox_io.c \
568 cms
/cms_menu_blackbox.c \
569 cms
/cms_menu_builtin.c \
571 cms
/cms_menu_ledstrip.c \
572 cms
/cms_menu_misc.c \
575 common
/colorconversion.c \
576 drivers
/display_ug2864hsweg01.c \
577 drivers
/light_ws2811strip.c \
578 drivers
/serial_escserial.c \
579 drivers
/serial_softserial.c \
580 drivers
/sonar_hcsr04.c \
582 flight
/navigation.c \
583 flight
/gps_conversion.c \
585 io
/displayport_max7456.c \
586 io
/displayport_msp.c \
587 io
/displayport_oled.c \
592 sensors
/barometer.c \
593 telemetry
/telemetry.c \
597 telemetry
/smartport.c \
599 telemetry
/mavlink.c \
600 sensors
/esc_sensor.c \
602 SPEED_OPTIMISED_SRC
:= ""
603 SIZE_OPTIMISED_SRC
:= ""
605 ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
606 SPEED_OPTIMISED_SRC
:= $(SPEED_OPTIMISED_SRC
) \
610 common
/typeconversion.c \
612 drivers
/buf_writer.c \
613 drivers
/bus_i2c_soft.c \
615 drivers
/bus_spi_soft.c \
617 drivers
/gyro_sync.c \
619 drivers
/light_led.c \
621 drivers
/rx_nrf24l01.c \
624 drivers
/pwm_output.c \
628 drivers
/serial_uart.c \
629 drivers
/sound_beeper.c \
630 drivers
/stack_check.c \
637 fc/runtime_config.c \
638 flight
/altitudehold.c \
646 io
/statusindicator.c \
664 scheduler
/scheduler.c \
665 sensors
/acceleration.c \
666 sensors
/boardalignment.c \
669 $(DEVICE_STDPERIPH_SRC
) \
670 blackbox
/blackbox.c \
671 blackbox
/blackbox_io.c \
672 drivers
/display_ug2864hsweg01.c \
673 drivers
/light_ws2811strip.c \
674 drivers
/serial_softserial.c \
676 io
/displayport_max7456.c \
677 io
/displayport_msp.c \
678 io
/displayport_oled.c \
681 telemetry
/telemetry.c \
685 telemetry
/smartport.c \
687 telemetry
/mavlink.c \
688 telemetry
/esc_telemetry.c \
690 SIZE_OPTIMISED_SRC
:= $(SIZE_OPTIMISED_SRC
) \
691 drivers
/serial_escserial.c \
694 io
/serial_4way_avrootloader.c \
695 io
/serial_4way_stk500v2.c \
698 cms
/cms_menu_blackbox.c \
699 cms
/cms_menu_builtin.c \
701 cms
/cms_menu_ledstrip.c \
702 cms
/cms_menu_misc.c \
707 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
709 vcpf4
/stm32f4xx_it.c \
713 vcpf4
/usbd_cdc_vcp.c \
714 drivers
/serial_usb_vcp.c
715 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
717 vcp_hal
/usbd_desc.c \
718 vcp_hal
/usbd_conf.c \
719 vcp_hal
/usbd_cdc_interface.c \
720 drivers
/serial_usb_vcp_hal.c
730 drivers
/serial_usb_vcp.c \
734 STM32F10x_COMMON_SRC
= \
735 startup_stm32f10x_md_gcc.S \
736 drivers
/adc_stm32f10x.c \
737 drivers
/bus_i2c_stm32f10x.c \
739 drivers
/gpio_stm32f10x.c \
741 drivers
/light_ws2811strip_stm32f10x.c \
742 drivers
/serial_uart_stm32f10x.c \
743 drivers
/system_stm32f10x.c \
744 drivers
/timer_stm32f10x.c
746 STM32F30x_COMMON_SRC
= \
747 startup_stm32f30x_md_gcc.S \
748 target
/system_stm32f30x.c \
749 drivers
/adc_stm32f30x.c \
750 drivers
/bus_i2c_stm32f30x.c \
752 drivers
/gpio_stm32f30x.c \
753 drivers
/light_ws2811strip_stm32f30x.c \
754 drivers
/pwm_output_stm32f3xx.c \
755 drivers
/serial_uart_stm32f30x.c \
756 drivers
/system_stm32f30x.c \
757 drivers
/timer_stm32f30x.c
759 STM32F4xx_COMMON_SRC
= \
760 startup_stm32f40xx.s \
761 target
/system_stm32f4xx.c \
762 drivers
/accgyro_mpu.c \
763 drivers
/adc_stm32f4xx.c \
764 drivers
/bus_i2c_stm32f10x.c \
765 drivers
/dma_stm32f4xx.c \
766 drivers
/gpio_stm32f4xx.c \
768 drivers
/light_ws2811strip_stm32f4xx.c \
769 drivers
/pwm_output_stm32f4xx.c \
770 drivers
/serial_uart_stm32f4xx.c \
771 drivers
/system_stm32f4xx.c \
772 drivers
/timer_stm32f4xx.c
774 STM32F7xx_COMMON_SRC
= \
775 startup_stm32f745xx.s \
776 target
/system_stm32f7xx.c \
777 drivers
/accgyro_mpu.c \
778 drivers
/adc_stm32f7xx.c \
779 drivers
/bus_i2c_hal.c \
780 drivers
/dma_stm32f7xx.c \
781 drivers
/gpio_stm32f7xx.c \
783 drivers
/bus_spi_hal.c \
784 drivers
/pwm_output_stm32f7xx.c \
785 drivers
/timer_hal.c \
786 drivers
/timer_stm32f7xx.c \
787 drivers
/pwm_output_hal.c \
788 drivers
/system_stm32f7xx.c \
789 drivers
/serial_uart_stm32f7xx.c \
790 drivers
/serial_uart_hal.c
792 F7EXCLUDES
= drivers
/bus_spi.c \
795 drivers
/pwm_output.c \
796 drivers
/serial_uart.c
798 # check if target.mk supplied
799 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
800 TARGET_SRC
:= $(STM32F4xx_COMMON_SRC
) $(TARGET_SRC
)
801 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
802 TARGET_SRC
:= $(STM32F7xx_COMMON_SRC
) $(TARGET_SRC
)
803 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
804 TARGET_SRC
:= $(STM32F30x_COMMON_SRC
) $(TARGET_SRC
)
805 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F1_TARGETS
)))
806 TARGET_SRC
:= $(STM32F10x_COMMON_SRC
) $(TARGET_SRC
)
809 ifneq ($(filter ONBOARDFLASH
,$(FEATURES
)),)
811 drivers
/flash_m25p16.c \
815 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
) $(F4_TARGETS
) $(F3_TARGETS
)))
816 TARGET_SRC
+= $(HIGHEND_SRC
)
817 else ifneq ($(filter HIGHEND
,$(FEATURES
)),)
818 TARGET_SRC
+= $(HIGHEND_SRC
)
821 TARGET_SRC
+= $(COMMON_SRC
)
823 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
824 TARGET_SRC
:= $(filter-out ${F7EXCLUDES}, $(TARGET_SRC
))
827 ifneq ($(filter SDCARD
,$(FEATURES
)),)
830 drivers
/sdcard_standard.c \
831 io
/asyncfatfs
/asyncfatfs.c \
832 io
/asyncfatfs
/fat_standard.c
835 ifneq ($(filter VCP
,$(FEATURES
)),)
836 TARGET_SRC
+= $(VCP_SRC
)
838 # end target specific make file checks
841 # Search path and source files for the ST stdperiph library
842 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/src
844 ###############################################################################
845 # Things that might need changing to use different tools
848 # Find out if ccache is installed on the system
850 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
856 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
857 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
858 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
859 SIZE
:= $(ARM_SDK_PREFIX
)size
866 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
870 ifeq ($(TARGET
),$(filter $(TARGET
),$(F1_TARGETS
)))
871 OPTIMISE_DEFAULT
:= -Os
873 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
875 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
876 OPTIMISE_DEFAULT
:= -O2
877 OPTIMISE_SPEED
:= -Ofast
880 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
883 OPTIMISE_DEFAULT
:= -Ofast
885 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
889 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
890 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
891 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
894 OPTIMISE_DEFAULT
:= -O0
896 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
898 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
901 DEBUG_FLAGS
= -ggdb3
-DDEBUG
903 CFLAGS
+= $(ARCH_FLAGS
) \
904 $(addprefix -D
,$(OPTIONS
)) \
905 $(addprefix -I
,$(INCLUDE_DIRS
)) \
908 -Wall
-Wextra
-Wunsafe-loop-optimizations
-Wdouble-promotion \
909 -ffunction-sections \
913 -DUSE_STDPERIPH_DRIVER \
916 -D
'__FORKNAME__="$(FORKNAME)"' \
917 -D
'__TARGET__="$(TARGET)"' \
918 -D
'__REVISION__="$(REVISION)"' \
922 ASFLAGS
= $(ARCH_FLAGS
) \
923 -x assembler-with-cpp \
924 $(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
)
969 # List of buildable ELF files and their object dependencies.
970 # It would be nice to compute these lists, but that seems to be just beyond make.
972 $(TARGET_HEX
): $(TARGET_ELF
)
973 $(V0
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
975 $(TARGET_BIN
): $(TARGET_ELF
)
976 $(V0
) $(OBJCOPY
) -O binary
$< $@
978 $(TARGET_ELF
): $(TARGET_OBJS
)
979 $(V1
) echo Linking
$(TARGET
)
980 $(V1
) $(CROSS_CC
) -o
$@
$^
$(LDFLAGS
)
981 $(V0
) $(SIZE
) $(TARGET_ELF
)
985 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
986 $(V1
) mkdir
-p
$(dir $@
)
987 $(V1
) $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
988 echo
"%% (speed optimised) $(notdir $<)" "$(STDOUT)" && \
989 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_SPEED_OPTIMISATION
) $<, \
990 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
991 echo
"%% (size optimised) $(notdir $<)" "$(STDOUT)" && \
992 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_SIZE_OPTIMISATION
) $<, \
993 echo
"%% $(notdir $<)" "$(STDOUT)" && \
994 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_DEFAULT_OPTIMISATION
) $<))
996 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
997 $(V1
) mkdir
-p
$(dir $@
)
998 $(V1
) echo
"%% $(notdir $<)" "$(STDOUT)" && \
999 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(CC_DEBUG_OPTIMISATION
) $<
1003 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
1004 $(V1
) mkdir
-p
$(dir $@
)
1005 $(V1
) echo
"%% $(notdir $<)" "$(STDOUT)"
1006 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
1008 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
1009 $(V1
) mkdir
-p
$(dir $@
)
1010 $(V1
) echo
"%% $(notdir $<)" "$(STDOUT)"
1011 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
1013 ## sample : Build all sample (travis) targets
1014 sample
: $(SAMPLE_TARGETS
)
1016 ## all : Build all valid targets
1017 all: $(VALID_TARGETS
)
1021 echo
"Building $@" && \
1022 $(MAKE
) binary hex TARGET
=$@
&& \
1023 echo
"Building $@ succeeded."
1027 CLEAN_TARGETS
= $(addprefix clean_
,$(VALID_TARGETS
) )
1028 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
) )
1030 ## clean : clean up temporary / machine-generated files
1032 $(V0
) echo
"Cleaning $(TARGET)"
1033 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
1034 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
1035 $(V0
) echo
"Cleaning $(TARGET) succeeded."
1037 ## clean_test : clean up temporary / machine-generated files (tests)
1039 $(V0
) cd src
/test && $(MAKE
) clean || true
1041 ## clean_<TARGET> : clean up one specific target
1043 $(V0
) $(MAKE
) -j TARGET
=$(subst clean_
,,$@
) clean
1045 ## <TARGET>_clean : clean up one specific target (alias for above)
1047 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
1049 ## clean_all : clean all valid targets
1050 clean_all
:$(CLEAN_TARGETS
)
1052 ## all_clean : clean all valid targets (alias for above)
1053 all_clean
:$(TARGETS_CLEAN
)
1056 flash_
$(TARGET
): $(TARGET_HEX
)
1057 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
1058 $(V0
) echo
-n
'R' >$(SERIAL_DEVICE
)
1059 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
1061 ## flash : flash firmware (.hex) onto flight controller
1062 flash
: flash_
$(TARGET
)
1064 st-flash_
$(TARGET
): $(TARGET_BIN
)
1065 $(V0
) st-flash
--reset write
$< 0x08000000
1067 ## st-flash : flash firmware (.bin) onto flight controller
1068 st-flash
: st-flash_
$(TARGET
)
1071 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
1074 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
1076 unbrick_
$(TARGET
): $(TARGET_HEX
)
1077 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
1078 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
1080 ## unbrick : unbrick flight controller
1081 unbrick
: unbrick_
$(TARGET
)
1083 ## cppcheck : run static analysis on C source code
1084 cppcheck
: $(CSOURCES
)
1087 cppcheck-result.xml
: $(CSOURCES
)
1088 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
1100 ## help : print this help message and exit
1101 help
: Makefile make
/tools.mk
1103 $(V0
) @echo
"Makefile for the $(FORKNAME) firmware"
1105 $(V0
) @echo
"Usage:"
1106 $(V0
) @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
1108 $(V0
) @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
1110 $(V0
) @echo
"Valid TARGET values are: $(VALID_TARGETS)"
1112 $(V0
) @sed
-n
's/^## //p' $?
1114 ## targets : print a list of all valid target platforms (for consumption by scripts)
1116 $(V0
) @echo
"Valid targets: $(VALID_TARGETS)"
1117 $(V0
) @echo
"Target: $(TARGET)"
1118 $(V0
) @echo
"Base target: $(BASE_TARGET)"
1120 ## test : run the cleanflight test suite
1121 ## junittest : run the cleanflight test suite, producing Junit XML result files.
1123 $(V0
) cd src
/test && $(MAKE
) $@
1125 # rebuild everything when makefile changes
1126 $(TARGET_OBJS
) : Makefile
1128 # include auto-generated dependencies
1129 -include $(TARGET_DEPS
)