Timeout issue at exit/switch ESC channel fixed
[betaflight.git] / Makefile
blob91e7186706d3b2a5e4cd6705517a7dd7a3563c64
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 ###############################################################################
14 # Things that the user might override on the commandline
17 # The target to build, see VALID_TARGETS below
18 TARGET ?= NAZE
20 # Compile-time options
21 OPTIONS ?=
23 # compile for OpenPilot BootLoader support
24 OPBL ?=no
26 # Debugger optons, must be empty or GDB
27 DEBUG ?=
29 # Serial port/Device for flashing
30 SERIAL_DEVICE ?= $(firstword $(wildcard /dev/ttyUSB*) no-port-found)
32 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
33 FLASH_SIZE ?=
35 ###############################################################################
36 # Things that need to be maintained as the source changes
39 FORKNAME = betaflight
41 VALID_TARGETS = NAZE NAZE32PRO OLIMEXINO STM32F3DISCOVERY CHEBUZZF3 CC3D CJMCU EUSTM32F103RC SPRACINGF3 PORT103R SPARKY ALIENWIIF1 ALIENWIIF3 COLIBRI_RACE MOTOLAB
43 # Valid targets for OP BootLoader support
44 OPBL_VALID_TARGETS = CC3D
46 # Configure default flash sizes for the targets
47 ifeq ($(FLASH_SIZE),)
48 ifeq ($(TARGET),$(filter $(TARGET),CJMCU))
49 FLASH_SIZE = 64
50 else ifeq ($(TARGET),$(filter $(TARGET),NAZE CC3D ALIENWIIF1 OLIMEXINO))
51 FLASH_SIZE = 128
52 else ifeq ($(TARGET),$(filter $(TARGET),EUSTM32F103RC PORT103R STM32F3DISCOVERY CHEBUZZF3 NAZE32PRO SPRACINGF3 SPARKY ALIENWIIF3 COLIBRI_RACE MOTOLAB))
53 FLASH_SIZE = 256
54 else
55 $(error FLASH_SIZE not configured for target)
56 endif
57 endif
59 REVISION = $(shell git log -1 --format="%h")
61 # Working directories
62 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
63 SRC_DIR = $(ROOT)/src/main
64 OBJECT_DIR = $(ROOT)/obj/main
65 BIN_DIR = $(ROOT)/obj
66 CMSIS_DIR = $(ROOT)/lib/main/CMSIS
67 INCLUDE_DIRS = $(SRC_DIR)
68 LINKER_DIR = $(ROOT)/src/main/target
70 # Search path for sources
71 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
72 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
73 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
75 ifeq ($(TARGET),$(filter $(TARGET),STM32F3DISCOVERY CHEBUZZF3 NAZE32PRO SPRACINGF3 SPARKY ALIENWIIF3 COLIBRI_RACE MOTOLAB))
77 CSOURCES := $(shell find $(SRC_DIR) -name '*.c')
79 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver
81 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
83 EXCLUDES = stm32f30x_crc.c \
84 stm32f30x_can.c
86 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
88 DEVICE_STDPERIPH_SRC = \
89 $(STDPERIPH_SRC)
92 VPATH := $(VPATH):$(CMSIS_DIR)/CM1/CoreSupport:$(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
93 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM1/CoreSupport/*.c \
94 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x/*.c))
96 INCLUDE_DIRS := $(INCLUDE_DIRS) \
97 $(STDPERIPH_DIR)/inc \
98 $(CMSIS_DIR)/CM1/CoreSupport \
99 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
101 ifneq ($(TARGET),SPRACINGF3)
102 INCLUDE_DIRS := $(INCLUDE_DIRS) \
103 $(USBFS_DIR)/inc \
104 $(ROOT)/src/main/vcp
106 VPATH := $(VPATH):$(USBFS_DIR)/src
108 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC)\
109 $(USBPERIPH_SRC)
111 endif
113 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k.ld
115 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
116 DEVICE_FLAGS = -DSTM32F303xC -DSTM32F303
117 TARGET_FLAGS = -D$(TARGET)
118 ifeq ($(TARGET),CHEBUZZF3)
119 # CHEBUZZ is a VARIANT of STM32F3DISCOVERY
120 TARGET_FLAGS := $(TARGET_FLAGS) -DSTM32F3DISCOVERY
121 endif
123 else ifeq ($(TARGET),$(filter $(TARGET),EUSTM32F103RC PORT103R))
126 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
128 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
130 EXCLUDES = stm32f10x_crc.c \
131 stm32f10x_cec.c \
132 stm32f10x_can.c
134 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
136 # Search path and source files for the CMSIS sources
137 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
138 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
139 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
141 INCLUDE_DIRS := $(INCLUDE_DIRS) \
142 $(STDPERIPH_DIR)/inc \
143 $(CMSIS_DIR)/CM3/CoreSupport \
144 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \
146 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
148 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
149 TARGET_FLAGS = -D$(TARGET) -pedantic
150 DEVICE_FLAGS = -DSTM32F10X_HD -DSTM32F10X
152 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
154 else
156 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
158 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
160 EXCLUDES = stm32f10x_crc.c \
161 stm32f10x_cec.c \
162 stm32f10x_can.c
164 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
166 # Search path and source files for the CMSIS sources
167 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
168 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
169 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
171 INCLUDE_DIRS := $(INCLUDE_DIRS) \
172 $(STDPERIPH_DIR)/inc \
173 $(CMSIS_DIR)/CM3/CoreSupport \
174 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \
176 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
178 ifeq ($(TARGET),CC3D)
179 INCLUDE_DIRS := $(INCLUDE_DIRS) \
180 $(USBFS_DIR)/inc \
181 $(ROOT)/src/main/vcp
183 VPATH := $(VPATH):$(USBFS_DIR)/src
185 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
186 $(USBPERIPH_SRC)
188 endif
190 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
192 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
193 TARGET_FLAGS = -D$(TARGET) -pedantic
194 DEVICE_FLAGS = -DSTM32F10X_MD -DSTM32F10X
196 endif
198 ifneq ($(FLASH_SIZE),)
199 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
200 endif
202 TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
203 TARGET_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
205 ifeq ($(TARGET),ALIENWIIF1)
206 # ALIENWIIF1 is a VARIANT of NAZE
207 TARGET_FLAGS := $(TARGET_FLAGS) -DNAZE -DALIENWII32
208 TARGET_DIR = $(ROOT)/src/main/target/NAZE
209 endif
211 INCLUDE_DIRS := $(INCLUDE_DIRS) \
212 $(TARGET_DIR)
214 VPATH := $(VPATH):$(TARGET_DIR)
216 COMMON_SRC = build_config.c \
217 debug.c \
218 version.c \
219 $(TARGET_SRC) \
220 config/config.c \
221 config/runtime_config.c \
222 common/maths.c \
223 common/printf.c \
224 common/typeconversion.c \
225 common/encoding.c \
226 common/filter.c \
227 main.c \
228 mw.c \
229 flight/altitudehold.c \
230 flight/failsafe.c \
231 flight/pid.c \
232 flight/imu.c \
233 flight/mixer.c \
234 flight/lowpass.c \
235 drivers/bus_i2c_soft.c \
236 drivers/serial.c \
237 drivers/sound_beeper.c \
238 drivers/system.c \
239 drivers/gyro_sync.c \
240 io/beeper.c \
241 io/rc_controls.c \
242 io/rc_curves.c \
243 io/serial.c \
244 io/serial_1wire.c \
245 io/serial_cli.c \
246 io/serial_msp.c \
247 io/statusindicator.c \
248 rx/rx.c \
249 rx/pwm.c \
250 rx/msp.c \
251 rx/sbus.c \
252 rx/sumd.c \
253 rx/sumh.c \
254 rx/spektrum.c \
255 rx/xbus.c \
256 sensors/acceleration.c \
257 sensors/battery.c \
258 sensors/boardalignment.c \
259 sensors/compass.c \
260 sensors/gyro.c \
261 sensors/initialisation.c \
262 $(CMSIS_SRC) \
263 $(DEVICE_STDPERIPH_SRC)
265 HIGHEND_SRC = flight/autotune.c \
266 flight/navigation.c \
267 flight/gps_conversion.c \
268 common/colorconversion.c \
269 io/gps.c \
270 io/ledstrip.c \
271 io/display.c \
272 telemetry/telemetry.c \
273 telemetry/frsky.c \
274 telemetry/hott.c \
275 telemetry/msp.c \
276 telemetry/smartport.c \
277 sensors/sonar.c \
278 sensors/barometer.c \
279 blackbox/blackbox.c \
280 blackbox/blackbox_io.c
282 VCP_SRC = \
283 vcp/hw_config.c \
284 vcp/stm32_it.c \
285 vcp/usb_desc.c \
286 vcp/usb_endp.c \
287 vcp/usb_istr.c \
288 vcp/usb_prop.c \
289 vcp/usb_pwr.c \
290 drivers/serial_usb_vcp.c
292 NAZE_SRC = startup_stm32f10x_md_gcc.S \
293 drivers/accgyro_adxl345.c \
294 drivers/accgyro_bma280.c \
295 drivers/accgyro_l3g4200d.c \
296 drivers/accgyro_mma845x.c \
297 drivers/accgyro_mpu3050.c \
298 drivers/accgyro_mpu6050.c \
299 drivers/accgyro_spi_mpu6500.c \
300 drivers/adc.c \
301 drivers/adc_stm32f10x.c \
302 drivers/barometer_bmp085.c \
303 drivers/barometer_bmp280.c \
304 drivers/barometer_ms5611.c \
305 drivers/bus_spi.c \
306 drivers/bus_i2c_stm32f10x.c \
307 drivers/compass_hmc5883l.c \
308 drivers/display_ug2864hsweg01.h \
309 drivers/flash_m25p16.c \
310 drivers/gpio_stm32f10x.c \
311 drivers/inverter.c \
312 drivers/light_led_stm32f10x.c \
313 drivers/light_ws2811strip.c \
314 drivers/light_ws2811strip_stm32f10x.c \
315 drivers/sonar_hcsr04.c \
316 drivers/pwm_mapping.c \
317 drivers/pwm_output.c \
318 drivers/pwm_rx.c \
319 drivers/serial_softserial.c \
320 drivers/serial_uart.c \
321 drivers/serial_uart_stm32f10x.c \
322 drivers/sound_beeper_stm32f10x.c \
323 drivers/system_stm32f10x.c \
324 drivers/timer.c \
325 drivers/timer_stm32f10x.c \
326 io/flashfs.c \
327 hardware_revision.c \
328 $(HIGHEND_SRC) \
329 $(COMMON_SRC)
331 ALIENWIIF1_SRC = $(NAZE_SRC)
333 EUSTM32F103RC_SRC = startup_stm32f10x_hd_gcc.S \
334 drivers/accgyro_adxl345.c \
335 drivers/accgyro_bma280.c \
336 drivers/accgyro_l3g4200d.c \
337 drivers/accgyro_mma845x.c \
338 drivers/accgyro_mpu3050.c \
339 drivers/accgyro_mpu6050.c \
340 drivers/accgyro_spi_mpu6000.c \
341 drivers/accgyro_spi_mpu6500.c \
342 drivers/adc.c \
343 drivers/adc_stm32f10x.c \
344 drivers/barometer_bmp085.c \
345 drivers/barometer_bmp280.c \
346 drivers/barometer_ms5611.c \
347 drivers/bus_i2c_stm32f10x.c \
348 drivers/bus_spi.c \
349 drivers/compass_ak8975.c \
350 drivers/compass_hmc5883l.c \
351 drivers/display_ug2864hsweg01.c \
352 drivers/flash_m25p16.c \
353 drivers/gpio_stm32f10x.c \
354 drivers/inverter.c \
355 drivers/light_led_stm32f10x.c \
356 drivers/light_ws2811strip.c \
357 drivers/light_ws2811strip_stm32f10x.c \
358 drivers/pwm_mapping.c \
359 drivers/pwm_output.c \
360 drivers/pwm_rx.c \
361 drivers/serial_softserial.c \
362 drivers/serial_uart.c \
363 drivers/serial_uart_stm32f10x.c \
364 drivers/sonar_hcsr04.c \
365 drivers/sound_beeper_stm32f10x.c \
366 drivers/system_stm32f10x.c \
367 drivers/timer.c \
368 drivers/timer_stm32f10x.c \
369 io/flashfs.c \
370 $(HIGHEND_SRC) \
371 $(COMMON_SRC)
373 PORT103R_SRC = $(EUSTM32F103RC_SRC)
375 OLIMEXINO_SRC = startup_stm32f10x_md_gcc.S \
376 drivers/accgyro_mpu6050.c \
377 drivers/adc.c \
378 drivers/adc_stm32f10x.c \
379 drivers/barometer_bmp085.c \
380 drivers/barometer_bmp280.c \
381 drivers/bus_i2c_stm32f10x.c \
382 drivers/bus_spi.c \
383 drivers/compass_hmc5883l.c \
384 drivers/gpio_stm32f10x.c \
385 drivers/light_led_stm32f10x.c \
386 drivers/light_ws2811strip.c \
387 drivers/light_ws2811strip_stm32f10x.c \
388 drivers/pwm_mapping.c \
389 drivers/pwm_output.c \
390 drivers/pwm_rx.c \
391 drivers/serial_softserial.c \
392 drivers/serial_uart.c \
393 drivers/serial_uart_stm32f10x.c \
394 drivers/sonar_hcsr04.c \
395 drivers/sound_beeper_stm32f10x.c \
396 drivers/system_stm32f10x.c \
397 drivers/timer.c \
398 drivers/timer_stm32f10x.c \
399 $(HIGHEND_SRC) \
400 $(COMMON_SRC)
402 ifeq ($(OPBL),yes)
403 ifneq ($(filter $(TARGET),$(OPBL_VALID_TARGETS)),)
404 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
405 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k_opbl.ld
406 .DEFAULT_GOAL := binary
407 else
408 $(error OPBL specified with a unsupported target)
409 endif
410 endif
412 CJMCU_SRC = \
413 startup_stm32f10x_md_gcc.S \
414 drivers/adc.c \
415 drivers/adc_stm32f10x.c \
416 drivers/accgyro_mpu6050.c \
417 drivers/bus_i2c_stm32f10x.c \
418 drivers/compass_hmc5883l.c \
419 drivers/gpio_stm32f10x.c \
420 drivers/light_led_stm32f10x.c \
421 drivers/pwm_mapping.c \
422 drivers/pwm_output.c \
423 drivers/pwm_rx.c \
424 drivers/serial_uart.c \
425 drivers/serial_uart_stm32f10x.c \
426 drivers/sound_beeper_stm32f10x.c \
427 drivers/system_stm32f10x.c \
428 drivers/timer.c \
429 drivers/timer_stm32f10x.c \
430 hardware_revision.c \
431 blackbox/blackbox.c \
432 blackbox/blackbox_io.c \
433 $(COMMON_SRC)
435 CC3D_SRC = \
436 startup_stm32f10x_md_gcc.S \
437 drivers/accgyro_spi_mpu6000.c \
438 drivers/adc.c \
439 drivers/adc_stm32f10x.c \
440 drivers/barometer_bmp085.c \
441 drivers/barometer_bmp280.c \
442 drivers/barometer_ms5611.c \
443 drivers/bus_spi.c \
444 drivers/bus_i2c_stm32f10x.c \
445 drivers/compass_hmc5883l.c \
446 drivers/display_ug2864hsweg01.c \
447 drivers/flash_m25p16.c \
448 drivers/gpio_stm32f10x.c \
449 drivers/inverter.c \
450 drivers/light_led_stm32f10x.c \
451 drivers/light_ws2811strip.c \
452 drivers/light_ws2811strip_stm32f10x.c \
453 drivers/pwm_mapping.c \
454 drivers/pwm_output.c \
455 drivers/pwm_rx.c \
456 drivers/serial_softserial.c \
457 drivers/serial_uart.c \
458 drivers/serial_uart_stm32f10x.c \
459 drivers/sonar_hcsr04.c \
460 drivers/sound_beeper_stm32f10x.c \
461 drivers/system_stm32f10x.c \
462 drivers/timer.c \
463 drivers/timer_stm32f10x.c \
464 io/flashfs.c \
465 $(HIGHEND_SRC) \
466 $(COMMON_SRC) \
467 $(VCP_SRC)
469 STM32F30x_COMMON_SRC = \
470 startup_stm32f30x_md_gcc.S \
471 drivers/adc.c \
472 drivers/adc_stm32f30x.c \
473 drivers/bus_i2c_stm32f30x.c \
474 drivers/bus_spi.c \
475 drivers/gpio_stm32f30x.c \
476 drivers/light_led_stm32f30x.c \
477 drivers/light_ws2811strip.c \
478 drivers/light_ws2811strip_stm32f30x.c \
479 drivers/pwm_mapping.c \
480 drivers/pwm_output.c \
481 drivers/pwm_rx.c \
482 drivers/serial_uart.c \
483 drivers/serial_uart_stm32f30x.c \
484 drivers/sound_beeper_stm32f30x.c \
485 drivers/system_stm32f30x.c \
486 drivers/timer.c \
487 drivers/timer_stm32f30x.c
489 NAZE32PRO_SRC = \
490 $(STM32F30x_COMMON_SRC) \
491 $(HIGHEND_SRC) \
492 $(COMMON_SRC) \
493 $(VCP_SRC)
495 STM32F3DISCOVERY_COMMON_SRC = \
496 $(STM32F30x_COMMON_SRC) \
497 drivers/accgyro_l3gd20.c \
498 drivers/accgyro_l3gd20.c \
499 drivers/accgyro_lsm303dlhc.c \
500 drivers/compass_hmc5883l.c \
501 $(VCP_SRC)
503 STM32F3DISCOVERY_SRC = \
504 $(STM32F3DISCOVERY_COMMON_SRC) \
505 drivers/accgyro_adxl345.c \
506 drivers/accgyro_bma280.c \
507 drivers/accgyro_mma845x.c \
508 drivers/accgyro_mpu3050.c \
509 drivers/accgyro_mpu6050.c \
510 drivers/accgyro_l3g4200d.c \
511 drivers/barometer_ms5611.c \
512 drivers/barometer_bmp280.c \
513 drivers/compass_ak8975.c \
514 $(HIGHEND_SRC) \
515 $(COMMON_SRC)
517 CHEBUZZF3_SRC = \
518 $(STM32F3DISCOVERY_SRC) \
519 $(HIGHEND_SRC) \
520 $(COMMON_SRC)
522 COLIBRI_RACE_SRC = \
523 $(STM32F30x_COMMON_SRC) \
524 drivers/display_ug2864hsweg01.c \
525 drivers/accgyro_spi_mpu6500.c \
526 drivers/barometer_ms5611.c \
527 drivers/compass_ak8975.c \
528 drivers/compass_hmc5883l.c \
529 drivers/serial_usb_vcp.c \
530 $(HIGHEND_SRC) \
531 $(COMMON_SRC) \
532 $(VCP_SRC)
534 SPARKY_SRC = \
535 $(STM32F30x_COMMON_SRC) \
536 drivers/display_ug2864hsweg01.c \
537 drivers/accgyro_mpu6050.c \
538 drivers/barometer_ms5611.c \
539 drivers/barometer_bmp280.c \
540 drivers/compass_ak8975.c \
541 drivers/serial_usb_vcp.c \
542 $(HIGHEND_SRC) \
543 $(COMMON_SRC) \
544 $(VCP_SRC)
546 ALIENWIIF3_SRC = $(SPARKY_SRC)
548 SPRACINGF3_SRC = \
549 $(STM32F30x_COMMON_SRC) \
550 drivers/accgyro_mpu6050.c \
551 drivers/barometer_ms5611.c \
552 drivers/compass_ak8975.c \
553 drivers/barometer_bmp280.c \
554 drivers/compass_hmc5883l.c \
555 drivers/display_ug2864hsweg01.h \
556 drivers/flash_m25p16.c \
557 drivers/serial_softserial.c \
558 drivers/sonar_hcsr04.c \
559 io/flashfs.c \
560 $(HIGHEND_SRC) \
561 $(COMMON_SRC)
563 MOTOLAB_SRC = \
564 $(STM32F30x_COMMON_SRC) \
565 drivers/display_ug2864hsweg01.c \
566 drivers/accgyro_mpu6050.c \
567 drivers/barometer_ms5611.c \
568 drivers/compass_hmc5883l.c \
569 drivers/serial_usb_vcp.c \
570 drivers/flash_m25p16.c \
571 io/flashfs.c \
572 $(HIGHEND_SRC) \
573 $(COMMON_SRC) \
574 $(VCP_SRC)
576 # Search path and source files for the ST stdperiph library
577 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
579 ###############################################################################
580 # Things that might need changing to use different tools
583 # Tool names
584 CC = arm-none-eabi-gcc
585 OBJCOPY = arm-none-eabi-objcopy
586 SIZE = arm-none-eabi-size
589 # Tool options.
592 ifeq ($(DEBUG),GDB)
593 OPTIMIZE = -O0
594 LTO_FLAGS = $(OPTIMIZE)
595 else
596 OPTIMIZE = -Os
597 LTO_FLAGS = -flto -fuse-linker-plugin $(OPTIMIZE)
598 endif
600 DEBUG_FLAGS = -ggdb3 -DDEBUG
602 CFLAGS = $(ARCH_FLAGS) \
603 $(LTO_FLAGS) \
604 $(addprefix -D,$(OPTIONS)) \
605 $(addprefix -I,$(INCLUDE_DIRS)) \
606 $(DEBUG_FLAGS) \
607 -std=gnu99 \
608 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
609 -ffunction-sections \
610 -fdata-sections \
611 $(DEVICE_FLAGS) \
612 -DUSE_STDPERIPH_DRIVER \
613 $(TARGET_FLAGS) \
614 -D'__FORKNAME__="$(FORKNAME)"' \
615 -D'__TARGET__="$(TARGET)"' \
616 -D'__REVISION__="$(REVISION)"' \
617 -save-temps=obj \
618 -MMD -MP
620 ASFLAGS = $(ARCH_FLAGS) \
621 -x assembler-with-cpp \
622 $(addprefix -I,$(INCLUDE_DIRS)) \
623 -MMD -MP
625 LDFLAGS = -lm \
626 -nostartfiles \
627 --specs=nano.specs \
628 -lc \
629 -lnosys \
630 $(ARCH_FLAGS) \
631 $(LTO_FLAGS) \
632 $(DEBUG_FLAGS) \
633 -static \
634 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
635 -Wl,-L$(LINKER_DIR) \
636 -Wl,--cref \
637 -T$(LD_SCRIPT)
639 ###############################################################################
640 # No user-serviceable parts below
641 ###############################################################################
643 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
644 --std=c99 --inline-suppr --quiet --force \
645 $(addprefix -I,$(INCLUDE_DIRS)) \
646 -I/usr/include -I/usr/include/linux
649 # Things we will build
651 ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
652 $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS))
653 endif
655 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(TARGET).bin
656 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(TARGET).hex
657 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
658 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
659 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
660 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
662 # List of buildable ELF files and their object dependencies.
663 # It would be nice to compute these lists, but that seems to be just beyond make.
665 $(TARGET_HEX): $(TARGET_ELF)
666 $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
668 $(TARGET_BIN): $(TARGET_ELF)
669 $(OBJCOPY) -O binary $< $@
671 $(TARGET_ELF): $(TARGET_OBJS)
672 $(CC) -o $@ $^ $(LDFLAGS)
673 $(SIZE) $(TARGET_ELF)
675 # Compile
676 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
677 @mkdir -p $(dir $@)
678 @echo %% $(notdir $<)
679 @$(CC) -c -o $@ $(CFLAGS) $<
681 # Assemble
682 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
683 @mkdir -p $(dir $@)
684 @echo %% $(notdir $<)
685 @$(CC) -c -o $@ $(ASFLAGS) $<
687 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
688 @mkdir -p $(dir $@)
689 @echo %% $(notdir $<)
690 @$(CC) -c -o $@ $(ASFLAGS) $<
692 clean:
693 rm -f $(TARGET_BIN) $(TARGET_HEX) $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
694 rm -rf $(OBJECT_DIR)/$(TARGET)
695 cd src/test && $(MAKE) clean || true
697 flash_$(TARGET): $(TARGET_HEX)
698 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
699 echo -n 'R' >$(SERIAL_DEVICE)
700 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
702 flash: flash_$(TARGET)
704 st-flash_$(TARGET): $(TARGET_BIN)
705 st-flash --reset write $< 0x08000000
707 st-flash: st-flash_$(TARGET)
709 binary: $(TARGET_BIN)
711 unbrick_$(TARGET): $(TARGET_HEX)
712 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
713 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
715 unbrick: unbrick_$(TARGET)
717 ## cppcheck : run static analysis on C source code
718 cppcheck: $(CSOURCES)
719 $(CPPCHECK)
721 cppcheck-result.xml: $(CSOURCES)
722 $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
724 help:
725 @echo ""
726 @echo "Makefile for the $(FORKNAME) firmware"
727 @echo ""
728 @echo "Usage:"
729 @echo " make [TARGET=<target>] [OPTIONS=\"<options>\"]"
730 @echo ""
731 @echo "Valid TARGET values are: $(VALID_TARGETS)"
732 @echo ""
734 ## test : run the cleanflight test suite
735 test:
736 cd src/test && $(MAKE) test || true
738 # rebuild everything when makefile changes
739 $(TARGET_OBJS) : Makefile
741 # include auto-generated dependencies
742 -include $(TARGET_DEPS)