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 # compile for External Storage Bootloader support
30 # compile for target loaded into RAM
33 # reserve space for custom defaults
34 CUSTOM_DEFAULTS_EXTENDED ?
= no
37 # empty - ordinary build with all optimizations enabled
38 # RELWITHDEBINFO - ordinary build with debug symbols and all optimizations enabled
39 # GDB - debug build with minimum number of optimizations
42 # Insert the debugging hardfault debugger
43 # releases should not be built with this flag as it does not disable pwm output
46 # Serial port/Device for flashing
47 SERIAL_DEVICE ?
= $(firstword $(wildcard /dev
/ttyACM
*) $(firstword $(wildcard /dev
/ttyUSB
*) no-port-found
))
49 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
53 ###############################################################################
54 # Things that need to be maintained as the source changes
60 ROOT
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
61 SRC_DIR
:= $(ROOT
)/src
/main
62 OBJECT_DIR
:= $(ROOT
)/obj
/main
63 BIN_DIR
:= $(ROOT
)/obj
64 CMSIS_DIR
:= $(ROOT
)/lib
/main
/CMSIS
65 INCLUDE_DIRS
:= $(SRC_DIR
) \
66 $(ROOT
)/src
/main
/target \
67 $(ROOT
)/src
/main
/startup
68 LINKER_DIR
:= $(ROOT
)/src
/link
70 ## V : Set verbosity level based on the V= parameter
73 include $(ROOT
)/make
/build_verbosity.mk
75 # Build tools, so we all share the same versions
76 # import macros common to all supported build systems
77 include $(ROOT
)/make
/system-id.mk
79 # developer preferences, edit these at will, they'll be gitignored
80 -include $(ROOT
)/make
/local.mk
82 # pre-build sanity checks
83 include $(ROOT
)/make
/checks.mk
85 # configure some directories that are relative to wherever ROOT_DIR is located
87 TOOLS_DIR
:= $(ROOT
)/tools
89 BUILD_DIR
:= $(ROOT
)/build
90 DL_DIR
:= $(ROOT
)/downloads
94 # import macros that are OS specific
95 include $(ROOT
)/make
/$(OSFAMILY
).mk
97 # include the tools makefile
98 include $(ROOT
)/make
/tools.mk
100 # default xtal value for F4 targets
103 # used for turning on features like VCP and SDCARD
106 # used to disable features based on flash space shortage (larger number => more features disabled)
107 FEATURE_CUT_LEVEL_SUPPLIED
:= $(FEATURE_CUT_LEVEL
)
110 # The list of targets to build for 'pre-push'
111 PRE_PUSH_TARGET_LIST ?
= OMNIBUSF4 STM32F405 SPRACINGF7DUAL STM32F7X2 NUCLEOH743 SITL test-representative
113 include $(ROOT
)/make
/targets.mk
115 REVISION
:= $(shell git log
-1 --format
="%h")
117 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
118 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
119 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
121 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
123 # Search path for sources
124 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
125 USBFS_DIR
= $(ROOT
)/lib
/main
/STM32_USB-FS-Device_Driver
126 USBPERIPH_SRC
= $(notdir $(wildcard $(USBFS_DIR
)/src
/*.c
))
127 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
128 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
130 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
136 # Default Tool options - can be overridden in {mcu}.mk files.
139 OPTIMISE_DEFAULT
:= -Og
141 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
142 DEBUG_FLAGS
= -ggdb3
-DDEBUG
147 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
148 OPTIMISE_DEFAULT
:= -O2
149 OPTIMISE_SPEED
:= -Ofast
152 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
155 VPATH
:= $(VPATH
):$(ROOT
)/make
/mcu
156 VPATH
:= $(VPATH
):$(ROOT
)/make
158 # start specific includes
159 include $(ROOT
)/make
/mcu
/$(TARGET_MCU
).mk
161 # openocd specific includes
162 include $(ROOT
)/make
/openocd.mk
164 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
165 ifeq ($(FLASH_SIZE
),)
166 ifneq ($(TARGET_FLASH
),)
167 FLASH_SIZE
:= $(TARGET_FLASH
)
169 $(error FLASH_SIZE not configured for target
$(TARGET
))
173 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFLASH_SIZE
=$(FLASH_SIZE
)
175 ifneq ($(HSE_VALUE
),)
176 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
179 ifneq ($(FEATURE_CUT_LEVEL_SUPPLIED
),)
180 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFEATURE_CUT_LEVEL
=$(FEATURE_CUT_LEVEL_SUPPLIED
)
181 else ifneq ($(FEATURE_CUT_LEVEL
),)
182 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFEATURE_CUT_LEVEL
=$(FEATURE_CUT_LEVEL
)
185 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)
186 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
189 TARGET_FLAGS
:= -DOPBL
$(TARGET_FLAGS
)
190 .DEFAULT_GOAL
:= binary
195 ifeq ($(CUSTOM_DEFAULTS_EXTENDED
),yes
)
196 TARGET_FLAGS
+= -DUSE_CUSTOM_DEFAULTS
=
197 EXTRA_LD_FLAGS
+= -Wl
,--defsym
=USE_CUSTOM_DEFAULTS_EXTENDED
=1
200 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
201 $(ROOT
)/lib
/main
/MAVLink
203 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
206 VPATH
:= $(VPATH
):$(TARGET_DIR
)
208 include $(ROOT
)/make
/source.mk
210 ###############################################################################
211 # Things that might need changing to use different tools
214 # Find out if ccache is installed on the system
216 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
222 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
223 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
224 CROSS_GDB
:= $(ARM_SDK_PREFIX
)gdb
225 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
226 OBJDUMP
:= $(ARM_SDK_PREFIX
)objdump
227 SIZE
:= $(ARM_SDK_PREFIX
)size
228 DFUSE-PACK
:= src
/utils
/dfuse-pack.py
233 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
234 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
235 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
236 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
237 CC_NO_OPTIMISATION
:=
240 # Added after GCC version update, remove once the warnings have been fixed
244 CFLAGS
+= $(ARCH_FLAGS
) \
245 $(addprefix -D
,$(OPTIONS
)) \
246 $(addprefix -I
,$(INCLUDE_DIRS
)) \
249 -Wall
-Wextra
-Wunsafe-loop-optimizations
-Wdouble-promotion \
250 -ffunction-sections \
257 -DUSE_STDPERIPH_DRIVER \
260 -D
'__FORKNAME__="$(FORKNAME)"' \
261 -D
'__TARGET__="$(TARGET)"' \
262 -D
'__REVISION__="$(REVISION)"' \
267 ASFLAGS
= $(ARCH_FLAGS
) \
269 -x assembler-with-cpp \
270 $(addprefix -I
,$(INCLUDE_DIRS
)) \
283 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
284 -Wl
,-L
$(LINKER_DIR
) \
286 -Wl
,--no-wchar-size-warning \
287 -Wl
,--print-memory-usage \
292 ###############################################################################
293 # No user-serviceable parts below
294 ###############################################################################
296 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
297 --std
=c99
--inline-suppr
--quiet
--force \
298 $(addprefix -I
,$(INCLUDE_DIRS
)) \
299 -I
/usr
/include -I
/usr
/include/linux
302 # Things we will build
304 TARGET_S19
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).s19
305 TARGET_BIN
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).bin
306 TARGET_HEX
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).hex
307 TARGET_DFU
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).dfu
308 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
309 TARGET_EXST_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_EXST.elf
310 TARGET_UNPATCHED_BIN
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_UNPATCHED.bin
311 TARGET_LST
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).lst
312 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
313 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
314 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
316 TARGET_EXST_HASH_SECTION_FILE
= $(OBJECT_DIR
)/$(TARGET
)/exst_hash_section.bin
318 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
319 CLEAN_ARTIFACTS
+= $(TARGET_HEX
)
320 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
321 CLEAN_ARTIFACTS
+= $(TARGET_LST
)
322 CLEAN_ARTIFACTS
+= $(TARGET_DFU
)
324 # Make sure build date and revision is updated on every incremental build
325 $(OBJECT_DIR
)/$(TARGET
)/build
/version.o
: $(SRC
)
327 # List of buildable ELF files and their object dependencies.
328 # It would be nice to compute these lists, but that seems to be just beyond make.
330 $(TARGET_LST
): $(TARGET_ELF
)
331 $(V0
) $(OBJDUMP
) -S
--disassemble
$< > $@
334 $(TARGET_S19
): $(TARGET_ELF
)
335 @echo
"Creating srec/S19 $(TARGET_S19)" "$(STDOUT)"
336 $(V1
) $(OBJCOPY
) --output-target
=srec
$(TARGET_S19
)
339 $(TARGET_BIN
): $(TARGET_ELF
)
340 @echo
"Creating BIN $(TARGET_BIN)" "$(STDOUT)"
341 $(V1
) $(OBJCOPY
) -O binary
$< $@
343 $(TARGET_HEX
): $(TARGET_ELF
)
344 @echo
"Creating HEX $(TARGET_HEX)" "$(STDOUT)"
345 $(V1
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
347 $(TARGET_DFU
): $(TARGET_HEX
)
348 @echo
"Creating DFU $(TARGET_DFU)" "$(STDOUT)"
349 $(V1
) $(DFUSE-PACK
) -i
$< $@
352 CLEAN_ARTIFACTS
+= $(TARGET_UNPATCHED_BIN
) $(TARGET_EXST_HASH_SECTION_FILE
) $(TARGET_EXST_ELF
)
354 $(TARGET_UNPATCHED_BIN
): $(TARGET_ELF
)
355 @echo
"Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
356 $(V1
) $(OBJCOPY
) -O binary
$< $@
358 $(TARGET_BIN
): $(TARGET_UNPATCHED_BIN
)
359 @echo
"Creating EXST $(TARGET_BIN)" "$(STDOUT)"
360 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
361 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
362 $(V1
) dd if
=/dev
/zero ibs
=1k count
=$(FIRMWARE_SIZE
) of
=$(TARGET_BIN
)
363 $(V1
) dd if
=$(TARGET_UNPATCHED_BIN
) of
=$(TARGET_BIN
) conv
=notrunc
365 @echo
"Generating MD5 hash of binary" "$(STDOUT)"
366 $(V1
) openssl dgst
-md5
$(TARGET_BIN
) > $(TARGET_UNPATCHED_BIN
).md5
368 @echo
"Patching MD5 hash into binary" "$(STDOUT)"
369 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd
-r
- $(TARGET_BIN
)
370 $(V1
) echo
$(FIRMWARE_SIZE
) | awk
'{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
372 # Note: From the objcopy manual "If you do not specify outfile, objcopy creates a temporary file and destructively renames the result with the name of infile"
373 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
374 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
375 # a) regeneration of $(TARGET_BIN), and
376 # b) the results of $(TARGET_BIN) will not be as expected.
377 @echo
"Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
378 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
).tmp
--dump-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
)
379 rm $(TARGET_EXST_ELF
).tmp
381 @echo
"Patching MD5 hash into HASH section" "$(STDOUT)"
382 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",64-16,$$2);}' | xxd
-r
- $(TARGET_EXST_HASH_SECTION_FILE
)
384 @echo
"Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
385 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
) --update-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
)
387 $(TARGET_HEX
): $(TARGET_BIN
)
388 $(if
$(EXST_ADJUST_VMA
),,$(error
"EXST_ADJUST_VMA not specified"))
390 @echo
"Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
391 $(V1
) $(OBJCOPY
) -I binary
-O ihex
--adjust-vma
=$(EXST_ADJUST_VMA
) $(TARGET_BIN
) $@
395 $(TARGET_ELF
): $(TARGET_OBJS
) $(LD_SCRIPT
)
396 @echo
"Linking $(TARGET)" "$(STDOUT)"
397 $(V1
) $(CROSS_CC
) -o
$@
$(filter-out %.
ld,$^
) $(LD_FLAGS
)
398 $(V1
) $(SIZE
) $(TARGET_ELF
)
402 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
404 echo
"%% ($(1)) $<" "$(STDOUT)" && \
405 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(2) $<
409 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
410 $(V1
) mkdir
-p
$(dir $@
)
411 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
412 $(call compile_file
,not optimised
, $(CC_NO_OPTIMISATION
)) \
414 $(call compile_file
,debug
,$(CC_DEBUG_OPTIMISATION
)) \
417 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
418 $(V1
) mkdir
-p
$(dir $@
)
419 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
420 $(call compile_file
,not optimised
,$(CC_NO_OPTIMISATION
)) \
422 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
423 $(call compile_file
,speed optimised
,$(CC_SPEED_OPTIMISATION
)) \
425 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
426 $(call compile_file
,size optimised
,$(CC_SIZE_OPTIMISATION
)) \
428 $(call compile_file
,optimised
,$(CC_DEFAULT_OPTIMISATION
)) \
435 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
436 $(V1
) mkdir
-p
$(dir $@
)
437 @echo
"%% $(notdir $<)" "$(STDOUT)"
438 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
440 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
441 $(V1
) mkdir
-p
$(dir $@
)
442 @echo
"%% $(notdir $<)" "$(STDOUT)"
443 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
446 ## all : Build all currently built targets
449 ## all_all : Build all targets (including legacy / unsupported)
450 all_all
: $(VALID_TARGETS
)
452 ## legacy : Build legacy targets
453 legacy
: $(LEGACY_TARGETS
)
455 ## unsupported : Build unsupported targets
456 unsupported
: $(UNSUPPORTED_TARGETS
)
458 ## pre-push : The minimum verification that should be run before pushing, to check if CI has a chance of succeeding
460 $(MAKE
) $(addsuffix _clean
,$(PRE_PUSH_TARGET_LIST
)) $(PRE_PUSH_TARGET_LIST
) EXTRA_FLAGS
=-Werror
462 ## targets-group-1 : build some targets
463 targets-group-1
: $(GROUP_1_TARGETS
)
465 ## targets-group-2 : build some targets
466 targets-group-2
: $(GROUP_2_TARGETS
)
468 ## targets-group-3 : build some targets
469 targets-group-3
: $(GROUP_3_TARGETS
)
471 ## targets-group-4 : build some targets
472 targets-group-4
: $(GROUP_4_TARGETS
)
474 ## targets-group-5 : build some targets
475 targets-group-5
: $(GROUP_5_TARGETS
)
477 ## targets-group-rest: build the rest of the targets (not listed in group 1, 2 or 3)
478 targets-group-rest
: $(GROUP_OTHER_TARGETS
)
481 $(V0
) @echo
"Building $@" && \
482 $(MAKE
) binary hex TARGET
=$@
&& \
483 echo
"Building $@ succeeded."
488 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
) )
490 ## clean : clean up temporary / machine-generated files
492 @echo
"Cleaning $(TARGET)"
493 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
494 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
495 @echo
"Cleaning $(TARGET) succeeded."
497 ## test_clean : clean up temporary / machine-generated files (tests)
502 $(V0
) cd src
/test && $(MAKE
) clean || true
504 ## <TARGET>_clean : clean up one specific target (alias for above)
506 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
508 ## clean_all : clean all valid targets
509 clean_all
: $(TARGETS_CLEAN
) test_clean
511 TARGETS_FLASH
= $(addsuffix _flash
,$(VALID_TARGETS
) )
513 ## <TARGET>_flash : build and flash a target
515 $(V0
) $(MAKE
) hex TARGET
=$(subst _flash
,,$@
)
516 ifneq (,$(findstring /dev
/ttyUSB
,$(SERIAL_DEVICE
)))
517 $(V0
) $(MAKE
) tty_flash TARGET
=$(subst _flash
,,$@
)
519 $(V0
) $(MAKE
) dfu_flash TARGET
=$(subst _flash
,,$@
)
522 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
524 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
525 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
526 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
528 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
530 ifneq (no-port-found
,$(SERIAL_DEVICE
))
531 # potentially this is because the MCU already is in DFU mode, try anyway
532 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
535 $(V0
) $(MAKE
) $(TARGET_DFU
)
536 $(V0
) dfu-util
-a
0 -D
$(TARGET_DFU
) -s
:leave
538 st-flash_
$(TARGET
): $(TARGET_BIN
)
539 $(V0
) st-flash
--reset write
$< 0x08000000
541 ## st-flash : flash firmware (.bin) onto flight controller
542 st-flash
: st-flash_
$(TARGET
)
544 ifneq ($(OPENOCD_COMMAND
),)
545 openocd-gdb
: $(TARGET_ELF
)
546 $(V0
) $(OPENOCD_COMMAND
) & $(CROSS_GDB
) $(TARGET_ELF
) -ex
"target remote localhost:3333" -ex
"load"
550 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
553 $(V0
) $(MAKE
) -j
$(TARGET_S19
)
556 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
558 unbrick_
$(TARGET
): $(TARGET_HEX
)
559 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
560 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
562 ## unbrick : unbrick flight controller
563 unbrick
: unbrick_
$(TARGET
)
565 ## cppcheck : run static analysis on C source code
566 cppcheck
: $(CSOURCES
)
569 cppcheck-result.xml
: $(CSOURCES
)
570 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
582 ## version : print firmware version
586 ## help : print this help message and exit
587 help
: Makefile make
/tools.mk
589 @echo
"Makefile for the $(FORKNAME) firmware"
592 @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
594 @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
596 @echo
"Valid TARGET values are: $(VALID_TARGETS)"
598 @sed
-n
's/^## //p' $?
600 ## targets : print a list of all valid target platforms (for consumption by scripts)
602 @echo
"Valid targets: $(VALID_TARGETS)"
603 @echo
"Built targets: $(CI_TARGETS)"
604 @echo
"Legacy targets: $(LEGACY_TARGETS)"
605 @echo
"Unsupported targets: $(UNSUPPORTED_TARGETS)"
606 @echo
"Target: $(TARGET)"
607 @echo
"Base target: $(BASE_TARGET)"
608 @echo
"targets-group-1: $(GROUP_1_TARGETS)"
609 @echo
"targets-group-2: $(GROUP_2_TARGETS)"
610 @echo
"targets-group-3: $(GROUP_3_TARGETS)"
611 @echo
"targets-group-4: $(GROUP_4_TARGETS)"
612 @echo
"targets-group-5: $(GROUP_5_TARGETS)"
613 @echo
"targets-group-rest: $(GROUP_OTHER_TARGETS)"
615 @echo
"targets-group-1: $(words $(GROUP_1_TARGETS)) targets"
616 @echo
"targets-group-2: $(words $(GROUP_2_TARGETS)) targets"
617 @echo
"targets-group-3: $(words $(GROUP_3_TARGETS)) targets"
618 @echo
"targets-group-4: $(words $(GROUP_4_TARGETS)) targets"
619 @echo
"targets-group-5: $(words $(GROUP_5_TARGETS)) targets"
620 @echo
"targets-group-rest: $(words $(GROUP_OTHER_TARGETS)) targets"
621 @echo
"total in all groups $(words $(CI_TARGETS)) targets"
623 ## target-mcu : print the MCU type of the target
627 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
629 $(V1
) for target in
$${TARGETS}; do \
630 TARGET_MCU_TYPE
=$$($(MAKE
) -s TARGET
=$${target} target-mcu
); \
631 if
[ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
632 if
[ "$${DO_BUILD}" = 1 ]; then \
633 echo
"Building target $${target}..."; \
634 $(MAKE
) TARGET
=$${target}; \
635 if
[ $$?
-ne
0 ]; then \
636 echo
"Building target $${target} failed, aborting."; \
640 echo
-n
"$${target} "; \
646 ## targets-f3 : make all F3 targets
648 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F3 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
651 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F3 TARGETS
="$(VALID_TARGETS)"
653 ## targets-f4 : make all F4 targets
655 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
658 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)"
661 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(CI_TARGETS)"
663 ## targets-f7 : make all F7 targets
665 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
668 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)"
671 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(CI_TARGETS)"
673 ## test : run the Betaflight test suite
674 ## junittest : run the Betaflight test suite, producing Junit XML result files.
675 ## test-representative: run a representative subset of the Betaflight test suite (i.e. run all tests, but run each expanded test only for one target)
676 ## test-all: run the Betaflight test suite including all per-target expanded tests
677 test junittest test-all test-representative
:
678 $(V0
) cd src
/test && $(MAKE
) $@
680 ## test_help : print the help message for the test suite (including a list of the available tests)
682 $(V0
) cd src
/test && $(MAKE
) help
684 ## test_% : run test 'test_%' from the test suite
686 $(V0
) cd src
/test && $(MAKE
) $@
689 # rebuild everything when makefile changes
690 $(TARGET_OBJS
): Makefile
$(TARGET_DIR
)/target.mk
$(wildcard make
/*)
692 # include auto-generated dependencies
693 -include $(TARGET_DEPS
)