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 External Storage Bootloader support
27 # compile for target loaded into RAM
30 # reserve space for custom defaults
31 CUSTOM_DEFAULTS_EXTENDED ?
= no
34 # empty - ordinary build with all optimizations enabled
35 # INFO - ordinary build with debug symbols and all optimizations enabled
36 # GDB - debug build with minimum number of optimizations
39 # Insert the debugging hardfault debugger
40 # releases should not be built with this flag as it does not disable pwm output
43 # Serial port/Device for flashing
44 SERIAL_DEVICE ?
= $(firstword $(wildcard /dev
/ttyACM
*) $(firstword $(wildcard /dev
/ttyUSB
*) no-port-found
))
46 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
49 ###############################################################################
50 # Things that need to be maintained as the source changes
56 ROOT
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
57 SRC_DIR
:= $(ROOT
)/src
/main
58 OBJECT_DIR
:= $(ROOT
)/obj
/main
59 BIN_DIR
:= $(ROOT
)/obj
60 CMSIS_DIR
:= $(ROOT
)/lib
/main
/CMSIS
61 INCLUDE_DIRS
:= $(SRC_DIR
) \
62 $(ROOT
)/src
/main
/target \
63 $(ROOT
)/src
/main
/startup
64 LINKER_DIR
:= $(ROOT
)/src
/link
66 ## V : Set verbosity level based on the V= parameter
69 include $(ROOT
)/make
/build_verbosity.mk
71 # Build tools, so we all share the same versions
72 # import macros common to all supported build systems
73 include $(ROOT
)/make
/system-id.mk
75 # developer preferences, edit these at will, they'll be gitignored
76 -include $(ROOT
)/make
/local.mk
78 # pre-build sanity checks
79 include $(ROOT
)/make
/checks.mk
81 # configure some directories that are relative to wherever ROOT_DIR is located
82 TOOLS_DIR ?
= $(ROOT
)/tools
83 DL_DIR
:= $(ROOT
)/downloads
87 # import macros that are OS specific
88 include $(ROOT
)/make
/$(OSFAMILY
).mk
90 # include the tools makefile
91 include $(ROOT
)/make
/tools.mk
93 # default xtal value for F4 targets
96 # used for turning on features like VCP and SDCARD
99 # used to disable features based on flash space shortage (larger number => more features disabled)
100 FEATURE_CUT_LEVEL_SUPPLIED
:= $(FEATURE_CUT_LEVEL
)
103 include $(ROOT
)/make
/targets.mk
105 REVISION
:= norevision
106 ifeq ($(shell git diff
--shortstat
),)
107 REVISION
:= $(shell git log
-1 --format
="%h")
110 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
111 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
112 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
114 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
116 # Search path for sources
117 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
118 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
119 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
121 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
127 # Default Tool options - can be overridden in {mcu}.mk files.
130 OPTIMISE_DEFAULT
:= -Og
132 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
133 DEBUG_FLAGS
= -ggdb3
-gdwarf-5
-DDEBUG
138 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
-fmerge-all-constants
139 OPTIMISE_DEFAULT
:= -O2
140 OPTIMISE_SPEED
:= -Ofast
143 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
146 VPATH
:= $(VPATH
):$(ROOT
)/make
/mcu
147 VPATH
:= $(VPATH
):$(ROOT
)/make
149 # start specific includes
150 include $(ROOT
)/make
/mcu
/$(TARGET_MCU
).mk
152 # openocd specific includes
153 include $(ROOT
)/make
/openocd.mk
155 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
156 ifeq ($(TARGET_FLASH_SIZE
),)
157 ifneq ($(MCU_FLASH_SIZE
),)
158 TARGET_FLASH_SIZE
:= $(MCU_FLASH_SIZE
)
160 $(error MCU_FLASH_SIZE not configured for target
$(TARGET
))
164 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DTARGET_FLASH_SIZE
=$(TARGET_FLASH_SIZE
)
166 ifneq ($(HSE_VALUE
),)
167 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
170 ifneq ($(FEATURE_CUT_LEVEL_SUPPLIED
),)
171 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFEATURE_CUT_LEVEL
=$(FEATURE_CUT_LEVEL_SUPPLIED
)
172 else ifneq ($(FEATURE_CUT_LEVEL
),)
173 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFEATURE_CUT_LEVEL
=$(FEATURE_CUT_LEVEL
)
176 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(TARGET
)
177 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
181 ifeq ($(CUSTOM_DEFAULTS_EXTENDED
),yes
)
182 TARGET_FLAGS
+= -DUSE_CUSTOM_DEFAULTS
=
183 EXTRA_LD_FLAGS
+= -Wl
,--defsym
=USE_CUSTOM_DEFAULTS_EXTENDED
=1
186 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
187 $(ROOT
)/lib
/main
/MAVLink
189 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
192 VPATH
:= $(VPATH
):$(TARGET_DIR
)
194 include $(ROOT
)/make
/source.mk
196 ###############################################################################
197 # Things that might need changing to use different tools
200 # Find out if ccache is installed on the system
202 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
208 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
209 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
210 CROSS_GDB
:= $(ARM_SDK_PREFIX
)gdb
211 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
212 OBJDUMP
:= $(ARM_SDK_PREFIX
)objdump
213 READELF
:= $(ARM_SDK_PREFIX
)readelf
214 SIZE
:= $(ARM_SDK_PREFIX
)size
215 DFUSE-PACK
:= src
/utils
/dfuse-pack.py
220 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
221 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
222 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
223 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
224 CC_NO_OPTIMISATION
:=
227 # Added after GCC version update, remove once the warnings have been fixed
231 EXTRA_WARNING_FLAGS
:= -Wold-style-definition
233 CFLAGS
+= $(ARCH_FLAGS
) \
234 $(addprefix -D
,$(OPTIONS
)) \
235 $(addprefix -I
,$(INCLUDE_DIRS
)) \
238 -Wall
-Wextra
-Werror
-Wpedantic
-Wunsafe-loop-optimizations
-Wdouble-promotion \
239 $(EXTRA_WARNING_FLAGS
) \
240 -ffunction-sections \
246 -DUSE_STDPERIPH_DRIVER \
249 -D
'__FORKNAME__="$(FORKNAME)"' \
250 -D
'__TARGET__="$(TARGET)"' \
251 -D
'__REVISION__="$(REVISION)"' \
256 ASFLAGS
= $(ARCH_FLAGS
) \
258 -x assembler-with-cpp \
259 $(addprefix -I
,$(INCLUDE_DIRS
)) \
272 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
273 -Wl
,-L
$(LINKER_DIR
) \
275 -Wl
,--no-wchar-size-warning \
276 -Wl
,--print-memory-usage \
281 ###############################################################################
282 # No user-serviceable parts below
283 ###############################################################################
285 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
286 --std
=c99
--inline-suppr
--quiet
--force \
287 $(addprefix -I
,$(INCLUDE_DIRS
)) \
288 -I
/usr
/include -I
/usr
/include/linux
290 TARGET_BASENAME
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
)
293 # Things we will build
295 TARGET_BIN
= $(TARGET_BASENAME
).bin
296 TARGET_HEX
= $(TARGET_BASENAME
).hex
297 TARGET_HEX_REV
= $(TARGET_BASENAME
)_
$(REVISION
).hex
298 TARGET_DFU
= $(TARGET_BASENAME
).dfu
299 TARGET_ZIP
= $(TARGET_BASENAME
).zip
300 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
301 TARGET_EXST_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_EXST.elf
302 TARGET_UNPATCHED_BIN
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_UNPATCHED.bin
303 TARGET_LST
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).lst
304 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
305 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
306 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
308 TARGET_EXST_HASH_SECTION_FILE
= $(OBJECT_DIR
)/$(TARGET
)/exst_hash_section.bin
310 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
311 CLEAN_ARTIFACTS
+= $(TARGET_HEX_REV
) $(TARGET_HEX
)
312 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
313 CLEAN_ARTIFACTS
+= $(TARGET_LST
)
314 CLEAN_ARTIFACTS
+= $(TARGET_DFU
)
316 # Make sure build date and revision is updated on every incremental build
317 $(OBJECT_DIR
)/$(TARGET
)/build
/version.o
: $(SRC
)
319 # List of buildable ELF files and their object dependencies.
320 # It would be nice to compute these lists, but that seems to be just beyond make.
322 $(TARGET_LST
): $(TARGET_ELF
)
323 $(V0
) $(OBJDUMP
) -S
--disassemble
$< > $@
326 $(TARGET_BIN
): $(TARGET_ELF
)
327 @echo
"Creating BIN $(TARGET_BIN)" "$(STDOUT)"
328 $(V1
) $(OBJCOPY
) -O binary
$< $@
330 $(TARGET_HEX
): $(TARGET_ELF
)
331 @echo
"Creating HEX $(TARGET_HEX)" "$(STDOUT)"
332 $(V1
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
334 $(TARGET_DFU
): $(TARGET_HEX
)
335 @echo
"Creating DFU $(TARGET_DFU)" "$(STDOUT)"
336 $(V1
) $(PYTHON
) $(DFUSE-PACK
) -i
$< $@
339 CLEAN_ARTIFACTS
+= $(TARGET_UNPATCHED_BIN
) $(TARGET_EXST_HASH_SECTION_FILE
) $(TARGET_EXST_ELF
)
341 $(TARGET_UNPATCHED_BIN
): $(TARGET_ELF
)
342 @echo
"Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
343 $(V1
) $(OBJCOPY
) -O binary
$< $@
345 $(TARGET_BIN
): $(TARGET_UNPATCHED_BIN
)
346 @echo
"Creating EXST $(TARGET_BIN)" "$(STDOUT)"
347 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
348 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
349 $(V1
) dd if
=/dev
/zero ibs
=1k count
=$(FIRMWARE_SIZE
) of
=$(TARGET_BIN
)
350 $(V1
) dd if
=$(TARGET_UNPATCHED_BIN
) of
=$(TARGET_BIN
) conv
=notrunc
352 @echo
"Generating MD5 hash of binary" "$(STDOUT)"
353 $(V1
) openssl dgst
-md5
$(TARGET_BIN
) > $(TARGET_UNPATCHED_BIN
).md5
355 @echo
"Patching MD5 hash into binary" "$(STDOUT)"
356 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd
-r
- $(TARGET_BIN
)
357 $(V1
) echo
$(FIRMWARE_SIZE
) | awk
'{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
359 # 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"
360 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
361 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
362 # a) regeneration of $(TARGET_BIN), and
363 # b) the results of $(TARGET_BIN) will not be as expected.
364 @echo
"Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
365 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
).tmp
--dump-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
) -j .exst_hash
366 rm $(TARGET_EXST_ELF
).tmp
368 @echo
"Patching MD5 hash into HASH section" "$(STDOUT)"
369 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",64-16,$$2);}' | xxd
-r
- $(TARGET_EXST_HASH_SECTION_FILE
)
371 # For some currently unknown reason, OBJCOPY, with only input/output files, will generate a file around 2GB for the H730 unless we remove an unused-section
372 # As a workaround drop the ._user_heap_stack section, which is only used during build to show errors if there's not enough space for the heap/stack.
373 # The issue can be seen with `readelf -S $(TARGET_EXST_ELF)' vs `readelf -S $(TARGET_ELF)`
374 $(V1
) @echo
"Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
375 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
) --remove-section ._user_heap_stack
--update-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
)
377 $(V1
) $(READELF
) -S
$(TARGET_EXST_ELF
)
378 $(V1
) $(READELF
) -l
$(TARGET_EXST_ELF
)
380 $(TARGET_HEX
): $(TARGET_BIN
)
381 $(if
$(EXST_ADJUST_VMA
),,$(error
"EXST_ADJUST_VMA not specified"))
383 @echo
"Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
384 $(V1
) $(OBJCOPY
) -I binary
-O ihex
--adjust-vma
=$(EXST_ADJUST_VMA
) $(TARGET_BIN
) $@
388 $(TARGET_ELF
): $(TARGET_OBJS
) $(LD_SCRIPT
) $(LD_SCRIPTS
)
389 @echo
"Linking $(TARGET)" "$(STDOUT)"
390 $(V1
) $(CROSS_CC
) -o
$@
$(filter-out %.
ld,$^
) $(LD_FLAGS
)
391 $(V1
) $(SIZE
) $(TARGET_ELF
)
395 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
397 echo
"%% ($(1)) $<" "$(STDOUT)" && \
398 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(2) $<
402 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
403 $(V1
) mkdir
-p
$(dir $@
)
404 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
405 $(call compile_file
,not optimised
, $(CC_NO_OPTIMISATION
)) \
407 $(call compile_file
,debug
,$(CC_DEBUG_OPTIMISATION
)) \
410 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
411 $(V1
) mkdir
-p
$(dir $@
)
412 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
413 $(call compile_file
,not optimised
,$(CC_NO_OPTIMISATION
)) \
415 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
416 $(call compile_file
,speed optimised
,$(CC_SPEED_OPTIMISATION
)) \
418 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
419 $(call compile_file
,size optimised
,$(CC_SIZE_OPTIMISATION
)) \
421 $(call compile_file
,optimised
,$(CC_DEFAULT_OPTIMISATION
)) \
428 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
429 $(V1
) mkdir
-p
$(dir $@
)
430 @echo
"%% $(notdir $<)" "$(STDOUT)"
431 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
433 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
434 $(V1
) mkdir
-p
$(dir $@
)
435 @echo
"%% $(notdir $<)" "$(STDOUT)"
436 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
439 ## all : Build all currently built targets
442 ## all_all : Build all targets (including legacy / unsupported)
443 all_all
: $(VALID_TARGETS
)
446 $(V0
) @echo
"Building $@" && \
447 $(MAKE
) hex TARGET
=$@
&& \
448 echo
"Building $@ succeeded."
453 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
))
455 ## clean : clean up temporary / machine-generated files
457 @echo
"Cleaning $(TARGET)"
458 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
459 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
460 @echo
"Cleaning $(TARGET) succeeded."
462 ## test_clean : clean up temporary / machine-generated files (tests)
467 $(V0
) cd src
/test && $(MAKE
) clean || true
469 ## <TARGET>_clean : clean up one specific target (alias for above)
471 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
473 ## clean_all : clean all valid targets
474 clean_all
: $(TARGETS_CLEAN
) test_clean
476 TARGETS_FLASH
= $(addsuffix _flash
,$(VALID_TARGETS
))
478 ## <TARGET>_flash : build and flash a target
480 $(V0
) $(MAKE
) hex TARGET
=$(subst _flash
,,$@
)
481 ifneq (,$(findstring /dev
/ttyUSB
,$(SERIAL_DEVICE
)))
482 $(V0
) $(MAKE
) tty_flash TARGET
=$(subst _flash
,,$@
)
484 $(V0
) $(MAKE
) dfu_flash TARGET
=$(subst _flash
,,$@
)
487 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
489 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
490 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
491 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
493 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
495 ifneq (no-port-found
,$(SERIAL_DEVICE
))
496 # potentially this is because the MCU already is in DFU mode, try anyway
497 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
500 $(V0
) $(MAKE
) $(TARGET_DFU
)
501 $(V0
) dfu-util
-a
0 -D
$(TARGET_DFU
) -s
:leave
503 st-flash_
$(TARGET
): $(TARGET_BIN
)
504 $(V0
) st-flash
--reset write
$< 0x08000000
506 ## st-flash : flash firmware (.bin) onto flight controller
507 st-flash
: st-flash_
$(TARGET
)
509 ifneq ($(OPENOCD_COMMAND
),)
510 openocd-gdb
: $(TARGET_ELF
)
511 $(V0
) $(OPENOCD_COMMAND
) & $(CROSS_GDB
) $(TARGET_ELF
) -ex
"target remote localhost:3333" -ex
"load"
514 TARGETS_ZIP
= $(addsuffix _zip
,$(VALID_TARGETS
))
516 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
518 $(V0
) $(MAKE
) hex TARGET
=$(subst _zip
,,$@
)
519 $(V0
) $(MAKE
) zip TARGET
=$(subst _zip
,,$@
)
522 $(V0
) zip
$(TARGET_ZIP
) $(TARGET_HEX
)
525 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
528 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
530 TARGETS_REVISION
= $(addsuffix _rev
,$(VALID_TARGETS
))
531 ## <TARGET>_rev : build target and add revision to filename
533 $(V0
) $(MAKE
) hex_rev TARGET
=$(subst _rev
,,$@
)
536 $(V0
) mv
-f
$(TARGET_HEX
) $(TARGET_HEX_REV
)
538 all_rev
: $(addsuffix _rev
,$(CI_TARGETS
))
540 unbrick_
$(TARGET
): $(TARGET_HEX
)
541 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
542 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
544 ## unbrick : unbrick flight controller
545 unbrick
: unbrick_
$(TARGET
)
547 ## cppcheck : run static analysis on C source code
548 cppcheck
: $(CSOURCES
)
551 cppcheck-result.xml
: $(CSOURCES
)
552 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
561 ## version : print firmware version
565 ## help : print this help message and exit
566 help
: Makefile make
/tools.mk
568 @echo
"Makefile for the $(FORKNAME) firmware"
571 @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
573 @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
575 @echo
"Valid TARGET values are: $(VALID_TARGETS)"
577 @sed
-n
's/^## //p' $?
579 ## targets : print a list of all valid target platforms (for consumption by scripts)
581 @echo
"Valid targets: $(VALID_TARGETS)"
582 @echo
"Built targets: $(CI_TARGETS)"
583 @echo
"Default target: $(TARGET)"
588 ## target-mcu : print the MCU type of the target
592 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
594 $(V1
) for target in
$${TARGETS}; do \
595 TARGET_MCU_TYPE
=$$($(MAKE
) -s TARGET
=$${target} target-mcu
); \
596 if
[ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
597 if
[ "$${DO_BUILD}" = 1 ]; then \
598 echo
"Building target $${target}..."; \
599 $(MAKE
) TARGET
=$${target}; \
600 if
[ $$?
-ne
0 ]; then \
601 echo
"Building target $${target} failed, aborting."; \
605 echo
-n
"$${target} "; \
611 ## targets-f4 : make all F4 targets
613 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
616 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)"
619 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(CI_TARGETS)"
621 ## targets-f7 : make all F7 targets
623 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
626 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)"
629 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(CI_TARGETS)"
631 ## test : run the Betaflight test suite
632 ## junittest : run the Betaflight test suite, producing Junit XML result files.
633 ## 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)
634 ## test-all: run the Betaflight test suite including all per-target expanded tests
635 test junittest test-all test-representative
:
636 $(V0
) cd src
/test && $(MAKE
) $@
638 ## test_help : print the help message for the test suite (including a list of the available tests)
640 $(V0
) cd src
/test && $(MAKE
) help
642 ## test_versions : print the compiler versions used for the test suite
644 $(V0
) cd src
/test && $(MAKE
) versions
646 ## test_% : run test 'test_%' from the test suite
648 $(V0
) cd src
/test && $(MAKE
) $@
651 # rebuild everything when makefile changes
652 $(TARGET_OBJS
): Makefile
$(TARGET_DIR
)/target.mk
$(wildcard make
/*)
654 # include auto-generated dependencies
655 -include $(TARGET_DEPS
)