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
54 ###############################################################################
55 # Things that need to be maintained as the source changes
61 ROOT
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
62 SRC_DIR
= $(ROOT
)/src
/main
63 OBJECT_DIR
= $(ROOT
)/obj
/main
65 CMSIS_DIR
= $(ROOT
)/lib
/main
/CMSIS
66 INCLUDE_DIRS
= $(SRC_DIR
) \
67 $(ROOT
)/src
/main
/target
68 LINKER_DIR
= $(ROOT
)/src
/main
/target
/link
70 # Build tools, so we all share the same versions
71 # import macros common to all supported build systems
72 include $(ROOT
)/make
/system-id.mk
73 # developer preferences, edit these at will, they'll be gitignored
74 include $(ROOT
)/make
/local.mk
76 # configure some directories that are relative to wherever ROOT_DIR is located
77 TOOLS_DIR
:= $(ROOT
)/tools
78 BUILD_DIR
:= $(ROOT
)/build
79 DL_DIR
:= $(ROOT
)/downloads
83 # import macros that are OS specific
84 include $(ROOT
)/make
/$(OSFAMILY
).mk
86 # include the tools makefile
87 include $(ROOT
)/make
/tools.mk
89 # default xtal value for F4 targets
92 # used for turning on features like VCP and SDCARD
95 SAMPLE_TARGETS
= ALIENFLIGHTF3 ALIENFLIGHTF4 ANYFCF7 BETAFLIGHTF3 BLUEJAYF4 CC3D FURYF4 NAZE REVO SIRINFPV SPARKY SPRACINGF3 SPRACINGF3EVO STM32F3DISCOVERY
96 ALT_TARGETS
= $(sort $(filter-out target
, $(basename $(notdir $(wildcard $(ROOT
)/src
/main
/target
/*/*.mk
)))))
97 OPBL_TARGETS
= $(filter %_OPBL
, $(ALT_TARGETS
))
99 #VALID_TARGETS = $(F1_TARGETS) $(F3_TARGETS) $(F4_TARGETS)
100 VALID_TARGETS
= $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/target.mk
))
101 VALID_TARGETS
:= $(subst /,, $(subst .
/src
/main
/target
/,, $(VALID_TARGETS
)))
102 VALID_TARGETS
:= $(VALID_TARGETS
) $(ALT_TARGETS
)
103 VALID_TARGETS
:= $(sort $(VALID_TARGETS
))
105 ifeq ($(filter $(TARGET
),$(ALT_TARGETS
)), $(TARGET
))
106 BASE_TARGET
:= $(firstword $(subst /,, $(subst .
/src
/main
/target
/,, $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/$(TARGET
).mk
)))))
107 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/$(TARGET
).mk
109 BASE_TARGET
:= $(TARGET
)
112 ifeq ($(filter $(TARGET
),$(OPBL_TARGETS
)), $(TARGET
))
116 # silently ignore if the file is not present. Allows for target specific.
117 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/target.mk
119 F4_TARGETS
= $(F405_TARGETS
) $(F411_TARGETS
)
120 F7_TARGETS
= $(F7X5XE_TARGETS
) $(F7X5XG_TARGETS
) $(F7X5XI_TARGETS
)
122 ifeq ($(filter $(TARGET
),$(VALID_TARGETS
)),)
123 $(error Target
'$(TARGET)' is not valid
, must be one of
$(VALID_TARGETS
). Have you prepared a valid target.mk?
)
126 ifeq ($(filter $(TARGET
),$(F1_TARGETS
) $(F3_TARGETS
) $(F4_TARGETS
) $(F7_TARGETS
)),)
127 $(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?
)
130 128K_TARGETS
= $(F1_TARGETS
)
131 256K_TARGETS
= $(F3_TARGETS
)
132 512K_TARGETS
= $(F411_TARGETS
) $(F7X5XE_TARGETS
)
133 1024K_TARGETS
= $(F405_TARGETS
) $(F7X5XG_TARGETS
)
134 2048K_TARGETS
= $(F7X5XI_TARGETS
)
136 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
137 ifeq ($(FLASH_SIZE
),)
138 ifeq ($(TARGET
),$(filter $(TARGET
),$(2048K_TARGETS
)))
140 else ifeq ($(TARGET
),$(filter $(TARGET
),$(1024K_TARGETS
)))
142 else ifeq ($(TARGET
),$(filter $(TARGET
),$(512K_TARGETS
)))
144 else ifeq ($(TARGET
),$(filter $(TARGET
),$(256K_TARGETS
)))
146 else ifeq ($(TARGET
),$(filter $(TARGET
),$(128K_TARGETS
)))
149 $(error FLASH_SIZE not configured for target
$(TARGET
))
153 # note that there is no hardfault debugging startup file assembly handler for other platforms
154 ifeq ($(DEBUG_HARDFAULTS
),F3
)
155 CFLAGS
+= -DDEBUG_HARDFAULTS
156 STM32F30x_COMMON_SRC
= startup_stm32f3_debug_hardfault_handler.S
158 STM32F30x_COMMON_SRC
= startup_stm32f30x_md_gcc.S
161 REVISION
= $(shell git log
-1 --format
="%h")
163 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
164 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
165 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
167 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
169 # Search path for sources
170 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
171 USBFS_DIR
= $(ROOT
)/lib
/main
/STM32_USB-FS-Device_Driver
172 USBPERIPH_SRC
= $(notdir $(wildcard $(USBFS_DIR
)/src
/*.c
))
173 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
174 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
176 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
178 ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
181 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F30x_StdPeriph_Driver
182 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
183 EXCLUDES
= stm32f30x_crc.c \
186 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
187 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
189 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM1
/CoreSupport
:$(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
190 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM1
/CoreSupport
/*.c \
191 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
/*.c
))
193 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
194 $(STDPERIPH_DIR
)/inc \
195 $(CMSIS_DIR
)/CM1
/CoreSupport \
196 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
198 ifneq ($(filter VCP
, $(FEATURES
)),)
199 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
203 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
205 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
)\
209 ifneq ($(filter SDCARD
, $(FEATURES
)),)
210 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
213 VPATH
:= $(VPATH
):$(FATFS_DIR
)
216 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k.
ld
218 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
219 DEVICE_FLAGS
= -DSTM32F303xC
-DSTM32F303
223 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F4_TARGETS
)))
226 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F4xx_StdPeriph_Driver
227 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
228 EXCLUDES
= stm32f4xx_crc.c \
234 stm32f4xx_flash_ramfunc.c \
238 stm32f4xx_spdifrx.c \
240 stm32f4xx_cryp_aes.c \
241 stm32f4xx_hash_md5.c \
242 stm32f4xx_cryp_des.c \
246 stm32f4xx_cryp_tdes.c \
247 stm32f4xx_hash_sha1.c
250 ifeq ($(TARGET
),$(filter $(TARGET
), $(F411_TARGETS
)))
251 EXCLUDES
+= stm32f4xx_fsmc.c
254 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
257 USBCORE_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Core
258 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/src
/*.c
))
259 USBOTG_DIR
= $(ROOT
)/lib
/main
/STM32_USB_OTG_Driver
260 USBOTG_SRC
= $(notdir $(wildcard $(USBOTG_DIR
)/src
/*.c
))
261 EXCLUDES
= usb_bsp_template.c \
262 usb_conf_template.c \
267 USBOTG_SRC
:= $(filter-out ${EXCLUDES}, $(USBOTG_SRC
))
268 USBCDC_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Class
/cdc
269 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/src
/*.c
))
270 EXCLUDES
= usbd_cdc_if_template.c
271 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
272 VPATH
:= $(VPATH
):$(USBOTG_DIR
)/src
:$(USBCORE_DIR
)/src
:$(USBCDC_DIR
)/src
274 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
280 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM4
/CoreSupport
:$(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
281 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM4
/CoreSupport
/*.c \
282 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
/*.c
))
283 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
284 $(STDPERIPH_DIR
)/inc \
289 $(CMSIS_DIR
)/CM4
/CoreSupport \
290 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx \
291 $(ROOT
)/src
/main
/vcpf4
293 ifneq ($(filter SDCARD
,$(FEATURES
)),)
294 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
296 VPATH
:= $(VPATH
):$(FATFS_DIR
)
300 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-march
=armv7e-m
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
302 ifeq ($(TARGET
),$(filter $(TARGET
),$(F411_TARGETS
)))
303 DEVICE_FLAGS
= -DSTM32F411xE
304 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411.
ld
305 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F405_TARGETS
)))
306 DEVICE_FLAGS
= -DSTM32F40_41xxx
307 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405.
ld
309 $(error Unknown MCU for F4 target
)
311 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
316 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F7_TARGETS
)))
319 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F7xx_HAL_Driver
320 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/Src
/*.c
))
321 EXCLUDES
= stm32f7xx_hal_timebase_rtc_wakeup_template.c \
322 stm32f7xx_hal_timebase_rtc_alarm_template.c \
323 stm32f7xx_hal_timebase_tim_template.c
325 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
328 USBCORE_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Core
329 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/Src
/*.c
))
330 EXCLUDES
= usbd_conf_template.c
331 USBCORE_SRC
:= $(filter-out ${EXCLUDES}, $(USBCORE_SRC
))
333 USBCDC_DIR
= $(ROOT
)/lib
/main
/Middlewares
/ST
/STM32_USB_Device_Library
/Class
/CDC
334 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/Src
/*.c
))
335 EXCLUDES
= usbd_cdc_if_template.c
336 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
338 VPATH
:= $(VPATH
):$(USBCDC_DIR
)/Src
:$(USBCORE_DIR
)/Src
340 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
345 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM7
/Include
:$(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
346 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/Src
347 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM7
/Include
/*.c \
348 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/*.c
))
349 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
350 $(STDPERIPH_DIR
)/Inc \
353 $(CMSIS_DIR
)/CM7
/Include \
354 $(CMSIS_DIR
)/CM7
/Device
/ST
/STM32F7xx
/Include \
355 $(ROOT
)/src
/main
/vcp_hal
357 ifneq ($(filter SDCARD
,$(FEATURES
)),)
358 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
360 VPATH
:= $(VPATH
):$(FATFS_DIR
)
364 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m7
-mfloat-abi
=hard
-mfpu
=fpv5-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
366 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7X5XG_TARGETS
)))
367 DEVICE_FLAGS
= -DSTM32F745xx
-DUSE_HAL_DRIVER
-D__FPU_PRESENT
-DDEBUG_HARDFAULTS
368 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f745.
ld
370 $(error Unknown MCU for F7 target
)
372 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
374 TARGET_FLAGS
= -D
$(TARGET
)
381 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F10x_StdPeriph_Driver
382 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
383 EXCLUDES
= stm32f10x_crc.c \
387 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
389 # Search path and source files for the CMSIS sources
390 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM3
/CoreSupport
:$(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
391 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM3
/CoreSupport
/*.c \
392 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
/*.c
))
394 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
395 $(STDPERIPH_DIR
)/inc \
396 $(CMSIS_DIR
)/CM3
/CoreSupport \
397 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x \
399 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
401 ifneq ($(filter VCP
, $(FEATURES
)),)
402 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
406 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
408 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
) \
413 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k.
ld
414 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m3
416 ifeq ($(DEVICE_FLAGS
),)
417 DEVICE_FLAGS
= -DSTM32F10X_MD
419 DEVICE_FLAGS
+= -DSTM32F10X
425 ifneq ($(BASE_TARGET
), $(TARGET
))
426 TARGET_FLAGS
:= $(TARGET_FLAGS
) -D
$(BASE_TARGET
)
429 ifneq ($(FLASH_SIZE
),)
430 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFLASH_SIZE
=$(FLASH_SIZE
)
433 ifneq ($(HSE_VALUE
),)
434 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
437 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)
438 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
441 TARGET_FLAGS
:= -DOPBL
$(TARGET_FLAGS
)
442 ifeq ($(TARGET
), $(filter $(TARGET
),$(F405_TARGETS
)))
443 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405_opbl.
ld
444 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F411_TARGETS
)))
445 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411_opbl.
ld
446 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F3_TARGETS
)))
447 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k_opbl.
ld
448 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F1_TARGETS
)))
449 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k_opbl.
ld
451 .DEFAULT_GOAL
:= binary
456 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
457 $(ROOT
)/lib
/main
/MAVLink
459 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
462 VPATH
:= $(VPATH
):$(TARGET_DIR
)
465 build
/build_config.c \
475 common
/typeconversion.c \
476 config
/config_eeprom.c \
478 config
/parameter_group.c \
480 drivers
/buf_writer.c \
481 drivers
/bus_i2c_soft.c \
483 drivers
/bus_spi_soft.c \
485 drivers
/gyro_sync.c \
487 drivers
/light_led.c \
488 drivers
/rx_nrf24l01.c \
491 drivers
/pwm_output.c \
495 drivers
/serial_uart.c \
496 drivers
/sound_beeper.c \
505 fc/runtime_config.c \
506 flight
/altitudehold.c \
515 io
/serial_4way_avrootloader.c \
516 io
/serial_4way_stk500v2.c \
518 io
/statusindicator.c \
536 scheduler
/scheduler.c \
537 sensors
/acceleration.c \
539 sensors
/boardalignment.c \
542 sensors
/initialisation.c \
544 $(DEVICE_STDPERIPH_SRC
)
547 blackbox
/blackbox.c \
548 blackbox
/blackbox_io.c \
549 common
/colorconversion.c \
550 drivers
/display_ug2864hsweg01.c \
551 drivers
/light_ws2811strip.c \
552 drivers
/serial_escserial.c \
553 drivers
/serial_softserial.c \
554 drivers
/sonar_hcsr04.c \
556 flight
/navigation.c \
557 flight
/gps_conversion.c \
562 sensors
/barometer.c \
563 telemetry
/telemetry.c \
566 telemetry
/smartport.c \
570 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
572 vcpf4
/stm32f4xx_it.c \
576 vcpf4
/usbd_cdc_vcp.c \
577 drivers
/serial_usb_vcp.c
578 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
580 vcp_hal
/usbd_desc.c \
581 vcp_hal
/usbd_conf.c \
582 vcp_hal
/usbd_cdc_interface.c \
583 drivers
/serial_usb_vcp_hal.c
593 drivers
/serial_usb_vcp.c \
597 STM32F10x_COMMON_SRC
= \
598 startup_stm32f10x_md_gcc.S \
599 drivers
/adc_stm32f10x.c \
600 drivers
/bus_i2c_stm32f10x.c \
602 drivers
/gpio_stm32f10x.c \
604 drivers
/light_ws2811strip_stm32f10x.c \
605 drivers
/serial_uart_stm32f10x.c \
606 drivers
/system_stm32f10x.c \
607 drivers
/timer_stm32f10x.c
609 STM32F30x_COMMON_SRC
= \
610 startup_stm32f30x_md_gcc.S \
611 target
/system_stm32f30x.c \
612 drivers
/adc_stm32f30x.c \
613 drivers
/bus_i2c_stm32f30x.c \
615 drivers
/gpio_stm32f30x.c \
616 drivers
/light_ws2811strip_stm32f30x.c \
617 drivers
/pwm_output_stm32f3xx.c \
618 drivers
/serial_uart_stm32f30x.c \
619 drivers
/system_stm32f30x.c \
620 drivers
/timer_stm32f30x.c
622 STM32F4xx_COMMON_SRC
= \
623 startup_stm32f40xx.s \
624 target
/system_stm32f4xx.c \
625 drivers
/accgyro_mpu.c \
626 drivers
/adc_stm32f4xx.c \
627 drivers
/bus_i2c_stm32f10x.c \
628 drivers
/dma_stm32f4xx.c \
629 drivers
/gpio_stm32f4xx.c \
631 drivers
/light_ws2811strip_stm32f4xx.c \
632 drivers
/pwm_output_stm32f4xx.c \
633 drivers
/serial_uart_stm32f4xx.c \
634 drivers
/system_stm32f4xx.c \
635 drivers
/timer_stm32f4xx.c
637 STM32F7xx_COMMON_SRC
= \
638 startup_stm32f745xx.s \
639 target
/system_stm32f7xx.c \
640 drivers
/accgyro_mpu.c \
641 drivers
/adc_stm32f7xx.c \
642 drivers
/bus_i2c_hal.c \
643 drivers
/dma_stm32f7xx.c \
644 drivers
/gpio_stm32f7xx.c \
646 drivers
/bus_spi_hal.c \
647 drivers
/pwm_output_stm32f7xx.c \
648 drivers
/timer_hal.c \
649 drivers
/timer_stm32f7xx.c \
650 drivers
/pwm_output_hal.c \
651 drivers
/system_stm32f7xx.c \
652 drivers
/serial_uart_stm32f7xx.c \
653 drivers
/serial_uart_hal.c
655 F7EXCLUDES
= drivers
/bus_spi.c \
658 drivers
/pwm_output.c \
659 drivers
/serial_uart.c
661 # check if target.mk supplied
662 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
663 TARGET_SRC
:= $(STM32F4xx_COMMON_SRC
) $(TARGET_SRC
)
664 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
665 TARGET_SRC
:= $(STM32F7xx_COMMON_SRC
) $(TARGET_SRC
)
666 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
667 TARGET_SRC
:= $(STM32F30x_COMMON_SRC
) $(TARGET_SRC
)
668 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F1_TARGETS
)))
669 TARGET_SRC
:= $(STM32F10x_COMMON_SRC
) $(TARGET_SRC
)
672 ifneq ($(filter ONBOARDFLASH
,$(FEATURES
)),)
674 drivers
/flash_m25p16.c \
678 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
) $(F4_TARGETS
) $(F3_TARGETS
)))
679 TARGET_SRC
+= $(HIGHEND_SRC
)
680 else ifneq ($(filter HIGHEND
,$(FEATURES
)),)
681 TARGET_SRC
+= $(HIGHEND_SRC
)
684 TARGET_SRC
+= $(COMMON_SRC
)
686 ifeq ($(TARGET
),$(filter $(TARGET
),$(F7_TARGETS
)))
687 TARGET_SRC
:= $(filter-out ${F7EXCLUDES}, $(TARGET_SRC
))
690 ifneq ($(filter SDCARD
,$(FEATURES
)),)
693 drivers
/sdcard_standard.c \
694 io
/asyncfatfs
/asyncfatfs.c \
695 io
/asyncfatfs
/fat_standard.c
698 ifneq ($(filter VCP
,$(FEATURES
)),)
699 TARGET_SRC
+= $(VCP_SRC
)
701 # end target specific make file checks
704 # Search path and source files for the ST stdperiph library
705 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/src
707 ###############################################################################
708 # Things that might need changing to use different tools
711 # Find out if ccache is installed on the system
713 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
719 CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
720 CPP
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
721 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
722 SIZE
:= $(ARM_SDK_PREFIX
)size
730 LTO_FLAGS
= $(OPTIMIZE
)
733 LTO_FLAGS
= -flto
-fuse-linker-plugin
$(OPTIMIZE
)
736 DEBUG_FLAGS
= -ggdb3
-DDEBUG
738 CFLAGS
+= $(ARCH_FLAGS
) \
740 $(addprefix -D
,$(OPTIONS
)) \
741 $(addprefix -I
,$(INCLUDE_DIRS
)) \
744 -Wall
-Wextra
-Wunsafe-loop-optimizations
-Wdouble-promotion \
745 -ffunction-sections \
749 -DUSE_STDPERIPH_DRIVER \
752 -D
'__FORKNAME__="$(FORKNAME)"' \
753 -D
'__TARGET__="$(TARGET)"' \
754 -D
'__REVISION__="$(REVISION)"' \
758 ASFLAGS
= $(ARCH_FLAGS
) \
759 -x assembler-with-cpp \
760 $(addprefix -I
,$(INCLUDE_DIRS
)) \
772 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
773 -Wl
,-L
$(LINKER_DIR
) \
775 -Wl
,--no-wchar-size-warning \
778 ###############################################################################
779 # No user-serviceable parts below
780 ###############################################################################
782 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
783 --std
=c99
--inline-suppr
--quiet
--force \
784 $(addprefix -I
,$(INCLUDE_DIRS
)) \
785 -I
/usr
/include -I
/usr
/include/linux
788 # Things we will build
790 TARGET_BIN
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).bin
791 TARGET_HEX
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).hex
792 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
793 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
794 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
795 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
798 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
799 CLEAN_ARTIFACTS
+= $(TARGET_HEX
)
800 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
802 # List of buildable ELF files and their object dependencies.
803 # It would be nice to compute these lists, but that seems to be just beyond make.
805 $(TARGET_HEX
): $(TARGET_ELF
)
806 $(V0
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
808 $(TARGET_BIN
): $(TARGET_ELF
)
809 $(V0
) $(OBJCOPY
) -O binary
$< $@
811 $(TARGET_ELF
): $(TARGET_OBJS
)
812 $(V1
) echo LD
$(notdir $@
)
813 $(V1
) $(CC
) -o
$@
$^
$(LDFLAGS
)
814 $(V0
) $(SIZE
) $(TARGET_ELF
)
817 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
818 $(V1
) mkdir
-p
$(dir $@
)
819 $(V1
) echo
%% $(notdir $<)
820 $(V1
) $(CC
) -c
-o
$@
$(CFLAGS
) $<
823 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
824 $(V1
) mkdir
-p
$(dir $@
)
825 $(V1
) echo
%% $(notdir $<)
826 $(V1
) $(CC
) -c
-o
$@
$(ASFLAGS
) $<
828 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
829 $(V1
) mkdir
-p
$(dir $@
)
830 $(V1
) echo
%% $(notdir $<)
831 $(V1
) $(CC
) -c
-o
$@
$(ASFLAGS
) $<
833 ## sample : Build all sample (travis) targets
834 sample
: $(SAMPLE_TARGETS
)
836 ## all : Build all valid targets
837 all: $(VALID_TARGETS
)
841 echo
"Building $@" && \
842 $(MAKE
) binary hex TARGET
=$@
&& \
843 echo
"Building $@ succeeded."
847 CLEAN_TARGETS
= $(addprefix clean_
,$(VALID_TARGETS
) )
848 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
) )
850 ## clean : clean up temporary / machine-generated files
852 $(V0
) echo
"Cleaning $(TARGET)"
853 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
854 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
855 $(V0
) echo
"Cleaning $(TARGET) succeeded."
857 ## clean_test : clean up temporary / machine-generated files (tests)
859 $(V0
) cd src
/test && $(MAKE
) clean || true
861 ## clean_<TARGET> : clean up one specific target
863 $(V0
) $(MAKE
) -j TARGET
=$(subst clean_
,,$@
) clean
865 ## <TARGET>_clean : clean up one specific target (alias for above)
867 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
869 ## clean_all : clean all valid targets
870 clean_all
:$(CLEAN_TARGETS
)
872 ## all_clean : clean all valid targets (alias for above)
873 all_clean
:$(TARGETS_CLEAN
)
876 flash_
$(TARGET
): $(TARGET_HEX
)
877 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
878 $(V0
) echo
-n
'R' >$(SERIAL_DEVICE
)
879 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
881 ## flash : flash firmware (.hex) onto flight controller
882 flash
: flash_
$(TARGET
)
884 st-flash_
$(TARGET
): $(TARGET_BIN
)
885 $(V0
) st-flash
--reset write
$< 0x08000000
887 ## st-flash : flash firmware (.bin) onto flight controller
888 st-flash
: st-flash_
$(TARGET
)
891 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
894 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
896 unbrick_
$(TARGET
): $(TARGET_HEX
)
897 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
898 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
900 ## unbrick : unbrick flight controller
901 unbrick
: unbrick_
$(TARGET
)
903 ## cppcheck : run static analysis on C source code
904 cppcheck
: $(CSOURCES
)
907 cppcheck-result.xml
: $(CSOURCES
)
908 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
920 ## help : print this help message and exit
921 help
: Makefile make
/tools.mk
923 $(V0
) @echo
"Makefile for the $(FORKNAME) firmware"
926 $(V0
) @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
928 $(V0
) @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
930 $(V0
) @echo
"Valid TARGET values are: $(VALID_TARGETS)"
932 $(V0
) @sed
-n
's/^## //p' $?
934 ## targets : print a list of all valid target platforms (for consumption by scripts)
936 $(V0
) @echo
"Valid targets: $(VALID_TARGETS)"
937 $(V0
) @echo
"Target: $(TARGET)"
938 $(V0
) @echo
"Base target: $(BASE_TARGET)"
940 ## test : run the cleanflight test suite
941 ## junittest : run the cleanflight test suite, producing Junit XML result files.
943 $(V0
) cd src
/test && $(MAKE
) $@ || true
945 # rebuild everything when makefile changes
946 $(TARGET_OBJS
) : Makefile
948 # include auto-generated dependencies
949 -include $(TARGET_DEPS
)