Naming adjustment for USE_SERIAL_RX to USE_SERIALRX (#11992)
[betaflight.git] / Makefile
blob9f06bc380ecc1e22fdaba259b038db90777f65fd
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
20 BOARD ?=
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 # used to disable features based on flash space shortage (larger number => more features disabled)
101 FEATURE_CUT_LEVEL_SUPPLIED := $(FEATURE_CUT_LEVEL)
102 FEATURE_CUT_LEVEL =
104 ifneq ($(BOARD),)
105 # silently ignore if the file is not present. Allows for target defaults.
106 -include $(ROOT)/src/main/board/$(BOARD)/board.mk
107 endif
109 include $(ROOT)/make/targets.mk
111 REVISION := norevision
112 ifeq ($(shell git diff --shortstat),)
113 REVISION := $(shell git log -1 --format="%h")
114 endif
116 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
117 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
118 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
120 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
122 # Search path for sources
123 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
124 FATFS_DIR = $(ROOT)/lib/main/FatFS
125 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
127 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
129 LD_FLAGS :=
130 EXTRA_LD_FLAGS :=
133 # Default Tool options - can be overridden in {mcu}.mk files.
135 ifeq ($(DEBUG),GDB)
136 OPTIMISE_DEFAULT := -Og
138 LTO_FLAGS := $(OPTIMISE_DEFAULT)
139 DEBUG_FLAGS = -ggdb3 -gdwarf-5 -DDEBUG
140 else
141 ifeq ($(DEBUG),INFO)
142 DEBUG_FLAGS = -ggdb3
143 endif
144 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math -fmerge-all-constants
145 OPTIMISE_DEFAULT := -O2
146 OPTIMISE_SPEED := -Ofast
147 OPTIMISE_SIZE := -Os
149 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
150 endif
152 VPATH := $(VPATH):$(ROOT)/make/mcu
153 VPATH := $(VPATH):$(ROOT)/make
155 # start specific includes
156 include $(ROOT)/make/mcu/$(TARGET_MCU).mk
158 # openocd specific includes
159 include $(ROOT)/make/openocd.mk
161 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
162 ifeq ($(TARGET_FLASH_SIZE),)
163 ifneq ($(MCU_FLASH_SIZE),)
164 TARGET_FLASH_SIZE := $(MCU_FLASH_SIZE)
165 else
166 $(error MCU_FLASH_SIZE not configured for target $(TARGET))
167 endif
168 endif
170 DEVICE_FLAGS := $(DEVICE_FLAGS) -DTARGET_FLASH_SIZE=$(TARGET_FLASH_SIZE)
172 ifneq ($(HSE_VALUE),)
173 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
174 endif
176 ifneq ($(FEATURE_CUT_LEVEL_SUPPLIED),)
177 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL_SUPPLIED)
178 else ifneq ($(FEATURE_CUT_LEVEL),)
179 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL)
180 endif
182 TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
183 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
185 .DEFAULT_GOAL := hex
187 ifeq ($(CUSTOM_DEFAULTS_EXTENDED),yes)
188 TARGET_FLAGS += -DUSE_CUSTOM_DEFAULTS=
189 EXTRA_LD_FLAGS += -Wl,--defsym=USE_CUSTOM_DEFAULTS_EXTENDED=1
190 endif
192 INCLUDE_DIRS := $(INCLUDE_DIRS) \
193 $(ROOT)/lib/main/MAVLink
195 INCLUDE_DIRS := $(INCLUDE_DIRS) \
196 $(TARGET_DIR)
198 VPATH := $(VPATH):$(TARGET_DIR)
200 include $(ROOT)/make/source.mk
202 ###############################################################################
203 # Things that might need changing to use different tools
206 # Find out if ccache is installed on the system
207 CCACHE := ccache
208 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
209 ifneq ($(RESULT),0)
210 CCACHE :=
211 endif
213 # Tool names
214 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
215 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
216 CROSS_GDB := $(ARM_SDK_PREFIX)gdb
217 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
218 OBJDUMP := $(ARM_SDK_PREFIX)objdump
219 READELF := $(ARM_SDK_PREFIX)readelf
220 SIZE := $(ARM_SDK_PREFIX)size
221 DFUSE-PACK := src/utils/dfuse-pack.py
224 # Tool options.
226 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
227 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
228 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
229 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
230 CC_NO_OPTIMISATION :=
233 # Added after GCC version update, remove once the warnings have been fixed
235 TEMPORARY_FLAGS :=
237 EXTRA_WARNING_FLAGS := -Wold-style-definition
239 CFLAGS += $(ARCH_FLAGS) \
240 $(addprefix -D,$(OPTIONS)) \
241 $(addprefix -I,$(INCLUDE_DIRS)) \
242 $(DEBUG_FLAGS) \
243 -std=gnu17 \
244 -Wall -Wextra -Werror -Wpedantic -Wunsafe-loop-optimizations -Wdouble-promotion \
245 $(EXTRA_WARNING_FLAGS) \
246 -ffunction-sections \
247 -fdata-sections \
248 -fno-common \
249 $(TEMPORARY_FLAGS) \
250 $(DEVICE_FLAGS) \
251 -D_GNU_SOURCE \
252 -DUSE_STDPERIPH_DRIVER \
253 -D$(TARGET) \
254 $(TARGET_FLAGS) \
255 -D'__FORKNAME__="$(FORKNAME)"' \
256 -D'__TARGET__="$(TARGET)"' \
257 -D'__REVISION__="$(REVISION)"' \
258 -pipe \
259 -MMD -MP \
260 $(EXTRA_FLAGS)
262 ASFLAGS = $(ARCH_FLAGS) \
263 $(DEBUG_FLAGS) \
264 -x assembler-with-cpp \
265 $(addprefix -I,$(INCLUDE_DIRS)) \
266 -MMD -MP
268 ifeq ($(LD_FLAGS),)
269 LD_FLAGS = -lm \
270 -nostartfiles \
271 --specs=nano.specs \
272 -lc \
273 -lnosys \
274 $(ARCH_FLAGS) \
275 $(LTO_FLAGS) \
276 $(DEBUG_FLAGS) \
277 -static \
278 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
279 -Wl,-L$(LINKER_DIR) \
280 -Wl,--cref \
281 -Wl,--no-wchar-size-warning \
282 -Wl,--print-memory-usage \
283 -T$(LD_SCRIPT) \
284 $(EXTRA_LD_FLAGS)
285 endif
287 ###############################################################################
288 # No user-serviceable parts below
289 ###############################################################################
291 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
292 --std=c99 --inline-suppr --quiet --force \
293 $(addprefix -I,$(INCLUDE_DIRS)) \
294 -I/usr/include -I/usr/include/linux
296 TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)
299 # Things we will build
301 TARGET_BIN = $(TARGET_BASENAME).bin
302 TARGET_HEX = $(TARGET_BASENAME).hex
303 TARGET_HEX_REV = $(TARGET_BASENAME)_$(REVISION).hex
304 TARGET_DFU = $(TARGET_BASENAME).dfu
305 TARGET_ZIP = $(TARGET_BASENAME).zip
306 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
307 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_EXST.elf
308 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_UNPATCHED.bin
309 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
310 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
311 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
312 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
314 TARGET_EXST_HASH_SECTION_FILE = $(OBJECT_DIR)/$(TARGET)/exst_hash_section.bin
316 CLEAN_ARTIFACTS := $(TARGET_BIN)
317 CLEAN_ARTIFACTS += $(TARGET_HEX_REV) $(TARGET_HEX)
318 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
319 CLEAN_ARTIFACTS += $(TARGET_LST)
320 CLEAN_ARTIFACTS += $(TARGET_DFU)
322 # Make sure build date and revision is updated on every incremental build
323 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
325 # List of buildable ELF files and their object dependencies.
326 # It would be nice to compute these lists, but that seems to be just beyond make.
328 $(TARGET_LST): $(TARGET_ELF)
329 $(V0) $(OBJDUMP) -S --disassemble $< > $@
331 ifeq ($(EXST),no)
332 $(TARGET_BIN): $(TARGET_ELF)
333 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
334 $(V1) $(OBJCOPY) -O binary $< $@
336 $(TARGET_HEX): $(TARGET_ELF)
337 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
338 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
340 $(TARGET_DFU): $(TARGET_HEX)
341 @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)"
342 $(V1) $(PYTHON) $(DFUSE-PACK) -i $< $@
344 else
345 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
347 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
348 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
349 $(V1) $(OBJCOPY) -O binary $< $@
351 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
352 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
353 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
354 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
355 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
356 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
358 @echo "Generating MD5 hash of binary" "$(STDOUT)"
359 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
361 @echo "Patching MD5 hash into binary" "$(STDOUT)"
362 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
363 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
365 # 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"
366 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
367 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
368 # a) regeneration of $(TARGET_BIN), and
369 # b) the results of $(TARGET_BIN) will not be as expected.
370 @echo "Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
371 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF).tmp --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE) -j .exst_hash
372 rm $(TARGET_EXST_ELF).tmp
374 @echo "Patching MD5 hash into HASH section" "$(STDOUT)"
375 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
377 # 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
378 # 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.
379 # The issue can be seen with `readelf -S $(TARGET_EXST_ELF)' vs `readelf -S $(TARGET_ELF)`
380 $(V1) @echo "Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
381 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --remove-section ._user_heap_stack --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
383 $(V1) $(READELF) -S $(TARGET_EXST_ELF)
384 $(V1) $(READELF) -l $(TARGET_EXST_ELF)
386 $(TARGET_HEX): $(TARGET_BIN)
387 $(if $(EXST_ADJUST_VMA),,$(error "EXST_ADJUST_VMA not specified"))
389 @echo "Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
390 $(V1) $(OBJCOPY) -I binary -O ihex --adjust-vma=$(EXST_ADJUST_VMA) $(TARGET_BIN) $@
392 endif
394 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT) $(LD_SCRIPTS)
395 @echo "Linking $(TARGET)" "$(STDOUT)"
396 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
397 $(V1) $(SIZE) $(TARGET_ELF)
399 # Compile
401 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
402 define compile_file
403 echo "%% ($(1)) $<" "$(STDOUT)" && \
404 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
405 endef
407 ifeq ($(DEBUG),GDB)
408 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
409 $(V1) mkdir -p $(dir $@)
410 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
411 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
413 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
415 else
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 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
422 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
424 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
425 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
427 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
431 endif
433 # Assemble
434 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
435 $(V1) mkdir -p $(dir $@)
436 @echo "%% $(notdir $<)" "$(STDOUT)"
437 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
439 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
440 $(V1) mkdir -p $(dir $@)
441 @echo "%% $(notdir $<)" "$(STDOUT)"
442 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
445 ## all : Build all currently built targets
446 all: $(CI_TARGETS)
448 ## all_all : Build all targets (including legacy / unsupported)
449 all_all: $(VALID_TARGETS)
451 $(VALID_TARGETS):
452 $(V0) @echo "Building $@" && \
453 $(MAKE) hex TARGET=$@ && \
454 echo "Building $@ succeeded."
456 $(NOBUILD_TARGETS):
457 $(MAKE) TARGET=$@
459 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS))
461 ## clean : clean up temporary / machine-generated files
462 clean:
463 @echo "Cleaning $(TARGET)"
464 $(V0) rm -f $(CLEAN_ARTIFACTS)
465 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
466 @echo "Cleaning $(TARGET) succeeded."
468 ## test_clean : clean up temporary / machine-generated files (tests)
469 test-%_clean:
470 $(MAKE) test_clean
472 test_clean:
473 $(V0) cd src/test && $(MAKE) clean || true
475 ## <TARGET>_clean : clean up one specific target (alias for above)
476 $(TARGETS_CLEAN):
477 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
479 ## clean_all : clean all valid targets
480 clean_all: $(TARGETS_CLEAN) test_clean
482 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS))
484 ## <TARGET>_flash : build and flash a target
485 $(TARGETS_FLASH):
486 $(V0) $(MAKE) hex TARGET=$(subst _flash,,$@)
487 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
488 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
489 else
490 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
491 endif
493 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
494 tty_flash:
495 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
496 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
497 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
499 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
500 dfu_flash:
501 ifneq (no-port-found,$(SERIAL_DEVICE))
502 # potentially this is because the MCU already is in DFU mode, try anyway
503 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
504 $(V0) sleep 1
505 endif
506 $(V0) $(MAKE) $(TARGET_DFU)
507 $(V0) dfu-util -a 0 -D $(TARGET_DFU) -s :leave
509 st-flash_$(TARGET): $(TARGET_BIN)
510 $(V0) st-flash --reset write $< 0x08000000
512 ## st-flash : flash firmware (.bin) onto flight controller
513 st-flash: st-flash_$(TARGET)
515 ifneq ($(OPENOCD_COMMAND),)
516 openocd-gdb: $(TARGET_ELF)
517 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
518 endif
520 TARGETS_ZIP = $(addsuffix _zip,$(VALID_TARGETS))
522 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
523 $(TARGETS_ZIP):
524 $(V0) $(MAKE) hex TARGET=$(subst _zip,,$@)
525 $(V0) $(MAKE) zip TARGET=$(subst _zip,,$@)
527 zip:
528 $(V0) zip $(TARGET_ZIP) $(TARGET_HEX)
530 binary:
531 $(V0) $(MAKE) -j $(TARGET_BIN)
533 hex:
534 $(V0) $(MAKE) -j $(TARGET_HEX)
536 TARGETS_REVISION = $(addsuffix _rev,$(VALID_TARGETS))
537 ## <TARGET>_rev : build target and add revision to filename
538 $(TARGETS_REVISION):
539 $(V0) $(MAKE) hex_rev TARGET=$(subst _rev,,$@)
541 hex_rev: hex
542 $(V0) mv -f $(TARGET_HEX) $(TARGET_HEX_REV)
544 all_rev: $(addsuffix _rev,$(CI_TARGETS))
546 unbrick_$(TARGET): $(TARGET_HEX)
547 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
548 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
550 ## unbrick : unbrick flight controller
551 unbrick: unbrick_$(TARGET)
553 ## cppcheck : run static analysis on C source code
554 cppcheck: $(CSOURCES)
555 $(V0) $(CPPCHECK)
557 cppcheck-result.xml: $(CSOURCES)
558 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
560 # mkdirs
561 $(DL_DIR):
562 mkdir -p $@
564 $(TOOLS_DIR):
565 mkdir -p $@
567 ## version : print firmware version
568 version:
569 @echo $(FC_VER)
571 ## help : print this help message and exit
572 help: Makefile make/tools.mk
573 @echo ""
574 @echo "Makefile for the $(FORKNAME) firmware"
575 @echo ""
576 @echo "Usage:"
577 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
578 @echo "Or:"
579 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
580 @echo ""
581 @echo "Valid TARGET values are: $(VALID_TARGETS)"
582 @echo ""
583 @sed -n 's/^## //p' $?
585 ## targets : print a list of all valid target platforms (for consumption by scripts)
586 targets:
587 @echo "Valid targets: $(VALID_TARGETS)"
588 @echo "Built targets: $(CI_TARGETS)"
589 @echo "Default target: $(TARGET)"
591 targets-ci-print:
592 @echo $(CI_TARGETS)
594 ## target-mcu : print the MCU type of the target
595 target-mcu:
596 @echo $(TARGET_MCU)
598 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
599 targets-by-mcu:
600 $(V1) for target in $${TARGETS}; do \
601 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
602 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
603 if [ "$${DO_BUILD}" = 1 ]; then \
604 echo "Building target $${target}..."; \
605 $(MAKE) TARGET=$${target}; \
606 if [ $$? -ne 0 ]; then \
607 echo "Building target $${target} failed, aborting."; \
608 exit 1; \
609 fi; \
610 else \
611 echo -n "$${target} "; \
612 fi; \
613 fi; \
614 done
615 @echo
617 ## targets-f4 : make all F4 targets
618 targets-f4:
619 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
621 targets-f4-print:
622 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)"
624 targets-ci-f4-print:
625 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(CI_TARGETS)"
627 ## targets-f7 : make all F7 targets
628 targets-f7:
629 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
631 targets-f7-print:
632 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)"
634 targets-ci-f7-print:
635 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(CI_TARGETS)"
637 ## test : run the Betaflight test suite
638 ## junittest : run the Betaflight test suite, producing Junit XML result files.
639 ## 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)
640 ## test-all: run the Betaflight test suite including all per-target expanded tests
641 test junittest test-all test-representative:
642 $(V0) cd src/test && $(MAKE) $@
644 ## test_help : print the help message for the test suite (including a list of the available tests)
645 test_help:
646 $(V0) cd src/test && $(MAKE) help
648 ## test_versions : print the compiler versions used for the test suite
649 test_versions:
650 $(V0) cd src/test && $(MAKE) versions
652 ## test_% : run test 'test_%' from the test suite
653 test_%:
654 $(V0) cd src/test && $(MAKE) $@
657 # rebuild everything when makefile changes
658 $(TARGET_OBJS): Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
660 # include auto-generated dependencies
661 -include $(TARGET_DEPS)