[4.4.2] Tri-state USART TX output if load due to powered down peripheral is d… (...
[betaflight.git] / Makefile
blobfdf87781eb5bba55b1441e11ed9703db6809658e
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 DEFAULT_TARGET ?= STM32F405
20 TARGET ?=
22 # Compile-time options
23 OPTIONS ?=
25 # compile for External Storage Bootloader support
26 EXST ?= no
28 # compile for target loaded into RAM
29 RAM_BASED ?= no
31 # reserve space for custom defaults
32 CUSTOM_DEFAULTS_EXTENDED ?= no
34 # Debugger optons:
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
38 DEBUG ?=
40 # Insert the debugging hardfault debugger
41 # releases should not be built with this flag as it does not disable pwm output
42 DEBUG_HARDFAULTS ?=
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.
48 FLASH_SIZE ?=
50 ###############################################################################
51 # Things that need to be maintained as the source changes
54 FORKNAME = betaflight
56 # Working directories
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
68 ## V=0 Low
69 ## V=1 High
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
86 export RM := rm
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
95 HSE_VALUE ?= 8000000
97 # used for turning on features like VCP and SDCARD
98 FEATURES =
100 ifeq ($(TARGET),)
101 TARGET := $(DEFAULT_TARGET)
102 endif
104 include $(ROOT)/make/targets.mk
106 REVISION := norevision
107 ifeq ($(shell git diff --shortstat),)
108 REVISION := $(shell git log -1 --format="%h")
109 endif
111 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
112 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
113 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
115 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
117 # Search path for sources
118 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
119 FATFS_DIR = $(ROOT)/lib/main/FatFS
120 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
122 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
124 LD_FLAGS :=
125 EXTRA_LD_FLAGS :=
128 # Default Tool options - can be overridden in {mcu}.mk files.
130 ifeq ($(DEBUG),GDB)
131 OPTIMISE_DEFAULT := -Og
133 LTO_FLAGS := $(OPTIMISE_DEFAULT)
134 DEBUG_FLAGS = -ggdb3 -gdwarf-5 -DDEBUG
135 else
136 ifeq ($(DEBUG),INFO)
137 DEBUG_FLAGS = -ggdb3
138 endif
139 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math -fmerge-all-constants
140 OPTIMISE_DEFAULT := -O2
141 OPTIMISE_SPEED := -Ofast
142 OPTIMISE_SIZE := -Os
144 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
145 endif
147 VPATH := $(VPATH):$(ROOT)/make/mcu
148 VPATH := $(VPATH):$(ROOT)/make
150 # start specific includes
151 include $(ROOT)/make/mcu/$(TARGET_MCU).mk
153 # openocd specific includes
154 include $(ROOT)/make/openocd.mk
156 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
157 ifeq ($(TARGET_FLASH_SIZE),)
158 ifneq ($(MCU_FLASH_SIZE),)
159 TARGET_FLASH_SIZE := $(MCU_FLASH_SIZE)
160 else
161 $(error MCU_FLASH_SIZE not configured for target $(TARGET))
162 endif
163 endif
165 DEVICE_FLAGS := $(DEVICE_FLAGS) -DTARGET_FLASH_SIZE=$(TARGET_FLASH_SIZE)
167 ifneq ($(HSE_VALUE),)
168 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
169 endif
171 TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
172 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
174 .DEFAULT_GOAL := hex
176 ifeq ($(CUSTOM_DEFAULTS_EXTENDED),yes)
177 TARGET_FLAGS += -DUSE_CUSTOM_DEFAULTS=
178 EXTRA_LD_FLAGS += -Wl,--defsym=USE_CUSTOM_DEFAULTS_EXTENDED=1
179 endif
181 INCLUDE_DIRS := $(INCLUDE_DIRS) \
182 $(ROOT)/lib/main/MAVLink
184 INCLUDE_DIRS := $(INCLUDE_DIRS) \
185 $(TARGET_DIR)
187 VPATH := $(VPATH):$(TARGET_DIR)
189 include $(ROOT)/make/source.mk
191 ###############################################################################
192 # Things that might need changing to use different tools
195 # Find out if ccache is installed on the system
196 CCACHE := ccache
197 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
198 ifneq ($(RESULT),0)
199 CCACHE :=
200 endif
202 # Tool names
203 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
204 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
205 CROSS_GDB := $(ARM_SDK_PREFIX)gdb
206 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
207 OBJDUMP := $(ARM_SDK_PREFIX)objdump
208 READELF := $(ARM_SDK_PREFIX)readelf
209 SIZE := $(ARM_SDK_PREFIX)size
210 DFUSE-PACK := src/utils/dfuse-pack.py
213 # Tool options.
215 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
216 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
217 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
218 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
219 CC_NO_OPTIMISATION :=
222 # Added after GCC version update, remove once the warnings have been fixed
224 TEMPORARY_FLAGS :=
226 EXTRA_WARNING_FLAGS := -Wold-style-definition
228 CFLAGS += $(ARCH_FLAGS) \
229 $(addprefix -D,$(OPTIONS)) \
230 $(addprefix -I,$(INCLUDE_DIRS)) \
231 $(DEBUG_FLAGS) \
232 -std=gnu17 \
233 -Wall -Wextra -Werror -Wpedantic -Wunsafe-loop-optimizations -Wdouble-promotion \
234 $(EXTRA_WARNING_FLAGS) \
235 -ffunction-sections \
236 -fdata-sections \
237 -fno-common \
238 $(TEMPORARY_FLAGS) \
239 $(DEVICE_FLAGS) \
240 -D_GNU_SOURCE \
241 -DUSE_STDPERIPH_DRIVER \
242 -D$(TARGET) \
243 $(TARGET_FLAGS) \
244 -D'__FORKNAME__="$(FORKNAME)"' \
245 -D'__TARGET__="$(TARGET)"' \
246 -D'__REVISION__="$(REVISION)"' \
247 -pipe \
248 -MMD -MP \
249 $(EXTRA_FLAGS)
251 ASFLAGS = $(ARCH_FLAGS) \
252 $(DEBUG_FLAGS) \
253 -x assembler-with-cpp \
254 $(addprefix -I,$(INCLUDE_DIRS)) \
255 -MMD -MP
257 ifeq ($(LD_FLAGS),)
258 LD_FLAGS = -lm \
259 -nostartfiles \
260 --specs=nano.specs \
261 -lc \
262 -lnosys \
263 $(ARCH_FLAGS) \
264 $(LTO_FLAGS) \
265 $(DEBUG_FLAGS) \
266 -static \
267 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
268 -Wl,-L$(LINKER_DIR) \
269 -Wl,--cref \
270 -Wl,--no-wchar-size-warning \
271 -Wl,--print-memory-usage \
272 -T$(LD_SCRIPT) \
273 $(EXTRA_LD_FLAGS)
274 endif
276 ###############################################################################
277 # No user-serviceable parts below
278 ###############################################################################
280 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
281 --std=c99 --inline-suppr --quiet --force \
282 $(addprefix -I,$(INCLUDE_DIRS)) \
283 -I/usr/include -I/usr/include/linux
285 TARGET_NAME := $(TARGET)
287 ifeq ($(REV),yes)
288 TARGET_NAME := $(TARGET_NAME)_$(REVISION)
289 endif
291 TARGET_FULLNAME = $(FORKNAME)_$(FC_VER)_$(TARGET_NAME)
294 # Things we will build
296 TARGET_BIN = $(BIN_DIR)/$(TARGET_FULLNAME).bin
297 TARGET_HEX = $(BIN_DIR)/$(TARGET_FULLNAME).hex
298 TARGET_DFU = $(BIN_DIR)/$(TARGET_FULLNAME).dfu
299 TARGET_ZIP = $(BIN_DIR)/$(TARGET_FULLNAME).zip
300 TARGET_OBJ_DIR = $(OBJECT_DIR)/$(TARGET_NAME)
301 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME).elf
302 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME)_EXST.elf
303 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME)_UNPATCHED.bin
304 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME).lst
305 TARGET_OBJS = $(addsuffix .o,$(addprefix $(TARGET_OBJ_DIR)/,$(basename $(SRC))))
306 TARGET_DEPS = $(addsuffix .d,$(addprefix $(TARGET_OBJ_DIR)/,$(basename $(SRC))))
307 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET_NAME).map
309 TARGET_EXST_HASH_SECTION_FILE = $(TARGET_OBJ_DIR)/exst_hash_section.bin
311 TARGET_EF_HASH := $(shell echo -n "$(EXTRA_FLAGS)" | openssl dgst -md5 | awk '{print $$2;}')
312 TARGET_EF_HASH_FILE := $(TARGET_OBJ_DIR)/.efhash_$(TARGET_EF_HASH)
314 CLEAN_ARTIFACTS := $(TARGET_BIN)
315 CLEAN_ARTIFACTS += $(TARGET_HEX_REV) $(TARGET_HEX)
316 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
317 CLEAN_ARTIFACTS += $(TARGET_LST)
318 CLEAN_ARTIFACTS += $(TARGET_DFU)
320 # Make sure build date and revision is updated on every incremental build
321 $(TARGET_OBJ_DIR)/build/version.o : $(SRC)
323 # List of buildable ELF files and their object dependencies.
324 # It would be nice to compute these lists, but that seems to be just beyond make.
326 $(TARGET_LST): $(TARGET_ELF)
327 $(V0) $(OBJDUMP) -S --disassemble $< > $@
329 ifeq ($(EXST),no)
330 $(TARGET_BIN): $(TARGET_ELF)
331 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
332 $(V1) $(OBJCOPY) -O binary $< $@
334 $(TARGET_HEX): $(TARGET_ELF)
335 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
336 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
338 $(TARGET_DFU): $(TARGET_HEX)
339 @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)"
340 $(V1) $(PYTHON) $(DFUSE-PACK) -i $< $@
342 else
343 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
345 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
346 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
347 $(V1) $(OBJCOPY) -O binary $< $@
349 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
350 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
351 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
352 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
353 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
354 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
356 @echo "Generating MD5 hash of binary" "$(STDOUT)"
357 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
359 @echo "Patching MD5 hash into binary" "$(STDOUT)"
360 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
361 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
363 # 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"
364 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
365 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
366 # a) regeneration of $(TARGET_BIN), and
367 # b) the results of $(TARGET_BIN) will not be as expected.
368 @echo "Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
369 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF).tmp --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE) -j .exst_hash
370 rm $(TARGET_EXST_ELF).tmp
372 @echo "Patching MD5 hash into HASH section" "$(STDOUT)"
373 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
375 $(V1) @echo "Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
376 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
378 $(V1) $(READELF) -S $(TARGET_EXST_ELF)
379 $(V1) $(READELF) -l $(TARGET_EXST_ELF)
381 $(TARGET_HEX): $(TARGET_BIN)
382 $(if $(EXST_ADJUST_VMA),,$(error "EXST_ADJUST_VMA not specified"))
384 @echo "Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
385 $(V1) $(OBJCOPY) -I binary -O ihex --adjust-vma=$(EXST_ADJUST_VMA) $(TARGET_BIN) $@
387 endif
389 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT) $(LD_SCRIPTS)
390 @echo "Linking $(TARGET_NAME)" "$(STDOUT)"
391 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
392 $(V1) $(SIZE) $(TARGET_ELF)
394 # Compile
396 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
397 define compile_file
398 echo "%% ($(1)) $<" "$(STDOUT)" && \
399 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
400 endef
402 ifeq ($(DEBUG),GDB)
403 $(TARGET_OBJ_DIR)/%.o: %.c
404 $(V1) mkdir -p $(dir $@)
405 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
406 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
408 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
410 else
411 $(TARGET_OBJ_DIR)/%.o: %.c
412 $(V1) mkdir -p $(dir $@)
413 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
414 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
416 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
417 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
419 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
420 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
422 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
426 endif
428 # Assemble
429 $(TARGET_OBJ_DIR)/%.o: %.s
430 $(V1) mkdir -p $(dir $@)
431 @echo "%% $(notdir $<)" "$(STDOUT)"
432 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
434 $(TARGET_OBJ_DIR)/%.o: %.S
435 $(V1) mkdir -p $(dir $@)
436 @echo "%% $(notdir $<)" "$(STDOUT)"
437 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
440 ## all : Build all currently built targets
441 all: $(CI_TARGETS)
443 ## all_all : Build all targets (including legacy / unsupported)
444 all_all: $(VALID_TARGETS)
446 $(BASE_TARGETS):
447 $(V0) @echo "Building $@" && \
448 $(MAKE) hex TARGET=$@ && \
449 echo "Building $@ succeeded."
451 $(NOBUILD_TARGETS):
452 $(MAKE) TARGET=$@
454 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS))
456 ## clean : clean up temporary / machine-generated files
457 clean:
458 @echo "Cleaning $(TARGET_NAME)"
459 $(V0) rm -f $(CLEAN_ARTIFACTS)
460 $(V0) rm -rf $(TARGET_OBJ_DIR)
461 @echo "Cleaning $(TARGET_NAME) succeeded."
463 ## test_clean : clean up temporary / machine-generated files (tests)
464 test-%_clean:
465 $(MAKE) test_clean
467 test_clean:
468 $(V0) cd src/test && $(MAKE) clean || true
470 ## <TARGET>_clean : clean up one specific target (alias for above)
471 $(TARGETS_CLEAN):
472 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
474 ## clean_all : clean all valid targets
475 clean_all: $(TARGETS_CLEAN) test_clean
477 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS))
479 ## <TARGET>_flash : build and flash a target
480 $(TARGETS_FLASH):
481 $(V0) $(MAKE) hex TARGET=$(subst _flash,,$@)
482 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
483 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
484 else
485 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
486 endif
488 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
489 tty_flash:
490 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
491 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
492 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
494 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
495 dfu_flash:
496 ifneq (no-port-found,$(SERIAL_DEVICE))
497 # potentially this is because the MCU already is in DFU mode, try anyway
498 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
499 $(V0) sleep 1
500 endif
501 $(V0) $(MAKE) $(TARGET_DFU)
502 $(V0) dfu-util -a 0 -D $(TARGET_DFU) -s :leave
504 st-flash_$(TARGET): $(TARGET_BIN)
505 $(V0) st-flash --reset write $< 0x08000000
507 ## st-flash : flash firmware (.bin) onto flight controller
508 st-flash: st-flash_$(TARGET)
510 ifneq ($(OPENOCD_COMMAND),)
511 openocd-gdb: $(TARGET_ELF)
512 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
513 endif
515 TARGETS_ZIP = $(addsuffix _zip,$(VALID_TARGETS))
517 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
518 $(TARGETS_ZIP):
519 $(V0) $(MAKE) hex TARGET=$(subst _zip,,$@)
520 $(V0) $(MAKE) zip TARGET=$(subst _zip,,$@)
522 zip:
523 $(V0) zip $(TARGET_ZIP) $(TARGET_HEX)
525 binary:
526 $(V0) $(MAKE) -j $(TARGET_BIN)
528 hex:
529 $(V0) $(MAKE) -j $(TARGET_HEX)
531 TARGETS_REVISION = $(addsuffix _rev,$(VALID_TARGETS))
532 ## <TARGET>_rev : build target and add revision to filename
533 $(TARGETS_REVISION):
534 $(V0) $(MAKE) hex REV=yes TARGET=$(subst _rev,,$@)
536 all_rev: $(addsuffix _rev,$(CI_TARGETS))
538 unbrick_$(TARGET): $(TARGET_HEX)
539 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
540 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
542 ## unbrick : unbrick flight controller
543 unbrick: unbrick_$(TARGET)
545 ## cppcheck : run static analysis on C source code
546 cppcheck: $(CSOURCES)
547 $(V0) $(CPPCHECK)
549 cppcheck-result.xml: $(CSOURCES)
550 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
552 # mkdirs
553 $(DL_DIR):
554 mkdir -p $@
556 $(TOOLS_DIR):
557 mkdir -p $@
559 ## version : print firmware version
560 version:
561 @echo $(FC_VER)
563 ## help : print this help message and exit
564 help: Makefile make/tools.mk
565 @echo ""
566 @echo "Makefile for the $(FORKNAME) firmware"
567 @echo ""
568 @echo "Usage:"
569 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
570 @echo "Or:"
571 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
572 @echo ""
573 @echo "Valid TARGET values are: $(VALID_TARGETS)"
574 @echo ""
575 @sed -n 's/^## //p' $?
577 ## targets : print a list of all valid target platforms (for consumption by scripts)
578 targets:
579 @echo "Valid targets: $(VALID_TARGETS)"
580 @echo "Built targets: $(CI_TARGETS)"
581 @echo "Default target: $(TARGET)"
583 targets-ci-print:
584 @echo $(CI_TARGETS)
586 ## target-mcu : print the MCU type of the target
587 target-mcu:
588 @echo $(TARGET_MCU)
590 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
591 targets-by-mcu:
592 $(V1) for target in $${TARGETS}; do \
593 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
594 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
595 if [ "$${DO_BUILD}" = 1 ]; then \
596 echo "Building target $${target}..."; \
597 $(MAKE) TARGET=$${target}; \
598 if [ $$? -ne 0 ]; then \
599 echo "Building target $${target} failed, aborting."; \
600 exit 1; \
601 fi; \
602 else \
603 echo -n "$${target} "; \
604 fi; \
605 fi; \
606 done
607 @echo
609 ## targets-f4 : make all F4 targets
610 targets-f4:
611 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
613 targets-f4-print:
614 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)"
616 targets-ci-f4-print:
617 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(CI_TARGETS)"
619 ## targets-f7 : make all F7 targets
620 targets-f7:
621 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
623 targets-f7-print:
624 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)"
626 targets-ci-f7-print:
627 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(CI_TARGETS)"
629 ## test : run the Betaflight test suite
630 ## junittest : run the Betaflight test suite, producing Junit XML result files.
631 ## 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)
632 ## test-all: run the Betaflight test suite including all per-target expanded tests
633 test junittest test-all test-representative:
634 $(V0) cd src/test && $(MAKE) $@
636 ## test_help : print the help message for the test suite (including a list of the available tests)
637 test_help:
638 $(V0) cd src/test && $(MAKE) help
640 ## test_versions : print the compiler versions used for the test suite
641 test_versions:
642 $(V0) cd src/test && $(MAKE) versions
644 ## test_% : run test 'test_%' from the test suite
645 test_%:
646 $(V0) cd src/test && $(MAKE) $@
648 $(TARGET_EF_HASH_FILE):
649 $(V1) mkdir -p $(dir $@)
650 $(V0) rm -f $(TARGET_OBJ_DIR)/.efhash_*
651 @echo "EF HASH -> $(TARGET_EF_HASH_FILE)"
652 $(V1) touch $(TARGET_EF_HASH_FILE)
654 # rebuild everything when makefile changes or the extra flags have changed
655 $(TARGET_OBJS): $(TARGET_EF_HASH_FILE) Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
657 # include auto-generated dependencies
658 -include $(TARGET_DEPS)