Merge pull request #9493 from mikeller/reduce_target_groups
[betaflight.git] / Makefile
blobadd0f477134bc9d57f8fcaca5a378cf99b984800
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 ifndef TOOLS_DIR
87 TOOLS_DIR := $(ROOT)/tools
88 endif
89 BUILD_DIR := $(ROOT)/build
90 DL_DIR := $(ROOT)/downloads
92 export RM := rm
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
101 HSE_VALUE ?= 8000000
103 # used for turning on features like VCP and SDCARD
104 FEATURES =
106 # used to disable features based on flash space shortage (larger number => more features disabled)
107 FEATURE_CUT_LEVEL_SUPPLIED := $(FEATURE_CUT_LEVEL)
108 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 := norevision
116 ifeq ($(shell git diff --shortstat),)
117 REVISION := $(shell git log -1 --format="%h")
118 endif
120 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
121 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
122 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
124 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
126 # Search path for sources
127 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
128 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
129 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
130 FATFS_DIR = $(ROOT)/lib/main/FatFS
131 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
133 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
135 LD_FLAGS :=
136 EXTRA_LD_FLAGS :=
139 # Default Tool options - can be overridden in {mcu}.mk files.
141 ifeq ($(DEBUG),GDB)
142 OPTIMISE_DEFAULT := -Og
144 LTO_FLAGS := $(OPTIMISE_DEFAULT)
145 DEBUG_FLAGS = -ggdb3 -DDEBUG
146 else
147 ifeq ($(DEBUG),INFO)
148 DEBUG_FLAGS = -ggdb3
149 endif
150 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
151 OPTIMISE_DEFAULT := -O2
152 OPTIMISE_SPEED := -Ofast
153 OPTIMISE_SIZE := -Os
155 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
156 endif
158 VPATH := $(VPATH):$(ROOT)/make/mcu
159 VPATH := $(VPATH):$(ROOT)/make
161 # start specific includes
162 include $(ROOT)/make/mcu/$(TARGET_MCU).mk
164 # openocd specific includes
165 include $(ROOT)/make/openocd.mk
167 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
168 ifeq ($(TARGET_FLASH_SIZE),)
169 ifneq ($(MCU_FLASH_SIZE),)
170 TARGET_FLASH_SIZE := $(MCU_FLASH_SIZE)
171 else
172 $(error MCU_FLASH_SIZE not configured for target $(TARGET))
173 endif
174 endif
176 DEVICE_FLAGS := $(DEVICE_FLAGS) -DTARGET_FLASH_SIZE=$(TARGET_FLASH_SIZE)
178 ifneq ($(HSE_VALUE),)
179 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
180 endif
182 ifneq ($(FEATURE_CUT_LEVEL_SUPPLIED),)
183 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL_SUPPLIED)
184 else ifneq ($(FEATURE_CUT_LEVEL),)
185 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL)
186 endif
188 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
189 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
191 ifeq ($(OPBL),yes)
192 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
193 .DEFAULT_GOAL := binary
194 else
195 .DEFAULT_GOAL := hex
196 endif
198 ifeq ($(CUSTOM_DEFAULTS_EXTENDED),yes)
199 TARGET_FLAGS += -DUSE_CUSTOM_DEFAULTS=
200 EXTRA_LD_FLAGS += -Wl,--defsym=USE_CUSTOM_DEFAULTS_EXTENDED=1
201 endif
203 INCLUDE_DIRS := $(INCLUDE_DIRS) \
204 $(ROOT)/lib/main/MAVLink
206 INCLUDE_DIRS := $(INCLUDE_DIRS) \
207 $(TARGET_DIR)
209 VPATH := $(VPATH):$(TARGET_DIR)
211 include $(ROOT)/make/source.mk
213 ###############################################################################
214 # Things that might need changing to use different tools
217 # Find out if ccache is installed on the system
218 CCACHE := ccache
219 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
220 ifneq ($(RESULT),0)
221 CCACHE :=
222 endif
224 # Tool names
225 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
226 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
227 CROSS_GDB := $(ARM_SDK_PREFIX)gdb
228 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
229 OBJDUMP := $(ARM_SDK_PREFIX)objdump
230 SIZE := $(ARM_SDK_PREFIX)size
231 DFUSE-PACK := src/utils/dfuse-pack.py
234 # Tool options.
236 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
237 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
238 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
239 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
240 CC_NO_OPTIMISATION :=
243 # Added after GCC version update, remove once the warnings have been fixed
245 TEMPORARY_FLAGS :=
247 CFLAGS += $(ARCH_FLAGS) \
248 $(addprefix -D,$(OPTIONS)) \
249 $(addprefix -I,$(INCLUDE_DIRS)) \
250 $(DEBUG_FLAGS) \
251 -std=gnu11 \
252 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
253 -ffunction-sections \
254 -fdata-sections \
255 -fno-common \
256 -pedantic \
257 $(TEMPORARY_FLAGS) \
258 $(DEVICE_FLAGS) \
259 -D_GNU_SOURCE \
260 -DUSE_STDPERIPH_DRIVER \
261 -D$(TARGET) \
262 $(TARGET_FLAGS) \
263 -D'__FORKNAME__="$(FORKNAME)"' \
264 -D'__TARGET__="$(TARGET)"' \
265 -D'__REVISION__="$(REVISION)"' \
266 -save-temps=obj \
267 -MMD -MP \
268 $(EXTRA_FLAGS)
270 ASFLAGS = $(ARCH_FLAGS) \
271 $(DEBUG_FLAGS) \
272 -x assembler-with-cpp \
273 $(addprefix -I,$(INCLUDE_DIRS)) \
274 -MMD -MP
276 ifeq ($(LD_FLAGS),)
277 LD_FLAGS = -lm \
278 -nostartfiles \
279 --specs=nano.specs \
280 -lc \
281 -lnosys \
282 $(ARCH_FLAGS) \
283 $(LTO_FLAGS) \
284 $(DEBUG_FLAGS) \
285 -static \
286 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
287 -Wl,-L$(LINKER_DIR) \
288 -Wl,--cref \
289 -Wl,--no-wchar-size-warning \
290 -Wl,--print-memory-usage \
291 -T$(LD_SCRIPT) \
292 $(EXTRA_LD_FLAGS)
293 endif
295 ###############################################################################
296 # No user-serviceable parts below
297 ###############################################################################
299 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
300 --std=c99 --inline-suppr --quiet --force \
301 $(addprefix -I,$(INCLUDE_DIRS)) \
302 -I/usr/include -I/usr/include/linux
305 TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)_$(REVISION)
308 # Things we will build
310 TARGET_S19 = $(TARGET_BASENAME).s19
311 TARGET_BIN = $(TARGET_BASENAME).bin
312 TARGET_HEX = $(TARGET_BASENAME).hex
313 TARGET_DFU = $(TARGET_BASENAME).dfu
314 TARGET_ZIP = $(TARGET_BASENAME).zip
315 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
316 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_EXST.elf
317 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_UNPATCHED.bin
318 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
319 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
320 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
321 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
323 TARGET_EXST_HASH_SECTION_FILE = $(OBJECT_DIR)/$(TARGET)/exst_hash_section.bin
325 CLEAN_ARTIFACTS := $(TARGET_BIN)
326 CLEAN_ARTIFACTS += $(TARGET_HEX)
327 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
328 CLEAN_ARTIFACTS += $(TARGET_LST)
329 CLEAN_ARTIFACTS += $(TARGET_DFU)
331 # Make sure build date and revision is updated on every incremental build
332 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
334 # List of buildable ELF files and their object dependencies.
335 # It would be nice to compute these lists, but that seems to be just beyond make.
337 $(TARGET_LST): $(TARGET_ELF)
338 $(V0) $(OBJDUMP) -S --disassemble $< > $@
341 $(TARGET_S19): $(TARGET_ELF)
342 @echo "Creating srec/S19 $(TARGET_S19)" "$(STDOUT)"
343 $(V1) $(OBJCOPY) --output-target=srec $(TARGET_S19)
345 ifeq ($(EXST),no)
346 $(TARGET_BIN): $(TARGET_ELF)
347 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
348 $(V1) $(OBJCOPY) -O binary $< $@
350 $(TARGET_HEX): $(TARGET_ELF)
351 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
352 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
354 $(TARGET_DFU): $(TARGET_HEX)
355 @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)"
356 $(V1) $(DFUSE-PACK) -i $< $@
358 else
359 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
361 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
362 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
363 $(V1) $(OBJCOPY) -O binary $< $@
365 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
366 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
367 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
368 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
369 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
370 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
372 @echo "Generating MD5 hash of binary" "$(STDOUT)"
373 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
375 @echo "Patching MD5 hash into binary" "$(STDOUT)"
376 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
377 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
379 # 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"
380 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
381 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
382 # a) regeneration of $(TARGET_BIN), and
383 # b) the results of $(TARGET_BIN) will not be as expected.
384 @echo "Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
385 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF).tmp --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
386 rm $(TARGET_EXST_ELF).tmp
388 @echo "Patching MD5 hash into HASH section" "$(STDOUT)"
389 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
391 @echo "Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
392 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
394 $(TARGET_HEX): $(TARGET_BIN)
395 $(if $(EXST_ADJUST_VMA),,$(error "EXST_ADJUST_VMA not specified"))
397 @echo "Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
398 $(V1) $(OBJCOPY) -I binary -O ihex --adjust-vma=$(EXST_ADJUST_VMA) $(TARGET_BIN) $@
400 endif
402 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT)
403 @echo "Linking $(TARGET)" "$(STDOUT)"
404 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
405 $(V1) $(SIZE) $(TARGET_ELF)
407 # Compile
409 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
410 define compile_file
411 echo "%% ($(1)) $<" "$(STDOUT)" && \
412 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
413 endef
415 ifeq ($(DEBUG),GDB)
416 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
417 $(V1) mkdir -p $(dir $@)
418 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
419 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
421 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
423 else
424 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
425 $(V1) mkdir -p $(dir $@)
426 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
427 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
429 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
430 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
432 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
433 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
435 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
439 endif
441 # Assemble
442 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
443 $(V1) mkdir -p $(dir $@)
444 @echo "%% $(notdir $<)" "$(STDOUT)"
445 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
447 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
448 $(V1) mkdir -p $(dir $@)
449 @echo "%% $(notdir $<)" "$(STDOUT)"
450 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
453 ## all : Build all currently built targets
454 all: $(CI_TARGETS)
456 ## all_all : Build all targets (including legacy / unsupported)
457 all_all: $(VALID_TARGETS)
459 ## unified : build all Unified Targets
460 unified: $(UNIFIED_TARGETS)
462 ## unified_zip : build all Unified Targets as zip files (for posting on GitHub)
463 unified_zip: $(addsuffix _zip,$(UNIFIED_TARGETS))
465 ## legacy : Build legacy targets
466 legacy: $(LEGACY_TARGETS)
468 ## unsupported : Build unsupported targets
469 unsupported: $(UNSUPPORTED_TARGETS)
471 ## pre-push : The minimum verification that should be run before pushing, to check if CI has a chance of succeeding
472 pre-push:
473 $(MAKE) $(addsuffix _clean,$(PRE_PUSH_TARGET_LIST)) $(PRE_PUSH_TARGET_LIST) EXTRA_FLAGS=-Werror
475 ## targets-group-1 : build some targets
476 targets-group-1: $(GROUP_1_TARGETS)
478 ## targets-group-2 : build some targets
479 targets-group-2: $(GROUP_2_TARGETS)
481 ## targets-group-rest: build the rest of the targets (not listed in the other groups)
482 targets-group-rest: $(GROUP_OTHER_TARGETS)
484 $(VALID_TARGETS):
485 $(V0) @echo "Building $@" && \
486 $(MAKE) binary hex TARGET=$@ && \
487 echo "Building $@ succeeded."
489 $(NOBUILD_TARGETS):
490 $(MAKE) TARGET=$@
492 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS))
494 ## clean : clean up temporary / machine-generated files
495 clean:
496 @echo "Cleaning $(TARGET)"
497 $(V0) rm -f $(CLEAN_ARTIFACTS)
498 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
499 @echo "Cleaning $(TARGET) succeeded."
501 ## test_clean : clean up temporary / machine-generated files (tests)
502 test-%_clean:
503 $(MAKE) test_clean
505 test_clean:
506 $(V0) cd src/test && $(MAKE) clean || true
508 ## <TARGET>_clean : clean up one specific target (alias for above)
509 $(TARGETS_CLEAN):
510 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
512 ## clean_all : clean all valid targets
513 clean_all: $(TARGETS_CLEAN) test_clean
515 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS))
517 ## <TARGET>_flash : build and flash a target
518 $(TARGETS_FLASH):
519 $(V0) $(MAKE) hex TARGET=$(subst _flash,,$@)
520 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
521 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
522 else
523 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
524 endif
526 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
527 tty_flash:
528 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
529 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
530 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
532 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
533 dfu_flash:
534 ifneq (no-port-found,$(SERIAL_DEVICE))
535 # potentially this is because the MCU already is in DFU mode, try anyway
536 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
537 $(V0) sleep 1
538 endif
539 $(V0) $(MAKE) $(TARGET_DFU)
540 $(V0) dfu-util -a 0 -D $(TARGET_DFU) -s :leave
542 st-flash_$(TARGET): $(TARGET_BIN)
543 $(V0) st-flash --reset write $< 0x08000000
545 ## st-flash : flash firmware (.bin) onto flight controller
546 st-flash: st-flash_$(TARGET)
548 ifneq ($(OPENOCD_COMMAND),)
549 openocd-gdb: $(TARGET_ELF)
550 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
551 endif
553 TARGETS_ZIP = $(addsuffix _zip,$(VALID_TARGETS))
555 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
556 $(TARGETS_ZIP):
557 $(V0) $(MAKE) hex TARGET=$(subst _zip,,$@)
558 $(V0) $(MAKE) zip TARGET=$(subst _zip,,$@)
560 zip:
561 $(V0) zip $(TARGET_ZIP) $(TARGET_HEX)
563 binary:
564 $(V0) $(MAKE) -j $(TARGET_BIN)
566 srec:
567 $(V0) $(MAKE) -j $(TARGET_S19)
569 hex:
570 $(V0) $(MAKE) -j $(TARGET_HEX)
572 unbrick_$(TARGET): $(TARGET_HEX)
573 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
574 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
576 ## unbrick : unbrick flight controller
577 unbrick: unbrick_$(TARGET)
579 ## cppcheck : run static analysis on C source code
580 cppcheck: $(CSOURCES)
581 $(V0) $(CPPCHECK)
583 cppcheck-result.xml: $(CSOURCES)
584 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
586 # mkdirs
587 $(DL_DIR):
588 mkdir -p $@
590 $(TOOLS_DIR):
591 mkdir -p $@
593 $(BUILD_DIR):
594 mkdir -p $@
596 ## version : print firmware version
597 version:
598 @echo $(FC_VER)
600 ## help : print this help message and exit
601 help: Makefile make/tools.mk
602 @echo ""
603 @echo "Makefile for the $(FORKNAME) firmware"
604 @echo ""
605 @echo "Usage:"
606 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
607 @echo "Or:"
608 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
609 @echo ""
610 @echo "Valid TARGET values are: $(VALID_TARGETS)"
611 @echo ""
612 @sed -n 's/^## //p' $?
614 ## targets : print a list of all valid target platforms (for consumption by scripts)
615 targets:
616 @echo "Valid targets: $(VALID_TARGETS)"
617 @echo "Built targets: $(CI_TARGETS)"
618 @echo "Unified targets: $(UNIFIED_TARGETS)"
619 @echo "Legacy targets: $(LEGACY_TARGETS)"
620 @echo "Unsupported targets: $(UNSUPPORTED_TARGETS)"
621 @echo "Target: $(TARGET)"
622 @echo "Base target: $(BASE_TARGET)"
623 @echo "targets-group-1: $(GROUP_1_TARGETS)"
624 @echo "targets-group-2: $(GROUP_2_TARGETS)"
625 @echo "targets-group-rest: $(GROUP_OTHER_TARGETS)"
627 @echo "targets-group-1: $(words $(GROUP_1_TARGETS)) targets"
628 @echo "targets-group-2: $(words $(GROUP_2_TARGETS)) targets"
629 @echo "targets-group-rest: $(words $(GROUP_OTHER_TARGETS)) targets"
630 @echo "total in all groups $(words $(CI_TARGETS)) targets"
632 ## target-mcu : print the MCU type of the target
633 target-mcu:
634 @echo $(TARGET_MCU)
636 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
637 targets-by-mcu:
638 $(V1) for target in $${TARGETS}; do \
639 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
640 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
641 if [ "$${DO_BUILD}" = 1 ]; then \
642 echo "Building target $${target}..."; \
643 $(MAKE) TARGET=$${target}; \
644 if [ $$? -ne 0 ]; then \
645 echo "Building target $${target} failed, aborting."; \
646 exit 1; \
647 fi; \
648 else \
649 echo -n "$${target} "; \
650 fi; \
651 fi; \
652 done
653 @echo
655 ## targets-f3 : make all F3 targets
656 targets-f3:
657 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
659 targets-f3-print:
660 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 TARGETS="$(VALID_TARGETS)"
662 ## targets-f4 : make all F4 targets
663 targets-f4:
664 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
666 targets-f4-print:
667 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)"
669 targets-ci-f4-print:
670 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(CI_TARGETS)"
672 ## targets-f7 : make all F7 targets
673 targets-f7:
674 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
676 targets-f7-print:
677 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)"
679 targets-ci-f7-print:
680 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(CI_TARGETS)"
682 ## test : run the Betaflight test suite
683 ## junittest : run the Betaflight test suite, producing Junit XML result files.
684 ## 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)
685 ## test-all: run the Betaflight test suite including all per-target expanded tests
686 test junittest test-all test-representative:
687 $(V0) cd src/test && $(MAKE) $@
689 ## test_help : print the help message for the test suite (including a list of the available tests)
690 test_help:
691 $(V0) cd src/test && $(MAKE) help
693 ## test_% : run test 'test_%' from the test suite
694 test_%:
695 $(V0) cd src/test && $(MAKE) $@
698 # rebuild everything when makefile changes
699 $(TARGET_OBJS): Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
701 # include auto-generated dependencies
702 -include $(TARGET_DEPS)