Merge pull request #215 from nathantsoi/sbus-inversion-2.4.1
[betaflight.git] / Makefile
blobebbe6b583e83f7719c710b78676b4e26194e5c46
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 cleanflight firmware.
10 # Invoke this with 'make help' to see the list of supported targets.
13 ###############################################################################
16 # Things that the user might override on the commandline
19 # The target to build, see VALID_TARGETS below
20 TARGET ?= NAZE
22 # Compile-time options
23 OPTIONS ?=
25 # compile for OpenPilot BootLoader support
26 OPBL ?=no
28 # Debugger optons, must be empty or GDB
29 DEBUG ?=
31 # Serial port/Device for flashing
32 SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyUSB*) no-port-found)
34 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
35 FLASH_SIZE ?=
37 ###############################################################################
38 # Things that need to be maintained as the source changes
41 FORKNAME = betaflight
43 CC3D_TARGETS = CC3D CC3D_OPBL
45 VALID_TARGETS = NAZE NAZE32PRO OLIMEXINO STM32F3DISCOVERY CHEBUZZF3 $(CC3D_TARGETS) CJMCU EUSTM32F103RC SPRACINGF3 PORT103R SPARKY ALIENFLIGHTF1 ALIENFLIGHTF3 COLIBRI_RACE LUX_RACE MOTOLAB RMDO IRCFUSIONF3 AFROMINI SPRACINGF3MINI
47 # Valid targets for OP VCP support
48 VCP_VALID_TARGETS = $(CC3D_TARGETS)
50 # Valid targets for OP BootLoader support
51 OPBL_VALID_TARGETS = CC3D_OPBL
53 64K_TARGETS = CJMCU
54 128K_TARGETS = ALIENFLIGHTF1 $(CC3D_TARGETS) NAZE OLIMEXINO RMDO AFROMINI
55 256K_TARGETS = EUSTM32F103RC PORT103R STM32F3DISCOVERY CHEBUZZF3 NAZE32PRO SPRACINGF3 IRCFUSIONF3 SPARKY ALIENFLIGHTF3 COLIBRI_RACE LUX_RACE MOTOLAB SPRACINGF3MINI
57 F3_TARGETS = STM32F3DISCOVERY CHEBUZZF3 NAZE32PRO SPRACINGF3 IRCFUSIONF3 SPARKY ALIENFLIGHTF3 COLIBRI_RACE LUX_RACE MOTOLAB RMDO SPRACINGF3MINI
60 # Configure default flash sizes for the targets
61 ifeq ($(FLASH_SIZE),)
62 ifeq ($(TARGET),$(filter $(TARGET),$(64K_TARGETS)))
63 FLASH_SIZE = 64
64 else ifeq ($(TARGET),$(filter $(TARGET),$(128K_TARGETS)))
65 FLASH_SIZE = 128
66 else ifeq ($(TARGET),$(filter $(TARGET),$(256K_TARGETS)))
67 FLASH_SIZE = 256
68 else
69 $(error FLASH_SIZE not configured for target $(TARGET))
70 endif
71 endif
73 REVISION = $(shell git log -1 --format="%h")
75 FC_VER_MAJOR := $(shell grep " FC_VERSION_MAJOR" src/main/version.h | awk '{print $$3}' )
76 FC_VER_MINOR := $(shell grep " FC_VERSION_MINOR" src/main/version.h | awk '{print $$3}' )
77 FC_VER_PATCH := $(shell grep " FC_VERSION_PATCH" src/main/version.h | awk '{print $$3}' )
79 FC_VER := $(FC_VER_MAJOR).$(FC_VER_MINOR).$(FC_VER_PATCH)
81 # Working directories
82 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
83 SRC_DIR = $(ROOT)/src/main
84 OBJECT_DIR = $(ROOT)/obj/main
85 BIN_DIR = $(ROOT)/obj
86 CMSIS_DIR = $(ROOT)/lib/main/CMSIS
87 INCLUDE_DIRS = $(SRC_DIR)
88 LINKER_DIR = $(ROOT)/src/main/target
90 # Search path for sources
91 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
92 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
93 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
94 FATFS_DIR = $(ROOT)/lib/main/FatFS
95 FATFS_SRC = $(notdir $(wildcard $(FATFS_DIR)/*.c))
97 ifeq ($(TARGET),$(filter $(TARGET),$(F3_TARGETS)))
99 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
101 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver
103 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
105 EXCLUDES = stm32f30x_crc.c \
106 stm32f30x_can.c
108 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
110 DEVICE_STDPERIPH_SRC = \
111 $(STDPERIPH_SRC)
114 VPATH := $(VPATH):$(CMSIS_DIR)/CM1/CoreSupport:$(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
115 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM1/CoreSupport/*.c \
116 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x/*.c))
118 INCLUDE_DIRS := $(INCLUDE_DIRS) \
119 $(STDPERIPH_DIR)/inc \
120 $(CMSIS_DIR)/CM1/CoreSupport \
121 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
123 ifneq ($(TARGET),$(filter $(TARGET),SPRACINGF3 IRCFUSIONF3))
124 INCLUDE_DIRS := $(INCLUDE_DIRS) \
125 $(USBFS_DIR)/inc \
126 $(ROOT)/src/main/vcp
128 VPATH := $(VPATH):$(USBFS_DIR)/src
130 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC)\
131 $(USBPERIPH_SRC)
133 endif
135 ifeq ($(TARGET),SPRACINGF3MINI)
136 INCLUDE_DIRS := $(INCLUDE_DIRS) \
137 $(FATFS_DIR) \
139 VPATH := $(VPATH):$(FATFS_DIR)
140 endif
142 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k.ld
144 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
145 DEVICE_FLAGS = -DSTM32F303xC -DSTM32F303
146 TARGET_FLAGS = -D$(TARGET)
147 ifeq ($(TARGET),CHEBUZZF3)
148 # CHEBUZZ is a VARIANT of STM32F3DISCOVERY
149 TARGET_FLAGS := $(TARGET_FLAGS) -DSTM32F3DISCOVERY
150 endif
152 ifeq ($(TARGET),$(filter $(TARGET),RMDO IRCFUSIONF3))
153 # RMDO and IRCFUSIONF3 are a VARIANT of SPRACINGF3
154 TARGET_FLAGS := $(TARGET_FLAGS) -DSPRACINGF3
155 endif
157 else ifeq ($(TARGET),$(filter $(TARGET),EUSTM32F103RC PORT103R))
160 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
162 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
164 EXCLUDES = stm32f10x_crc.c \
165 stm32f10x_cec.c \
166 stm32f10x_can.c
168 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
170 # Search path and source files for the CMSIS sources
171 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
172 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
173 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
175 INCLUDE_DIRS := $(INCLUDE_DIRS) \
176 $(STDPERIPH_DIR)/inc \
177 $(CMSIS_DIR)/CM3/CoreSupport \
178 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \
180 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
182 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
183 TARGET_FLAGS = -D$(TARGET) -pedantic
184 DEVICE_FLAGS = -DSTM32F10X_HD -DSTM32F10X
186 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
188 else
190 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
192 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
194 EXCLUDES = stm32f10x_crc.c \
195 stm32f10x_cec.c \
196 stm32f10x_can.c
198 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
200 # Search path and source files for the CMSIS sources
201 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
202 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
203 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
205 INCLUDE_DIRS := $(INCLUDE_DIRS) \
206 $(STDPERIPH_DIR)/inc \
207 $(CMSIS_DIR)/CM3/CoreSupport \
208 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \
210 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
212 ifeq ($(TARGET),$(filter $(TARGET), $(VCP_VALID_TARGETS)))
213 INCLUDE_DIRS := $(INCLUDE_DIRS) \
214 $(USBFS_DIR)/inc \
215 $(ROOT)/src/main/vcp
217 VPATH := $(VPATH):$(USBFS_DIR)/src
219 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
220 $(USBPERIPH_SRC)
222 endif
224 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
226 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
227 TARGET_FLAGS = -D$(TARGET) -pedantic
228 DEVICE_FLAGS = -DSTM32F10X_MD -DSTM32F10X
230 endif
232 ifneq ($(FLASH_SIZE),)
233 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
234 endif
236 TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
237 TARGET_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
239 ifeq ($(TARGET),ALIENFLIGHTF1)
240 # ALIENFLIGHTF1 is a VARIANT of NAZE
241 TARGET_FLAGS := $(TARGET_FLAGS) -DNAZE -DALIENFLIGHT
242 TARGET_DIR = $(ROOT)/src/main/target/NAZE
243 endif
245 ifeq ($(TARGET),$(filter $(TARGET), $(CC3D_TARGETS)))
246 TARGET_FLAGS := $(TARGET_FLAGS) -DCC3D
247 TARGET_DIR = $(ROOT)/src/main/target/CC3D
248 endif
250 ifneq ($(filter $(TARGET),$(OPBL_VALID_TARGETS)),)
251 OPBL=yes
252 endif
254 ifeq ($(OPBL),yes)
255 ifneq ($(filter $(TARGET),$(OPBL_VALID_TARGETS)),)
256 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
257 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k_opbl.ld
258 .DEFAULT_GOAL := binary
259 else
260 $(error OPBL specified with a unsupported target)
261 endif
262 endif
264 ifeq ($(TARGET),AFROMINI)
265 # AFROMINI is a VARIANT of NAZE being recognized as rev4, but needs to use rev5 config
266 TARGET_FLAGS := $(TARGET_FLAGS) -DNAZE -DAFROMINI
267 TARGET_DIR = $(ROOT)/src/main/target/NAZE
268 endif
270 INCLUDE_DIRS := $(INCLUDE_DIRS) \
271 $(TARGET_DIR)
273 VPATH := $(VPATH):$(TARGET_DIR)
275 COMMON_SRC = build_config.c \
276 debug.c \
277 version.c \
278 $(TARGET_SRC) \
279 config/config.c \
280 config/runtime_config.c \
281 common/maths.c \
282 common/printf.c \
283 common/typeconversion.c \
284 common/encoding.c \
285 common/filter.c \
286 scheduler.c \
287 main.c \
288 mw.c \
289 flight/altitudehold.c \
290 flight/failsafe.c \
291 flight/pid.c \
292 flight/imu.c \
293 flight/mixer.c \
294 drivers/bus_i2c_soft.c \
295 drivers/serial.c \
296 drivers/sound_beeper.c \
297 drivers/system.c \
298 drivers/gyro_sync.c \
299 drivers/dma.c \
300 drivers/buf_writer.c \
301 io/beeper.c \
302 io/rc_controls.c \
303 io/rc_curves.c \
304 io/serial.c \
305 io/serial_1wire.c \
306 io/serial_cli.c \
307 io/serial_msp.c \
308 io/statusindicator.c \
309 rx/rx.c \
310 rx/pwm.c \
311 rx/msp.c \
312 rx/sbus.c \
313 rx/sumd.c \
314 rx/sumh.c \
315 rx/spektrum.c \
316 rx/xbus.c \
317 rx/ibus.c \
318 rx/jetiexbus.c \
319 sensors/acceleration.c \
320 sensors/battery.c \
321 sensors/boardalignment.c \
322 sensors/compass.c \
323 sensors/gyro.c \
324 sensors/initialisation.c \
325 $(CMSIS_SRC) \
326 $(DEVICE_STDPERIPH_SRC)
328 HIGHEND_SRC = \
329 flight/gtune.c \
330 flight/navigation.c \
331 flight/gps_conversion.c \
332 common/colorconversion.c \
333 io/gps.c \
334 io/ledstrip.c \
335 io/display.c \
336 telemetry/telemetry.c \
337 telemetry/frsky.c \
338 telemetry/hott.c \
339 telemetry/smartport.c \
340 telemetry/ltm.c \
341 sensors/sonar.c \
342 sensors/barometer.c \
343 blackbox/blackbox.c \
344 blackbox/blackbox_io.c
346 VCP_SRC = \
347 vcp/hw_config.c \
348 vcp/stm32_it.c \
349 vcp/usb_desc.c \
350 vcp/usb_endp.c \
351 vcp/usb_istr.c \
352 vcp/usb_prop.c \
353 vcp/usb_pwr.c \
354 drivers/serial_usb_vcp.c
356 NAZE_SRC = startup_stm32f10x_md_gcc.S \
357 drivers/accgyro_adxl345.c \
358 drivers/accgyro_bma280.c \
359 drivers/accgyro_l3g4200d.c \
360 drivers/accgyro_mma845x.c \
361 drivers/accgyro_mpu.c \
362 drivers/accgyro_mpu3050.c \
363 drivers/accgyro_mpu6050.c \
364 drivers/accgyro_mpu6500.c \
365 drivers/accgyro_spi_mpu6500.c \
366 drivers/adc.c \
367 drivers/adc_stm32f10x.c \
368 drivers/barometer_bmp085.c \
369 drivers/barometer_bmp280.c \
370 drivers/barometer_ms5611.c \
371 drivers/barometer_bmp280.c \
372 drivers/bus_spi.c \
373 drivers/bus_i2c_stm32f10x.c \
374 drivers/compass_hmc5883l.c \
375 drivers/display_ug2864hsweg01.h \
376 drivers/flash_m25p16.c \
377 drivers/gpio_stm32f10x.c \
378 drivers/inverter.c \
379 drivers/light_led_stm32f10x.c \
380 drivers/light_ws2811strip.c \
381 drivers/light_ws2811strip_stm32f10x.c \
382 drivers/sonar_hcsr04.c \
383 drivers/pwm_mapping.c \
384 drivers/pwm_output.c \
385 drivers/pwm_rx.c \
386 drivers/serial_softserial.c \
387 drivers/serial_uart.c \
388 drivers/serial_uart_stm32f10x.c \
389 drivers/sound_beeper_stm32f10x.c \
390 drivers/system_stm32f10x.c \
391 drivers/timer.c \
392 drivers/timer_stm32f10x.c \
393 io/flashfs.c \
394 hardware_revision.c \
395 $(HIGHEND_SRC) \
396 $(COMMON_SRC)
398 ALIENFLIGHTF1_SRC = $(NAZE_SRC)
400 AFROMINI_SRC = $(NAZE_SRC)
402 EUSTM32F103RC_SRC = startup_stm32f10x_hd_gcc.S \
403 drivers/accgyro_adxl345.c \
404 drivers/accgyro_bma280.c \
405 drivers/accgyro_l3g4200d.c \
406 drivers/accgyro_mma845x.c \
407 drivers/accgyro_mpu.c \
408 drivers/accgyro_mpu3050.c \
409 drivers/accgyro_mpu6050.c \
410 drivers/accgyro_spi_mpu6000.c \
411 drivers/accgyro_spi_mpu6500.c \
412 drivers/adc.c \
413 drivers/adc_stm32f10x.c \
414 drivers/barometer_bmp085.c \
415 drivers/barometer_bmp280.c \
416 drivers/barometer_ms5611.c \
417 drivers/bus_i2c_stm32f10x.c \
418 drivers/bus_spi.c \
419 drivers/compass_ak8975.c \
420 drivers/compass_hmc5883l.c \
421 drivers/display_ug2864hsweg01.c \
422 drivers/flash_m25p16.c \
423 drivers/gpio_stm32f10x.c \
424 drivers/inverter.c \
425 drivers/light_led_stm32f10x.c \
426 drivers/light_ws2811strip.c \
427 drivers/light_ws2811strip_stm32f10x.c \
428 drivers/pwm_mapping.c \
429 drivers/pwm_output.c \
430 drivers/pwm_rx.c \
431 drivers/serial_softserial.c \
432 drivers/serial_uart.c \
433 drivers/serial_uart_stm32f10x.c \
434 drivers/sonar_hcsr04.c \
435 drivers/sound_beeper_stm32f10x.c \
436 drivers/system_stm32f10x.c \
437 drivers/timer.c \
438 drivers/timer_stm32f10x.c \
439 io/flashfs.c \
440 $(HIGHEND_SRC) \
441 $(COMMON_SRC)
443 PORT103R_SRC = $(EUSTM32F103RC_SRC)
445 OLIMEXINO_SRC = startup_stm32f10x_md_gcc.S \
446 drivers/accgyro_mpu.c \
447 drivers/accgyro_mpu6050.c \
448 drivers/adc.c \
449 drivers/adc_stm32f10x.c \
450 drivers/barometer_bmp085.c \
451 drivers/barometer_bmp280.c \
452 drivers/bus_i2c_stm32f10x.c \
453 drivers/bus_spi.c \
454 drivers/compass_hmc5883l.c \
455 drivers/gpio_stm32f10x.c \
456 drivers/light_led_stm32f10x.c \
457 drivers/light_ws2811strip.c \
458 drivers/light_ws2811strip_stm32f10x.c \
459 drivers/pwm_mapping.c \
460 drivers/pwm_output.c \
461 drivers/pwm_rx.c \
462 drivers/serial_softserial.c \
463 drivers/serial_uart.c \
464 drivers/serial_uart_stm32f10x.c \
465 drivers/sonar_hcsr04.c \
466 drivers/sound_beeper_stm32f10x.c \
467 drivers/system_stm32f10x.c \
468 drivers/timer.c \
469 drivers/timer_stm32f10x.c \
470 $(HIGHEND_SRC) \
471 $(COMMON_SRC)
473 CJMCU_SRC = \
474 startup_stm32f10x_md_gcc.S \
475 drivers/adc.c \
476 drivers/adc_stm32f10x.c \
477 drivers/accgyro_mpu.c \
478 drivers/accgyro_mpu6050.c \
479 drivers/bus_i2c_stm32f10x.c \
480 drivers/compass_hmc5883l.c \
481 drivers/gpio_stm32f10x.c \
482 drivers/light_led_stm32f10x.c \
483 drivers/pwm_mapping.c \
484 drivers/pwm_output.c \
485 drivers/pwm_rx.c \
486 drivers/serial_uart.c \
487 drivers/serial_uart_stm32f10x.c \
488 drivers/sound_beeper_stm32f10x.c \
489 drivers/system_stm32f10x.c \
490 drivers/timer.c \
491 drivers/timer_stm32f10x.c \
492 hardware_revision.c \
493 flight/gtune.c \
494 blackbox/blackbox.c \
495 blackbox/blackbox_io.c \
496 $(COMMON_SRC)
498 CC3D_SRC = \
499 startup_stm32f10x_md_gcc.S \
500 drivers/accgyro_mpu.c \
501 drivers/accgyro_spi_mpu6000.c \
502 drivers/adc.c \
503 drivers/adc_stm32f10x.c \
504 drivers/barometer_bmp085.c \
505 drivers/barometer_bmp280.c \
506 drivers/barometer_ms5611.c \
507 drivers/bus_spi.c \
508 drivers/bus_i2c_stm32f10x.c \
509 drivers/compass_hmc5883l.c \
510 drivers/display_ug2864hsweg01.c \
511 drivers/flash_m25p16.c \
512 drivers/gpio_stm32f10x.c \
513 drivers/inverter.c \
514 drivers/light_led_stm32f10x.c \
515 drivers/light_ws2811strip.c \
516 drivers/light_ws2811strip_stm32f10x.c \
517 drivers/pwm_mapping.c \
518 drivers/pwm_output.c \
519 drivers/pwm_rx.c \
520 drivers/serial_softserial.c \
521 drivers/serial_uart.c \
522 drivers/serial_uart_stm32f10x.c \
523 drivers/sonar_hcsr04.c \
524 drivers/sound_beeper_stm32f10x.c \
525 drivers/system_stm32f10x.c \
526 drivers/timer.c \
527 drivers/timer_stm32f10x.c \
528 io/flashfs.c \
529 $(HIGHEND_SRC) \
530 $(COMMON_SRC) \
531 $(VCP_SRC)
533 STM32F30x_COMMON_SRC = \
534 startup_stm32f30x_md_gcc.S \
535 drivers/adc.c \
536 drivers/adc_stm32f30x.c \
537 drivers/bus_i2c_stm32f30x.c \
538 drivers/bus_spi.c \
539 drivers/display_ug2864hsweg01.h \
540 drivers/gpio_stm32f30x.c \
541 drivers/light_led_stm32f30x.c \
542 drivers/pwm_mapping.c \
543 drivers/pwm_output.c \
544 drivers/pwm_rx.c \
545 drivers/serial_uart.c \
546 drivers/serial_uart_stm32f30x.c \
547 drivers/sound_beeper_stm32f30x.c \
548 drivers/system_stm32f30x.c \
549 drivers/timer.c \
550 drivers/timer_stm32f30x.c
552 NAZE32PRO_SRC = \
553 $(STM32F30x_COMMON_SRC) \
554 $(HIGHEND_SRC) \
555 $(COMMON_SRC) \
556 $(VCP_SRC)
558 STM32F3DISCOVERY_COMMON_SRC = \
559 $(STM32F30x_COMMON_SRC) \
560 drivers/light_ws2811strip.c \
561 drivers/light_ws2811strip_stm32f30x.c \
562 drivers/accgyro_l3gd20.c \
563 drivers/accgyro_l3gd20.c \
564 drivers/accgyro_lsm303dlhc.c \
565 drivers/compass_hmc5883l.c \
566 $(VCP_SRC)
568 STM32F3DISCOVERY_SRC = \
569 $(STM32F3DISCOVERY_COMMON_SRC) \
570 drivers/accgyro_adxl345.c \
571 drivers/accgyro_bma280.c \
572 drivers/accgyro_mma845x.c \
573 drivers/accgyro_mpu.c \
574 drivers/accgyro_mpu3050.c \
575 drivers/accgyro_mpu6050.c \
576 drivers/accgyro_l3g4200d.c \
577 drivers/barometer_ms5611.c \
578 drivers/barometer_bmp280.c \
579 drivers/compass_ak8975.c \
580 drivers/sdcard.c \
581 drivers/sdcard_standard.c \
582 io/asyncfatfs/asyncfatfs.c \
583 io/asyncfatfs/fat_standard.c \
584 $(HIGHEND_SRC) \
585 $(COMMON_SRC)
587 CHEBUZZF3_SRC = \
588 $(STM32F3DISCOVERY_SRC) \
589 $(HIGHEND_SRC) \
590 $(COMMON_SRC)
592 COLIBRI_RACE_SRC = \
593 $(STM32F30x_COMMON_SRC) \
594 io/i2c_bst.c \
595 drivers/bus_bst_stm32f30x.c \
596 drivers/accgyro_mpu.c \
597 drivers/accgyro_mpu6500.c \
598 drivers/accgyro_spi_mpu6500.c \
599 drivers/accgyro_mpu6500.c \
600 drivers/barometer_ms5611.c \
601 drivers/compass_ak8975.c \
602 drivers/compass_hmc5883l.c \
603 drivers/display_ug2864hsweg01.c \
604 drivers/light_ws2811strip.c \
605 drivers/light_ws2811strip_stm32f30x.c \
606 drivers/serial_usb_vcp.c \
607 $(HIGHEND_SRC) \
608 $(COMMON_SRC) \
609 $(VCP_SRC)
611 LUX_RACE_SRC = \
612 $(STM32F30x_COMMON_SRC) \
613 drivers/accgyro_mpu.c \
614 drivers/accgyro_mpu6500.c \
615 drivers/accgyro_spi_mpu6500.c \
616 drivers/accgyro_mpu6500.c \
617 drivers/light_ws2811strip.c \
618 drivers/light_ws2811strip_stm32f30x.c \
619 drivers/serial_usb_vcp.c \
620 $(HIGHEND_SRC) \
621 $(COMMON_SRC) \
622 $(VCP_SRC)
624 SPARKY_SRC = \
625 $(STM32F30x_COMMON_SRC) \
626 drivers/display_ug2864hsweg01.c \
627 drivers/accgyro_mpu.c \
628 drivers/accgyro_mpu6050.c \
629 drivers/barometer_ms5611.c \
630 drivers/barometer_bmp280.c \
631 drivers/compass_ak8975.c \
632 drivers/light_ws2811strip.c \
633 drivers/light_ws2811strip_stm32f30x.c \
634 drivers/serial_usb_vcp.c \
635 $(HIGHEND_SRC) \
636 $(COMMON_SRC) \
637 $(VCP_SRC)
639 ALIENFLIGHTF3_SRC = \
640 $(STM32F30x_COMMON_SRC) \
641 drivers/accgyro_mpu.c \
642 drivers/accgyro_mpu6050.c \
643 drivers/accgyro_mpu.c \
644 drivers/accgyro_mpu6500.c \
645 drivers/accgyro_spi_mpu6500.c \
646 drivers/compass_ak8963.c \
647 hardware_revision.c \
648 drivers/serial_usb_vcp.c \
649 drivers/sonar_hcsr04.c \
650 $(HIGHEND_SRC) \
651 $(COMMON_SRC) \
652 $(VCP_SRC)
654 RMDO_SRC = \
655 $(STM32F30x_COMMON_SRC) \
656 drivers/accgyro_mpu.c \
657 drivers/accgyro_mpu6050.c \
658 drivers/barometer_bmp280.c \
659 drivers/display_ug2864hsweg01.h \
660 drivers/flash_m25p16.c \
661 drivers/light_ws2811strip.c \
662 drivers/light_ws2811strip_stm32f30x.c \
663 drivers/serial_softserial.c \
664 drivers/sonar_hcsr04.c \
665 io/flashfs.c \
666 $(HIGHEND_SRC) \
667 $(COMMON_SRC)
669 SPRACINGF3_SRC = \
670 $(STM32F30x_COMMON_SRC) \
671 drivers/accgyro_mpu.c \
672 drivers/accgyro_mpu6050.c \
673 drivers/barometer_ms5611.c \
674 drivers/compass_ak8975.c \
675 drivers/barometer_bmp085.c \
676 drivers/barometer_bmp280.c \
677 drivers/compass_hmc5883l.c \
678 drivers/display_ug2864hsweg01.h \
679 drivers/flash_m25p16.c \
680 drivers/light_ws2811strip.c \
681 drivers/light_ws2811strip_stm32f30x.c \
682 drivers/serial_softserial.c \
683 drivers/sonar_hcsr04.c \
684 io/flashfs.c \
685 $(HIGHEND_SRC) \
686 $(COMMON_SRC)
688 IRCFUSIONF3_SRC = \
689 $(STM32F30x_COMMON_SRC) \
690 drivers/accgyro_mpu.c \
691 drivers/accgyro_mpu6050.c \
692 drivers/barometer_ms5611.c \
693 drivers/compass_ak8975.c \
694 drivers/barometer_bmp085.c \
695 drivers/barometer_bmp280.c \
696 drivers/compass_hmc5883l.c \
697 drivers/display_ug2864hsweg01.h \
698 drivers/flash_m25p16.c \
699 drivers/light_ws2811strip.c \
700 drivers/light_ws2811strip_stm32f30x.c \
701 drivers/serial_softserial.c \
702 drivers/sonar_hcsr04.c \
703 io/flashfs.c \
704 $(HIGHEND_SRC) \
705 $(COMMON_SRC)
707 MOTOLAB_SRC = \
708 $(STM32F30x_COMMON_SRC) \
709 drivers/accgyro_mpu.c \
710 drivers/display_ug2864hsweg01.c \
711 drivers/accgyro_mpu6050.c \
712 drivers/accgyro_spi_mpu6000.c \
713 drivers/barometer_ms5611.c \
714 drivers/compass_hmc5883l.c \
715 drivers/light_ws2811strip.c \
716 drivers/light_ws2811strip_stm32f30x.c \
717 drivers/serial_softserial.c \
718 drivers/serial_usb_vcp.c \
719 drivers/flash_m25p16.c \
720 io/flashfs.c \
721 $(HIGHEND_SRC) \
722 $(COMMON_SRC) \
723 $(VCP_SRC)
725 SPRACINGF3MINI_SRC = \
726 $(STM32F30x_COMMON_SRC) \
727 drivers/accgyro_mpu.c \
728 drivers/accgyro_mpu6500.c \
729 drivers/barometer_bmp280.c \
730 drivers/compass_ak8975.c \
731 drivers/compass_hmc5883l.c \
732 drivers/display_ug2864hsweg01.h \
733 drivers/flash_m25p16.c \
734 drivers/light_ws2811strip.c \
735 drivers/light_ws2811strip_stm32f30x.c \
736 drivers/serial_softserial.c \
737 drivers/serial_usb_vcp.c \
738 drivers/sonar_hcsr04.c \
739 drivers/sdcard.c \
740 drivers/sdcard_standard.c \
741 drivers/transponder_ir.c \
742 drivers/transponder_ir_stm32f30x.c \
743 io/asyncfatfs/asyncfatfs.c \
744 io/asyncfatfs/fat_standard.c \
745 io/transponder_ir.c \
746 $(HIGHEND_SRC) \
747 $(COMMON_SRC) \
748 $(VCP_SRC)
749 # $(FATFS_SRC)
751 # Search path and source files for the ST stdperiph library
752 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
754 ###############################################################################
755 # Things that might need changing to use different tools
758 # Tool names
759 CC = arm-none-eabi-gcc
760 OBJCOPY = arm-none-eabi-objcopy
761 SIZE = arm-none-eabi-size
764 # Tool options.
767 ifeq ($(DEBUG),GDB)
768 OPTIMIZE = -O0
769 LTO_FLAGS = $(OPTIMIZE)
770 else
771 OPTIMIZE = -Os
772 LTO_FLAGS = -flto -fuse-linker-plugin $(OPTIMIZE)
773 endif
775 DEBUG_FLAGS = -ggdb3 -DDEBUG
777 CFLAGS = $(ARCH_FLAGS) \
778 $(LTO_FLAGS) \
779 $(addprefix -D,$(OPTIONS)) \
780 $(addprefix -I,$(INCLUDE_DIRS)) \
781 $(DEBUG_FLAGS) \
782 -std=gnu99 \
783 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
784 -ffunction-sections \
785 -fdata-sections \
786 $(DEVICE_FLAGS) \
787 -DUSE_STDPERIPH_DRIVER \
788 $(TARGET_FLAGS) \
789 -D'__FORKNAME__="$(FORKNAME)"' \
790 -D'__TARGET__="$(TARGET)"' \
791 -D'__REVISION__="$(REVISION)"' \
792 -save-temps=obj \
793 -MMD -MP
795 ASFLAGS = $(ARCH_FLAGS) \
796 -x assembler-with-cpp \
797 $(addprefix -I,$(INCLUDE_DIRS)) \
798 -MMD -MP
800 LDFLAGS = -lm \
801 -nostartfiles \
802 --specs=nano.specs \
803 -lc \
804 -lnosys \
805 $(ARCH_FLAGS) \
806 $(LTO_FLAGS) \
807 $(DEBUG_FLAGS) \
808 -static \
809 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
810 -Wl,-L$(LINKER_DIR) \
811 -Wl,--cref \
812 -T$(LD_SCRIPT)
814 ###############################################################################
815 # No user-serviceable parts below
816 ###############################################################################
818 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
819 --std=c99 --inline-suppr --quiet --force \
820 $(addprefix -I,$(INCLUDE_DIRS)) \
821 -I/usr/include -I/usr/include/linux
824 # Things we will build
826 ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
827 $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS))
828 endif
830 CC3D_OPBL_SRC = $(CC3D_SRC)
832 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).bin
833 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(FC_VER)_$(TARGET).hex
834 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
835 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
836 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
837 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
840 ifeq ($(OPBL),yes)
841 CLEAN_ARTIFACTS := $(TARGET_BIN)
842 else
843 CLEAN_ARTIFACTS := $(TARGET_HEX)
844 endif
845 CLEAN_ARTIFACTS += $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
847 # List of buildable ELF files and their object dependencies.
848 # It would be nice to compute these lists, but that seems to be just beyond make.
850 $(TARGET_HEX): $(TARGET_ELF)
851 $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
853 $(TARGET_BIN): $(TARGET_ELF)
854 $(OBJCOPY) -O binary $< $@
856 $(TARGET_ELF): $(TARGET_OBJS)
857 $(CC) -o $@ $^ $(LDFLAGS)
858 $(SIZE) $(TARGET_ELF)
860 # Compile
861 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
862 @mkdir -p $(dir $@)
863 @echo %% $(notdir $<)
864 @$(CC) -c -o $@ $(CFLAGS) $<
866 # Assemble
867 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
868 @mkdir -p $(dir $@)
869 @echo %% $(notdir $<)
870 @$(CC) -c -o $@ $(ASFLAGS) $<
872 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
873 @mkdir -p $(dir $@)
874 @echo %% $(notdir $<)
875 @$(CC) -c -o $@ $(ASFLAGS) $<
878 ## all : default task; compile C code, build firmware
879 all: binary
881 ## clean : clean up all temporary / machine-generated files
882 clean:
883 rm -f $(CLEAN_ARTIFACTS)
884 rm -rf $(OBJECT_DIR)/$(TARGET)
885 cd src/test && $(MAKE) clean || true
887 flash_$(TARGET): $(TARGET_HEX)
888 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
889 echo -n 'R' >$(SERIAL_DEVICE)
890 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
892 ## flash : flash firmware (.hex) onto flight controller
893 flash: flash_$(TARGET)
895 st-flash_$(TARGET): $(TARGET_BIN)
896 st-flash --reset write $< 0x08000000
898 ## st-flash : flash firmware (.bin) onto flight controller
899 st-flash: st-flash_$(TARGET)
901 binary: $(TARGET_BIN)
902 hex: $(TARGET_HEX)
904 unbrick_$(TARGET): $(TARGET_HEX)
905 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
906 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
908 ## unbrick : unbrick flight controller
909 unbrick: unbrick_$(TARGET)
911 ## cppcheck : run static analysis on C source code
912 cppcheck: $(CSOURCES)
913 $(CPPCHECK)
915 cppcheck-result.xml: $(CSOURCES)
916 $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
918 ## help : print this help message and exit
919 help: Makefile
920 @echo ""
921 @echo "Makefile for the $(FORKNAME) firmware"
922 @echo ""
923 @echo "Usage:"
924 @echo " make [TARGET=<target>] [OPTIONS=\"<options>\"]"
925 @echo ""
926 @echo "Valid TARGET values are: $(VALID_TARGETS)"
927 @echo ""
928 @sed -n 's/^## //p' $<
930 ## test : run the cleanflight test suite
931 test:
932 cd src/test && $(MAKE) test || true
934 # rebuild everything when makefile changes
935 $(TARGET_OBJS) : Makefile
937 # include auto-generated dependencies
938 -include $(TARGET_DEPS)