Debug - Fix dbgPinLo checking the first pin instead of the desired pin.
[betaflight.git] / Makefile
blob80397607460180a1d759ad2e73f39415e7201370
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
19 TARGET ?= STM32F405
21 # Compile-time options
22 OPTIONS ?=
24 # compile for OpenPilot BootLoader support
25 OPBL ?= no
27 # compile for External Storage Bootloader support
28 EXST ?= no
30 # compile for target loaded into RAM
31 RAM_BASED ?= no
33 # reserve space for custom defaults
34 CUSTOM_DEFAULTS_EXTENDED ?= no
36 # Debugger optons:
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
40 DEBUG ?=
42 # Insert the debugging hardfault debugger
43 # releases should not be built with this flag as it does not disable pwm output
44 DEBUG_HARDFAULTS ?=
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.
50 FLASH_SIZE ?=
53 ###############################################################################
54 # Things that need to be maintained as the source changes
57 FORKNAME = betaflight
59 # Working directories
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
71 ## V=0 Low
72 ## V=1 High
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
86 TOOLS_DIR ?= $(ROOT)/tools
87 DL_DIR := $(ROOT)/downloads
89 export RM := rm
91 # import macros that are OS specific
92 include $(ROOT)/make/$(OSFAMILY).mk
94 # include the tools makefile
95 include $(ROOT)/make/tools.mk
97 # default xtal value for F4 targets
98 HSE_VALUE ?= 8000000
100 # used for turning on features like VCP and SDCARD
101 FEATURES =
103 # used to disable features based on flash space shortage (larger number => more features disabled)
104 FEATURE_CUT_LEVEL_SUPPLIED := $(FEATURE_CUT_LEVEL)
105 FEATURE_CUT_LEVEL =
107 # The list of targets to build for 'pre-push'
108 PRE_PUSH_TARGET_LIST ?= $(UNIFIED_TARGETS) NUCLEOH743 SITL STM32F4DISCOVERY_DEBUG test-representative
110 include $(ROOT)/make/targets.mk
112 REVISION := norevision
113 ifeq ($(shell git diff --shortstat),)
114 REVISION := $(shell git log -1 --format="%h")
115 endif
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')
132 LD_FLAGS :=
133 EXTRA_LD_FLAGS :=
136 # Default Tool options - can be overridden in {mcu}.mk files.
138 ifeq ($(DEBUG),GDB)
139 OPTIMISE_DEFAULT := -Og
141 LTO_FLAGS := $(OPTIMISE_DEFAULT)
142 DEBUG_FLAGS = -ggdb3 -DDEBUG
143 else
144 ifeq ($(DEBUG),INFO)
145 DEBUG_FLAGS = -ggdb3
146 endif
147 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
148 OPTIMISE_DEFAULT := -O2
149 OPTIMISE_SPEED := -Ofast
150 OPTIMISE_SIZE := -Os
152 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
153 endif
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 ($(TARGET_FLASH_SIZE),)
166 ifneq ($(MCU_FLASH_SIZE),)
167 TARGET_FLASH_SIZE := $(MCU_FLASH_SIZE)
168 else
169 $(error MCU_FLASH_SIZE not configured for target $(TARGET))
170 endif
171 endif
173 DEVICE_FLAGS := $(DEVICE_FLAGS) -DTARGET_FLASH_SIZE=$(TARGET_FLASH_SIZE)
175 ifneq ($(HSE_VALUE),)
176 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
177 endif
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)
183 endif
185 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
186 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
188 ifeq ($(OPBL),yes)
189 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
190 .DEFAULT_GOAL := binary
191 else
192 .DEFAULT_GOAL := hex
193 endif
195 ifeq ($(CUSTOM_DEFAULTS_EXTENDED),yes)
196 TARGET_FLAGS += -DUSE_CUSTOM_DEFAULTS=
197 EXTRA_LD_FLAGS += -Wl,--defsym=USE_CUSTOM_DEFAULTS_EXTENDED=1
198 endif
200 INCLUDE_DIRS := $(INCLUDE_DIRS) \
201 $(ROOT)/lib/main/MAVLink
203 INCLUDE_DIRS := $(INCLUDE_DIRS) \
204 $(TARGET_DIR)
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
215 CCACHE := ccache
216 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
217 ifneq ($(RESULT),0)
218 CCACHE :=
219 endif
221 # Tool names
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
231 # Tool options.
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
242 TEMPORARY_FLAGS :=
244 CFLAGS += $(ARCH_FLAGS) \
245 $(addprefix -D,$(OPTIONS)) \
246 $(addprefix -I,$(INCLUDE_DIRS)) \
247 $(DEBUG_FLAGS) \
248 -std=gnu11 \
249 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
250 -ffunction-sections \
251 -fdata-sections \
252 -fno-common \
253 -pedantic \
254 $(TEMPORARY_FLAGS) \
255 $(DEVICE_FLAGS) \
256 -D_GNU_SOURCE \
257 -DUSE_STDPERIPH_DRIVER \
258 -D$(TARGET) \
259 $(TARGET_FLAGS) \
260 -D'__FORKNAME__="$(FORKNAME)"' \
261 -D'__TARGET__="$(TARGET)"' \
262 -D'__REVISION__="$(REVISION)"' \
263 -save-temps=obj \
264 -MMD -MP \
265 $(EXTRA_FLAGS)
267 ASFLAGS = $(ARCH_FLAGS) \
268 $(DEBUG_FLAGS) \
269 -x assembler-with-cpp \
270 $(addprefix -I,$(INCLUDE_DIRS)) \
271 -MMD -MP
273 ifeq ($(LD_FLAGS),)
274 LD_FLAGS = -lm \
275 -nostartfiles \
276 --specs=nano.specs \
277 -lc \
278 -lnosys \
279 $(ARCH_FLAGS) \
280 $(LTO_FLAGS) \
281 $(DEBUG_FLAGS) \
282 -static \
283 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
284 -Wl,-L$(LINKER_DIR) \
285 -Wl,--cref \
286 -Wl,--no-wchar-size-warning \
287 -Wl,--print-memory-usage \
288 -T$(LD_SCRIPT) \
289 $(EXTRA_LD_FLAGS)
290 endif
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 TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)_$(REVISION)
305 # Things we will build
307 TARGET_BIN = $(TARGET_BASENAME).bin
308 TARGET_HEX = $(TARGET_BASENAME).hex
309 TARGET_DFU = $(TARGET_BASENAME).dfu
310 TARGET_ZIP = $(TARGET_BASENAME).zip
311 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
312 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_EXST.elf
313 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_UNPATCHED.bin
314 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
315 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
316 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
317 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
319 TARGET_EXST_HASH_SECTION_FILE = $(OBJECT_DIR)/$(TARGET)/exst_hash_section.bin
321 CLEAN_ARTIFACTS := $(TARGET_BIN)
322 CLEAN_ARTIFACTS += $(TARGET_HEX)
323 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
324 CLEAN_ARTIFACTS += $(TARGET_LST)
325 CLEAN_ARTIFACTS += $(TARGET_DFU)
327 # Make sure build date and revision is updated on every incremental build
328 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
330 # List of buildable ELF files and their object dependencies.
331 # It would be nice to compute these lists, but that seems to be just beyond make.
333 $(TARGET_LST): $(TARGET_ELF)
334 $(V0) $(OBJDUMP) -S --disassemble $< > $@
336 ifeq ($(EXST),no)
337 $(TARGET_BIN): $(TARGET_ELF)
338 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
339 $(V1) $(OBJCOPY) -O binary $< $@
341 $(TARGET_HEX): $(TARGET_ELF)
342 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
343 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
345 $(TARGET_DFU): $(TARGET_HEX)
346 @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)"
347 $(V1) $(PYTHON) $(DFUSE-PACK) -i $< $@
349 else
350 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
352 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
353 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
354 $(V1) $(OBJCOPY) -O binary $< $@
356 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
357 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
358 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
359 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
360 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
361 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
363 @echo "Generating MD5 hash of binary" "$(STDOUT)"
364 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
366 @echo "Patching MD5 hash into binary" "$(STDOUT)"
367 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
368 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
370 # 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"
371 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
372 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
373 # a) regeneration of $(TARGET_BIN), and
374 # b) the results of $(TARGET_BIN) will not be as expected.
375 @echo "Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
376 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF).tmp --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
377 rm $(TARGET_EXST_ELF).tmp
379 @echo "Patching MD5 hash into HASH section" "$(STDOUT)"
380 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
382 @echo "Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
383 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
385 $(TARGET_HEX): $(TARGET_BIN)
386 $(if $(EXST_ADJUST_VMA),,$(error "EXST_ADJUST_VMA not specified"))
388 @echo "Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
389 $(V1) $(OBJCOPY) -I binary -O ihex --adjust-vma=$(EXST_ADJUST_VMA) $(TARGET_BIN) $@
391 endif
393 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT)
394 @echo "Linking $(TARGET)" "$(STDOUT)"
395 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
396 $(V1) $(SIZE) $(TARGET_ELF)
398 # Compile
400 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
401 define compile_file
402 echo "%% ($(1)) $<" "$(STDOUT)" && \
403 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
404 endef
406 ifeq ($(DEBUG),GDB)
407 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
408 $(V1) mkdir -p $(dir $@)
409 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
410 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
412 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
414 else
415 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
416 $(V1) mkdir -p $(dir $@)
417 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
418 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
420 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
421 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
423 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
424 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
426 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
430 endif
432 # Assemble
433 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
434 $(V1) mkdir -p $(dir $@)
435 @echo "%% $(notdir $<)" "$(STDOUT)"
436 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
438 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
439 $(V1) mkdir -p $(dir $@)
440 @echo "%% $(notdir $<)" "$(STDOUT)"
441 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
444 ## all : Build all currently built targets
445 all: $(CI_TARGETS)
447 ## all_all : Build all targets (including legacy / unsupported)
448 all_all: $(VALID_TARGETS)
450 ## unified : build all Unified Targets
451 unified: $(UNIFIED_TARGETS)
453 ## unified_zip : build all Unified Targets as zip files (for posting on GitHub)
454 unified_zip: $(addsuffix _clean,$(UNIFIED_TARGETS)) $(addsuffix _zip,$(UNIFIED_TARGETS))
456 ## legacy : Build legacy targets
457 legacy: $(LEGACY_TARGETS)
459 ## unsupported : Build unsupported targets
460 unsupported: $(UNSUPPORTED_TARGETS)
462 ## pre-push : The minimum verification that should be run before pushing, to check if CI has a chance of succeeding
463 pre-push:
464 $(MAKE) $(addsuffix _clean,$(PRE_PUSH_TARGET_LIST)) $(PRE_PUSH_TARGET_LIST) EXTRA_FLAGS=-Werror
466 ## targets-group-1 : build some targets
467 targets-group-1: $(GROUP_1_TARGETS)
469 ## targets-group-2 : build some targets
470 targets-group-2: $(GROUP_2_TARGETS)
472 ## targets-group-rest: build the rest of the targets (not listed in the other groups)
473 targets-group-rest: $(GROUP_OTHER_TARGETS)
475 $(VALID_TARGETS):
476 $(V0) @echo "Building $@" && \
477 $(MAKE) binary hex TARGET=$@ && \
478 echo "Building $@ succeeded."
480 $(NOBUILD_TARGETS):
481 $(MAKE) TARGET=$@
483 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS))
485 ## clean : clean up temporary / machine-generated files
486 clean:
487 @echo "Cleaning $(TARGET)"
488 $(V0) rm -f $(CLEAN_ARTIFACTS)
489 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
490 @echo "Cleaning $(TARGET) succeeded."
492 ## test_clean : clean up temporary / machine-generated files (tests)
493 test-%_clean:
494 $(MAKE) test_clean
496 test_clean:
497 $(V0) cd src/test && $(MAKE) clean || true
499 ## <TARGET>_clean : clean up one specific target (alias for above)
500 $(TARGETS_CLEAN):
501 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
503 ## clean_all : clean all valid targets
504 clean_all: $(TARGETS_CLEAN) test_clean
506 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS))
508 ## <TARGET>_flash : build and flash a target
509 $(TARGETS_FLASH):
510 $(V0) $(MAKE) hex TARGET=$(subst _flash,,$@)
511 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
512 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
513 else
514 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
515 endif
517 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
518 tty_flash:
519 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
520 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
521 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
523 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
524 dfu_flash:
525 ifneq (no-port-found,$(SERIAL_DEVICE))
526 # potentially this is because the MCU already is in DFU mode, try anyway
527 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
528 $(V0) sleep 1
529 endif
530 $(V0) $(MAKE) $(TARGET_DFU)
531 $(V0) dfu-util -a 0 -D $(TARGET_DFU) -s :leave
533 st-flash_$(TARGET): $(TARGET_BIN)
534 $(V0) st-flash --reset write $< 0x08000000
536 ## st-flash : flash firmware (.bin) onto flight controller
537 st-flash: st-flash_$(TARGET)
539 ifneq ($(OPENOCD_COMMAND),)
540 openocd-gdb: $(TARGET_ELF)
541 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
542 endif
544 TARGETS_ZIP = $(addsuffix _zip,$(VALID_TARGETS))
546 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
547 $(TARGETS_ZIP):
548 $(V0) $(MAKE) hex TARGET=$(subst _zip,,$@)
549 $(V0) $(MAKE) zip TARGET=$(subst _zip,,$@)
551 zip:
552 $(V0) zip $(TARGET_ZIP) $(TARGET_HEX)
554 binary:
555 $(V0) $(MAKE) -j $(TARGET_BIN)
557 hex:
558 $(V0) $(MAKE) -j $(TARGET_HEX)
560 unbrick_$(TARGET): $(TARGET_HEX)
561 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
562 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
564 ## unbrick : unbrick flight controller
565 unbrick: unbrick_$(TARGET)
567 ## cppcheck : run static analysis on C source code
568 cppcheck: $(CSOURCES)
569 $(V0) $(CPPCHECK)
571 cppcheck-result.xml: $(CSOURCES)
572 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
574 # mkdirs
575 $(DL_DIR):
576 mkdir -p $@
578 $(TOOLS_DIR):
579 mkdir -p $@
581 ## version : print firmware version
582 version:
583 @echo $(FC_VER)
585 ## help : print this help message and exit
586 help: Makefile make/tools.mk
587 @echo ""
588 @echo "Makefile for the $(FORKNAME) firmware"
589 @echo ""
590 @echo "Usage:"
591 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
592 @echo "Or:"
593 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
594 @echo ""
595 @echo "Valid TARGET values are: $(VALID_TARGETS)"
596 @echo ""
597 @sed -n 's/^## //p' $?
599 ## targets : print a list of all valid target platforms (for consumption by scripts)
600 targets:
601 @echo "Valid targets: $(VALID_TARGETS)"
602 @echo "Built targets: $(CI_TARGETS)"
603 @echo "Unified targets: $(UNIFIED_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-rest: $(GROUP_OTHER_TARGETS)"
612 @echo "targets-group-1: $(words $(GROUP_1_TARGETS)) targets"
613 @echo "targets-group-2: $(words $(GROUP_2_TARGETS)) targets"
614 @echo "targets-group-rest: $(words $(GROUP_OTHER_TARGETS)) targets"
615 @echo "total in all groups $(words $(CI_TARGETS)) targets"
617 ## target-mcu : print the MCU type of the target
618 target-mcu:
619 @echo $(TARGET_MCU)
621 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
622 targets-by-mcu:
623 $(V1) for target in $${TARGETS}; do \
624 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
625 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
626 if [ "$${DO_BUILD}" = 1 ]; then \
627 echo "Building target $${target}..."; \
628 $(MAKE) TARGET=$${target}; \
629 if [ $$? -ne 0 ]; then \
630 echo "Building target $${target} failed, aborting."; \
631 exit 1; \
632 fi; \
633 else \
634 echo -n "$${target} "; \
635 fi; \
636 fi; \
637 done
638 @echo
640 ## targets-f3 : make all F3 targets
641 targets-f3:
642 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
644 targets-f3-print:
645 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 TARGETS="$(VALID_TARGETS)"
647 ## targets-f4 : make all F4 targets
648 targets-f4:
649 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
651 targets-f4-print:
652 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)"
654 targets-ci-f4-print:
655 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(CI_TARGETS)"
657 ## targets-f7 : make all F7 targets
658 targets-f7:
659 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
661 targets-f7-print:
662 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)"
664 targets-ci-f7-print:
665 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(CI_TARGETS)"
667 ## test : run the Betaflight test suite
668 ## junittest : run the Betaflight test suite, producing Junit XML result files.
669 ## 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)
670 ## test-all: run the Betaflight test suite including all per-target expanded tests
671 test junittest test-all test-representative:
672 $(V0) cd src/test && $(MAKE) $@
674 ## test_help : print the help message for the test suite (including a list of the available tests)
675 test_help:
676 $(V0) cd src/test && $(MAKE) help
678 ## test_versions : print the compiler versions used for the test suite
679 test_versions:
680 $(V0) cd src/test && $(MAKE) versions
682 ## test_% : run test 'test_%' from the test suite
683 test_%:
684 $(V0) cd src/test && $(MAKE) $@
687 # rebuild everything when makefile changes
688 $(TARGET_OBJS): Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
690 # include auto-generated dependencies
691 -include $(TARGET_DEPS)