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
20 # Compile-time options
23 # Debugger optons, must be empty or GDB
26 # Serial port/Device for flashing
27 SERIAL_DEVICE ?
= $(firstword $(wildcard /dev
/ttyUSB
*) no-port-found
)
29 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
32 ###############################################################################
33 # Things that need to be maintained as the source changes
38 VALID_TARGETS
= ALIENWIIF1 ALIENWIIF3 CC3D CHEBUZZF3 CJMCU COLIBRI_RACE EUSTM32F103RC LUX_RACE MOTOLAB NAZE NAZE32PRO OLIMEXINO PORT103R RMDO SPARKY SPRACINGF3 STM32F3DISCOVERY
40 # Configure default flash sizes for the targets
42 ifeq ($(TARGET
),$(filter $(TARGET
),CJMCU
))
44 else ifeq ($(TARGET
),$(filter $(TARGET
),ALIENWIIF1 CC3D NAZE OLIMEXINO RMDO
))
46 else ifeq ($(TARGET
),$(filter $(TARGET
),ALIENWIIF3 CHEBUZZF3 COLIBRI_RACE LUX_RACE EUSTM32F103RC MOTOLAB NAZE32PRO PORT103R SPARKY SPRACINGF3 STM32F3DISCOVERY
))
49 $(error FLASH_SIZE not configured for target
)
53 REVISION
:= $(shell git log
-1 --format
="%h")
56 ROOT
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
57 SRC_DIR
= $(ROOT
)/src
/main
58 OBJECT_DIR
= $(ROOT
)/obj
/main
60 CMSIS_DIR
= $(ROOT
)/lib
/main
/CMSIS
61 INCLUDE_DIRS
= $(SRC_DIR
)
62 LINKER_DIR
= $(ROOT
)/src
/main
/target
64 # Search path for sources
65 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
66 USBFS_DIR
= $(ROOT
)/lib
/main
/STM32_USB-FS-Device_Driver
67 USBPERIPH_SRC
= $(notdir $(wildcard $(USBFS_DIR
)/src
/*.c
))
69 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
71 ifeq ($(TARGET
),$(filter $(TARGET
),ALIENWIIF3 CHEBUZZF3 COLIBRI_RACE LUX_RACE MOTOLAB NAZE32PRO RMDO SPARKY SPRACINGF3 STM32F3DISCOVERY
))
73 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F30x_StdPeriph_Driver
75 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
77 EXCLUDES
= stm32f30x_crc.c \
80 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
82 DEVICE_STDPERIPH_SRC
= \
86 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM1
/CoreSupport
:$(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
87 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM1
/CoreSupport
/*.c \
88 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
/*.c
))
90 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
91 $(STDPERIPH_DIR
)/inc \
92 $(CMSIS_DIR
)/CM1
/CoreSupport \
93 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
95 ifneq ($(TARGET
),SPRACINGF3
)
96 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
100 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
102 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
)\
107 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k.
ld
109 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
110 DEVICE_FLAGS
= -DSTM32F303xC
-DSTM32F303
111 TARGET_FLAGS
= -D
$(TARGET
)
112 ifeq ($(TARGET
),CHEBUZZF3
)
113 # CHEBUZZ is a VARIANT of STM32F3DISCOVERY
114 TARGET_FLAGS
:= $(TARGET_FLAGS
) -DSTM32F3DISCOVERY
117 ifeq ($(TARGET
),RMDO
)
118 # RMDO is a VARIANT of SPRACINGF3
119 TARGET_FLAGS
:= $(TARGET_FLAGS
) -DSPRACINGF3
122 else ifeq ($(TARGET
),$(filter $(TARGET
),EUSTM32F103RC PORT103R
))
125 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F10x_StdPeriph_Driver
127 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
129 EXCLUDES
= stm32f10x_crc.c \
133 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
135 # Search path and source files for the CMSIS sources
136 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM3
/CoreSupport
:$(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
137 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM3
/CoreSupport
/*.c \
138 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
/*.c
))
140 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
141 $(STDPERIPH_DIR
)/inc \
142 $(CMSIS_DIR
)/CM3
/CoreSupport \
143 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x \
145 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k.
ld
147 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m3
148 TARGET_FLAGS
= -D
$(TARGET
) -pedantic
149 DEVICE_FLAGS
= -DSTM32F10X_HD
-DSTM32F10X
151 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
155 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F10x_StdPeriph_Driver
157 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
159 EXCLUDES
= stm32f10x_crc.c \
163 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
165 # Search path and source files for the CMSIS sources
166 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM3
/CoreSupport
:$(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
167 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM3
/CoreSupport
/*.c \
168 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
/*.c
))
170 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
171 $(STDPERIPH_DIR
)/inc \
172 $(CMSIS_DIR
)/CM3
/CoreSupport \
173 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x \
175 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
177 ifeq ($(TARGET
),CC3D
)
178 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
182 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
184 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
) \
189 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k.
ld
191 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m3
192 TARGET_FLAGS
= -D
$(TARGET
) -pedantic
193 DEVICE_FLAGS
= -DSTM32F10X_MD
-DSTM32F10X
197 ifneq ($(FLASH_SIZE
),)
198 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFLASH_SIZE
=$(FLASH_SIZE
)
201 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(TARGET
)
202 TARGET_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
204 ifeq ($(TARGET
),ALIENWIIF1
)
205 # ALIENWIIF1 is a VARIANT of NAZE
206 TARGET_FLAGS
:= $(TARGET_FLAGS
) -DNAZE
-DALIENWII32
207 TARGET_DIR
= $(ROOT
)/src
/main
/target
/NAZE
210 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
213 VPATH
:= $(VPATH
):$(TARGET_DIR
)
215 COMMON_SRC
= build_config.c \
220 config
/runtime_config.c \
223 common
/typeconversion.c \
226 scheduler
/scheduler.c \
227 scheduler
/scheduler_tasks.c \
235 drivers
/bus_i2c_soft.c \
237 drivers
/sound_beeper.c \
239 drivers
/gps_i2cnav.c \
240 drivers
/gyro_sync.c \
248 io
/statusindicator.c \
258 sensors
/acceleration.c \
260 sensors
/boardalignment.c \
263 sensors
/initialisation.c \
265 $(DEVICE_STDPERIPH_SRC
)
269 flight
/navigation_rewrite.c \
270 flight
/navigation_rewrite_multicopter.c \
271 flight
/navigation_rewrite_fixedwing.c \
272 flight
/navigation_rewrite_pos_estimator.c \
273 flight
/navigation_rewrite_geo.c \
274 flight
/gps_conversion.c \
275 common
/colorconversion.c \
283 telemetry
/telemetry.c \
286 telemetry
/smartport.c \
289 sensors
/barometer.c \
290 blackbox
/blackbox.c \
291 blackbox
/blackbox_io.c
301 drivers
/serial_usb_vcp.c
303 NAZE_SRC
= startup_stm32f10x_md_gcc.S \
304 drivers
/accgyro_adxl345.c \
305 drivers
/accgyro_bma280.c \
306 drivers
/accgyro_l3g4200d.c \
307 drivers
/accgyro_mma845x.c \
308 drivers
/accgyro_mpu.c \
309 drivers
/accgyro_mpu3050.c \
310 drivers
/accgyro_mpu6050.c \
311 drivers
/accgyro_mpu6500.c \
312 drivers
/accgyro_spi_mpu6500.c \
314 drivers
/adc_stm32f10x.c \
315 drivers
/barometer_bmp085.c \
316 drivers
/barometer_ms5611.c \
317 drivers
/barometer_bmp280.c \
319 drivers
/bus_i2c_stm32f10x.c \
320 drivers
/compass_hmc5883l.c \
321 drivers
/compass_mag3110.c \
322 drivers
/compass_ak8975.c \
323 drivers
/display_ug2864hsweg01.h \
324 drivers
/flash_m25p16.c \
325 drivers
/gpio_stm32f10x.c \
327 drivers
/light_led_stm32f10x.c \
328 drivers
/light_ws2811strip.c \
329 drivers
/light_ws2811strip_stm32f10x.c \
330 drivers
/sonar_hcsr04.c \
331 drivers
/pwm_mapping.c \
332 drivers
/pwm_output.c \
334 drivers
/serial_softserial.c \
335 drivers
/serial_uart.c \
336 drivers
/serial_uart_stm32f10x.c \
337 drivers
/sound_beeper_stm32f10x.c \
338 drivers
/system_stm32f10x.c \
340 drivers
/timer_stm32f10x.c \
342 hardware_revision.c \
346 ALIENWIIF1_SRC
= $(NAZE_SRC
)
348 EUSTM32F103RC_SRC
= startup_stm32f10x_hd_gcc.S \
349 drivers
/accgyro_adxl345.c \
350 drivers
/accgyro_bma280.c \
351 drivers
/accgyro_l3g4200d.c \
352 drivers
/accgyro_mma845x.c \
353 drivers
/accgyro_mpu.c \
354 drivers
/accgyro_mpu3050.c \
355 drivers
/accgyro_mpu6050.c \
356 drivers
/accgyro_spi_mpu6000.c \
357 drivers
/accgyro_spi_mpu6500.c \
359 drivers
/adc_stm32f10x.c \
360 drivers
/barometer_bmp085.c \
361 drivers
/barometer_ms5611.c \
362 drivers
/bus_i2c_stm32f10x.c \
364 drivers
/compass_ak8975.c \
365 drivers
/compass_mag3110.c \
366 drivers
/compass_hmc5883l.c \
367 drivers
/display_ug2864hsweg01.c \
368 drivers
/flash_m25p16.c \
369 drivers
/gpio_stm32f10x.c \
371 drivers
/light_led_stm32f10x.c \
372 drivers
/light_ws2811strip.c \
373 drivers
/light_ws2811strip_stm32f10x.c \
374 drivers
/pwm_mapping.c \
375 drivers
/pwm_output.c \
377 drivers
/serial_softserial.c \
378 drivers
/serial_uart.c \
379 drivers
/serial_uart_stm32f10x.c \
380 drivers
/sonar_hcsr04.c \
381 drivers
/sound_beeper_stm32f10x.c \
382 drivers
/system_stm32f10x.c \
384 drivers
/timer_stm32f10x.c \
389 PORT103R_SRC
= $(EUSTM32F103RC_SRC
)
391 OLIMEXINO_SRC
= startup_stm32f10x_md_gcc.S \
392 drivers
/accgyro_mpu.c \
393 drivers
/accgyro_mpu6050.c \
395 drivers
/adc_stm32f10x.c \
396 drivers
/barometer_bmp085.c \
397 drivers
/bus_i2c_stm32f10x.c \
399 drivers
/compass_hmc5883l.c \
400 drivers
/compass_mag3110.c \
401 drivers
/compass_ak8975.c \
402 drivers
/gpio_stm32f10x.c \
403 drivers
/light_led_stm32f10x.c \
404 drivers
/light_ws2811strip.c \
405 drivers
/light_ws2811strip_stm32f10x.c \
406 drivers
/pwm_mapping.c \
407 drivers
/pwm_output.c \
409 drivers
/serial_softserial.c \
410 drivers
/serial_uart.c \
411 drivers
/serial_uart_stm32f10x.c \
412 drivers
/sonar_hcsr04.c \
413 drivers
/sound_beeper_stm32f10x.c \
414 drivers
/system_stm32f10x.c \
416 drivers
/timer_stm32f10x.c \
421 startup_stm32f10x_md_gcc.S \
423 drivers
/adc_stm32f10x.c \
424 drivers
/accgyro_mpu.c \
425 drivers
/accgyro_mpu6050.c \
426 drivers
/bus_i2c_stm32f10x.c \
427 drivers
/compass_mag3110.c \
428 drivers
/compass_hmc5883l.c \
429 drivers
/compass_ak8975.c \
430 drivers
/gpio_stm32f10x.c \
431 drivers
/light_led_stm32f10x.c \
432 drivers
/pwm_mapping.c \
433 drivers
/pwm_output.c \
435 drivers
/serial_uart.c \
436 drivers
/serial_uart_stm32f10x.c \
437 drivers
/sound_beeper_stm32f10x.c \
438 drivers
/system_stm32f10x.c \
440 drivers
/timer_stm32f10x.c \
441 hardware_revision.c \
443 blackbox
/blackbox.c \
444 blackbox
/blackbox_io.c \
448 startup_stm32f10x_md_gcc.S \
449 drivers
/accgyro_mpu.c \
450 drivers
/accgyro_spi_mpu6000.c \
452 drivers
/adc_stm32f10x.c \
453 drivers
/barometer_bmp085.c \
454 drivers
/barometer_ms5611.c \
455 drivers
/barometer_bmp280.c \
457 drivers
/bus_i2c_stm32f10x.c \
458 drivers
/compass_mag3110.c \
459 drivers
/compass_hmc5883l.c \
460 drivers
/compass_ak8975.c \
461 drivers
/display_ug2864hsweg01.c \
462 drivers
/flash_m25p16.c \
463 drivers
/gpio_stm32f10x.c \
465 drivers
/light_led_stm32f10x.c \
466 drivers
/light_ws2811strip.c \
467 drivers
/light_ws2811strip_stm32f10x.c \
468 drivers
/pwm_mapping.c \
469 drivers
/pwm_output.c \
471 drivers
/serial_softserial.c \
472 drivers
/serial_uart.c \
473 drivers
/serial_uart_stm32f10x.c \
474 drivers
/sonar_hcsr04.c \
475 drivers
/sound_beeper_stm32f10x.c \
476 drivers
/system_stm32f10x.c \
478 drivers
/timer_stm32f10x.c \
484 STM32F30x_COMMON_SRC
= \
485 startup_stm32f30x_md_gcc.S \
487 drivers
/adc_stm32f30x.c \
488 drivers
/bus_i2c_stm32f30x.c \
490 drivers
/gpio_stm32f30x.c \
491 drivers
/light_led_stm32f30x.c \
492 drivers
/light_ws2811strip.c \
493 drivers
/light_ws2811strip_stm32f30x.c \
494 drivers
/pwm_mapping.c \
495 drivers
/pwm_output.c \
497 drivers
/serial_uart.c \
498 drivers
/serial_uart_stm32f30x.c \
499 drivers
/sound_beeper_stm32f30x.c \
500 drivers
/system_stm32f30x.c \
502 drivers
/timer_stm32f30x.c
505 $(STM32F30x_COMMON_SRC
) \
510 STM32F3DISCOVERY_COMMON_SRC
= \
511 $(STM32F30x_COMMON_SRC
) \
512 drivers
/accgyro_l3gd20.c \
513 drivers
/accgyro_l3gd20.c \
514 drivers
/accgyro_lsm303dlhc.c \
515 drivers
/compass_mag3110.c \
516 drivers
/compass_hmc5883l.c \
517 drivers
/compass_ak8975.c \
520 STM32F3DISCOVERY_SRC
= \
521 $(STM32F3DISCOVERY_COMMON_SRC
) \
522 drivers
/accgyro_adxl345.c \
523 drivers
/accgyro_bma280.c \
524 drivers
/accgyro_mma845x.c \
525 drivers
/accgyro_mpu.c \
526 drivers
/accgyro_mpu3050.c \
527 drivers
/accgyro_mpu6050.c \
528 drivers
/accgyro_l3g4200d.c \
529 drivers
/barometer_ms5611.c \
530 drivers
/compass_mag3110.c \
531 drivers
/compass_hmc5883l.c \
532 drivers
/compass_ak8975.c \
537 $(STM32F3DISCOVERY_SRC
) \
542 $(STM32F30x_COMMON_SRC
) \
543 drivers
/display_ug2864hsweg01.c \
544 drivers
/accgyro_mpu.c \
545 drivers
/accgyro_mpu6500.c \
546 drivers
/accgyro_spi_mpu6500.c \
547 drivers
/accgyro_mpu6500.c \
548 drivers
/barometer_ms5611.c \
549 drivers
/compass_mag3110.c \
550 drivers
/compass_ak8975.c \
551 drivers
/compass_hmc5883l.c \
552 drivers
/serial_usb_vcp.c \
558 $(STM32F30x_COMMON_SRC
) \
559 drivers
/accgyro_mpu.c \
560 drivers
/accgyro_mpu6500.c \
561 drivers
/accgyro_spi_mpu6500.c \
562 drivers
/accgyro_mpu6500.c \
563 drivers
/light_ws2811strip.c \
564 drivers
/light_ws2811strip_stm32f30x.c \
565 drivers
/serial_usb_vcp.c \
571 $(STM32F30x_COMMON_SRC
) \
572 drivers
/display_ug2864hsweg01.c \
573 drivers
/accgyro_mpu.c \
574 drivers
/accgyro_mpu6050.c \
575 drivers
/barometer_bmp085.c \
576 drivers
/barometer_ms5611.c \
577 drivers
/barometer_bmp280.c \
578 drivers
/compass_mag3110.c \
579 drivers
/compass_ak8975.c \
580 drivers
/compass_hmc5883l.c \
581 drivers
/serial_usb_vcp.c \
590 $(STM32F30x_COMMON_SRC
) \
591 drivers
/accgyro_mpu.c \
592 drivers
/accgyro_mpu6050.c \
593 drivers
/barometer_bmp085.c \
594 drivers
/barometer_ms5611.c \
595 drivers
/barometer_bmp280.c \
596 drivers
/compass_mag3110.c \
597 drivers
/compass_ak8975.c \
598 drivers
/compass_hmc5883l.c \
599 drivers
/display_ug2864hsweg01.h \
600 drivers
/flash_m25p16.c \
601 drivers
/serial_softserial.c \
602 drivers
/sonar_hcsr04.c \
608 $(STM32F30x_COMMON_SRC
) \
609 drivers
/accgyro_mpu.c \
610 drivers
/accgyro_mpu6050.c \
611 drivers
/barometer_bmp085.c \
612 drivers
/barometer_ms5611.c \
613 drivers
/barometer_bmp280.c \
614 drivers
/compass_mag3110.c \
615 drivers
/compass_ak8975.c \
616 drivers
/compass_hmc5883l.c \
617 drivers
/display_ug2864hsweg01.h \
618 drivers
/flash_m25p16.c \
619 drivers
/serial_softserial.c \
620 drivers
/sonar_hcsr04.c \
626 $(STM32F30x_COMMON_SRC
) \
627 drivers
/accgyro_mpu.c \
628 drivers
/accgyro_mpu6050.c \
629 drivers
/barometer_ms5611.c \
630 drivers
/compass_mag3110.c \
631 drivers
/compass_ak8975.c \
632 drivers
/compass_hmc5883l.c \
633 drivers
/display_ug2864hsweg01.c \
634 drivers
/serial_usb_vcp.c \
635 drivers
/flash_m25p16.c \
641 # Search path and source files for the ST stdperiph library
642 VPATH
:= $(VPATH
):$(STDPERIPH_DIR
)/src
644 ###############################################################################
645 # Things that might need changing to use different tools
649 CC
= arm-none-eabi-gcc
650 OBJCOPY
= arm-none-eabi-objcopy
651 SIZE
= arm-none-eabi-size
659 LTO_FLAGS
= $(OPTIMIZE
)
662 LTO_FLAGS
= -flto
-fuse-linker-plugin
$(OPTIMIZE
)
665 DEBUG_FLAGS
= -ggdb3
-DDEBUG
667 CFLAGS
= $(ARCH_FLAGS
) \
669 $(addprefix -D
,$(OPTIONS
)) \
670 $(addprefix -I
,$(INCLUDE_DIRS
)) \
673 -Wall
-Wextra
-Wunsafe-loop-optimizations
-Wdouble-promotion \
674 -ffunction-sections \
677 -DUSE_STDPERIPH_DRIVER \
679 -D
'__FORKNAME__="$(FORKNAME)"' \
680 -D
'__TARGET__="$(TARGET)"' \
681 -D
'__REVISION__="$(REVISION)"' \
685 ASFLAGS
= $(ARCH_FLAGS
) \
686 -x assembler-with-cpp \
687 $(addprefix -I
,$(INCLUDE_DIRS
)) \
699 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
700 -Wl
,-L
$(LINKER_DIR
) \
704 ###############################################################################
705 # No user-serviceable parts below
706 ###############################################################################
708 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
709 --std
=c99
--inline-suppr
--quiet
--force \
710 $(addprefix -I
,$(INCLUDE_DIRS
)) \
711 -I
/usr
/include -I
/usr
/include/linux
714 # Things we will build
716 ifeq ($(filter $(TARGET
),$(VALID_TARGETS
)),)
717 $(error Target
'$(TARGET)' is not valid
, must be one of
$(VALID_TARGETS
))
720 TARGET_BIN
= $(BIN_DIR
)/$(FORKNAME
)_
$(TARGET
).bin
721 TARGET_HEX
= $(BIN_DIR
)/$(FORKNAME
)_
$(TARGET
).hex
722 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
723 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $($(TARGET
)_SRC
))))
724 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $($(TARGET
)_SRC
))))
725 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
727 ## Default make goal:
728 ## hex : Make filetype hex only
731 ## Optional make goals:
732 ## all : Make all filetypes, binary and hex
735 ## binary : Make binary filetype
736 ## bin : Alias of 'binary'
737 ## hex : Make hex filetype
739 binary
: $(TARGET_BIN
)
742 # rule to reinvoke make with TARGET= parameter
743 # rules that should be handled in toplevel Makefile, not dependent on TARGET
744 GLOBAL_GOALS
= all_targets cppcheck
test
746 .PHONY
: $(VALID_TARGETS
)
748 $(MAKE
) TARGET
=$@
$(filter-out $(VALID_TARGETS
) $(GLOBAL_GOALS
), $(MAKECMDGOALS
))
750 ## all_targets : Make all TARGETs
752 all_targets
: $(VALID_TARGETS
)
754 ## clean : clean up all temporary / machine-generated files
756 rm -f
$(TARGET_BIN
) $(TARGET_HEX
) $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
757 rm -rf
$(OBJECT_DIR
)/$(TARGET
)
758 cd src
/test && $(MAKE
) clean || true
760 flash_
$(TARGET
): $(TARGET_HEX
)
761 stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
762 echo
-n
'R' >$(SERIAL_DEVICE
)
763 stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
765 ## flash : flash firmware (.hex) onto flight controller
766 flash
: flash_
$(TARGET
)
768 st-flash_
$(TARGET
): $(TARGET_BIN
)
769 st-flash
--reset write
$< 0x08000000
771 ## st-flash : flash firmware (.bin) onto flight controller
772 st-flash
: st-flash_
$(TARGET
)
774 binary
: $(TARGET_BIN
)
776 unbrick_
$(TARGET
): $(TARGET_HEX
)
777 stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
778 stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
780 ## unbrick : unbrick flight controller
781 unbrick
: unbrick_
$(TARGET
)
783 ## cppcheck : run static analysis on C source code
784 cppcheck
: $(CSOURCES
)
787 cppcheck-result.xml
: $(CSOURCES
)
788 $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
790 ## help : print this help message and exit
793 @echo
"Makefile for the $(FORKNAME) firmware"
796 @echo
" make [TARGET=<target>] [OPTIONS=\"<options>\"]"
798 @echo
"Valid TARGET values are: $(VALID_TARGETS)"
800 @sed
-n
's/^## //p' $<
802 ## test : run the cleanflight test suite
804 cd src
/test && $(MAKE
) test || true
806 # rebuild everything when makefile changes
807 $(TARGET_OBJS
) : Makefile
809 # List of buildable ELF files and their object dependencies.
810 # It would be nice to compute these lists, but that seems to be just beyond make.
812 $(TARGET_HEX
): $(TARGET_ELF
)
813 $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
815 $(TARGET_BIN
): $(TARGET_ELF
)
816 $(OBJCOPY
) -O binary
$< $@
818 $(TARGET_ELF
): $(TARGET_OBJS
)
819 $(CC
) -o
$@
$^
$(LDFLAGS
)
820 $(SIZE
) $(TARGET_ELF
)
823 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
825 @echo
%% $(notdir $<)
826 @
$(CC
) -c
-o
$@
$(CFLAGS
) $<
829 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
831 @echo
%% $(notdir $<)
832 @
$(CC
) -c
-o
$@
$(ASFLAGS
) $<
834 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
836 @echo
%% $(notdir $<)
837 @
$(CC
) -c
-o
$@
$(ASFLAGS
) $<
840 # include auto-generated dependencies
841 -include $(TARGET_DEPS
)