Register changes fired by modified EOL code for html files
[betaflight.git] / Makefile
blob1547cec74d21d05ac234febecd38b703bfad0421
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 ?= OMNIBUSF4
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 SITL test-representative
113 include $(ROOT)/make/targets.mk
115 REVISION := $(shell git log -1 --format="%h")
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 ($(FLASH_SIZE),)
166 ifneq ($(TARGET_FLASH),)
167 FLASH_SIZE := $(TARGET_FLASH)
168 else
169 $(error FLASH_SIZE not configured for target $(TARGET))
170 endif
171 endif
173 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(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
230 # Tool options.
232 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
233 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
234 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
235 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
236 CC_NO_OPTIMISATION :=
238 CFLAGS += $(ARCH_FLAGS) \
239 $(addprefix -D,$(OPTIONS)) \
240 $(addprefix -I,$(INCLUDE_DIRS)) \
241 $(DEBUG_FLAGS) \
242 -std=gnu11 \
243 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
244 -ffunction-sections \
245 -fdata-sections \
246 -fno-common \
247 -pedantic \
248 $(DEVICE_FLAGS) \
249 -D_GNU_SOURCE \
250 -DUSE_STDPERIPH_DRIVER \
251 -D$(TARGET) \
252 $(TARGET_FLAGS) \
253 -D'__FORKNAME__="$(FORKNAME)"' \
254 -D'__TARGET__="$(TARGET)"' \
255 -D'__REVISION__="$(REVISION)"' \
256 -save-temps=obj \
257 -MMD -MP \
258 $(EXTRA_FLAGS)
260 ASFLAGS = $(ARCH_FLAGS) \
261 $(DEBUG_FLAGS) \
262 -x assembler-with-cpp \
263 $(addprefix -I,$(INCLUDE_DIRS)) \
264 -MMD -MP
266 ifeq ($(LD_FLAGS),)
267 LD_FLAGS = -lm \
268 -nostartfiles \
269 --specs=nano.specs \
270 -lc \
271 -lnosys \
272 $(ARCH_FLAGS) \
273 $(LTO_FLAGS) \
274 $(DEBUG_FLAGS) \
275 -static \
276 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
277 -Wl,-L$(LINKER_DIR) \
278 -Wl,--cref \
279 -Wl,--no-wchar-size-warning \
280 -Wl,--print-memory-usage \
281 -T$(LD_SCRIPT) \
282 $(EXTRA_LD_FLAGS)
283 endif
285 ###############################################################################
286 # No user-serviceable parts below
287 ###############################################################################
289 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
290 --std=c99 --inline-suppr --quiet --force \
291 $(addprefix -I,$(INCLUDE_DIRS)) \
292 -I/usr/include -I/usr/include/linux
295 # Things we will build
297 TARGET_S19 = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).s19
298 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
299 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
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)
312 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
313 CLEAN_ARTIFACTS += $(TARGET_LST)
315 # Make sure build date and revision is updated on every incremental build
316 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
318 # List of buildable ELF files and their object dependencies.
319 # It would be nice to compute these lists, but that seems to be just beyond make.
321 $(TARGET_LST): $(TARGET_ELF)
322 $(V0) $(OBJDUMP) -S --disassemble $< > $@
325 $(TARGET_S19): $(TARGET_ELF)
326 @echo "Creating srec/S19 $(TARGET_S19)" "$(STDOUT)"
327 $(V1) $(OBJCOPY) --output-target=srec $(TARGET_S19)
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 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)
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 @echo "Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
372 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
374 $(TARGET_HEX): $(TARGET_BIN)
375 $(if $(EXST_ADJUST_VMA),,$(error "EXST_ADJUST_VMA not specified"))
377 @echo "Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
378 $(V1) $(OBJCOPY) -I binary -O ihex --adjust-vma=$(EXST_ADJUST_VMA) $(TARGET_BIN) $@
380 endif
382 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT)
383 @echo "Linking $(TARGET)" "$(STDOUT)"
384 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
385 $(V1) $(SIZE) $(TARGET_ELF)
387 # Compile
389 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
390 define compile_file
391 echo "%% ($(1)) $<" "$(STDOUT)" && \
392 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
393 endef
395 ifeq ($(DEBUG),GDB)
396 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
397 $(V1) mkdir -p $(dir $@)
398 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
399 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
401 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
403 else
404 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
405 $(V1) mkdir -p $(dir $@)
406 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
407 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
409 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
410 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
412 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
413 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
415 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
419 endif
421 # Assemble
422 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
423 $(V1) mkdir -p $(dir $@)
424 @echo "%% $(notdir $<)" "$(STDOUT)"
425 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
427 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
428 $(V1) mkdir -p $(dir $@)
429 @echo "%% $(notdir $<)" "$(STDOUT)"
430 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
433 ## all : Build all targets (excluding unsupported)
434 all: $(SUPPORTED_TARGETS)
436 ## all_with_unsupported : Build all targets (including unsupported)
437 all_with_unsupported: $(VALID_TARGETS)
439 ## unsupported : Build unsupported targets
440 unsupported: $(UNSUPPORTED_TARGETS)
442 ## pre-push : The minimum verification that should be run before pushing, to check if CI has a chance of succeeding
443 pre-push:
444 $(MAKE) $(addsuffix _clean,$(PRE_PUSH_TARGET_LIST)) $(PRE_PUSH_TARGET_LIST) EXTRA_FLAGS=-Werror
446 ## official : Build all official (travis) targets
447 official: $(OFFICIAL_TARGETS)
449 ## targets-group-1 : build some targets
450 targets-group-1: $(GROUP_1_TARGETS)
452 ## targets-group-2 : build some targets
453 targets-group-2: $(GROUP_2_TARGETS)
455 ## targets-group-3 : build some targets
456 targets-group-3: $(GROUP_3_TARGETS)
458 ## targets-group-3 : build some targets
459 targets-group-4: $(GROUP_4_TARGETS)
461 ## targets-group-rest: build the rest of the targets (not listed in group 1, 2 or 3)
462 targets-group-rest: $(GROUP_OTHER_TARGETS)
464 $(VALID_TARGETS):
465 $(V0) @echo "Building $@" && \
466 $(MAKE) binary hex TARGET=$@ && \
467 echo "Building $@ succeeded."
469 $(NOBUILD_TARGETS):
470 $(MAKE) TARGET=$@
472 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
474 ## clean : clean up temporary / machine-generated files
475 clean:
476 @echo "Cleaning $(TARGET)"
477 $(V0) rm -f $(CLEAN_ARTIFACTS)
478 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
479 @echo "Cleaning $(TARGET) succeeded."
481 ## test_clean : clean up temporary / machine-generated files (tests)
482 test-%_clean:
483 $(MAKE) test_clean
485 test_clean:
486 $(V0) cd src/test && $(MAKE) clean || true
488 ## <TARGET>_clean : clean up one specific target (alias for above)
489 $(TARGETS_CLEAN):
490 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
492 ## clean_all : clean all valid targets
493 clean_all: $(TARGETS_CLEAN) test_clean
495 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS) )
497 ## <TARGET>_flash : build and flash a target
498 $(TARGETS_FLASH):
499 $(V0) $(MAKE) binary hex TARGET=$(subst _flash,,$@)
500 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
501 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
502 else
503 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
504 endif
506 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
507 tty_flash:
508 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
509 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
510 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
512 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
513 dfu_flash:
514 ifneq (no-port-found,$(SERIAL_DEVICE))
515 # potentially this is because the MCU already is in DFU mode, try anyway
516 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
517 $(V0) sleep 1
518 endif
519 $(V0) dfu-util -a 0 -D $(TARGET_BIN) -s 0x08000000:leave
521 st-flash_$(TARGET): $(TARGET_BIN)
522 $(V0) st-flash --reset write $< 0x08000000
524 ## st-flash : flash firmware (.bin) onto flight controller
525 st-flash: st-flash_$(TARGET)
527 ifneq ($(OPENOCD_COMMAND),)
528 openocd-gdb: $(TARGET_ELF)
529 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
530 endif
532 binary:
533 $(V0) $(MAKE) -j $(TARGET_BIN)
535 srec:
536 $(V0) $(MAKE) -j $(TARGET_S19)
538 hex:
539 $(V0) $(MAKE) -j $(TARGET_HEX)
541 unbrick_$(TARGET): $(TARGET_HEX)
542 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
543 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
545 ## unbrick : unbrick flight controller
546 unbrick: unbrick_$(TARGET)
548 ## cppcheck : run static analysis on C source code
549 cppcheck: $(CSOURCES)
550 $(V0) $(CPPCHECK)
552 cppcheck-result.xml: $(CSOURCES)
553 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
555 # mkdirs
556 $(DL_DIR):
557 mkdir -p $@
559 $(TOOLS_DIR):
560 mkdir -p $@
562 $(BUILD_DIR):
563 mkdir -p $@
565 ## version : print firmware version
566 version:
567 @echo $(FC_VER)
569 ## help : print this help message and exit
570 help: Makefile make/tools.mk
571 @echo ""
572 @echo "Makefile for the $(FORKNAME) firmware"
573 @echo ""
574 @echo "Usage:"
575 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
576 @echo "Or:"
577 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
578 @echo ""
579 @echo "Valid TARGET values are: $(VALID_TARGETS)"
580 @echo ""
581 @sed -n 's/^## //p' $?
583 ## targets : print a list of all valid target platforms (for consumption by scripts)
584 targets:
585 @echo "Valid targets: $(VALID_TARGETS)"
586 @echo "Supported targets: $(SUPPORTED_TARGETS)"
587 @echo "Unsupported targets: $(UNSUPPORTED_TARGETS)"
588 @echo "Target: $(TARGET)"
589 @echo "Base target: $(BASE_TARGET)"
590 @echo "targets-group-1: $(GROUP_1_TARGETS)"
591 @echo "targets-group-2: $(GROUP_2_TARGETS)"
592 @echo "targets-group-3: $(GROUP_3_TARGETS)"
593 @echo "targets-group-4: $(GROUP_4_TARGETS)"
594 @echo "targets-group-rest: $(GROUP_OTHER_TARGETS)"
596 @echo "targets-group-1: $(words $(GROUP_1_TARGETS)) targets"
597 @echo "targets-group-2: $(words $(GROUP_2_TARGETS)) targets"
598 @echo "targets-group-3: $(words $(GROUP_3_TARGETS)) targets"
599 @echo "targets-group-4: $(words $(GROUP_4_TARGETS)) targets"
600 @echo "targets-group-rest: $(words $(GROUP_OTHER_TARGETS)) targets"
601 @echo "total in all groups $(words $(SUPPORTED_TARGETS)) targets"
603 ## target-mcu : print the MCU type of the target
604 target-mcu:
605 @echo $(TARGET_MCU)
607 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
608 targets-by-mcu:
609 $(V1) for target in $(VALID_TARGETS); do \
610 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
611 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
612 if [ "$${DO_BUILD}" = 1 ]; then \
613 echo "Building target $${target}..."; \
614 $(MAKE) TARGET=$${target}; \
615 if [ $$? -ne 0 ]; then \
616 echo "Building target $${target} failed, aborting."; \
617 exit 1; \
618 fi; \
619 else \
620 echo -n "$${target} "; \
621 fi; \
622 fi; \
623 done
624 @echo
626 ## targets-f3 : make all F3 targets
627 targets-f3:
628 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 DO_BUILD=1
630 targets-f3-print:
631 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3
633 ## targets-f4 : make all F4 targets
634 targets-f4:
635 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 DO_BUILD=1
637 targets-f4-print:
638 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4
640 ## targets-f7 : make all F7 targets
641 targets-f7:
642 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 DO_BUILD=1
644 targets-f7-print:
645 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7
647 ## test : run the Betaflight test suite
648 ## junittest : run the Betaflight test suite, producing Junit XML result files.
649 ## 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)
650 ## test-all: run the Betaflight test suite including all per-target expanded tests
651 test junittest test-all test-representative:
652 $(V0) cd src/test && $(MAKE) $@
654 ## test_help : print the help message for the test suite (including a list of the available tests)
655 test_help:
656 $(V0) cd src/test && $(MAKE) help
658 ## test_% : run test 'test_%' from the test suite
659 test_%:
660 $(V0) cd src/test && $(MAKE) $@
663 # rebuild everything when makefile changes
664 $(TARGET_OBJS): Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
666 # include auto-generated dependencies
667 -include $(TARGET_DEPS)