Scale down dtermSetpointWeight
[betaflight.git] / Makefile
blobaabdf94544bdb5858483e8c6f6e034ba130cca9c
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 SAMPLE_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)
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) $(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 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
268 #USB
269 USBCORE_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Core
270 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/src/*.c))
271 USBOTG_DIR = $(ROOT)/lib/main/STM32_USB_OTG_Driver
272 USBOTG_SRC = $(notdir $(wildcard $(USBOTG_DIR)/src/*.c))
273 EXCLUDES = usb_bsp_template.c \
274 usb_conf_template.c \
275 usb_hcd_int.c \
276 usb_hcd.c \
277 usb_otg.c
279 USBOTG_SRC := $(filter-out ${EXCLUDES}, $(USBOTG_SRC))
280 USBCDC_DIR = $(ROOT)/lib/main/STM32_USB_Device_Library/Class/cdc
281 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/src/*.c))
282 EXCLUDES = usbd_cdc_if_template.c
283 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
284 VPATH := $(VPATH):$(USBOTG_DIR)/src:$(USBCORE_DIR)/src:$(USBCDC_DIR)/src
286 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
287 $(USBOTG_SRC) \
288 $(USBCORE_SRC) \
289 $(USBCDC_SRC)
291 #CMSIS
292 VPATH := $(VPATH):$(CMSIS_DIR)/CM4/CoreSupport:$(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx
293 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM4/CoreSupport/*.c \
294 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx/*.c))
295 INCLUDE_DIRS := $(INCLUDE_DIRS) \
296 $(STDPERIPH_DIR)/inc \
297 $(USBOTG_DIR)/inc \
298 $(USBCORE_DIR)/inc \
299 $(USBCDC_DIR)/inc \
300 $(USBFS_DIR)/inc \
301 $(CMSIS_DIR)/CM4/CoreSupport \
302 $(CMSIS_DIR)/CM4/DeviceSupport/ST/STM32F4xx \
303 $(ROOT)/src/main/vcpf4
305 ifneq ($(filter SDCARD,$(FEATURES)),)
306 INCLUDE_DIRS := $(INCLUDE_DIRS) \
307 $(FATFS_DIR)
308 VPATH := $(VPATH):$(FATFS_DIR)
309 endif
311 #Flags
312 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
314 ifeq ($(TARGET),$(filter $(TARGET),$(F411_TARGETS)))
315 DEVICE_FLAGS = -DSTM32F411xE
316 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411.ld
317 STARTUP_SRC = startup_stm32f411xe.s
318 else ifeq ($(TARGET),$(filter $(TARGET),$(F405_TARGETS)))
319 DEVICE_FLAGS = -DSTM32F40_41xxx
320 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405.ld
321 STARTUP_SRC = startup_stm32f40xx.s
322 else
323 $(error Unknown MCU for F4 target)
324 endif
325 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE)
327 # End F4 targets
329 # Start F7 targets
330 else ifeq ($(TARGET),$(filter $(TARGET), $(F7_TARGETS)))
332 #STDPERIPH
333 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F7xx_HAL_Driver
334 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/Src/*.c))
335 EXCLUDES = stm32f7xx_hal_can.c \
336 stm32f7xx_hal_cec.c \
337 stm32f7xx_hal_crc.c \
338 stm32f7xx_hal_crc_ex.c \
339 stm32f7xx_hal_cryp.c \
340 stm32f7xx_hal_cryp_ex.c \
341 stm32f7xx_hal_dac.c \
342 stm32f7xx_hal_dac_ex.c \
343 stm32f7xx_hal_dcmi.c \
344 stm32f7xx_hal_dcmi_ex.c \
345 stm32f7xx_hal_dfsdm.c \
346 stm32f7xx_hal_dma2d.c \
347 stm32f7xx_hal_dsi.c \
348 stm32f7xx_hal_eth.c \
349 stm32f7xx_hal_hash.c \
350 stm32f7xx_hal_hash_ex.c \
351 stm32f7xx_hal_hcd.c \
352 stm32f7xx_hal_i2s.c \
353 stm32f7xx_hal_irda.c \
354 stm32f7xx_hal_iwdg.c \
355 stm32f7xx_hal_jpeg.c \
356 stm32f7xx_hal_lptim.c \
357 stm32f7xx_hal_ltdc.c \
358 stm32f7xx_hal_ltdc_ex.c \
359 stm32f7xx_hal_mdios.c \
360 stm32f7xx_hal_mmc.c \
361 stm32f7xx_hal_msp_template.c \
362 stm32f7xx_hal_nand.c \
363 stm32f7xx_hal_nor.c \
364 stm32f7xx_hal_qspi.c \
365 stm32f7xx_hal_rng.c \
366 stm32f7xx_hal_rtc.c \
367 stm32f7xx_hal_rtc_ex.c \
368 stm32f7xx_hal_sai.c \
369 stm32f7xx_hal_sai_ex.c \
370 stm32f7xx_hal_sd.c \
371 stm32f7xx_hal_sdram.c \
372 stm32f7xx_hal_smartcard.c \
373 stm32f7xx_hal_smartcard_ex.c \
374 stm32f7xx_hal_smbus.c \
375 stm32f7xx_hal_spdifrx.c \
376 stm32f7xx_hal_sram.c \
377 stm32f7xx_hal_timebase_rtc_alarm_template.c \
378 stm32f7xx_hal_timebase_rtc_wakeup_template.c \
379 stm32f7xx_hal_timebase_tim_template.c \
380 stm32f7xx_hal_wwdg.c \
381 stm32f7xx_ll_adc.c \
382 stm32f7xx_ll_crc.c \
383 stm32f7xx_ll_dac.c \
384 stm32f7xx_ll_dma.c \
385 stm32f7xx_ll_dma2d.c \
386 stm32f7xx_ll_exti.c \
387 stm32f7xx_ll_fmc.c \
388 stm32f7xx_ll_gpio.c \
389 stm32f7xx_ll_i2c.c \
390 stm32f7xx_ll_lptim.c \
391 stm32f7xx_ll_pwr.c \
392 stm32f7xx_ll_rcc.c \
393 stm32f7xx_ll_rng.c \
394 stm32f7xx_ll_rtc.c \
395 stm32f7xx_ll_sdmmc.c \
396 stm32f7xx_ll_spi.c \
397 stm32f7xx_ll_tim.c \
398 stm32f7xx_ll_usart.c \
399 stm32f7xx_ll_utils.c
401 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
403 #USB
404 USBCORE_DIR = $(ROOT)/lib/main/Middlewares/ST/STM32_USB_Device_Library/Core
405 USBCORE_SRC = $(notdir $(wildcard $(USBCORE_DIR)/Src/*.c))
406 EXCLUDES = usbd_conf_template.c
407 USBCORE_SRC := $(filter-out ${EXCLUDES}, $(USBCORE_SRC))
409 USBCDC_DIR = $(ROOT)/lib/main/Middlewares/ST/STM32_USB_Device_Library/Class/CDC
410 USBCDC_SRC = $(notdir $(wildcard $(USBCDC_DIR)/Src/*.c))
411 EXCLUDES = usbd_cdc_if_template.c
412 USBCDC_SRC := $(filter-out ${EXCLUDES}, $(USBCDC_SRC))
414 VPATH := $(VPATH):$(USBCDC_DIR)/Src:$(USBCORE_DIR)/Src
416 DEVICE_STDPERIPH_SRC := $(STDPERIPH_SRC) \
417 $(USBCORE_SRC) \
418 $(USBCDC_SRC)
420 #CMSIS
421 VPATH := $(VPATH):$(CMSIS_DIR)/CM7/Include:$(CMSIS_DIR)/CM7/Device/ST/STM32F7xx
422 VPATH := $(VPATH):$(STDPERIPH_DIR)/Src
423 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM7/Include/*.c \
424 $(CMSIS_DIR)/CM7/Device/ST/STM32F7xx/*.c))
425 INCLUDE_DIRS := $(INCLUDE_DIRS) \
426 $(STDPERIPH_DIR)/Inc \
427 $(USBCORE_DIR)/Inc \
428 $(USBCDC_DIR)/Inc \
429 $(CMSIS_DIR)/CM7/Include \
430 $(CMSIS_DIR)/CM7/Device/ST/STM32F7xx/Include \
431 $(ROOT)/src/main/vcp_hal
433 ifneq ($(filter SDCARD,$(FEATURES)),)
434 INCLUDE_DIRS := $(INCLUDE_DIRS) \
435 $(FATFS_DIR)
436 VPATH := $(VPATH):$(FATFS_DIR)
437 endif
439 #Flags
440 ARCH_FLAGS = -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -fsingle-precision-constant -Wdouble-promotion
442 ifeq ($(TARGET),$(filter $(TARGET),$(F7X5XG_TARGETS)))
443 DEVICE_FLAGS = -DSTM32F745xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
444 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f745.ld
445 STARTUP_SRC = startup_stm32f745xx.s
446 else ifeq ($(TARGET),$(filter $(TARGET),$(F7X6XG_TARGETS)))
447 DEVICE_FLAGS = -DSTM32F746xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
448 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f746.ld
449 STARTUP_SRC = startup_stm32f746xx.s
450 else ifeq ($(TARGET),$(filter $(TARGET),$(F7X2RE_TARGETS)))
451 DEVICE_FLAGS = -DSTM32F722xx -DUSE_HAL_DRIVER -D__FPU_PRESENT
452 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f722.ld
453 STARTUP_SRC = startup_stm32f722xx.s
454 else
455 $(error Unknown MCU for F7 target)
456 endif
457 DEVICE_FLAGS += -DHSE_VALUE=$(HSE_VALUE)
459 TARGET_FLAGS = -D$(TARGET)
461 # End F7 targets
463 # Start F1 targets
464 else
466 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
467 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
468 EXCLUDES = stm32f10x_crc.c \
469 stm32f10x_cec.c \
470 stm32f10x_can.c
471 STARTUP_SRC = startup_stm32f10x_md_gcc.S
472 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
474 # Search path and source files for the CMSIS sources
475 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
476 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
477 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
479 INCLUDE_DIRS := $(INCLUDE_DIRS) \
480 $(STDPERIPH_DIR)/inc \
481 $(CMSIS_DIR)/CM3/CoreSupport \
482 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
484 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
486 ifneq ($(filter VCP, $(FEATURES)),)
487 INCLUDE_DIRS := $(INCLUDE_DIRS) \
488 $(USBFS_DIR)/inc \
489 $(ROOT)/src/main/vcp
491 VPATH := $(VPATH):$(USBFS_DIR)/src
493 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
494 $(USBPERIPH_SRC)
496 endif
498 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
499 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
501 ifeq ($(DEVICE_FLAGS),)
502 DEVICE_FLAGS = -DSTM32F10X_MD
503 endif
504 DEVICE_FLAGS += -DSTM32F10X
506 endif
508 # End F1 targets
510 ifneq ($(BASE_TARGET), $(TARGET))
511 TARGET_FLAGS := $(TARGET_FLAGS) -D$(BASE_TARGET)
512 endif
514 ifneq ($(FLASH_SIZE),)
515 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
516 endif
518 ifneq ($(HSE_VALUE),)
519 DEVICE_FLAGS := $(DEVICE_FLAGS) -DHSE_VALUE=$(HSE_VALUE)
520 endif
522 TARGET_DIR = $(ROOT)/src/main/target/$(BASE_TARGET)
523 TARGET_DIR_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
525 ifeq ($(OPBL),yes)
526 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
527 ifeq ($(TARGET), $(filter $(TARGET),$(F405_TARGETS)))
528 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f405_opbl.ld
529 else ifeq ($(TARGET), $(filter $(TARGET),$(F411_TARGETS)))
530 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f411_opbl.ld
531 else ifeq ($(TARGET), $(filter $(TARGET),$(F3_TARGETS)))
532 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k_opbl.ld
533 else ifeq ($(TARGET), $(filter $(TARGET),$(F1_TARGETS)))
534 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k_opbl.ld
535 endif
536 .DEFAULT_GOAL := binary
537 else
538 .DEFAULT_GOAL := hex
539 endif
541 INCLUDE_DIRS := $(INCLUDE_DIRS) \
542 $(ROOT)/lib/main/MAVLink
544 INCLUDE_DIRS := $(INCLUDE_DIRS) \
545 $(TARGET_DIR)
547 VPATH := $(VPATH):$(TARGET_DIR)
549 COMMON_SRC = \
550 build/build_config.c \
551 build/debug.c \
552 build/version.c \
553 $(TARGET_DIR_SRC) \
554 main.c \
555 common/encoding.c \
556 common/filter.c \
557 common/maths.c \
558 common/printf.c \
559 common/streambuf.c \
560 common/typeconversion.c \
561 config/config_eeprom.c \
562 config/feature.c \
563 config/parameter_group.c \
564 drivers/adc.c \
565 drivers/buf_writer.c \
566 drivers/bus_i2c_soft.c \
567 drivers/bus_spi.c \
568 drivers/bus_spi_soft.c \
569 drivers/display.c \
570 drivers/exti.c \
571 drivers/gyro_sync.c \
572 drivers/io.c \
573 drivers/light_led.c \
574 drivers/resource.c \
575 drivers/rx_nrf24l01.c \
576 drivers/rx_spi.c \
577 drivers/rx_xn297.c \
578 drivers/pwm_esc_detect.c \
579 drivers/pwm_output.c \
580 drivers/rcc.c \
581 drivers/rx_pwm.c \
582 drivers/serial.c \
583 drivers/serial_uart.c \
584 drivers/serial_softserial.c \
585 drivers/sound_beeper.c \
586 drivers/stack_check.c \
587 drivers/system.c \
588 drivers/timer.c \
589 fc/config.c \
590 fc/fc_init.c \
591 fc/fc_dispatch.c \
592 fc/fc_hardfaults.c \
593 fc/fc_core.c \
594 fc/fc_rc.c \
595 fc/fc_msp.c \
596 fc/fc_tasks.c \
597 fc/rc_controls.c \
598 fc/runtime_config.c \
599 fc/cli.c \
600 flight/altitudehold.c \
601 flight/failsafe.c \
602 flight/imu.c \
603 flight/mixer.c \
604 flight/pid.c \
605 flight/servos.c \
606 io/beeper.c \
607 io/serial.c \
608 io/serial_4way.c \
609 io/serial_4way_avrootloader.c \
610 io/serial_4way_stk500v2.c \
611 io/statusindicator.c \
612 msp/msp_serial.c \
613 rx/ibus.c \
614 rx/jetiexbus.c \
615 rx/msp.c \
616 rx/nrf24_cx10.c \
617 rx/nrf24_inav.c \
618 rx/nrf24_h8_3d.c \
619 rx/nrf24_syma.c \
620 rx/nrf24_v202.c \
621 rx/pwm.c \
622 rx/rx.c \
623 rx/rx_spi.c \
624 rx/crsf.c \
625 rx/sbus.c \
626 rx/spektrum.c \
627 rx/sumd.c \
628 rx/sumh.c \
629 rx/xbus.c \
630 scheduler/scheduler.c \
631 sensors/acceleration.c \
632 sensors/battery.c \
633 sensors/boardalignment.c \
634 sensors/compass.c \
635 sensors/gyro.c \
636 sensors/initialisation.c \
637 $(CMSIS_SRC) \
638 $(DEVICE_STDPERIPH_SRC)
640 HIGHEND_SRC = \
641 blackbox/blackbox.c \
642 blackbox/blackbox_io.c \
643 cms/cms.c \
644 cms/cms_menu_blackbox.c \
645 cms/cms_menu_builtin.c \
646 cms/cms_menu_imu.c \
647 cms/cms_menu_ledstrip.c \
648 cms/cms_menu_misc.c \
649 cms/cms_menu_osd.c \
650 cms/cms_menu_vtx.c \
651 common/colorconversion.c \
652 drivers/display_ug2864hsweg01.c \
653 drivers/light_ws2811strip.c \
654 drivers/serial_escserial.c \
655 drivers/sonar_hcsr04.c \
656 drivers/vtx_common.c \
657 flight/navigation.c \
658 flight/gps_conversion.c \
659 io/dashboard.c \
660 io/displayport_max7456.c \
661 io/displayport_msp.c \
662 io/displayport_oled.c \
663 io/gps.c \
664 io/ledstrip.c \
665 io/osd.c \
666 sensors/sonar.c \
667 sensors/barometer.c \
668 telemetry/telemetry.c \
669 telemetry/crsf.c \
670 telemetry/srxl.c \
671 telemetry/frsky.c \
672 telemetry/hott.c \
673 telemetry/smartport.c \
674 telemetry/ltm.c \
675 telemetry/mavlink.c \
676 telemetry/ibus.c \
677 sensors/esc_sensor.c \
678 io/vtx_string.c \
679 io/vtx_smartaudio.c \
680 io/vtx_tramp.c
682 SPEED_OPTIMISED_SRC := ""
683 SIZE_OPTIMISED_SRC := ""
685 ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
686 SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
687 common/encoding.c \
688 common/filter.c \
689 common/maths.c \
690 common/typeconversion.c \
691 drivers/adc.c \
692 drivers/buf_writer.c \
693 drivers/bus_i2c_soft.c \
694 drivers/bus_spi.c \
695 drivers/bus_spi_soft.c \
696 drivers/exti.c \
697 drivers/gyro_sync.c \
698 drivers/io.c \
699 drivers/light_led.c \
700 drivers/resource.c \
701 drivers/rx_nrf24l01.c \
702 drivers/rx_spi.c \
703 drivers/rx_xn297.c \
704 drivers/pwm_output.c \
705 drivers/rcc.c \
706 drivers/rx_pwm.c \
707 drivers/serial.c \
708 drivers/serial_uart.c \
709 drivers/sound_beeper.c \
710 drivers/stack_check.c \
711 drivers/system.c \
712 drivers/timer.c \
713 fc/fc_tasks.c \
714 fc/fc_rc.c \
715 fc/rc_controls.c \
716 fc/runtime_config.c \
717 flight/altitudehold.c \
718 flight/failsafe.c \
719 flight/imu.c \
720 flight/mixer.c \
721 flight/pid.c \
722 flight/servos.c \
723 io/beeper.c \
724 io/serial.c \
725 io/statusindicator.c \
726 rx/ibus.c \
727 rx/jetiexbus.c \
728 rx/msp.c \
729 rx/nrf24_cx10.c \
730 rx/nrf24_inav.c \
731 rx/nrf24_h8_3d.c \
732 rx/nrf24_syma.c \
733 rx/nrf24_v202.c \
734 rx/pwm.c \
735 rx/rx.c \
736 rx/rx_spi.c \
737 rx/crsf.c \
738 rx/sbus.c \
739 rx/spektrum.c \
740 rx/sumd.c \
741 rx/sumh.c \
742 rx/xbus.c \
743 scheduler/scheduler.c \
744 sensors/acceleration.c \
745 sensors/boardalignment.c \
746 sensors/gyro.c \
747 $(CMSIS_SRC) \
748 $(DEVICE_STDPERIPH_SRC) \
749 blackbox/blackbox.c \
750 blackbox/blackbox_io.c \
751 drivers/display_ug2864hsweg01.c \
752 drivers/light_ws2811strip.c \
753 drivers/serial_softserial.c \
754 io/dashboard.c \
755 io/displayport_max7456.c \
756 io/displayport_msp.c \
757 io/displayport_oled.c \
758 io/ledstrip.c \
759 io/osd.c \
760 telemetry/telemetry.c \
761 telemetry/crsf.c \
762 telemetry/frsky.c \
763 telemetry/hott.c \
764 telemetry/smartport.c \
765 telemetry/ltm.c \
766 telemetry/mavlink.c \
767 telemetry/esc_telemetry.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 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
798 VCP_SRC = \
799 vcp_hal/usbd_desc.c \
800 vcp_hal/usbd_conf.c \
801 vcp_hal/usbd_cdc_interface.c \
802 drivers/serial_usb_vcp.c
803 else
804 VCP_SRC = \
805 vcp/hw_config.c \
806 vcp/stm32_it.c \
807 vcp/usb_desc.c \
808 vcp/usb_endp.c \
809 vcp/usb_istr.c \
810 vcp/usb_prop.c \
811 vcp/usb_pwr.c \
812 drivers/serial_usb_vcp.c \
813 drivers/usb_io.c
814 endif
816 STM32F10x_COMMON_SRC = \
817 drivers/adc_stm32f10x.c \
818 drivers/bus_i2c_stm32f10x.c \
819 drivers/dma.c \
820 drivers/gpio_stm32f10x.c \
821 drivers/inverter.c \
822 drivers/light_ws2811strip_stm32f10x.c \
823 drivers/serial_uart_stm32f10x.c \
824 drivers/system_stm32f10x.c \
825 drivers/timer_stm32f10x.c
827 STM32F30x_COMMON_SRC = \
828 target/system_stm32f30x.c \
829 drivers/adc_stm32f30x.c \
830 drivers/bus_i2c_stm32f30x.c \
831 drivers/dma.c \
832 drivers/gpio_stm32f30x.c \
833 drivers/light_ws2811strip_stm32f30x.c \
834 drivers/pwm_output_stm32f3xx.c \
835 drivers/serial_uart_stm32f30x.c \
836 drivers/system_stm32f30x.c \
837 drivers/timer_stm32f30x.c
839 STM32F4xx_COMMON_SRC = \
840 target/system_stm32f4xx.c \
841 drivers/accgyro_mpu.c \
842 drivers/adc_stm32f4xx.c \
843 drivers/bus_i2c_stm32f10x.c \
844 drivers/dma_stm32f4xx.c \
845 drivers/gpio_stm32f4xx.c \
846 drivers/inverter.c \
847 drivers/light_ws2811strip_stm32f4xx.c \
848 drivers/pwm_output_stm32f4xx.c \
849 drivers/serial_uart_stm32f4xx.c \
850 drivers/system_stm32f4xx.c \
851 drivers/timer_stm32f4xx.c
853 STM32F7xx_COMMON_SRC = \
854 target/system_stm32f7xx.c \
855 drivers/accgyro_mpu.c \
856 drivers/adc_stm32f7xx.c \
857 drivers/bus_i2c_hal.c \
858 drivers/dma_stm32f7xx.c \
859 drivers/gpio_stm32f7xx.c \
860 drivers/inverter.c \
861 drivers/bus_spi_hal.c \
862 drivers/pwm_output_stm32f7xx.c \
863 drivers/timer_hal.c \
864 drivers/timer_stm32f7xx.c \
865 drivers/system_stm32f7xx.c \
866 drivers/serial_uart_stm32f7xx.c \
867 drivers/serial_uart_hal.c
869 F7EXCLUDES = drivers/bus_spi.c \
870 drivers/bus_i2c.c \
871 drivers/timer.c \
872 drivers/serial_uart.c
874 # check if target.mk supplied
875 ifeq ($(TARGET),$(filter $(TARGET),$(F4_TARGETS)))
876 TARGET_SRC := $(STARTUP_SRC) $(STM32F4xx_COMMON_SRC) $(TARGET_SRC)
877 else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
878 TARGET_SRC := $(STARTUP_SRC) $(STM32F7xx_COMMON_SRC) $(TARGET_SRC)
879 else ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
880 TARGET_SRC := $(STARTUP_SRC) $(STM32F30x_COMMON_SRC) $(TARGET_SRC)
881 else ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
882 TARGET_SRC := $(STARTUP_SRC) $(STM32F10x_COMMON_SRC) $(TARGET_SRC)
883 endif
885 ifneq ($(filter ONBOARDFLASH,$(FEATURES)),)
886 TARGET_SRC += \
887 drivers/flash_m25p16.c \
888 io/flashfs.c
889 endif
891 ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS) $(F4_TARGETS) $(F3_TARGETS)))
892 TARGET_SRC += $(HIGHEND_SRC)
893 else ifneq ($(filter HIGHEND,$(FEATURES)),)
894 TARGET_SRC += $(HIGHEND_SRC)
895 endif
897 TARGET_SRC += $(COMMON_SRC)
898 #excludes
899 ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
900 TARGET_SRC := $(filter-out ${F7EXCLUDES}, $(TARGET_SRC))
901 endif
903 ifneq ($(filter SDCARD,$(FEATURES)),)
904 TARGET_SRC += \
905 drivers/sdcard.c \
906 drivers/sdcard_standard.c \
907 io/asyncfatfs/asyncfatfs.c \
908 io/asyncfatfs/fat_standard.c
909 endif
911 ifneq ($(filter VCP,$(FEATURES)),)
912 TARGET_SRC += $(VCP_SRC)
913 endif
914 # end target specific make file checks
917 # Search path and source files for the ST stdperiph library
918 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
920 ###############################################################################
921 # Things that might need changing to use different tools
924 # Find out if ccache is installed on the system
925 CCACHE := ccache
926 RESULT = $(shell (which $(CCACHE) > /dev/null 2>&1; echo $$?) )
927 ifneq ($(RESULT),0)
928 CCACHE :=
929 endif
931 # Tool names
932 CROSS_CC := $(CCACHE) $(ARM_SDK_PREFIX)gcc
933 CROSS_CXX := $(CCACHE) $(ARM_SDK_PREFIX)g++
934 OBJCOPY := $(ARM_SDK_PREFIX)objcopy
935 SIZE := $(ARM_SDK_PREFIX)size
938 # Tool options.
941 ifneq ($(DEBUG),GDB)
942 OPTIMISATION_BASE := -flto -fuse-linker-plugin -ffast-math
943 OPTIMISE_SPEED := ""
944 OPTIMISE_SIZE := ""
946 ifeq ($(TARGET),$(filter $(TARGET),$(F1_TARGETS)))
947 OPTIMISE_DEFAULT := -Os
949 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
951 else ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
952 OPTIMISE_DEFAULT := -O2
953 OPTIMISE_SPEED := -Ofast
954 OPTIMISE_SIZE := -Os
956 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
958 else
959 OPTIMISE_DEFAULT := -Ofast
961 LTO_FLAGS := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
963 endif #TARGETS
965 CC_DEFAULT_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_DEFAULT)
966 CC_SPEED_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SPEED)
967 CC_SIZE_OPTIMISATION := $(OPTIMISATION_BASE) $(OPTIMISE_SIZE)
969 else #DEBUG
970 OPTIMISE_DEFAULT := -O0
972 CC_DEBUG_OPTIMISATION := $(OPTIMISE_DEFAULT)
974 LTO_FLAGS := $(OPTIMISE_DEFAULT)
975 endif #DEBUG
977 DEBUG_FLAGS = -ggdb3 -DDEBUG
979 CFLAGS += $(ARCH_FLAGS) \
980 $(addprefix -D,$(OPTIONS)) \
981 $(addprefix -I,$(INCLUDE_DIRS)) \
982 $(DEBUG_FLAGS) \
983 -std=gnu99 \
984 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
985 -ffunction-sections \
986 -fdata-sections \
987 -pedantic \
988 $(DEVICE_FLAGS) \
989 -DUSE_STDPERIPH_DRIVER \
990 -D$(TARGET) \
991 $(TARGET_FLAGS) \
992 -D'__FORKNAME__="$(FORKNAME)"' \
993 -D'__TARGET__="$(TARGET)"' \
994 -D'__REVISION__="$(REVISION)"' \
995 -save-temps=obj \
996 -MMD -MP
998 ASFLAGS = $(ARCH_FLAGS) \
999 -x assembler-with-cpp \
1000 $(addprefix -I,$(INCLUDE_DIRS)) \
1001 -MMD -MP
1003 LDFLAGS = -lm \
1004 -nostartfiles \
1005 --specs=nano.specs \
1006 -lc \
1007 -lnosys \
1008 $(ARCH_FLAGS) \
1009 $(LTO_FLAGS) \
1010 $(DEBUG_FLAGS) \
1011 -static \
1012 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
1013 -Wl,-L$(LINKER_DIR) \
1014 -Wl,--cref \
1015 -Wl,--no-wchar-size-warning \
1016 -T$(LD_SCRIPT)
1018 ###############################################################################
1019 # No user-serviceable parts below
1020 ###############################################################################
1022 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
1023 --std=c99 --inline-suppr --quiet --force \
1024 $(addprefix -I,$(INCLUDE_DIRS)) \
1025 -I/usr/include -I/usr/include/linux
1028 # Things we will build
1030 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
1031 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
1032 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
1033 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(TARGET_SRC))))
1034 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $(TARGET_SRC))))
1035 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
1038 CLEAN_ARTIFACTS := $(TARGET_BIN)
1039 CLEAN_ARTIFACTS += $(TARGET_HEX)
1040 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
1042 # Make sure build date and revision is updated on every incremental build
1043 $(OBJECT_DIR)/$(TARGET)/build/version.o : $(TARGET_SRC)
1045 # List of buildable ELF files and their object dependencies.
1046 # It would be nice to compute these lists, but that seems to be just beyond make.
1048 $(TARGET_HEX): $(TARGET_ELF)
1049 $(V0) $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
1051 $(TARGET_BIN): $(TARGET_ELF)
1052 $(V0) $(OBJCOPY) -O binary $< $@
1054 $(TARGET_ELF): $(TARGET_OBJS)
1055 $(V1) echo Linking $(TARGET)
1056 $(V1) $(CROSS_CC) -o $@ $^ $(LDFLAGS)
1057 $(V0) $(SIZE) $(TARGET_ELF)
1059 # Compile
1060 ifneq ($(DEBUG),GDB)
1061 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1062 $(V1) mkdir -p $(dir $@)
1063 $(V1) $(if $(findstring $(subst ./src/main/,,$<),$(SPEED_OPTIMISED_SRC)), \
1064 echo "%% (speed optimised) $(notdir $<)" "$(STDOUT)" && \
1065 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SPEED_OPTIMISATION) $<, \
1066 $(if $(findstring $(subst ./src/main/,,$<),$(SIZE_OPTIMISED_SRC)), \
1067 echo "%% (size optimised) $(notdir $<)" "$(STDOUT)" && \
1068 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_SIZE_OPTIMISATION) $<, \
1069 echo "%% $(notdir $<)" "$(STDOUT)" && \
1070 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEFAULT_OPTIMISATION) $<))
1071 else
1072 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
1073 $(V1) mkdir -p $(dir $@)
1074 $(V1) echo "%% $(notdir $<)" "$(STDOUT)" && \
1075 $(CROSS_CC) -c -o $@ $(CFLAGS) $(CC_DEBUG_OPTIMISATION) $<
1076 endif
1078 # Assemble
1079 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
1080 $(V1) mkdir -p $(dir $@)
1081 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1082 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1084 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
1085 $(V1) mkdir -p $(dir $@)
1086 $(V1) echo "%% $(notdir $<)" "$(STDOUT)"
1087 $(V1) $(CROSS_CC) -c -o $@ $(ASFLAGS) $<
1089 ## sample : Build all sample (travis) targets
1090 sample: $(SAMPLE_TARGETS)
1092 ## all : Build all valid targets
1093 all: $(VALID_TARGETS)
1095 $(VALID_TARGETS):
1096 $(V0) echo "" && \
1097 echo "Building $@" && \
1098 $(MAKE) binary hex TARGET=$@ && \
1099 echo "Building $@ succeeded."
1103 CLEAN_TARGETS = $(addprefix clean_,$(VALID_TARGETS) )
1104 TARGETS_CLEAN = $(addsuffix _clean,$(VALID_TARGETS) )
1106 ## clean : clean up temporary / machine-generated files
1107 clean:
1108 $(V0) echo "Cleaning $(TARGET)"
1109 $(V0) rm -f $(CLEAN_ARTIFACTS)
1110 $(V0) rm -rf $(OBJECT_DIR)/$(TARGET)
1111 $(V0) echo "Cleaning $(TARGET) succeeded."
1113 ## clean_test : clean up temporary / machine-generated files (tests)
1114 clean_test:
1115 $(V0) cd src/test && $(MAKE) clean || true
1117 ## clean_<TARGET> : clean up one specific target
1118 $(CLEAN_TARGETS) :
1119 $(V0) $(MAKE) -j TARGET=$(subst clean_,,$@) clean
1121 ## <TARGET>_clean : clean up one specific target (alias for above)
1122 $(TARGETS_CLEAN) :
1123 $(V0) $(MAKE) -j TARGET=$(subst _clean,,$@) clean
1125 ## clean_all : clean all valid targets
1126 clean_all:$(CLEAN_TARGETS)
1128 ## all_clean : clean all valid targets (alias for above)
1129 all_clean:$(TARGETS_CLEAN)
1132 flash_$(TARGET): $(TARGET_HEX)
1133 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1134 $(V0) echo -n 'R' >$(SERIAL_DEVICE)
1135 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1137 ## flash : flash firmware (.hex) onto flight controller
1138 flash: flash_$(TARGET)
1140 st-flash_$(TARGET): $(TARGET_BIN)
1141 $(V0) st-flash --reset write $< 0x08000000
1143 ## st-flash : flash firmware (.bin) onto flight controller
1144 st-flash: st-flash_$(TARGET)
1146 binary:
1147 $(V0) $(MAKE) -j $(TARGET_BIN)
1149 hex:
1150 $(V0) $(MAKE) -j $(TARGET_HEX)
1152 unbrick_$(TARGET): $(TARGET_HEX)
1153 $(V0) stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
1154 $(V0) stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
1156 ## unbrick : unbrick flight controller
1157 unbrick: unbrick_$(TARGET)
1159 ## cppcheck : run static analysis on C source code
1160 cppcheck: $(CSOURCES)
1161 $(V0) $(CPPCHECK)
1163 cppcheck-result.xml: $(CSOURCES)
1164 $(V0) $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
1166 # mkdirs
1167 $(DL_DIR):
1168 mkdir -p $@
1170 $(TOOLS_DIR):
1171 mkdir -p $@
1173 $(BUILD_DIR):
1174 mkdir -p $@
1176 ## help : print this help message and exit
1177 help: Makefile make/tools.mk
1178 $(V0) @echo ""
1179 $(V0) @echo "Makefile for the $(FORKNAME) firmware"
1180 $(V0) @echo ""
1181 $(V0) @echo "Usage:"
1182 $(V0) @echo " make [V=<verbosity>] [TARGET=<target>] [OPTIONS=\"<options>\"]"
1183 $(V0) @echo "Or:"
1184 $(V0) @echo " make <target> [V=<verbosity>] [OPTIONS=\"<options>\"]"
1185 $(V0) @echo ""
1186 $(V0) @echo "Valid TARGET values are: $(VALID_TARGETS)"
1187 $(V0) @echo ""
1188 $(V0) @sed -n 's/^## //p' $?
1190 ## targets : print a list of all valid target platforms (for consumption by scripts)
1191 targets:
1192 $(V0) @echo "Valid targets: $(VALID_TARGETS)"
1193 $(V0) @echo "Target: $(TARGET)"
1194 $(V0) @echo "Base target: $(BASE_TARGET)"
1196 ## test : run the cleanflight test suite
1197 ## junittest : run the cleanflight test suite, producing Junit XML result files.
1198 test junittest:
1199 $(V0) cd src/test && $(MAKE) $@
1201 # rebuild everything when makefile changes
1202 $(TARGET_OBJS) : Makefile
1204 # include auto-generated dependencies
1205 -include $(TARGET_DEPS)