Merge pull request #11935 from haslinghuis/fix-gps-cloudbuild
[betaflight.git] / Makefile
blob7b2dced8f95ae8366c509b2b046cef3846577cde
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 External Storage Bootloader support
25 EXST ?= no
27 # compile for target loaded into RAM
28 RAM_BASED ?= no
30 # reserve space for custom defaults
31 CUSTOM_DEFAULTS_EXTENDED ?= no
33 # Debugger optons:
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
37 DEBUG ?=
39 # Insert the debugging hardfault debugger
40 # releases should not be built with this flag as it does not disable pwm output
41 DEBUG_HARDFAULTS ?=
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.
47 FLASH_SIZE ?=
49 ###############################################################################
50 # Things that need to be maintained as the source changes
53 FORKNAME = betaflight
55 # Working directories
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
67 ## V=0 Low
68 ## V=1 High
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
85 export RM := rm
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
94 HSE_VALUE ?= 8000000
96 # used for turning on features like VCP and SDCARD
97 FEATURES =
99 # used to disable features based on flash space shortage (larger number => more features disabled)
100 FEATURE_CUT_LEVEL_SUPPLIED := $(FEATURE_CUT_LEVEL)
101 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")
108 endif
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')
123 LD_FLAGS :=
124 EXTRA_LD_FLAGS :=
127 # Default Tool options - can be overridden in {mcu}.mk files.
129 ifeq ($(DEBUG),GDB)
130 OPTIMISE_DEFAULT := -Og
132 LTO_FLAGS := $(OPTIMISE_DEFAULT)
133 DEBUG_FLAGS = -ggdb3 -gdwarf-5 -DDEBUG
134 else
135 ifeq ($(DEBUG),INFO)
136 DEBUG_FLAGS = -ggdb3
137 endif
138 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math -fmerge-all-constants
139 OPTIMISE_DEFAULT := -O2
140 OPTIMISE_SPEED := -Ofast
141 OPTIMISE_SIZE := -Os
143 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
144 endif
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)
159 else
160 $(error MCU_FLASH_SIZE not configured for target $(TARGET))
161 endif
162 endif
164 DEVICE_FLAGS := $(DEVICE_FLAGS) -DTARGET_FLASH_SIZE=$(TARGET_FLASH_SIZE)
166 ifneq ($(HSE_VALUE),)
167 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
168 endif
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)
174 endif
176 TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
177 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
179 .DEFAULT_GOAL := hex
181 ifeq ($(CUSTOM_DEFAULTS_EXTENDED),yes)
182 TARGET_FLAGS += -DUSE_CUSTOM_DEFAULTS=
183 EXTRA_LD_FLAGS += -Wl,--defsym=USE_CUSTOM_DEFAULTS_EXTENDED=1
184 endif
186 INCLUDE_DIRS := $(INCLUDE_DIRS) \
187 $(ROOT)/lib/main/MAVLink
189 INCLUDE_DIRS := $(INCLUDE_DIRS) \
190 $(TARGET_DIR)
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
201 CCACHE := ccache
202 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
203 ifneq ($(RESULT),0)
204 CCACHE :=
205 endif
207 # Tool names
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
218 # Tool options.
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
229 TEMPORARY_FLAGS :=
231 EXTRA_WARNING_FLAGS := -Wold-style-definition
233 CFLAGS += $(ARCH_FLAGS) \
234 $(addprefix -D,$(OPTIONS)) \
235 $(addprefix -I,$(INCLUDE_DIRS)) \
236 $(DEBUG_FLAGS) \
237 -std=gnu17 \
238 -Wall -Wextra -Werror -Wpedantic -Wunsafe-loop-optimizations -Wdouble-promotion \
239 $(EXTRA_WARNING_FLAGS) \
240 -ffunction-sections \
241 -fdata-sections \
242 -fno-common \
243 $(TEMPORARY_FLAGS) \
244 $(DEVICE_FLAGS) \
245 -D_GNU_SOURCE \
246 -DUSE_STDPERIPH_DRIVER \
247 -D$(TARGET) \
248 $(TARGET_FLAGS) \
249 -D'__FORKNAME__="$(FORKNAME)"' \
250 -D'__TARGET__="$(TARGET)"' \
251 -D'__REVISION__="$(REVISION)"' \
252 -pipe \
253 -MMD -MP \
254 $(EXTRA_FLAGS)
256 ASFLAGS = $(ARCH_FLAGS) \
257 $(DEBUG_FLAGS) \
258 -x assembler-with-cpp \
259 $(addprefix -I,$(INCLUDE_DIRS)) \
260 -MMD -MP
262 ifeq ($(LD_FLAGS),)
263 LD_FLAGS = -lm \
264 -nostartfiles \
265 --specs=nano.specs \
266 -lc \
267 -lnosys \
268 $(ARCH_FLAGS) \
269 $(LTO_FLAGS) \
270 $(DEBUG_FLAGS) \
271 -static \
272 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
273 -Wl,-L$(LINKER_DIR) \
274 -Wl,--cref \
275 -Wl,--no-wchar-size-warning \
276 -Wl,--print-memory-usage \
277 -T$(LD_SCRIPT) \
278 $(EXTRA_LD_FLAGS)
279 endif
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 $< > $@
325 ifeq ($(EXST),no)
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 $< $@
338 else
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) $@
386 endif
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)
393 # Compile
395 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
396 define compile_file
397 echo "%% ($(1)) $<" "$(STDOUT)" && \
398 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
399 endef
401 ifeq ($(DEBUG),GDB)
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)) \
409 else
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)) \
425 endif
427 # Assemble
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
440 all: $(CI_TARGETS)
442 ## all_all : Build all targets (including legacy / unsupported)
443 all_all: $(VALID_TARGETS)
445 $(VALID_TARGETS):
446 $(V0) @echo "Building $@" && \
447 $(MAKE) hex TARGET=$@ && \
448 echo "Building $@ succeeded."
450 $(NOBUILD_TARGETS):
451 $(MAKE) TARGET=$@
453 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS))
455 ## clean : clean up temporary / machine-generated files
456 clean:
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)
463 test-%_clean:
464 $(MAKE) test_clean
466 test_clean:
467 $(V0) cd src/test && $(MAKE) clean || true
469 ## <TARGET>_clean : clean up one specific target (alias for above)
470 $(TARGETS_CLEAN):
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
479 $(TARGETS_FLASH):
480 $(V0) $(MAKE) hex TARGET=$(subst _flash,,$@)
481 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
482 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
483 else
484 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
485 endif
487 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
488 tty_flash:
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
494 dfu_flash:
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)
498 $(V0) sleep 1
499 endif
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"
512 endif
514 TARGETS_ZIP = $(addsuffix _zip,$(VALID_TARGETS))
516 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
517 $(TARGETS_ZIP):
518 $(V0) $(MAKE) hex TARGET=$(subst _zip,,$@)
519 $(V0) $(MAKE) zip TARGET=$(subst _zip,,$@)
521 zip:
522 $(V0) zip $(TARGET_ZIP) $(TARGET_HEX)
524 binary:
525 $(V0) $(MAKE) -j $(TARGET_BIN)
527 hex:
528 $(V0) $(MAKE) -j $(TARGET_HEX)
530 TARGETS_REVISION = $(addsuffix _rev,$(VALID_TARGETS))
531 ## <TARGET>_rev : build target and add revision to filename
532 $(TARGETS_REVISION):
533 $(V0) $(MAKE) hex_rev TARGET=$(subst _rev,,$@)
535 hex_rev: hex
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)
549 $(V0) $(CPPCHECK)
551 cppcheck-result.xml: $(CSOURCES)
552 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
554 # mkdirs
555 $(DL_DIR):
556 mkdir -p $@
558 $(TOOLS_DIR):
559 mkdir -p $@
561 ## version : print firmware version
562 version:
563 @echo $(FC_VER)
565 ## help : print this help message and exit
566 help: Makefile make/tools.mk
567 @echo ""
568 @echo "Makefile for the $(FORKNAME) firmware"
569 @echo ""
570 @echo "Usage:"
571 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
572 @echo "Or:"
573 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
574 @echo ""
575 @echo "Valid TARGET values are: $(VALID_TARGETS)"
576 @echo ""
577 @sed -n 's/^## //p' $?
579 ## targets : print a list of all valid target platforms (for consumption by scripts)
580 targets:
581 @echo "Valid targets: $(VALID_TARGETS)"
582 @echo "Built targets: $(CI_TARGETS)"
583 @echo "Default target: $(TARGET)"
585 targets-ci-print:
586 @echo $(CI_TARGETS)
588 ## target-mcu : print the MCU type of the target
589 target-mcu:
590 @echo $(TARGET_MCU)
592 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
593 targets-by-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."; \
602 exit 1; \
603 fi; \
604 else \
605 echo -n "$${target} "; \
606 fi; \
607 fi; \
608 done
609 @echo
611 ## targets-f4 : make all F4 targets
612 targets-f4:
613 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
615 targets-f4-print:
616 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)"
618 targets-ci-f4-print:
619 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(CI_TARGETS)"
621 ## targets-f7 : make all F7 targets
622 targets-f7:
623 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
625 targets-f7-print:
626 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)"
628 targets-ci-f7-print:
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)
639 test_help:
640 $(V0) cd src/test && $(MAKE) help
642 ## test_versions : print the compiler versions used for the test suite
643 test_versions:
644 $(V0) cd src/test && $(MAKE) versions
646 ## test_% : run test 'test_%' from the test suite
647 test_%:
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)