Add RacePIT mini (#8387)
[betaflight.git] / Makefile
blob6c37848f6bf169f24042571e588f4c3e2af65ba4
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 # Debugger optons:
31 # empty - ordinary build with all optimizations enabled
32 # RELWITHDEBINFO - ordinary build with debug symbols and all optimizations enabled
33 # GDB - debug build with minimum number of optimizations
34 DEBUG ?=
36 # Insert the debugging hardfault debugger
37 # releases should not be built with this flag as it does not disable pwm output
38 DEBUG_HARDFAULTS ?=
40 # Serial port/Device for flashing
41 SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyACM*) $(firstword $(wildcard /dev/ttyUSB*) no-port-found))
43 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
44 FLASH_SIZE ?=
47 ###############################################################################
48 # Things that need to be maintained as the source changes
51 FORKNAME = betaflight
53 # Working directories
54 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
55 SRC_DIR := $(ROOT)/src/main
56 OBJECT_DIR := $(ROOT)/obj/main
57 BIN_DIR := $(ROOT)/obj
58 CMSIS_DIR := $(ROOT)/lib/main/CMSIS
59 INCLUDE_DIRS := $(SRC_DIR) \
60 $(ROOT)/src/main/target \
61 $(ROOT)/src/main/startup
62 LINKER_DIR := $(ROOT)/src/link
64 ## V : Set verbosity level based on the V= parameter
65 ## V=0 Low
66 ## V=1 High
67 include $(ROOT)/make/build_verbosity.mk
69 # Build tools, so we all share the same versions
70 # import macros common to all supported build systems
71 include $(ROOT)/make/system-id.mk
73 # developer preferences, edit these at will, they'll be gitignored
74 -include $(ROOT)/make/local.mk
76 # configure some directories that are relative to wherever ROOT_DIR is located
77 ifndef TOOLS_DIR
78 TOOLS_DIR := $(ROOT)/tools
79 endif
80 BUILD_DIR := $(ROOT)/build
81 DL_DIR := $(ROOT)/downloads
83 export RM := rm
85 # import macros that are OS specific
86 include $(ROOT)/make/$(OSFAMILY).mk
88 # include the tools makefile
89 include $(ROOT)/make/tools.mk
91 # default xtal value for F4 targets
92 HSE_VALUE ?= 8000000
94 # used for turning on features like VCP and SDCARD
95 FEATURES =
97 # used to disable features based on flash space shortage (larger number => more features disabled)
98 FEATURE_CUT_LEVEL_SUPPLIED := $(FEATURE_CUT_LEVEL)
99 FEATURE_CUT_LEVEL =
101 # The list of targets to build for 'pre-push'
102 PRE_PUSH_TARGET_LIST ?= OMNIBUSF4 STM32F405 SPRACINGF7DUAL STM32F7X2 SITL test-representative
104 include $(ROOT)/make/targets.mk
106 REVISION := $(shell git log -1 --format="%h")
108 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
109 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
110 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
112 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
114 # Search path for sources
115 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
116 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
117 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
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 :=
126 # Default Tool options - can be overridden in {mcu}.mk files.
128 ifeq ($(DEBUG),GDB)
129 OPTIMISE_DEFAULT := -Og
131 LTO_FLAGS := $(OPTIMISE_DEFAULT)
132 DEBUG_FLAGS = -ggdb3 -DDEBUG
133 else
134 ifeq ($(DEBUG),INFO)
135 DEBUG_FLAGS = -ggdb3
136 endif
137 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
138 OPTIMISE_DEFAULT := -O2
139 OPTIMISE_SPEED := -Ofast
140 OPTIMISE_SIZE := -Os
142 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
143 endif
145 VPATH := $(VPATH):$(ROOT)/make/mcu
146 VPATH := $(VPATH):$(ROOT)/make
148 # start specific includes
149 include $(ROOT)/make/mcu/$(TARGET_MCU).mk
151 # openocd specific includes
152 include $(ROOT)/make/openocd.mk
154 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
155 ifeq ($(FLASH_SIZE),)
156 ifneq ($(TARGET_FLASH),)
157 FLASH_SIZE := $(TARGET_FLASH)
158 else
159 $(error FLASH_SIZE not configured for target $(TARGET))
160 endif
161 endif
163 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
165 ifneq ($(HSE_VALUE),)
166 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
167 endif
169 ifneq ($(FEATURE_CUT_LEVEL_SUPPLIED),)
170 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL_SUPPLIED)
171 else ifneq ($(FEATURE_CUT_LEVEL),)
172 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFEATURE_CUT_LEVEL=$(FEATURE_CUT_LEVEL)
173 endif
175 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
176 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
178 ifeq ($(OPBL),yes)
179 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
180 .DEFAULT_GOAL := binary
181 else
182 .DEFAULT_GOAL := hex
183 endif
185 INCLUDE_DIRS := $(INCLUDE_DIRS) \
186 $(ROOT)/lib/main/MAVLink
188 INCLUDE_DIRS := $(INCLUDE_DIRS) \
189 $(TARGET_DIR)
191 VPATH := $(VPATH):$(TARGET_DIR)
193 include $(ROOT)/make/source.mk
195 ###############################################################################
196 # Things that might need changing to use different tools
199 # Find out if ccache is installed on the system
200 CCACHE := ccache
201 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
202 ifneq ($(RESULT),0)
203 CCACHE :=
204 endif
206 # Tool names
207 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
208 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
209 CROSS_GDB := $(ARM_SDK_PREFIX)gdb
210 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
211 OBJDUMP := $(ARM_SDK_PREFIX)objdump
212 SIZE := $(ARM_SDK_PREFIX)size
215 # Tool options.
217 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
218 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
219 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
220 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
221 CC_NO_OPTIMISATION :=
223 CFLAGS += $(ARCH_FLAGS) \
224 $(addprefix -D,$(OPTIONS)) \
225 $(addprefix -I,$(INCLUDE_DIRS)) \
226 $(DEBUG_FLAGS) \
227 -std=gnu11 \
228 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
229 -ffunction-sections \
230 -fdata-sections \
231 -fno-common \
232 -pedantic \
233 $(DEVICE_FLAGS) \
234 -D_GNU_SOURCE \
235 -DUSE_STDPERIPH_DRIVER \
236 -D$(TARGET) \
237 $(TARGET_FLAGS) \
238 -D'__FORKNAME__="$(FORKNAME)"' \
239 -D'__TARGET__="$(TARGET)"' \
240 -D'__REVISION__="$(REVISION)"' \
241 -save-temps=obj \
242 -MMD -MP \
243 $(EXTRA_FLAGS)
245 ASFLAGS = $(ARCH_FLAGS) \
246 $(DEBUG_FLAGS) \
247 -x assembler-with-cpp \
248 $(addprefix -I,$(INCLUDE_DIRS)) \
249 -MMD -MP
251 ifeq ($(LD_FLAGS),)
252 LD_FLAGS = -lm \
253 -nostartfiles \
254 --specs=nano.specs \
255 -lc \
256 -lnosys \
257 $(ARCH_FLAGS) \
258 $(LTO_FLAGS) \
259 $(DEBUG_FLAGS) \
260 -static \
261 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
262 -Wl,-L$(LINKER_DIR) \
263 -Wl,--cref \
264 -Wl,--no-wchar-size-warning \
265 -Wl,--print-memory-usage \
266 -T$(LD_SCRIPT)
267 endif
269 ###############################################################################
270 # No user-serviceable parts below
271 ###############################################################################
273 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
274 --std=c99 --inline-suppr --quiet --force \
275 $(addprefix -I,$(INCLUDE_DIRS)) \
276 -I/usr/include -I/usr/include/linux
279 # Things we will build
281 TARGET_S19 = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).s19
282 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
283 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
284 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
285 TARGET_EXST_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_EXST.elf
286 TARGET_UNPATCHED_BIN = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET)_UNPATCHED.bin
287 TARGET_LST = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).lst
288 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
289 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
290 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
292 TARGET_EXST_HASH_SECTION_FILE = $(OBJECT_DIR)/$(TARGET)/exst_hash_section.bin
294 CLEAN_ARTIFACTS := $(TARGET_BIN)
295 CLEAN_ARTIFACTS += $(TARGET_HEX)
296 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
297 CLEAN_ARTIFACTS += $(TARGET_LST)
299 # Make sure build date and revision is updated on every incremental build
300 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
302 # List of buildable ELF files and their object dependencies.
303 # It would be nice to compute these lists, but that seems to be just beyond make.
305 $(TARGET_LST): $(TARGET_ELF)
306 $(V0) $(OBJDUMP) -S --disassemble $< > $@
309 $(TARGET_S19): $(TARGET_ELF)
310 @echo "Creating srec/S19 $(TARGET_S19)" "$(STDOUT)"
311 $(V1) $(OBJCOPY) --output-target=srec $(TARGET_S19)
313 ifeq ($(EXST),no)
314 $(TARGET_BIN): $(TARGET_ELF)
315 @echo "Creating BIN $(TARGET_BIN)" "$(STDOUT)"
316 $(V1) $(OBJCOPY) -O binary $< $@
318 $(TARGET_HEX): $(TARGET_ELF)
319 @echo "Creating HEX $(TARGET_HEX)" "$(STDOUT)"
320 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
322 else
323 CLEAN_ARTIFACTS += $(TARGET_UNPATCHED_BIN) $(TARGET_EXST_HASH_SECTION_FILE) $(TARGET_EXST_ELF)
325 $(TARGET_UNPATCHED_BIN): $(TARGET_ELF)
326 @echo "Creating BIN (without checksum) $(TARGET_UNPATCHED_BIN)" "$(STDOUT)"
327 $(V1) $(OBJCOPY) -O binary $< $@
329 $(TARGET_BIN): $(TARGET_UNPATCHED_BIN)
330 @echo "Creating EXST $(TARGET_BIN)" "$(STDOUT)"
331 # Linker script should allow .bin generation from a .elf which results in a file that is the same length as the FIRMWARE_SIZE.
332 # These 'dd' commands will pad a short binary to length FIRMWARE_SIZE.
333 $(V1) dd if=/dev/zero ibs=1k count=$(FIRMWARE_SIZE) of=$(TARGET_BIN)
334 $(V1) dd if=$(TARGET_UNPATCHED_BIN) of=$(TARGET_BIN) conv=notrunc
336 @echo "Generating MD5 hash of binary" "$(STDOUT)"
337 $(V1) openssl dgst -md5 $(TARGET_BIN) > $(TARGET_UNPATCHED_BIN).md5
339 @echo "Patching MD5 hash into binary" "$(STDOUT)"
340 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",(1024*$(FIRMWARE_SIZE))-16,$$2);}' | xxd -r - $(TARGET_BIN)
341 $(V1) echo $(FIRMWARE_SIZE) | awk '{printf("-s 0x%08x -l 16 -c 16 %s",(1024*$$1)-16,"$(TARGET_BIN)");}' | xargs xxd
343 @echo "Patching MD5 hash into exst elf" "$(STDOUT)"
344 $(OBJCOPY) $(TARGET_ELF) --dump-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
345 $(V1) cat $(TARGET_UNPATCHED_BIN).md5 | awk '{printf("%08x: %s",64-16,$$2);}' | xxd -r - $(TARGET_EXST_HASH_SECTION_FILE)
346 $(OBJCOPY) $(TARGET_ELF) $(TARGET_EXST_ELF) --update-section .exst_hash=$(TARGET_EXST_HASH_SECTION_FILE)
348 $(TARGET_HEX): $(TARGET_BIN)
349 @echo "Creating EXST HEX from patched EXST ELF $(TARGET_HEX)" "$(STDOUT)"
350 $(V1) $(OBJCOPY) -O ihex --set-start 0x8000000 $(TARGET_EXST_ELF) $@
352 endif
354 $(TARGET_ELF): $(TARGET_OBJS) $(LD_SCRIPT)
355 @echo "Linking $(TARGET)" "$(STDOUT)"
356 $(V1) $(CROSS_CC) -o $@ $(filter-out %.ld,$^) $(LD_FLAGS)
357 $(V1) $(SIZE) $(TARGET_ELF)
359 # Compile
361 ## compile_file takes two arguments: (1) optimisation description string and (2) optimisation compiler flag
362 define compile_file
363 echo "%% ($(1)) $<" "$(STDOUT)" && \
364 $(CROSS_CC) -c -o $@ $(CFLAGS) $(2) $<
365 endef
367 ifeq ($(DEBUG),GDB)
368 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
369 $(V1) mkdir -p $(dir $@)
370 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
371 $(call compile_file,not optimised, $(CC_NO_OPTIMISATION)) \
373 $(call compile_file,debug,$(CC_DEBUG_OPTIMISATION)) \
375 else
376 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
377 $(V1) mkdir -p $(dir $@)
378 $(V1) $(if $(findstring $<,$(NOT_OPTIMISED_SRC)), \
379 $(call compile_file,not optimised,$(CC_NO_OPTIMISATION)) \
381 $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
382 $(call compile_file,speed optimised,$(CC_SPEED_OPTIMISATION)) \
384 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
385 $(call compile_file,size optimised,$(CC_SIZE_OPTIMISATION)) \
387 $(call compile_file,optimised,$(CC_DEFAULT_OPTIMISATION)) \
391 endif
393 # Assemble
394 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
395 $(V1) mkdir -p $(dir $@)
396 @echo "%% $(notdir $<)" "$(STDOUT)"
397 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
399 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
400 $(V1) mkdir -p $(dir $@)
401 @echo "%% $(notdir $<)" "$(STDOUT)"
402 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
405 ## all : Build all targets (excluding unsupported)
406 all: $(SUPPORTED_TARGETS)
408 ## all_with_unsupported : Build all targets (including unsupported)
409 all_with_unsupported: $(VALID_TARGETS)
411 ## unsupported : Build unsupported targets
412 unsupported: $(UNSUPPORTED_TARGETS)
414 ## pre-push : The minimum verification that should be run before pushing, to check if CI has a chance of succeeding
415 pre-push:
416 $(MAKE) $(addprefix clean_,$(PRE_PUSH_TARGET_LIST)) $(PRE_PUSH_TARGET_LIST) EXTRA_FLAGS=-Werror
418 ## official : Build all official (travis) targets
419 official: $(OFFICIAL_TARGETS)
421 ## targets-group-1 : build some targets
422 targets-group-1: $(GROUP_1_TARGETS)
424 ## targets-group-2 : build some targets
425 targets-group-2: $(GROUP_2_TARGETS)
427 ## targets-group-3 : build some targets
428 targets-group-3: $(GROUP_3_TARGETS)
430 ## targets-group-3 : build some targets
431 targets-group-4: $(GROUP_4_TARGETS)
433 ## targets-group-rest: build the rest of the targets (not listed in group 1, 2 or 3)
434 targets-group-rest: $(GROUP_OTHER_TARGETS)
436 $(VALID_TARGETS):
437 $(V0) @echo "Building $@" && \
438 $(MAKE) binary hex TARGET=$@ && \
439 echo "Building $@ succeeded."
441 $(NOBUILD_TARGETS):
442 $(MAKE) TARGET=$@
444 CLEAN_TARGETS = $(addprefix clean_,$(VALID_TARGETS) )
445 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
447 ## clean : clean up temporary / machine-generated files
448 clean:
449 @echo "Cleaning $(TARGET)"
450 $(V0) rm -f $(CLEAN_ARTIFACTS)
451 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
452 @echo "Cleaning $(TARGET) succeeded."
454 ## clean_test : clean up temporary / machine-generated files (tests)
455 clean_test-%:
456 $(MAKE) clean_test
458 clean_test:
459 $(V0) cd src/test && $(MAKE) clean || true
461 ## clean_<TARGET> : clean up one specific target
462 $(CLEAN_TARGETS):
463 $(V0) $(MAKE) -j TARGET=$(subst clean_,,$@) clean
465 ## <TARGET>_clean : clean up one specific target (alias for above)
466 $(TARGETS_CLEAN):
467 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
469 ## clean_all : clean all valid targets
470 clean_all: $(CLEAN_TARGETS)
472 ## all_clean : clean all valid targets (alias for above)
473 all_clean: $(TARGETS_CLEAN)
475 FLASH_TARGETS = $(addprefix flash_,$(VALID_TARGETS) )
477 ## flash_<TARGET> : build and flash a target
478 $(FLASH_TARGETS):
479 ifneq (,$(findstring /dev/ttyUSB,$(SERIAL_DEVICE)))
480 $(V0) $(MAKE) -j hex TARGET=$(subst flash_,,$@)
481 $(V0) $(MAKE) tty_flash TARGET=$(subst flash_,,$@)
482 else
483 $(V0) $(MAKE) -j binary TARGET=$(subst flash_,,$@)
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) dfu-util -a 0 -D $(TARGET_BIN) -s 0x08000000:leave
502 st-flash_$(TARGET): $(TARGET_BIN)
503 $(V0) st-flash --reset write $< 0x08000000
505 ## st-flash : flash firmware (.bin) onto flight controller
506 st-flash: st-flash_$(TARGET)
508 ifneq ($(OPENOCD_COMMAND),)
509 openocd-gdb: $(TARGET_ELF)
510 $(V0) $(OPENOCD_COMMAND) & $(CROSS_GDB) $(TARGET_ELF) -ex "target remote localhost:3333" -ex "load"
511 endif
513 binary:
514 $(V0) $(MAKE) -j $(TARGET_BIN)
516 srec:
517 $(V0) $(MAKE) -j $(TARGET_S19)
519 hex:
520 $(V0) $(MAKE) -j $(TARGET_HEX)
522 unbrick_$(TARGET): $(TARGET_HEX)
523 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
524 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
526 ## unbrick : unbrick flight controller
527 unbrick: unbrick_$(TARGET)
529 ## cppcheck : run static analysis on C source code
530 cppcheck: $(CSOURCES)
531 $(V0) $(CPPCHECK)
533 cppcheck-result.xml: $(CSOURCES)
534 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
536 # mkdirs
537 $(DL_DIR):
538 mkdir -p $@
540 $(TOOLS_DIR):
541 mkdir -p $@
543 $(BUILD_DIR):
544 mkdir -p $@
546 ## version : print firmware version
547 version:
548 @echo $(FC_VER)
550 ## help : print this help message and exit
551 help: Makefile make/tools.mk
552 @echo ""
553 @echo "Makefile for the $(FORKNAME) firmware"
554 @echo ""
555 @echo "Usage:"
556 @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
557 @echo "Or:"
558 @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
559 @echo ""
560 @echo "Valid TARGET values are: $(VALID_TARGETS)"
561 @echo ""
562 @sed -n 's/^## //p' $?
564 ## targets : print a list of all valid target platforms (for consumption by scripts)
565 targets:
566 @echo "Valid targets: $(VALID_TARGETS)"
567 @echo "Supported targets: $(SUPPORTED_TARGETS)"
568 @echo "Unsupported targets: $(UNSUPPORTED_TARGETS)"
569 @echo "Target: $(TARGET)"
570 @echo "Base target: $(BASE_TARGET)"
571 @echo "targets-group-1: $(GROUP_1_TARGETS)"
572 @echo "targets-group-2: $(GROUP_2_TARGETS)"
573 @echo "targets-group-3: $(GROUP_3_TARGETS)"
574 @echo "targets-group-4: $(GROUP_4_TARGETS)"
575 @echo "targets-group-rest: $(GROUP_OTHER_TARGETS)"
577 @echo "targets-group-1: $(words $(GROUP_1_TARGETS)) targets"
578 @echo "targets-group-2: $(words $(GROUP_2_TARGETS)) targets"
579 @echo "targets-group-3: $(words $(GROUP_3_TARGETS)) targets"
580 @echo "targets-group-4: $(words $(GROUP_4_TARGETS)) targets"
581 @echo "targets-group-rest: $(words $(GROUP_OTHER_TARGETS)) targets"
582 @echo "total in all groups $(words $(SUPPORTED_TARGETS)) targets"
584 ## target-mcu : print the MCU type of the target
585 target-mcu:
586 @echo $(TARGET_MCU)
588 ## targets-by-mcu : make all targets that have a MCU_TYPE mcu
589 targets-by-mcu:
590 $(V1) for target in $(VALID_TARGETS); do \
591 TARGET_MCU_TYPE=$$($(MAKE) -s TARGET=$${target} target-mcu); \
592 if [ "$${TARGET_MCU_TYPE}" = "$${MCU_TYPE}" ]; then \
593 if [ "$${DO_BUILD}" = 1 ]; then \
594 echo "Building target $${target}..."; \
595 $(MAKE) TARGET=$${target}; \
596 if [ $$? -ne 0 ]; then \
597 echo "Building target $${target} failed, aborting."; \
598 exit 1; \
599 fi; \
600 else \
601 echo -n "$${target} "; \
602 fi; \
603 fi; \
604 done
605 @echo
607 ## targets-f3 : make all F3 targets
608 targets-f3:
609 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3 DO_BUILD=1
611 targets-f3-print:
612 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F3
614 ## targets-f4 : make all F4 targets
615 targets-f4:
616 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4 DO_BUILD=1
618 targets-f4-print:
619 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F4
621 ## targets-f7 : make all F7 targets
622 targets-f7:
623 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7 DO_BUILD=1
625 targets-f7-print:
626 $(V1) $(MAKE) -s targets-by-mcu MCU_TYPE=STM32F7
628 ## test : run the Betaflight test suite
629 ## junittest : run the Betaflight test suite, producing Junit XML result files.
630 ## 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)
631 ## test-all: run the Betaflight test suite including all per-target expanded tests
632 test junittest test-all test-representative:
633 $(V0) cd src/test && $(MAKE) $@
635 ## test_help : print the help message for the test suite (including a list of the available tests)
636 test_help:
637 $(V0) cd src/test && $(MAKE) help
639 ## test_% : run test 'test_%' from the test suite
640 test_%:
641 $(V0) cd src/test && $(MAKE) $@
644 check-target-independence:
645 $(V1) for test_target in $(VALID_TARGETS); do \
646 FOUND=$$(grep -rE "\W$${test_target}(\W.*)?$$" src/main | grep -vE "(//)|(/\*).*\W$${test_target}(\W.*)?$$" | grep -vE "^src/main/target"); \
647 if [ "$${FOUND}" != "" ]; then \
648 echo "Target dependencies for target '$${test_target}' found:"; \
649 echo "$${FOUND}"; \
650 exit 1; \
651 fi; \
652 done
654 check-fastram-usage-correctness:
655 $(V1) NON_TRIVIALLY_INITIALIZED=$$(grep -Ern "\W?FAST_RAM_ZERO_INIT\W.*=.*" src/main/ | grep -Ev "=\s*(false|NULL|0(\.0*f?)?)\s*[,;]"); \
656 if [ "$${NON_TRIVIALLY_INITIALIZED}" != "" ]; then \
657 echo "Non-trivially initialized FAST_RAM_ZERO_INIT variables found, use FAST_RAM instead:"; \
658 echo "$${NON_TRIVIALLY_INITIALIZED}"; \
659 exit 1; \
660 fi; \
661 TRIVIALLY_INITIALIZED=$$(grep -Ern "\W?FAST_RAM\W.*;" src/main/ | grep -v "="); \
662 EXPLICITLY_TRIVIALLY_INITIALIZED=$$(grep -Ern "\W?FAST_RAM\W.*;" src/main/ | grep -E "=\s*(false|NULL|0(\.0*f?)?)\s*[,;]"); \
663 if [ "$${TRIVIALLY_INITIALIZED}$${EXPLICITLY_TRIVIALLY_INITIALIZED}" != "" ]; then \
664 echo "Trivially initialized FAST_RAM variables found, use FAST_RAM_ZERO_INIT instead to save FLASH:"; \
665 echo "$${TRIVIALLY_INITIALIZED}\n$${EXPLICITLY_TRIVIALLY_INITIALIZED}"; \
666 exit 1; \
669 check-platform-included:
670 $(V1) PLATFORM_NOT_INCLUDED=$$(find src/main -type d -name target -prune -o -type f -name \*.c -exec grep -L "^#include \"platform.h\"" {} \;); \
671 if [ "$$(echo $${PLATFORM_NOT_INCLUDED} | grep -v -e '^$$' | wc -l)" -ne 0 ]; then \
672 echo "The following compilation units do not include the required target specific configuration provided by 'platform.h':"; \
673 echo "$${PLATFORM_NOT_INCLUDED}"; \
674 exit 1; \
677 # rebuild everything when makefile changes
678 $(TARGET_OBJS): Makefile $(TARGET_DIR)/target.mk $(wildcard make/*)
681 # include auto-generated dependencies
682 -include $(TARGET_DEPS)