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
22 # Compile-time options
25 # compile for External Storage Bootloader support
28 # compile for target loaded into RAM
31 # reserve space for custom defaults
32 CUSTOM_DEFAULTS_EXTENDED ?
= no
35 # empty - ordinary build with all optimizations enabled
36 # INFO - ordinary build with debug symbols and all optimizations enabled
37 # GDB - debug build with minimum number of optimizations
40 # Insert the debugging hardfault debugger
41 # releases should not be built with this flag as it does not disable pwm output
44 # Serial port/Device for flashing
45 SERIAL_DEVICE ?
= $(firstword $(wildcard /dev
/ttyACM
*) $(firstword $(wildcard /dev
/ttyUSB
*) no-port-found
))
47 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
50 ###############################################################################
51 # Things that need to be maintained as the source changes
57 ROOT
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
58 SRC_DIR
:= $(ROOT
)/src
/main
59 OBJECT_DIR
:= $(ROOT
)/obj
/main
60 BIN_DIR
:= $(ROOT
)/obj
61 CMSIS_DIR
:= $(ROOT
)/lib
/main
/CMSIS
62 INCLUDE_DIRS
:= $(SRC_DIR
) \
63 $(ROOT
)/src
/main
/target \
64 $(ROOT
)/src
/main
/startup
65 LINKER_DIR
:= $(ROOT
)/src
/link
67 ## V : Set verbosity level based on the V= parameter
70 include $(ROOT
)/make
/build_verbosity.mk
72 # Build tools, so we all share the same versions
73 # import macros common to all supported build systems
74 include $(ROOT
)/make
/system-id.mk
76 # developer preferences, edit these at will, they'll be gitignored
77 -include $(ROOT
)/make
/local.mk
79 # pre-build sanity checks
80 include $(ROOT
)/make
/checks.mk
82 # configure some directories that are relative to wherever ROOT_DIR is located
83 TOOLS_DIR ?
= $(ROOT
)/tools
84 DL_DIR
:= $(ROOT
)/downloads
88 # import macros that are OS specific
89 include $(ROOT
)/make
/$(OSFAMILY
).mk
91 # include the tools makefile
92 include $(ROOT
)/make
/tools.mk
94 # default xtal value for F4 targets
97 # used for turning on features like VCP and SDCARD
101 # silently ignore if the file is not present. Allows for target defaults.
102 -include $(ROOT
)/src
/main
/board
/$(BOARD
)/board.mk
105 include $(ROOT
)/make
/targets.mk
107 REVISION
:= norevision
108 ifeq ($(shell git diff
--shortstat
),)
109 REVISION
:= $(shell git log
-1 --format
="%h")
112 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
113 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
114 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
116 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
118 # Search path for sources
119 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
120 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
121 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
123 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
129 # Default Tool options - can be overridden in {mcu}.mk files.
132 OPTIMISE_DEFAULT
:= -Og
134 LTO_FLAGS
:= $(OPTIMISE_DEFAULT
)
135 DEBUG_FLAGS
= -ggdb3
-gdwarf-5
-DDEBUG
140 OPTIMISATION_BASE
:= -flto
-fuse-linker-plugin
-ffast-math
-fmerge-all-constants
141 OPTIMISE_DEFAULT
:= -O2
142 OPTIMISE_SPEED
:= -Ofast
145 LTO_FLAGS
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
148 VPATH
:= $(VPATH
):$(ROOT
)/make
/mcu
149 VPATH
:= $(VPATH
):$(ROOT
)/make
151 # start specific includes
152 include $(ROOT
)/make
/mcu
/$(TARGET_MCU
).mk
154 # openocd specific includes
155 include $(ROOT
)/make
/openocd.mk
157 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
158 ifeq ($(TARGET_FLASH_SIZE
),)
159 ifneq ($(MCU_FLASH_SIZE
),)
160 TARGET_FLASH_SIZE
:= $(MCU_FLASH_SIZE
)
162 $(error MCU_FLASH_SIZE not configured for target
$(TARGET
))
166 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DTARGET_FLASH_SIZE
=$(TARGET_FLASH_SIZE
)
168 ifneq ($(HSE_VALUE
),)
169 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DHSE_VALUE
=$(HSE_VALUE
)
172 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(TARGET
)
173 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
177 ifeq ($(CUSTOM_DEFAULTS_EXTENDED
),yes
)
178 TARGET_FLAGS
+= -DUSE_CUSTOM_DEFAULTS
=
179 EXTRA_LD_FLAGS
+= -Wl
,--defsym
=USE_CUSTOM_DEFAULTS_EXTENDED
=1
182 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
183 $(ROOT
)/lib
/main
/MAVLink
185 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
188 VPATH
:= $(VPATH
):$(TARGET_DIR
)
190 include $(ROOT
)/make
/source.mk
192 ###############################################################################
193 # Things that might need changing to use different tools
196 # Find out if ccache is installed on the system
198 RESULT
= $(shell (which
$(CCACHE
) > /dev
/null
2>&1; echo
$$?
) )
204 CROSS_CC
:= $(CCACHE
) $(ARM_SDK_PREFIX
)gcc
205 CROSS_CXX
:= $(CCACHE
) $(ARM_SDK_PREFIX
)g
++
206 CROSS_GDB
:= $(ARM_SDK_PREFIX
)gdb
207 OBJCOPY
:= $(ARM_SDK_PREFIX
)objcopy
208 OBJDUMP
:= $(ARM_SDK_PREFIX
)objdump
209 READELF
:= $(ARM_SDK_PREFIX
)readelf
210 SIZE
:= $(ARM_SDK_PREFIX
)size
211 DFUSE-PACK
:= src
/utils
/dfuse-pack.py
216 CC_DEBUG_OPTIMISATION
:= $(OPTIMISE_DEFAULT
)
217 CC_DEFAULT_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_DEFAULT
)
218 CC_SPEED_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SPEED
)
219 CC_SIZE_OPTIMISATION
:= $(OPTIMISATION_BASE
) $(OPTIMISE_SIZE
)
220 CC_NO_OPTIMISATION
:=
223 # Added after GCC version update, remove once the warnings have been fixed
227 EXTRA_WARNING_FLAGS
:= -Wold-style-definition
229 CFLAGS
+= $(ARCH_FLAGS
) \
230 $(addprefix -D
,$(OPTIONS
)) \
231 $(addprefix -I
,$(INCLUDE_DIRS
)) \
234 -Wall
-Wextra
-Werror
-Wpedantic
-Wunsafe-loop-optimizations
-Wdouble-promotion \
235 $(EXTRA_WARNING_FLAGS
) \
236 -ffunction-sections \
242 -DUSE_STDPERIPH_DRIVER \
245 -D
'__FORKNAME__="$(FORKNAME)"' \
246 -D
'__TARGET__="$(TARGET)"' \
247 -D
'__REVISION__="$(REVISION)"' \
252 ASFLAGS
= $(ARCH_FLAGS
) \
254 -x assembler-with-cpp \
255 $(addprefix -I
,$(INCLUDE_DIRS
)) \
268 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
269 -Wl
,-L
$(LINKER_DIR
) \
271 -Wl
,--no-wchar-size-warning \
272 -Wl
,--print-memory-usage \
277 ###############################################################################
278 # No user-serviceable parts below
279 ###############################################################################
281 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
282 --std
=c99
--inline-suppr
--quiet
--force \
283 $(addprefix -I
,$(INCLUDE_DIRS
)) \
284 -I
/usr
/include -I
/usr
/include/linux
286 TARGET_BASENAME
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
)
289 # Things we will build
291 TARGET_BIN
= $(TARGET_BASENAME
).bin
292 TARGET_HEX
= $(TARGET_BASENAME
).hex
293 TARGET_HEX_REV
= $(TARGET_BASENAME
)_
$(REVISION
).hex
294 TARGET_DFU
= $(TARGET_BASENAME
).dfu
295 TARGET_ZIP
= $(TARGET_BASENAME
).zip
296 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
297 TARGET_EXST_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_EXST.elf
298 TARGET_UNPATCHED_BIN
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
)_UNPATCHED.bin
299 TARGET_LST
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).lst
300 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
301 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(SRC
))))
302 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
304 TARGET_EXST_HASH_SECTION_FILE
= $(OBJECT_DIR
)/$(TARGET
)/exst_hash_section.bin
306 TARGET_EF_HASH
:= $(shell echo
-n
"$(EXTRA_FLAGS)" | openssl dgst
-md5 | awk
'{print $$2;}')
307 TARGET_EF_HASH_FILE
:= $(OBJECT_DIR
)/$(TARGET
)/.efhash_
$(TARGET_EF_HASH
)
309 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
310 CLEAN_ARTIFACTS
+= $(TARGET_HEX_REV
) $(TARGET_HEX
)
311 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
312 CLEAN_ARTIFACTS
+= $(TARGET_LST
)
313 CLEAN_ARTIFACTS
+= $(TARGET_DFU
)
315 # Make sure build date and revision is updated on every incremental build
316 $(OBJECT_DIR
)/$(TARGET
)/build
/version.o
: $(SRC
)
318 # List of buildable ELF files and their object dependencies.
319 # It would be nice to compute these lists, but that seems to be just beyond make.
321 $(TARGET_LST
): $(TARGET_ELF
)
322 $(V0
) $(OBJDUMP
) -S
--disassemble
$< > $@
325 $(TARGET_BIN
): $(TARGET_ELF
)
326 @echo
"Creating BIN $(TARGET_BIN)" "$(STDOUT)"
327 $(V1
) $(OBJCOPY
) -O binary
$< $@
329 $(TARGET_HEX
): $(TARGET_ELF
)
330 @echo
"Creating HEX $(TARGET_HEX)" "$(STDOUT)"
331 $(V1
) $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
333 $(TARGET_DFU
): $(TARGET_HEX
)
334 @echo
"Creating DFU $(TARGET_DFU)" "$(STDOUT)"
335 $(V1
) $(PYTHON
) $(DFUSE-PACK
) -i
$< $@
338 CLEAN_ARTIFACTS
+= $(TARGET_UNPATCHED_BIN
) $(TARGET_EXST_HASH_SECTION_FILE
) $(TARGET_EXST_ELF
)
340 $(TARGET_UNPATCHED_BIN
): $(TARGET_ELF
)
341 @echo
"Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
342 $(V1
) $(OBJCOPY
) -O binary
$< $@
344 $(TARGET_BIN
): $(TARGET_UNPATCHED_BIN
)
345 @echo
"Creating EXST $(TARGET_BIN)" "$(STDOUT)"
346 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
347 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
348 $(V1
) dd if
=/dev
/zero ibs
=1k count
=$(FIRMWARE_SIZE
) of
=$(TARGET_BIN
)
349 $(V1
) dd if
=$(TARGET_UNPATCHED_BIN
) of
=$(TARGET_BIN
) conv
=notrunc
351 @echo
"Generating MD5 hash of binary" "$(STDOUT)"
352 $(V1
) openssl dgst
-md5
$(TARGET_BIN
) > $(TARGET_UNPATCHED_BIN
).md5
354 @echo
"Patching MD5 hash into binary" "$(STDOUT)"
355 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd
-r
- $(TARGET_BIN
)
356 $(V1
) echo
$(FIRMWARE_SIZE
) | awk
'{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
358 # 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"
359 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
360 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
361 # a) regeneration of $(TARGET_BIN), and
362 # b) the results of $(TARGET_BIN) will not be as expected.
363 @echo
"Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
364 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
).tmp
--dump-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
) -j .exst_hash
365 rm $(TARGET_EXST_ELF
).tmp
367 @echo
"Patching MD5 hash into HASH section" "$(STDOUT)"
368 $(V1
) cat
$(TARGET_UNPATCHED_BIN
).md5 | awk
'{printf("%08x: %s",64-16,$$2);}' | xxd
-r
- $(TARGET_EXST_HASH_SECTION_FILE
)
370 # 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
371 # 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.
372 # The issue can be seen with `readelf -S $(TARGET_EXST_ELF)' vs `readelf -S $(TARGET_ELF)`
373 $(V1
) @echo
"Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
374 $(OBJCOPY
) $(TARGET_ELF
) $(TARGET_EXST_ELF
) --remove-section ._user_heap_stack
--update-section .exst_hash
=$(TARGET_EXST_HASH_SECTION_FILE
)
376 $(V1
) $(READELF
) -S
$(TARGET_EXST_ELF
)
377 $(V1
) $(READELF
) -l
$(TARGET_EXST_ELF
)
379 $(TARGET_HEX
): $(TARGET_BIN
)
380 $(if
$(EXST_ADJUST_VMA
),,$(error
"EXST_ADJUST_VMA not specified"))
382 @echo
"Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
383 $(V1
) $(OBJCOPY
) -I binary
-O ihex
--adjust-vma
=$(EXST_ADJUST_VMA
) $(TARGET_BIN
) $@
387 $(TARGET_ELF
): $(TARGET_OBJS
) $(LD_SCRIPT
) $(LD_SCRIPTS
)
388 @echo
"Linking $(TARGET)" "$(STDOUT)"
389 $(V1
) $(CROSS_CC
) -o
$@
$(filter-out %.
ld,$^
) $(LD_FLAGS
)
390 $(V1
) $(SIZE
) $(TARGET_ELF
)
394 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
396 echo
"%% ($(1)) $<" "$(STDOUT)" && \
397 $(CROSS_CC
) -c
-o
$@
$(CFLAGS
) $(2) $<
401 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
402 $(V1
) mkdir
-p
$(dir $@
)
403 $(V1
) $(if
$(findstring $<,$(NOT_OPTIMISED_SRC
)), \
404 $(call compile_file
,not optimised
, $(CC_NO_OPTIMISATION
)) \
406 $(call compile_file
,debug
,$(CC_DEBUG_OPTIMISATION
)) \
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 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SPEED_OPTIMISED_SRC
)), \
415 $(call compile_file
,speed optimised
,$(CC_SPEED_OPTIMISATION
)) \
417 $(if
$(findstring $(subst .
/src
/main
/,,$<),$(SIZE_OPTIMISED_SRC
)), \
418 $(call compile_file
,size optimised
,$(CC_SIZE_OPTIMISATION
)) \
420 $(call compile_file
,optimised
,$(CC_DEFAULT_OPTIMISATION
)) \
427 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
428 $(V1
) mkdir
-p
$(dir $@
)
429 @echo
"%% $(notdir $<)" "$(STDOUT)"
430 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
432 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
433 $(V1
) mkdir
-p
$(dir $@
)
434 @echo
"%% $(notdir $<)" "$(STDOUT)"
435 $(V1
) $(CROSS_CC
) -c
-o
$@
$(ASFLAGS
) $<
438 ## all : Build all currently built targets
441 ## all_all : Build all targets (including legacy / unsupported)
442 all_all
: $(VALID_TARGETS
)
445 $(V0
) @echo
"Building $@" && \
446 $(MAKE
) hex TARGET
=$@
&& \
447 echo
"Building $@ succeeded."
452 TARGETS_CLEAN
= $(addsuffix _clean
,$(VALID_TARGETS
))
454 ## clean : clean up temporary / machine-generated files
456 @echo
"Cleaning $(TARGET)"
457 $(V0
) rm -f
$(CLEAN_ARTIFACTS
)
458 $(V0
) rm -rf
$(OBJECT_DIR
)/$(TARGET
)
459 @echo
"Cleaning $(TARGET) succeeded."
461 ## test_clean : clean up temporary / machine-generated files (tests)
466 $(V0
) cd src
/test && $(MAKE
) clean || true
468 ## <TARGET>_clean : clean up one specific target (alias for above)
470 $(V0
) $(MAKE
) -j TARGET
=$(subst _clean
,,$@
) clean
472 ## clean_all : clean all valid targets
473 clean_all
: $(TARGETS_CLEAN
) test_clean
475 TARGETS_FLASH
= $(addsuffix _flash
,$(VALID_TARGETS
))
477 ## <TARGET>_flash : build and flash a target
479 $(V0
) $(MAKE
) hex TARGET
=$(subst _flash
,,$@
)
480 ifneq (,$(findstring /dev
/ttyUSB
,$(SERIAL_DEVICE
)))
481 $(V0
) $(MAKE
) tty_flash TARGET
=$(subst _flash
,,$@
)
483 $(V0
) $(MAKE
) dfu_flash TARGET
=$(subst _flash
,,$@
)
486 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
488 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
489 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
490 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
492 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
494 ifneq (no-port-found
,$(SERIAL_DEVICE
))
495 # potentially this is because the MCU already is in DFU mode, try anyway
496 $(V0
) echo
-n
'R' > $(SERIAL_DEVICE
)
499 $(V0
) $(MAKE
) $(TARGET_DFU
)
500 $(V0
) dfu-util
-a
0 -D
$(TARGET_DFU
) -s
:leave
502 st-flash_
$(TARGET
): $(TARGET_BIN
)
503 $(V0
) st-flash
--reset write
$< 0x08000000
505 ## st-flash : flash firmware (.bin) onto flight controller
506 st-flash
: st-flash_
$(TARGET
)
508 ifneq ($(OPENOCD_COMMAND
),)
509 openocd-gdb
: $(TARGET_ELF
)
510 $(V0
) $(OPENOCD_COMMAND
) & $(CROSS_GDB
) $(TARGET_ELF
) -ex
"target remote localhost:3333" -ex
"load"
513 TARGETS_ZIP
= $(addsuffix _zip
,$(VALID_TARGETS
))
515 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
517 $(V0
) $(MAKE
) hex TARGET
=$(subst _zip
,,$@
)
518 $(V0
) $(MAKE
) zip TARGET
=$(subst _zip
,,$@
)
521 $(V0
) zip
$(TARGET_ZIP
) $(TARGET_HEX
)
524 $(V0
) $(MAKE
) -j
$(TARGET_BIN
)
527 $(V0
) $(MAKE
) -j
$(TARGET_HEX
)
529 TARGETS_REVISION
= $(addsuffix _rev
,$(VALID_TARGETS
))
530 ## <TARGET>_rev : build target and add revision to filename
532 $(V0
) $(MAKE
) hex_rev TARGET
=$(subst _rev
,,$@
)
535 $(V0
) mv
-f
$(TARGET_HEX
) $(TARGET_HEX_REV
)
537 all_rev
: $(addsuffix _rev
,$(CI_TARGETS
))
539 unbrick_
$(TARGET
): $(TARGET_HEX
)
540 $(V0
) stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
541 $(V0
) stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
543 ## unbrick : unbrick flight controller
544 unbrick
: unbrick_
$(TARGET
)
546 ## cppcheck : run static analysis on C source code
547 cppcheck
: $(CSOURCES
)
550 cppcheck-result.xml
: $(CSOURCES
)
551 $(V0
) $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
560 ## version : print firmware version
564 ## help : print this help message and exit
565 help
: Makefile make
/tools.mk
567 @echo
"Makefile for the $(FORKNAME) firmware"
570 @echo
" make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
572 @echo
" make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
574 @echo
"Valid TARGET values are: $(VALID_TARGETS)"
576 @sed
-n
's/^## //p' $?
578 ## targets : print a list of all valid target platforms (for consumption by scripts)
580 @echo
"Valid targets: $(VALID_TARGETS)"
581 @echo
"Built targets: $(CI_TARGETS)"
582 @echo
"Default target: $(TARGET)"
587 ## target-mcu : print the MCU type of the target
591 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
593 $(V1
) for target in
$${TARGETS}; do \
594 TARGET_MCU_TYPE
=$$($(MAKE
) -s TARGET
=$${target} target-mcu
); \
595 if
[ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
596 if
[ "$${DO_BUILD}" = 1 ]; then \
597 echo
"Building target $${target}..."; \
598 $(MAKE
) TARGET
=$${target}; \
599 if
[ $$?
-ne
0 ]; then \
600 echo
"Building target $${target} failed, aborting."; \
604 echo
-n
"$${target} "; \
610 ## targets-f4 : make all F4 targets
612 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
615 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(VALID_TARGETS)"
618 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F4 TARGETS
="$(CI_TARGETS)"
620 ## targets-f7 : make all F7 targets
622 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)" DO_BUILD
=1
625 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(VALID_TARGETS)"
628 $(V1
) $(MAKE
) -s targets-by-mcu MCU_TYPE
=STM32F7 TARGETS
="$(CI_TARGETS)"
630 ## test : run the Betaflight test suite
631 ## junittest : run the Betaflight test suite, producing Junit XML result files.
632 ## 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)
633 ## test-all: run the Betaflight test suite including all per-target expanded tests
634 test junittest test-all test-representative
:
635 $(V0
) cd src
/test && $(MAKE
) $@
637 ## test_help : print the help message for the test suite (including a list of the available tests)
639 $(V0
) cd src
/test && $(MAKE
) help
641 ## test_versions : print the compiler versions used for the test suite
643 $(V0
) cd src
/test && $(MAKE
) versions
645 ## test_% : run test 'test_%' from the test suite
647 $(V0
) cd src
/test && $(MAKE
) $@
649 $(TARGET_EF_HASH_FILE
):
650 $(V1
) mkdir
-p
$(dir $@
)
651 $(V0
) rm -f
$(OBJECT_DIR
)/$(TARGET
)/.efhash_
*
652 @echo
"EF HASH -> $(TARGET_EF_HASH_FILE)"
653 $(V1
) touch
$(TARGET_EF_HASH_FILE
)
655 # rebuild everything when makefile changes or the extra flags have changed
656 $(TARGET_OBJS
): $(TARGET_EF_HASH_FILE
) Makefile
$(TARGET_DIR
)/target.mk
$(wildcard make
/*)
658 # include auto-generated dependencies
659 -include $(TARGET_DEPS
)