Split initialised/non-initialised task data
[betaflight.git] / Makefile
blob868bd8dd2d60ff94d4d04236c329cb09ef46b923
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 # INFO - 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 TOOLS_DIR ?= $(ROOT)/tools
87 DL_DIR := $(ROOT)/downloads
89 export RM := rm
91 # import macros that are OS specific
92 include $(ROOT)/make/$(OSFAMILY).mk
94 # include the tools makefile
95 include $(ROOT)/make/tools.mk
97 # default xtal value for F4 targets
98 HSE_VALUE ?= 8000000
100 # used for turning on features like VCP and SDCARD
101 FEATURES =
103 # used to disable features based on flash space shortage (larger number => more features disabled)
104 FEATURE_CUT_LEVEL_SUPPLIED := $(FEATURE_CUT_LEVEL)
105 FEATURE_CUT_LEVEL =
107 # The list of targets to build for 'pre-push'
108 ifeq ($(OSFAMILY), macosx)
109 # SITL is not buildable on MacOS
110 PRE_PUSH_TARGET_LIST ?= $(UNIFIED_TARGETS) STM32F4DISCOVERY_DEBUG test-representative
111 else
112 PRE_PUSH_TARGET_LIST ?= $(UNIFIED_TARGETS) SITL STM32F4DISCOVERY_DEBUG test-representative
113 endif
115 include $(ROOT)/make/targets.mk
117 REVISION := norevision
118 ifeq ($(shell git diff --shortstat),)
119 REVISION := $(shell git log -1 --format="%h")
120 endif
122 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
123 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
124 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
126 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
128 # Search path for sources
129 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
130 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
131 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
132 FATFS_DIR = $(ROOT)/lib/main/FatFS
133 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
135 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
137 LD_FLAGS :=
138 EXTRA_LD_FLAGS :=
141 # Default Tool options - can be overridden in {mcu}.mk files.
143 ifeq ($(DEBUG),GDB)
144 OPTIMISE_DEFAULT := -Og
146 LTO_FLAGS := $(OPTIMISE_DEFAULT)
147 DEBUG_FLAGS = -ggdb3 -DDEBUG
148 else
149 ifeq ($(DEBUG),INFO)
150 DEBUG_FLAGS = -ggdb3
151 endif
152 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math -fmerge-all-constants
153 OPTIMISE_DEFAULT := -O2
154 OPTIMISE_SPEED := -Ofast
155 OPTIMISE_SIZE := -Os
157 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
158 endif
160 VPATH := $(VPATH):$(ROOT)/make/mcu
161 VPATH := $(VPATH):$(ROOT)/make
163 # start specific includes
164 include $(ROOT)/make/mcu/$(TARGET_MCU).mk
166 # openocd specific includes
167 include $(ROOT)/make/openocd.mk
169 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
170 ifeq ($(TARGET_FLASH_SIZE),)
171 ifneq ($(MCU_FLASH_SIZE),)
172 TARGET_FLASH_SIZE := $(MCU_FLASH_SIZE)
173 else
174 $(error MCU_FLASH_SIZE not configured for target $(TARGET))
175 endif
176 endif
178 DEVICE_FLAGS := $(DEVICE_FLAGS) -DTARGET_FLASH_SIZE=$(TARGET_FLASH_SIZE)
180 ifneq ($(HSE_VALUE),)
181 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
182 endif
184 ifneq ($(FEATURE_CUT_LEVEL_SUPPLIED),)
185 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL_SUPPLIED)
186 else ifneq ($(FEATURE_CUT_LEVEL),)
187 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL)
188 endif
190 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
191 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
193 ifeq ($(OPBL),yes)
194 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
195 .DEFAULT_GOAL := binary
196 else
197 .DEFAULT_GOAL := hex
198 endif
200 ifeq ($(CUSTOM_DEFAULTS_EXTENDED),yes)
201 TARGET_FLAGS += -DUSE_CUSTOM_DEFAULTS=
202 EXTRA_LD_FLAGS += -Wl,--defsym=USE_CUSTOM_DEFAULTS_EXTENDED=1
203 endif
205 INCLUDE_DIRS := $(INCLUDE_DIRS) \
206 $(ROOT)/lib/main/MAVLink
208 INCLUDE_DIRS := $(INCLUDE_DIRS) \
209 $(TARGET_DIR)
211 VPATH := $(VPATH):$(TARGET_DIR)
213 include $(ROOT)/make/source.mk
215 ###############################################################################
216 # Things that might need changing to use different tools
219 # Find out if ccache is installed on the system
220 CCACHE := ccache
221 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
222 ifneq ($(RESULT),0)
223 CCACHE :=
224 endif
226 # Tool names
227 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
228 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
229 CROSS_GDB := $(ARM_SDK_PREFIX)gdb
230 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
231 OBJDUMP := $(ARM_SDK_PREFIX)objdump
232 READELF := $(ARM_SDK_PREFIX)readelf
233 SIZE := $(ARM_SDK_PREFIX)size
234 DFUSE-PACK := src/utils/dfuse-pack.py
237 # Tool options.
239 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
240 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
241 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
242 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
243 CC_NO_OPTIMISATION :=
246 # Added after GCC version update, remove once the warnings have been fixed
248 TEMPORARY_FLAGS :=
250 CFLAGS += $(ARCH_FLAGS) \
251 $(addprefix -D,$(OPTIONS)) \
252 $(addprefix -I,$(INCLUDE_DIRS)) \
253 $(DEBUG_FLAGS) \
254 -std=gnu11 \
255 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
256 -ffunction-sections \
257 -fdata-sections \
258 -fno-common \
259 -pedantic \
260 $(TEMPORARY_FLAGS) \
261 $(DEVICE_FLAGS) \
262 -D_GNU_SOURCE \
263 -DUSE_STDPERIPH_DRIVER \
264 -D$(TARGET) \
265 $(TARGET_FLAGS) \
266 -D'__FORKNAME__="$(FORKNAME)"' \
267 -D'__TARGET__="$(TARGET)"' \
268 -D'__REVISION__="$(REVISION)"' \
269 -save-temps=obj \
270 -MMD -MP \
271 $(EXTRA_FLAGS)
273 ASFLAGS = $(ARCH_FLAGS) \
274 $(DEBUG_FLAGS) \
275 -x assembler-with-cpp \
276 $(addprefix -I,$(INCLUDE_DIRS)) \
277 -MMD -MP
279 ifeq ($(LD_FLAGS),)
280 LD_FLAGS = -lm \
281 -nostartfiles \
282 --specs=nano.specs \
283 -lc \
284 -lnosys \
285 $(ARCH_FLAGS) \
286 $(LTO_FLAGS) \
287 $(DEBUG_FLAGS) \
288 -static \
289 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
290 -Wl,-L$(LINKER_DIR) \
291 -Wl,--cref \
292 -Wl,--no-wchar-size-warning \
293 -Wl,--print-memory-usage \
294 -T$(LD_SCRIPT) \
295 $(EXTRA_LD_FLAGS)
296 endif
298 ###############################################################################
299 # No user-serviceable parts below
300 ###############################################################################
302 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
303 --std=c99 --inline-suppr --quiet --force \
304 $(addprefix -I,$(INCLUDE_DIRS)) \
305 -I/usr/include -I/usr/include/linux
308 TARGET_BASENAME = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET)_$(REVISION)
311 # Things we will build
313 TARGET_BIN = $(TARGET_BASENAME).bin
314 TARGET_HEX = $(TARGET_BASENAME).hex
315 TARGET_DFU = $(TARGET_BASENAME).dfu
316 TARGET_ZIP = $(TARGET_BASENAME).zip
317 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
318 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_EXST.elf
319 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_UNPATCHED.bin
320 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
321 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
322 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
323 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
325 TARGET_EXST_HASH_SECTION_FILE = $(OBJECT_DIR)/$(TARGET)/exst_hash_section.bin
327 CLEAN_ARTIFACTS := $(TARGET_BIN)
328 CLEAN_ARTIFACTS += $(TARGET_HEX)
329 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
330 CLEAN_ARTIFACTS += $(TARGET_LST)
331 CLEAN_ARTIFACTS += $(TARGET_DFU)
333 # Make sure build date and revision is updated on every incremental build
334 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
336 # List of buildable ELF files and their object dependencies.
337 # It would be nice to compute these lists, but that seems to be just beyond make.
339 $(TARGET_LST): $(TARGET_ELF)
340 $(V0) $(OBJDUMP) -S --disassemble $< > $@
342 ifeq ($(EXST),no)
343 $(TARGET_BIN): $(TARGET_ELF)
344 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
345 $(V1) $(OBJCOPY) -O binary $< $@
347 $(TARGET_HEX): $(TARGET_ELF)
348 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
349 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
351 $(TARGET_DFU): $(TARGET_HEX)
352 @echo "Creating DFU $(TARGET_DFU)" "$(STDOUT)"
353 $(V1) $(PYTHON) $(DFUSE-PACK) -i $< $@
355 else
356 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
358 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
359 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
360 $(V1) $(OBJCOPY) -O binary $< $@
362 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
363 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
364 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
365 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
366 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
367 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
369 @echo "Generating MD5 hash of binary" "$(STDOUT)"
370 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
372 @echo "Patching MD5 hash into binary" "$(STDOUT)"
373 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
374 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
376 # 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"
377 # Due to this a temporary file must be created and removed, even though we're only extracting data from the input file.
378 # If this temporary file is NOT used the $(TARGET_ELF) is modified, and running make a second time will result in
379 # a) regeneration of $(TARGET_BIN), and
380 # b) the results of $(TARGET_BIN) will not be as expected.
381 @echo "Extracting HASH section from unpatched EXST elf $(TARGET_ELF)" "$(STDOUT)"
382 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF).tmp --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE) -j .exst_hash
383 rm $(TARGET_EXST_ELF).tmp
385 @echo "Patching MD5 hash into HASH section" "$(STDOUT)"
386 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
388 # 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
389 # 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.
390 # The issue can be seen with `readelf -S $(TARGET_EXST_ELF)' vs `readelf -S $(TARGET_ELF)`
391 $(V1) @echo "Patching updated HASH section into $(TARGET_EXST_ELF)" "$(STDOUT)"
392 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --remove-section ._user_heap_stack --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
394 $(V1) $(READELF) -S $(TARGET_EXST_ELF)
395 $(V1) $(READELF) -l $(TARGET_EXST_ELF)
397 $(TARGET_HEX): $(TARGET_BIN)
398 $(if $(EXST_ADJUST_VMA),,$(error "EXST_ADJUST_VMA not specified"))
400 @echo "Creating EXST HEX from patched EXST BIN $(TARGET_BIN), VMA Adjust $(EXST_ADJUST_VMA)" "$(STDOUT)"
401 $(V1) $(OBJCOPY) -I binary -O ihex --adjust-vma=$(EXST_ADJUST_VMA) $(TARGET_BIN) $@
403 endif
405 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT) $(LD_SCRIPTS)
406 @echo "Linking $(TARGET)" "$(STDOUT)"
407 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
408 $(V1) $(SIZE) $(TARGET_ELF)
410 # Compile
412 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
413 define compile_file
414 echo "%% ($(1)) $<" "$(STDOUT)" && \
415 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
416 endef
418 ifeq ($(DEBUG),GDB)
419 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
420 $(V1) mkdir -p $(dir $@)
421 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
422 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
424 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
426 else
427 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
428 $(V1) mkdir -p $(dir $@)
429 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
430 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
432 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
433 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
435 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
436 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
438 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
442 endif
444 # Assemble
445 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
446 $(V1) mkdir -p $(dir $@)
447 @echo "%% $(notdir $<)" "$(STDOUT)"
448 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
450 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
451 $(V1) mkdir -p $(dir $@)
452 @echo "%% $(notdir $<)" "$(STDOUT)"
453 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
456 ## all : Build all currently built targets
457 all: $(CI_TARGETS)
459 ## all_all : Build all targets (including legacy / unsupported)
460 all_all: $(VALID_TARGETS)
462 ## unified : build all Unified Targets
463 unified: $(UNIFIED_TARGETS)
465 ## unified_zip : build all Unified Targets as zip files (for posting on GitHub)
466 unified_zip: $(addsuffix _clean,$(UNIFIED_TARGETS)) $(addsuffix _zip,$(UNIFIED_TARGETS))
468 ## legacy : Build legacy targets
469 legacy: $(LEGACY_TARGETS)
471 ## unsupported : Build unsupported targets
472 unsupported: $(UNSUPPORTED_TARGETS)
474 ## pre-push : The minimum verification that should be run before pushing, to check if CI has a chance of succeeding
475 pre-push:
476 $(MAKE) $(addsuffix _clean,$(PRE_PUSH_TARGET_LIST)) $(PRE_PUSH_TARGET_LIST) EXTRA_FLAGS=-Werror
478 ## targets-group-1 : build some targets
479 targets-group-1: $(GROUP_1_TARGETS)
481 ## targets-group-2 : build some targets
482 targets-group-2: $(GROUP_2_TARGETS)
484 ## targets-group-rest: build the rest of the targets (not listed in the other groups)
485 targets-group-rest: $(GROUP_OTHER_TARGETS)
487 $(VALID_TARGETS):
488 $(V0) @echo "Building $@" && \
489 $(MAKE) binary hex TARGET=$@ && \
490 echo "Building $@ succeeded."
492 $(NOBUILD_TARGETS):
493 $(MAKE) TARGET=$@
495 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS))
497 ## clean : clean up temporary / machine-generated files
498 clean:
499 @echo "Cleaning $(TARGET)"
500 $(V0) rm -f $(CLEAN_ARTIFACTS)
501 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
502 @echo "Cleaning $(TARGET) succeeded."
504 ## test_clean : clean up temporary / machine-generated files (tests)
505 test-%_clean:
506 $(MAKE) test_clean
508 test_clean:
509 $(V0) cd src/test && $(MAKE) clean || true
511 ## <TARGET>_clean : clean up one specific target (alias for above)
512 $(TARGETS_CLEAN):
513 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
515 ## clean_all : clean all valid targets
516 clean_all: $(TARGETS_CLEAN) test_clean
518 TARGETS_FLASH = $(addsuffix _flash,$(VALID_TARGETS))
520 ## <TARGET>_flash : build and flash a target
521 $(TARGETS_FLASH):
522 $(V0) $(MAKE) hex TARGET=$(subst _flash,,$@)
523 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
524 $(V0) $(MAKE) tty_flash TARGET=$(subst _flash,,$@)
525 else
526 $(V0) $(MAKE) dfu_flash TARGET=$(subst _flash,,$@)
527 endif
529 ## tty_flash : flash firmware (.hex) onto flight controller via a serial port
530 tty_flash:
531 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
532 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
533 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
535 ## dfu_flash : flash firmware (.bin) onto flight controller via a DFU mode
536 dfu_flash:
537 ifneq (no-port-found,$(SERIAL_DEVICE))
538 # potentially this is because the MCU already is in DFU mode, try anyway
539 $(V0) echo -n 'R' > $(SERIAL_DEVICE)
540 $(V0) sleep 1
541 endif
542 $(V0) $(MAKE) $(TARGET_DFU)
543 $(V0) dfu-util -a 0 -D $(TARGET_DFU) -s :leave
545 st-flash_$(TARGET): $(TARGET_BIN)
546 $(V0) st-flash --reset write $< 0x08000000
548 ## st-flash : flash firmware (.bin) onto flight controller
549 st-flash: st-flash_$(TARGET)
551 ifneq ($(OPENOCD_COMMAND),)
552 openocd-gdb: $(TARGET_ELF)
553 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
554 endif
556 TARGETS_ZIP = $(addsuffix _zip,$(VALID_TARGETS))
558 ## <TARGET>_zip : build target and zip it (useful for posting to GitHub)
559 $(TARGETS_ZIP):
560 $(V0) $(MAKE) hex TARGET=$(subst _zip,,$@)
561 $(V0) $(MAKE) zip TARGET=$(subst _zip,,$@)
563 zip:
564 $(V0) zip $(TARGET_ZIP) $(TARGET_HEX)
566 binary:
567 $(V0) $(MAKE) -j $(TARGET_BIN)
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 ## version : print firmware version
594 version:
595 @echo $(FC_VER)
597 ## help : print this help message and exit
598 help: Makefile make/tools.mk
599 @echo ""
600 @echo "Makefile for the $(FORKNAME) firmware"
601 @echo ""
602 @echo "Usage:"
603 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
604 @echo "Or:"
605 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
606 @echo ""
607 @echo "Valid TARGET values are: $(VALID_TARGETS)"
608 @echo ""
609 @sed -n 's/^## //p' $?
611 ## targets : print a list of all valid target platforms (for consumption by scripts)
612 targets:
613 @echo "Valid targets: $(VALID_TARGETS)"
614 @echo "Built targets: $(CI_TARGETS)"
615 @echo "Unified targets: $(UNIFIED_TARGETS)"
616 @echo "Legacy targets: $(LEGACY_TARGETS)"
617 @echo "Unsupported targets: $(UNSUPPORTED_TARGETS)"
618 @echo "Default target: $(TARGET)"
619 @echo "targets-group-1: $(GROUP_1_TARGETS)"
620 @echo "targets-group-2: $(GROUP_2_TARGETS)"
621 @echo "targets-group-rest: $(GROUP_OTHER_TARGETS)"
623 @echo "targets-group-1: $(words $(GROUP_1_TARGETS)) targets"
624 @echo "targets-group-2: $(words $(GROUP_2_TARGETS)) targets"
625 @echo "targets-group-rest: $(words $(GROUP_OTHER_TARGETS)) targets"
626 @echo "total in all groups $(words $(CI_TARGETS)) targets"
628 ## target-mcu : print the MCU type of the target
629 target-mcu:
630 @echo $(TARGET_MCU)
632 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
633 targets-by-mcu:
634 $(V1) for target in $${TARGETS}; do \
635 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
636 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
637 if [ "$${DO_BUILD}" = 1 ]; then \
638 echo "Building target $${target}..."; \
639 $(MAKE) TARGET=$${target}; \
640 if [ $$? -ne 0 ]; then \
641 echo "Building target $${target} failed, aborting."; \
642 exit 1; \
643 fi; \
644 else \
645 echo -n "$${target} "; \
646 fi; \
647 fi; \
648 done
649 @echo
651 ## targets-f3 : make all F3 targets
652 targets-f3:
653 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
655 targets-f3-print:
656 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 TARGETS="$(VALID_TARGETS)"
658 ## targets-f4 : make all F4 targets
659 targets-f4:
660 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
662 targets-f4-print:
663 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(VALID_TARGETS)"
665 targets-ci-f4-print:
666 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 TARGETS="$(CI_TARGETS)"
668 ## targets-f7 : make all F7 targets
669 targets-f7:
670 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)" DO_BUILD=1
672 targets-f7-print:
673 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(VALID_TARGETS)"
675 targets-ci-f7-print:
676 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 TARGETS="$(CI_TARGETS)"
678 ## test : run the Betaflight test suite
679 ## junittest : run the Betaflight test suite, producing Junit XML result files.
680 ## 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)
681 ## test-all: run the Betaflight test suite including all per-target expanded tests
682 test junittest test-all test-representative:
683 $(V0) cd src/test && $(MAKE) $@
685 ## test_help : print the help message for the test suite (including a list of the available tests)
686 test_help:
687 $(V0) cd src/test && $(MAKE) help
689 ## test_versions : print the compiler versions used for the test suite
690 test_versions:
691 $(V0) cd src/test && $(MAKE) versions
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)