CF/BF - First cut of Current/Voltage/Battery cleanup.
[betaflight.git] / Makefile
blob432f6533bf297dd25f550e3c1730804261a828a1
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 ?= NAZE
21 # Compile-time options
22 OPTIONS ?=
24 # compile for OpenPilot BootLoader support
25 OPBL ?= no
27 # Debugger optons, must be empty or GDB
28 DEBUG ?=
30 # Insert the debugging hardfault debugger
31 # releases should not be built with this flag as it does not disable pwm output
32 DEBUG_HARDFAULTS ?=
34 # Serial port/Device for flashing
35 SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyUSB*) no-port-found)
37 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
38 FLASH_SIZE ?=
40 ## V : Set verbosity level based on the V= parameter
41 ## V=0 Low
42 ## V=1 High
43 export AT := @
45 ifndef V
46 export V0 :=
47 export V1 := $(AT)
48 export STDOUT :=
49 else ifeq ($(V), 0)
50 export V0 := $(AT)
51 export V1 := $(AT)
52 export STDOUT:= "> /dev/null"
53 export MAKE := $(MAKE) --no-print-directory
54 else ifeq ($(V), 1)
55 export V0 :=
56 export V1 :=
57 export STDOUT :=
58 endif
60 ###############################################################################
61 # Things that need to be maintained as the source changes
64 FORKNAME = betaflight
66 # Working directories
67 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
68 SRC_DIR = $(ROOT)/src/main
69 OBJECT_DIR = $(ROOT)/obj/main
70 BIN_DIR = $(ROOT)/obj
71 CMSIS_DIR = $(ROOT)/lib/main/CMSIS
72 INCLUDE_DIRS = $(SRC_DIR) \
73 $(ROOT)/src/main/target
74 LINKER_DIR = $(ROOT)/src/main/target/link
76 # Build tools, so we all share the same versions
77 # import macros common to all supported build systems
78 include $(ROOT)/make/system-id.mk
80 # developer preferences, edit these at will, they'll be gitignored
81 -include $(ROOT)/make/local.mk
83 # configure some directories that are relative to wherever ROOT_DIR is located
84 ifndef TOOLS_DIR
85 TOOLS_DIR := $(ROOT)/tools
86 endif
87 BUILD_DIR := $(ROOT)/build
88 DL_DIR := $(ROOT)/downloads
90 export RM := rm
92 # import macros that are OS specific
93 include $(ROOT)/make/$(OSFAMILY).mk
95 # include the tools makefile
96 include $(ROOT)/make/tools.mk
98 # default xtal value for F4 targets
99 HSE_VALUE ?= 8000000
101 # used for turning on features like VCP and SDCARD
102 FEATURES =
104 OFFICIAL_TARGETS = ALIENFLIGHTF3 ALIENFLIGHTF4 ANYFCF7 BETAFLIGHTF3 BLUEJAYF4 CC3D FURYF4 NAZE REVO SIRINFPV SPARKY SPRACINGF3 SPRACINGF3EVO STM32F3DISCOVERY
105 ALT_TARGETS = $(sort $(filter-out target, $(basename $(notdir $(wildcard $(ROOT)/src/main/target/*/*.mk)))))
106 OPBL_TARGETS = $(filter %_OPBL, $(ALT_TARGETS))
108 VALID_TARGETS = $(dir $(wildcard $(ROOT)/src/main/target/*/target.mk))
109 VALID_TARGETS := $(subst /,, $(subst ./src/main/target/,, $(VALID_TARGETS)))
110 VALID_TARGETS := $(VALID_TARGETS) $(ALT_TARGETS)
111 VALID_TARGETS := $(sort $(VALID_TARGETS))
113 ifeq ($(filter $(TARGET),$(ALT_TARGETS)), $(TARGET))
114 BASE_TARGET := $(firstword $(subst /,, $(subst ./src/main/target/,, $(dir $(wildcard $(ROOT)/src/main/target/*/$(TARGET).mk)))))
115 -include $(ROOT)/src/main/target/$(BASE_TARGET)/$(TARGET).mk
116 else
117 BASE_TARGET := $(TARGET)
118 endif
120 ifeq ($(filter $(TARGET),$(OPBL_TARGETS)), $(TARGET))
121 OPBL = yes
122 endif
124 # silently ignore if the file is not present. Allows for target specific.
125 -include $(ROOT)/src/main/target/$(BASE_TARGET)/target.mk
127 F4_TARGETS = $(F405_TARGETS) $(F411_TARGETS) $(F446_TARGETS)
128 F7_TARGETS = $(F7X2RE_TARGETS) $(F7X5XE_TARGETS) $(F7X5XG_TARGETS) $(F7X5XI_TARGETS) $(F7X6XG_TARGETS)
130 ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
131 $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS). Have you prepared a valid target.mk?)
132 endif
134 ifeq ($(filter $(TARGET),$(F1_TARGETS) $(F3_TARGETS) $(F4_TARGETS) $(F7_TARGETS)),)
135 $(error Target '$(TARGET)' has not specified a valid STM group, must be one of F1, F3, F405, F411 or F7x5. Have you prepared a valid target.mk?)
136 endif
138 128K_TARGETS = $(F1_TARGETS)
139 256K_TARGETS = $(F3_TARGETS)
140 512K_TARGETS = $(F411_TARGETS) $(F446_TARGETS) $(F7X2RE_TARGETS) $(F7X5XE_TARGETS)
141 1024K_TARGETS = $(F405_TARGETS) $(F7X5XG_TARGETS) $(F7X6XG_TARGETS)
142 2048K_TARGETS = $(F7X5XI_TARGETS)
144 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
145 ifeq ($(FLASH_SIZE),)
146 ifeq ($(TARGET),$(filter $(TARGET),$(2048K_TARGETS)))
147 FLASH_SIZE = 2048
148 else ifeq ($(TARGET),$(filter $(TARGET),$(1024K_TARGETS)))
149 FLASH_SIZE = 1024
150 else ifeq ($(TARGET),$(filter $(TARGET),$(512K_TARGETS)))
151 FLASH_SIZE = 512
152 else ifeq ($(TARGET),$(filter $(TARGET),$(256K_TARGETS)))
153 FLASH_SIZE = 256
154 else ifeq ($(TARGET),$(filter $(TARGET),$(128K_TARGETS)))
155 FLASH_SIZE = 128
156 else
157 $(error FLASH_SIZE not configured for target $(TARGET))
158 endif
159 endif
161 # note that there is no hardfault debugging startup file assembly handler for other platforms
162 ifeq ($(DEBUG_HARDFAULTS),F3)
163 CFLAGS += -DDEBUG_HARDFAULTS
164 STM32F30x_COMMON_SRC = startup_stm32f3_debug_hardfault_handler.S
165 else
166 STM32F30x_COMMON_SRC = startup_stm32f30x_md_gcc.S
167 endif
169 ifeq ($(DEBUG_HARDFAULTS),F7)
170 CFLAGS += -DDEBUG_HARDFAULTS
171 endif
173 REVISION := $(shell git log -1 --format="%h")
175 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/build/version.h | awk '{print $$3}' )
176 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/build/version.h | awk '{print $$3}' )
177 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/build/version.h | awk '{print $$3}' )
179 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
181 # Search path for sources
182 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
183 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
184 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
185 FATFS_DIR = $(ROOT)/lib/main/FatFS
186 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
188 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
190 ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
191 # F3 TARGETS
193 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver
194 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
195 EXCLUDES = stm32f30x_crc.c \
196 stm32f30x_can.c
197 STARTUP_SRC = startup_stm32f30x_md_gcc.S
199 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
200 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
202 VPATH := $(VPATH):$(CMSIS_DIR)/CM1/CoreSupport:$(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
203 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM1/CoreSupport/*.c \
204 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x/*.c))
206 INCLUDE_DIRS := $(INCLUDE_DIRS) \
207 $(STDPERIPH_DIR)/inc \
208 $(CMSIS_DIR)/CM1/CoreSupport \
209 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
211 ifneq ($(filter VCP, $(FEATURES)),)
212 INCLUDE_DIRS := $(INCLUDE_DIRS) \
213 $(USBFS_DIR)/inc \
214 $(ROOT)/src/main/vcp
216 VPATH := $(VPATH):$(USBFS_DIR)/src
218 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC)\
219 $(USBPERIPH_SRC)
220 endif
222 ifneq ($(filter SDCARD, $(FEATURES)),)
223 INCLUDE_DIRS := $(INCLUDE_DIRS) \
224 $(FATFS_DIR) \
226 VPATH := $(VPATH):$(FATFS_DIR)
227 endif
229 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k.ld
231 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
232 DEVICE_FLAGS = -DSTM32F303xC -DSTM32F303
233 # End F3 targets
235 # Start F4 targets
236 else ifeq ($(TARGET),$(filter $(TARGET), $(F4_TARGETS)))
238 #STDPERIPH
239 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F4xx_StdPeriph_Driver
240 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
241 EXCLUDES = stm32f4xx_crc.c \
242 stm32f4xx_can.c \
243 stm32f4xx_fmc.c \
244 stm32f4xx_sai.c \
245 stm32f4xx_cec.c \
246 stm32f4xx_dsi.c \
247 stm32f4xx_flash_ramfunc.c \
248 stm32f4xx_fmpi2c.c \
249 stm32f4xx_lptim.c \
250 stm32f4xx_qspi.c \
251 stm32f4xx_spdifrx.c \
252 stm32f4xx_cryp.c \
253 stm32f4xx_cryp_aes.c \
254 stm32f4xx_hash_md5.c \
255 stm32f4xx_cryp_des.c \
256 stm32f4xx_rtc.c \
257 stm32f4xx_hash.c \
258 stm32f4xx_dbgmcu.c \
259 stm32f4xx_cryp_tdes.c \
260 stm32f4xx_hash_sha1.c
262 ifeq ($(TARGET),$(filter $(TARGET), $(F411_TARGETS)))
263 EXCLUDES += stm32f4xx_fsmc.c
264 endif
266 ifeq ($(TARGET),$(filter $(TARGET), $(F446_TARGETS)))
267 EXCLUDES += stm32f4xx_fsmc.c
268 endif
270 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
272 #USB
273 USBCORE_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Core
274 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/src/*.c))
275 USBOTG_DIR = $(ROOT)/lib/main/STM32_USB_OTG_Driver
276 USBOTG_SRC = $(notdir $(wildcard $(USBOTG_DIR)/src/*.c))
277 EXCLUDES = usb_bsp_template.c \
278 usb_conf_template.c \
279 usb_hcd_int.c \
280 usb_hcd.c \
281 usb_otg.c
283 USBOTG_SRC := $(filter-out ${EXCLUDES}, $(USBOTG_SRC))
284 USBCDC_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Class/cdc
285 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/src/*.c))
286 EXCLUDES = usbd_cdc_if_template.c
287 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
288 VPATH := $(VPATH):$(USBOTG_DIR)/src:$(USBCORE_DIR)/src:$(USBCDC_DIR)/src
290 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
291 $(USBOTG_SRC) \
292 $(USBCORE_SRC) \
293 $(USBCDC_SRC)
295 #CMSIS
296 VPATH := $(VPATH):$(CMSIS_DIR)/CM4/CoreSupport:$(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx
297 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM4/CoreSupport/*.c \
298 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx/*.c))
299 INCLUDE_DIRS := $(INCLUDE_DIRS) \
300 $(STDPERIPH_DIR)/inc \
301 $(USBOTG_DIR)/inc \
302 $(USBCORE_DIR)/inc \
303 $(USBCDC_DIR)/inc \
304 $(USBFS_DIR)/inc \
305 $(CMSIS_DIR)/CM4/CoreSupport \
306 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx \
307 $(ROOT)/src/main/vcpf4
309 ifneq ($(filter SDCARD,$(FEATURES)),)
310 INCLUDE_DIRS := $(INCLUDE_DIRS) \
311 $(FATFS_DIR)
312 VPATH := $(VPATH):$(FATFS_DIR)
313 endif
315 #Flags
316 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
318 ifeq ($(TARGET),$(filter $(TARGET),$(F411_TARGETS)))
319 DEVICE_FLAGS = -DSTM32F411xE
320 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411.ld
321 STARTUP_SRC = startup_stm32f411xe.s
322 else ifeq ($(TARGET),$(filter $(TARGET),$(F405_TARGETS)))
323 DEVICE_FLAGS = -DSTM32F40_41xxx
324 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405.ld
325 STARTUP_SRC = startup_stm32f40xx.s
326 else ifeq ($(TARGET),$(filter $(TARGET),$(F446_TARGETS)))
327 DEVICE_FLAGS = -DSTM32F446xx
328 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f446.ld
329 STARTUP_SRC = startup_stm32f446xx.s
330 else
331 $(error Unknown MCU for F4 target)
332 endif
333 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE)
335 # End F4 targets
337 # Start F7 targets
338 else ifeq ($(TARGET),$(filter $(TARGET), $(F7_TARGETS)))
340 #STDPERIPH
341 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F7xx_HAL_Driver
342 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/Src/*.c))
343 EXCLUDES = stm32f7xx_hal_can.c \
344 stm32f7xx_hal_cec.c \
345 stm32f7xx_hal_crc.c \
346 stm32f7xx_hal_crc_ex.c \
347 stm32f7xx_hal_cryp.c \
348 stm32f7xx_hal_cryp_ex.c \
349 stm32f7xx_hal_dac.c \
350 stm32f7xx_hal_dac_ex.c \
351 stm32f7xx_hal_dcmi.c \
352 stm32f7xx_hal_dcmi_ex.c \
353 stm32f7xx_hal_dfsdm.c \
354 stm32f7xx_hal_dma2d.c \
355 stm32f7xx_hal_dsi.c \
356 stm32f7xx_hal_eth.c \
357 stm32f7xx_hal_hash.c \
358 stm32f7xx_hal_hash_ex.c \
359 stm32f7xx_hal_hcd.c \
360 stm32f7xx_hal_i2s.c \
361 stm32f7xx_hal_irda.c \
362 stm32f7xx_hal_iwdg.c \
363 stm32f7xx_hal_jpeg.c \
364 stm32f7xx_hal_lptim.c \
365 stm32f7xx_hal_ltdc.c \
366 stm32f7xx_hal_ltdc_ex.c \
367 stm32f7xx_hal_mdios.c \
368 stm32f7xx_hal_mmc.c \
369 stm32f7xx_hal_msp_template.c \
370 stm32f7xx_hal_nand.c \
371 stm32f7xx_hal_nor.c \
372 stm32f7xx_hal_qspi.c \
373 stm32f7xx_hal_rng.c \
374 stm32f7xx_hal_rtc.c \
375 stm32f7xx_hal_rtc_ex.c \
376 stm32f7xx_hal_sai.c \
377 stm32f7xx_hal_sai_ex.c \
378 stm32f7xx_hal_sd.c \
379 stm32f7xx_hal_sdram.c \
380 stm32f7xx_hal_smartcard.c \
381 stm32f7xx_hal_smartcard_ex.c \
382 stm32f7xx_hal_smbus.c \
383 stm32f7xx_hal_spdifrx.c \
384 stm32f7xx_hal_sram.c \
385 stm32f7xx_hal_timebase_rtc_alarm_template.c \
386 stm32f7xx_hal_timebase_rtc_wakeup_template.c \
387 stm32f7xx_hal_timebase_tim_template.c \
388 stm32f7xx_hal_wwdg.c \
389 stm32f7xx_ll_adc.c \
390 stm32f7xx_ll_crc.c \
391 stm32f7xx_ll_dac.c \
392 stm32f7xx_ll_dma.c \
393 stm32f7xx_ll_dma2d.c \
394 stm32f7xx_ll_exti.c \
395 stm32f7xx_ll_fmc.c \
396 stm32f7xx_ll_gpio.c \
397 stm32f7xx_ll_i2c.c \
398 stm32f7xx_ll_lptim.c \
399 stm32f7xx_ll_pwr.c \
400 stm32f7xx_ll_rcc.c \
401 stm32f7xx_ll_rng.c \
402 stm32f7xx_ll_rtc.c \
403 stm32f7xx_ll_sdmmc.c \
404 stm32f7xx_ll_spi.c \
405 stm32f7xx_ll_tim.c \
406 stm32f7xx_ll_usart.c \
407 stm32f7xx_ll_utils.c
409 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
411 #USB
412 USBCORE_DIR = $(ROOT)/lib/main/Middlewares/ST/STM32_USB_Device_Library/Core
413 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/Src/*.c))
414 EXCLUDES = usbd_conf_template.c
415 USBCORE_SRC := $(filter-out ${EXCLUDES}, $(USBCORE_SRC))
417 USBCDC_DIR = $(ROOT)/lib/main/Middlewares/ST/STM32_USB_Device_Library/Class/CDC
418 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/Src/*.c))
419 EXCLUDES = usbd_cdc_if_template.c
420 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
422 VPATH := $(VPATH):$(USBCDC_DIR)/Src:$(USBCORE_DIR)/Src
424 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
425 $(USBCORE_SRC) \
426 $(USBCDC_SRC)
428 #CMSIS
429 VPATH := $(VPATH):$(CMSIS_DIR)/CM7/Include:$(CMSIS_DIR)/CM7/Device/ST/STM32F7xx
430 VPATH := $(VPATH):$(STDPERIPH_DIR)/Src
431 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM7/Include/*.c \
432 $(CMSIS_DIR)/CM7/Device/ST/STM32F7xx/*.c))
433 INCLUDE_DIRS := $(INCLUDE_DIRS) \
434 $(STDPERIPH_DIR)/Inc \
435 $(USBCORE_DIR)/Inc \
436 $(USBCDC_DIR)/Inc \
437 $(CMSIS_DIR)/CM7/Include \
438 $(CMSIS_DIR)/CM7/Device/ST/STM32F7xx/Include \
439 $(ROOT)/src/main/vcp_hal
441 ifneq ($(filter SDCARD,$(FEATURES)),)
442 INCLUDE_DIRS := $(INCLUDE_DIRS) \
443 $(FATFS_DIR)
444 VPATH := $(VPATH):$(FATFS_DIR)
445 endif
447 #Flags
448 ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsingle-precision-constant -Wdouble-promotion
450 ifeq ($(TARGET),$(filter $(TARGET),$(F7X5XG_TARGETS)))
451 DEVICE_FLAGS = -DSTM32F745xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
452 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f745.ld
453 STARTUP_SRC = startup_stm32f745xx.s
454 else ifeq ($(TARGET),$(filter $(TARGET),$(F7X6XG_TARGETS)))
455 DEVICE_FLAGS = -DSTM32F746xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
456 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f746.ld
457 STARTUP_SRC = startup_stm32f746xx.s
458 else ifeq ($(TARGET),$(filter $(TARGET),$(F7X2RE_TARGETS)))
459 DEVICE_FLAGS = -DSTM32F722xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
460 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f722.ld
461 STARTUP_SRC = startup_stm32f722xx.s
462 else
463 $(error Unknown MCU for F7 target)
464 endif
465 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE)
467 TARGET_FLAGS = -D$(TARGET)
469 # End F7 targets
471 # Start F1 targets
472 else
474 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
475 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
476 EXCLUDES = stm32f10x_crc.c \
477 stm32f10x_cec.c \
478 stm32f10x_can.c
479 STARTUP_SRC = startup_stm32f10x_md_gcc.S
480 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
482 # Search path and source files for the CMSIS sources
483 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
484 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
485 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
487 INCLUDE_DIRS := $(INCLUDE_DIRS) \
488 $(STDPERIPH_DIR)/inc \
489 $(CMSIS_DIR)/CM3/CoreSupport \
490 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
492 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
494 ifneq ($(filter VCP, $(FEATURES)),)
495 INCLUDE_DIRS := $(INCLUDE_DIRS) \
496 $(USBFS_DIR)/inc \
497 $(ROOT)/src/main/vcp
499 VPATH := $(VPATH):$(USBFS_DIR)/src
501 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
502 $(USBPERIPH_SRC)
504 endif
506 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
507 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
509 ifeq ($(DEVICE_FLAGS),)
510 DEVICE_FLAGS = -DSTM32F10X_MD
511 endif
512 DEVICE_FLAGS += -DSTM32F10X
514 endif
516 # End F1 targets
518 ifneq ($(BASE_TARGET), $(TARGET))
519 TARGET_FLAGS := $(TARGET_FLAGS) -D$(BASE_TARGET)
520 endif
522 ifneq ($(FLASH_SIZE),)
523 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
524 endif
526 ifneq ($(HSE_VALUE),)
527 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
528 endif
530 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
531 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
533 ifeq ($(OPBL),yes)
534 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
535 ifeq ($(TARGET), $(filter $(TARGET),$(F405_TARGETS)))
536 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405_opbl.ld
537 else ifeq ($(TARGET), $(filter $(TARGET),$(F411_TARGETS)))
538 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411_opbl.ld
539 else ifeq ($(TARGET), $(filter $(TARGET),$(F3_TARGETS)))
540 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k_opbl.ld
541 else ifeq ($(TARGET), $(filter $(TARGET),$(F1_TARGETS)))
542 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k_opbl.ld
543 endif
544 .DEFAULT_GOAL := binary
545 else
546 .DEFAULT_GOAL := hex
547 endif
549 INCLUDE_DIRS := $(INCLUDE_DIRS) \
550 $(ROOT)/lib/main/MAVLink
552 INCLUDE_DIRS := $(INCLUDE_DIRS) \
553 $(TARGET_DIR)
555 VPATH := $(VPATH):$(TARGET_DIR)
557 COMMON_SRC = \
558 build/build_config.c \
559 build/debug.c \
560 build/version.c \
561 $(TARGET_DIR_SRC) \
562 main.c \
563 common/encoding.c \
564 common/filter.c \
565 common/maths.c \
566 common/printf.c \
567 common/streambuf.c \
568 common/typeconversion.c \
569 config/config_eeprom.c \
570 config/feature.c \
571 config/parameter_group.c \
572 config/config_streamer.c \
573 drivers/adc.c \
574 drivers/buf_writer.c \
575 drivers/bus_i2c_soft.c \
576 drivers/bus_spi.c \
577 drivers/bus_spi_soft.c \
578 drivers/display.c \
579 drivers/exti.c \
580 drivers/gyro_sync.c \
581 drivers/io.c \
582 drivers/light_led.c \
583 drivers/resource.c \
584 drivers/rx_nrf24l01.c \
585 drivers/rx_spi.c \
586 drivers/rx_xn297.c \
587 drivers/pwm_esc_detect.c \
588 drivers/pwm_output.c \
589 drivers/rcc.c \
590 drivers/rx_pwm.c \
591 drivers/serial.c \
592 drivers/serial_uart.c \
593 drivers/serial_softserial.c \
594 drivers/sound_beeper.c \
595 drivers/stack_check.c \
596 drivers/system.c \
597 drivers/timer.c \
598 fc/config.c \
599 fc/controlrate_profile.c \
600 fc/fc_init.c \
601 fc/fc_dispatch.c \
602 fc/fc_hardfaults.c \
603 fc/fc_core.c \
604 fc/fc_rc.c \
605 fc/fc_msp.c \
606 fc/fc_tasks.c \
607 fc/rc_adjustments.c \
608 fc/rc_controls.c \
609 fc/runtime_config.c \
610 fc/cli.c \
611 flight/altitudehold.c \
612 flight/failsafe.c \
613 flight/imu.c \
614 flight/mixer.c \
615 flight/pid.c \
616 flight/servos.c \
617 io/beeper.c \
618 io/serial.c \
619 io/serial_4way.c \
620 io/serial_4way_avrootloader.c \
621 io/serial_4way_stk500v2.c \
622 io/statusindicator.c \
623 msp/msp_serial.c \
624 rx/ibus.c \
625 rx/jetiexbus.c \
626 rx/msp.c \
627 rx/nrf24_cx10.c \
628 rx/nrf24_inav.c \
629 rx/nrf24_h8_3d.c \
630 rx/nrf24_syma.c \
631 rx/nrf24_v202.c \
632 rx/pwm.c \
633 rx/rx.c \
634 rx/rx_spi.c \
635 rx/crsf.c \
636 rx/sbus.c \
637 rx/spektrum.c \
638 rx/sumd.c \
639 rx/sumh.c \
640 rx/xbus.c \
641 scheduler/scheduler.c \
642 sensors/acceleration.c \
643 sensors/battery.c \
644 sensors/current.c \
645 sensors/voltage.c \
646 sensors/boardalignment.c \
647 sensors/compass.c \
648 sensors/gyro.c \
649 sensors/gyroanalyse.c \
650 sensors/initialisation.c \
651 blackbox/blackbox.c \
652 blackbox/blackbox_io.c \
653 cms/cms.c \
654 cms/cms_menu_blackbox.c \
655 cms/cms_menu_builtin.c \
656 cms/cms_menu_imu.c \
657 cms/cms_menu_ledstrip.c \
658 cms/cms_menu_misc.c \
659 cms/cms_menu_osd.c \
660 cms/cms_menu_vtx.c \
661 common/colorconversion.c \
662 common/gps_conversion.c \
663 drivers/display_ug2864hsweg01.c \
664 drivers/light_ws2811strip.c \
665 drivers/serial_escserial.c \
666 drivers/sonar_hcsr04.c \
667 drivers/vtx_common.c \
668 drivers/transponder_ir.c \
669 flight/navigation.c \
670 io/dashboard.c \
671 io/displayport_max7456.c \
672 io/displayport_msp.c \
673 io/displayport_oled.c \
674 io/gps.c \
675 io/ledstrip.c \
676 io/osd.c \
677 io/transponder_ir.c \
678 sensors/sonar.c \
679 sensors/barometer.c \
680 telemetry/telemetry.c \
681 telemetry/crsf.c \
682 telemetry/srxl.c \
683 telemetry/frsky.c \
684 telemetry/hott.c \
685 telemetry/smartport.c \
686 telemetry/ltm.c \
687 telemetry/mavlink.c \
688 telemetry/ibus.c \
689 telemetry/ibus_shared.c \
690 sensors/esc_sensor.c \
691 io/vtx_string.c \
692 io/vtx_smartaudio.c \
693 io/vtx_tramp.c \
694 io/vtx.c \
695 $(CMSIS_SRC) \
696 $(DEVICE_STDPERIPH_SRC)
699 SPEED_OPTIMISED_SRC := ""
700 SIZE_OPTIMISED_SRC := ""
702 ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
703 SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
704 common/encoding.c \
705 common/filter.c \
706 common/maths.c \
707 common/typeconversion.c \
708 drivers/adc.c \
709 drivers/buf_writer.c \
710 drivers/bus_i2c_soft.c \
711 drivers/bus_spi.c \
712 drivers/bus_spi_soft.c \
713 drivers/exti.c \
714 drivers/gyro_sync.c \
715 drivers/io.c \
716 drivers/light_led.c \
717 drivers/resource.c \
718 drivers/rx_nrf24l01.c \
719 drivers/rx_spi.c \
720 drivers/rx_xn297.c \
721 drivers/pwm_output.c \
722 drivers/rcc.c \
723 drivers/rx_pwm.c \
724 drivers/serial.c \
725 drivers/serial_uart.c \
726 drivers/sound_beeper.c \
727 drivers/system.c \
728 drivers/timer.c \
729 fc/fc_core.c \
730 fc/fc_tasks.c \
731 fc/fc_rc.c \
732 fc/rc_controls.c \
733 fc/runtime_config.c \
734 flight/imu.c \
735 flight/mixer.c \
736 flight/pid.c \
737 flight/servos.c \
738 io/serial.c \
739 rx/ibus.c \
740 rx/jetiexbus.c \
741 rx/nrf24_cx10.c \
742 rx/nrf24_inav.c \
743 rx/nrf24_h8_3d.c \
744 rx/nrf24_syma.c \
745 rx/nrf24_v202.c \
746 rx/pwm.c \
747 rx/rx.c \
748 rx/rx_spi.c \
749 rx/crsf.c \
750 rx/sbus.c \
751 rx/spektrum.c \
752 rx/sumd.c \
753 rx/sumh.c \
754 rx/xbus.c \
755 scheduler/scheduler.c \
756 sensors/acceleration.c \
757 sensors/boardalignment.c \
758 sensors/gyro.c \
759 sensors/gyroanalyse.c \
760 $(CMSIS_SRC) \
761 $(DEVICE_STDPERIPH_SRC) \
762 drivers/display_ug2864hsweg01.c \
763 drivers/light_ws2811strip.c \
764 drivers/serial_softserial.c \
765 io/dashboard.c \
766 io/displayport_max7456.c \
767 io/osd.c \
769 SIZE_OPTIMISED_SRC := $(SIZE_OPTIMISED_SRC) \
770 drivers/serial_escserial.c \
771 drivers/vtx_common.c \
772 io/cli.c \
773 io/serial_4way.c \
774 io/serial_4way_avrootloader.c \
775 io/serial_4way_stk500v2.c \
776 msp/msp_serial.c \
777 cms/cms.c \
778 cms/cms_menu_blackbox.c \
779 cms/cms_menu_builtin.c \
780 cms/cms_menu_imu.c \
781 cms/cms_menu_ledstrip.c \
782 cms/cms_menu_misc.c \
783 cms/cms_menu_osd.c \
784 cms/cms_menu_vtx.c \
785 io/vtx_smartaudio.c \
786 io/vtx_tramp.c
787 endif #F3
789 ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS)))
790 VCP_SRC = \
791 vcpf4/stm32f4xx_it.c \
792 vcpf4/usb_bsp.c \
793 vcpf4/usbd_desc.c \
794 vcpf4/usbd_usr.c \
795 vcpf4/usbd_cdc_vcp.c \
796 drivers/serial_usb_vcp.c \
797 drivers/usb_io.c
798 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
799 VCP_SRC = \
800 vcp_hal/usbd_desc.c \
801 vcp_hal/usbd_conf.c \
802 vcp_hal/usbd_cdc_interface.c \
803 drivers/serial_usb_vcp.c \
804 drivers/usb_io.c
805 else
806 VCP_SRC = \
807 vcp/hw_config.c \
808 vcp/stm32_it.c \
809 vcp/usb_desc.c \
810 vcp/usb_endp.c \
811 vcp/usb_istr.c \
812 vcp/usb_prop.c \
813 vcp/usb_pwr.c \
814 drivers/serial_usb_vcp.c \
815 drivers/usb_io.c
816 endif
818 STM32F10x_COMMON_SRC = \
819 drivers/adc_stm32f10x.c \
820 drivers/bus_i2c_stm32f10x.c \
821 drivers/dma.c \
822 drivers/gpio_stm32f10x.c \
823 drivers/inverter.c \
824 drivers/light_ws2811strip_stdperiph.c \
825 drivers/serial_uart_stm32f10x.c \
826 drivers/system_stm32f10x.c \
827 drivers/timer_stm32f10x.c
829 STM32F30x_COMMON_SRC = \
830 target/system_stm32f30x.c \
831 drivers/adc_stm32f30x.c \
832 drivers/bus_i2c_stm32f30x.c \
833 drivers/dma.c \
834 drivers/gpio_stm32f30x.c \
835 drivers/light_ws2811strip_stdperiph.c \
836 drivers/pwm_output_dshot.c \
837 drivers/serial_uart_stm32f30x.c \
838 drivers/system_stm32f30x.c \
839 drivers/timer_stm32f30x.c
841 STM32F4xx_COMMON_SRC = \
842 target/system_stm32f4xx.c \
843 drivers/accgyro_mpu.c \
844 drivers/adc_stm32f4xx.c \
845 drivers/bus_i2c_stm32f10x.c \
846 drivers/dma_stm32f4xx.c \
847 drivers/gpio_stm32f4xx.c \
848 drivers/inverter.c \
849 drivers/light_ws2811strip_stdperiph.c \
850 drivers/pwm_output_dshot.c \
851 drivers/serial_uart_stm32f4xx.c \
852 drivers/system_stm32f4xx.c \
853 drivers/timer_stm32f4xx.c
855 STM32F7xx_COMMON_SRC = \
856 target/system_stm32f7xx.c \
857 drivers/accgyro_mpu.c \
858 drivers/adc_stm32f7xx.c \
859 drivers/bus_i2c_hal.c \
860 drivers/dma_stm32f7xx.c \
861 drivers/gpio_stm32f7xx.c \
862 drivers/inverter.c \
863 drivers/bus_spi_hal.c \
864 drivers/pwm_output_stm32f7xx.c \
865 drivers/timer_hal.c \
866 drivers/timer_stm32f7xx.c \
867 drivers/system_stm32f7xx.c \
868 drivers/serial_uart_stm32f7xx.c \
869 drivers/serial_uart_hal.c
871 F7EXCLUDES = drivers/bus_spi.c \
872 drivers/bus_i2c.c \
873 drivers/timer.c \
874 drivers/serial_uart.c
876 # check if target.mk supplied
877 ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS)))
878 SRC := $(STARTUP_SRC) $(STM32F4xx_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
879 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
880 SRC := $(STARTUP_SRC) $(STM32F7xx_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
881 else ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
882 SRC := $(STARTUP_SRC) $(STM32F30x_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
883 else ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
884 SRC := $(STARTUP_SRC) $(STM32F10x_COMMON_SRC) $(TARGET_SRC) $(VARIANT_SRC)
885 endif
887 ifneq ($(filter $(TARGET),$(F4_TARGETS) $(F7_TARGETS)),)
888 DSPLIB := $(ROOT)/lib/main/DSP_Lib
889 DEVICE_FLAGS += -DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1 -DUNALIGNED_SUPPORT_DISABLE
891 INCLUDE_DIRS += $(DSPLIB)/Include
893 SRC += $(DSPLIB)/Source/TransformFunctions/arm_rfft_fast_f32.c
894 SRC += $(DSPLIB)/Source/TransformFunctions/arm_cfft_f32.c
895 SRC += $(DSPLIB)/Source/TransformFunctions/arm_rfft_fast_init_f32.c
896 SRC += $(DSPLIB)/Source/TransformFunctions/arm_cfft_radix8_f32.c
897 SRC += $(DSPLIB)/Source/CommonTables/arm_common_tables.c
899 SRC += $(DSPLIB)/Source/ComplexMathFunctions/arm_cmplx_mag_f32.c
900 SRC += $(DSPLIB)/Source/StatisticsFunctions/arm_max_f32.c
902 SRC += $(wildcard $(DSPLIB)/Source/*/*.S)
903 endif
906 ifneq ($(filter ONBOARDFLASH,$(FEATURES)),)
907 SRC += \
908 drivers/flash_m25p16.c \
909 io/flashfs.c
910 endif
912 SRC += $(COMMON_SRC)
914 #excludes
915 ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
916 SRC := $(filter-out ${F7EXCLUDES}, $(SRC))
917 endif
919 ifneq ($(filter SDCARD,$(FEATURES)),)
920 SRC += \
921 drivers/sdcard.c \
922 drivers/sdcard_standard.c \
923 io/asyncfatfs/asyncfatfs.c \
924 io/asyncfatfs/fat_standard.c
925 endif
927 ifneq ($(filter VCP,$(FEATURES)),)
928 SRC += $(VCP_SRC)
929 endif
930 # end target specific make file checks
933 # Search path and source files for the ST stdperiph library
934 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
936 ###############################################################################
937 # Things that might need changing to use different tools
940 # Find out if ccache is installed on the system
941 CCACHE := ccache
942 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
943 ifneq ($(RESULT),0)
944 CCACHE :=
945 endif
947 # Tool names
948 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
949 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
950 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
951 SIZE := $(ARM_SDK_PREFIX)size
954 # Tool options.
957 ifneq ($(DEBUG),GDB)
958 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
959 OPTIMISE_SPEED := ""
960 OPTIMISE_SIZE := ""
962 ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
963 OPTIMISE_DEFAULT := -Os
965 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
967 else ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
968 OPTIMISE_DEFAULT := -O2
969 OPTIMISE_SPEED := -Ofast
970 OPTIMISE_SIZE := -Os
972 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
974 else
975 OPTIMISE_DEFAULT := -Ofast
977 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
979 endif #TARGETS
981 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
982 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
983 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
985 else #DEBUG
986 OPTIMISE_DEFAULT := -O0
988 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
990 LTO_FLAGS := $(OPTIMISE_DEFAULT)
991 endif #DEBUG
993 DEBUG_FLAGS = -ggdb3 -DDEBUG
995 CFLAGS += $(ARCH_FLAGS) \
996 $(addprefix -D,$(OPTIONS)) \
997 $(addprefix -I,$(INCLUDE_DIRS)) \
998 $(DEBUG_FLAGS) \
999 -std=gnu99 \
1000 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
1001 -ffunction-sections \
1002 -fdata-sections \
1003 -pedantic \
1004 $(DEVICE_FLAGS) \
1005 -DUSE_STDPERIPH_DRIVER \
1006 -D$(TARGET) \
1007 $(TARGET_FLAGS) \
1008 -D'__FORKNAME__="$(FORKNAME)"' \
1009 -D'__TARGET__="$(TARGET)"' \
1010 -D'__REVISION__="$(REVISION)"' \
1011 -save-temps=obj \
1012 -MMD -MP
1014 ASFLAGS = $(ARCH_FLAGS) \
1015 -x assembler-with-cpp \
1016 $(addprefix -I,$(INCLUDE_DIRS)) \
1017 -MMD -MP
1019 LDFLAGS = -lm \
1020 -nostartfiles \
1021 --specs=nano.specs \
1022 -lc \
1023 -lnosys \
1024 $(ARCH_FLAGS) \
1025 $(LTO_FLAGS) \
1026 $(DEBUG_FLAGS) \
1027 -static \
1028 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
1029 -Wl,-L$(LINKER_DIR) \
1030 -Wl,--cref \
1031 -Wl,--no-wchar-size-warning \
1032 -T$(LD_SCRIPT)
1034 ###############################################################################
1035 # No user-serviceable parts below
1036 ###############################################################################
1038 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
1039 --std=c99 --inline-suppr --quiet --force \
1040 $(addprefix -I,$(INCLUDE_DIRS)) \
1041 -I/usr/include -I/usr/include/linux
1044 # Things we will build
1046 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
1047 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
1048 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
1049 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
1050 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(SRC))))
1051 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
1054 CLEAN_ARTIFACTS := $(TARGET_BIN)
1055 CLEAN_ARTIFACTS += $(TARGET_HEX)
1056 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
1058 # Make sure build date and revision is updated on every incremental build
1059 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(SRC)
1061 # List of buildable ELF files and their object dependencies.
1062 # It would be nice to compute these lists, but that seems to be just beyond make.
1064 $(TARGET_HEX): $(TARGET_ELF)
1065 $(V0) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
1067 $(TARGET_BIN): $(TARGET_ELF)
1068 $(V0) $(OBJCOPY) -O binary $< $@
1070 $(TARGET_ELF): $(TARGET_OBJS)
1071 $(V1) echo Linking $(TARGET)
1072 $(V1) $(CROSS_CC) -o $@ $^ $(LDFLAGS)
1073 $(V0) $(SIZE) $(TARGET_ELF)
1075 # Compile
1076 ifneq ($(DEBUG),GDB)
1077 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1078 $(V1) mkdir -p $(dir $@)
1079 $(V1) $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
1080 echo "%% (speed optimised) $(notdir $<)" "$(STDOUT)" && \
1081 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SPEED_OPTIMISATION) $<, \
1082 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
1083 echo "%% (size optimised) $(notdir $<)" "$(STDOUT)" && \
1084 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SIZE_OPTIMISATION) $<, \
1085 echo "%% $(notdir $<)" "$(STDOUT)" && \
1086 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEFAULT_OPTIMISATION) $<))
1087 else
1088 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1089 $(V1) mkdir -p $(dir $@)
1090 $(V1) echo "%% $(notdir $<)" "$(STDOUT)" && \
1091 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEBUG_OPTIMISATION) $<
1092 endif
1094 # Assemble
1095 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
1096 $(V1) mkdir -p $(dir $@)
1097 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1098 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1100 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
1101 $(V1) mkdir -p $(dir $@)
1102 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1103 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1105 ## official : Build all official (travis) targets
1106 official: $(OFFICIAL_TARGETS)
1108 ## all : Build all valid targets
1109 all: $(VALID_TARGETS)
1111 $(VALID_TARGETS):
1112 $(V0) echo "" && \
1113 echo "Building $@" && \
1114 $(MAKE) binary hex TARGET=$@ && \
1115 echo "Building $@ succeeded."
1119 CLEAN_TARGETS = $(addprefix clean_,$(VALID_TARGETS) )
1120 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
1122 ## clean : clean up temporary / machine-generated files
1123 clean:
1124 $(V0) echo "Cleaning $(TARGET)"
1125 $(V0) rm -f $(CLEAN_ARTIFACTS)
1126 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
1127 $(V0) echo "Cleaning $(TARGET) succeeded."
1129 ## clean_test : clean up temporary / machine-generated files (tests)
1130 clean_test:
1131 $(V0) cd src/test && $(MAKE) clean || true
1133 ## clean_<TARGET> : clean up one specific target
1134 $(CLEAN_TARGETS) :
1135 $(V0) $(MAKE) -j TARGET=$(subst clean_,,$@) clean
1137 ## <TARGET>_clean : clean up one specific target (alias for above)
1138 $(TARGETS_CLEAN) :
1139 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
1141 ## clean_all : clean all valid targets
1142 clean_all:$(CLEAN_TARGETS)
1144 ## all_clean : clean all valid targets (alias for above)
1145 all_clean:$(TARGETS_CLEAN)
1148 flash_$(TARGET): $(TARGET_HEX)
1149 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1150 $(V0) echo -n 'R' >$(SERIAL_DEVICE)
1151 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1153 ## flash : flash firmware (.hex) onto flight controller
1154 flash: flash_$(TARGET)
1156 st-flash_$(TARGET): $(TARGET_BIN)
1157 $(V0) st-flash --reset write $< 0x08000000
1159 ## st-flash : flash firmware (.bin) onto flight controller
1160 st-flash: st-flash_$(TARGET)
1162 binary:
1163 $(V0) $(MAKE) -j $(TARGET_BIN)
1165 hex:
1166 $(V0) $(MAKE) -j $(TARGET_HEX)
1168 unbrick_$(TARGET): $(TARGET_HEX)
1169 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1170 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1172 ## unbrick : unbrick flight controller
1173 unbrick: unbrick_$(TARGET)
1175 ## cppcheck : run static analysis on C source code
1176 cppcheck: $(CSOURCES)
1177 $(V0) $(CPPCHECK)
1179 cppcheck-result.xml: $(CSOURCES)
1180 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
1182 # mkdirs
1183 $(DL_DIR):
1184 mkdir -p $@
1186 $(TOOLS_DIR):
1187 mkdir -p $@
1189 $(BUILD_DIR):
1190 mkdir -p $@
1192 ## help : print this help message and exit
1193 help: Makefile make/tools.mk
1194 $(V0) @echo ""
1195 $(V0) @echo "Makefile for the $(FORKNAME) firmware"
1196 $(V0) @echo ""
1197 $(V0) @echo "Usage:"
1198 $(V0) @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
1199 $(V0) @echo "Or:"
1200 $(V0) @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
1201 $(V0) @echo ""
1202 $(V0) @echo "Valid TARGET values are: $(VALID_TARGETS)"
1203 $(V0) @echo ""
1204 $(V0) @sed -n 's/^## //p' $?
1206 ## targets : print a list of all valid target platforms (for consumption by scripts)
1207 targets:
1208 $(V0) @echo "Valid targets: $(VALID_TARGETS)"
1209 $(V0) @echo "Target: $(TARGET)"
1210 $(V0) @echo "Base target: $(BASE_TARGET)"
1212 ## test : run the cleanflight test suite
1213 ## junittest : run the cleanflight test suite, producing Junit XML result files.
1214 test junittest:
1215 $(V0) cd src/test && $(MAKE) $@
1217 # rebuild everything when makefile changes
1218 $(TARGET_OBJS) : Makefile
1220 # include auto-generated dependencies
1221 -include $(TARGET_DEPS)