code simplification
[betaflight.git] / Makefile
blob88f600479d0b0f86cfe27d5d7910706413b491cd
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 # Debugger optons, must be empty or GDB
24 DEBUG ?=
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.
30 FLASH_SIZE ?=
32 ###############################################################################
33 # Things that need to be maintained as the source changes
36 FORKNAME = inav
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
41 ifeq ($(FLASH_SIZE),)
42 ifeq ($(TARGET),$(filter $(TARGET),CJMCU))
43 FLASH_SIZE = 64
44 else ifeq ($(TARGET),$(filter $(TARGET),ALIENWIIF1 CC3D NAZE OLIMEXINO RMDO))
45 FLASH_SIZE = 128
46 else ifeq ($(TARGET),$(filter $(TARGET),ALIENWIIF3 CHEBUZZF3 COLIBRI_RACE LUX_RACE EUSTM32F103RC MOTOLAB NAZE32PRO PORT103R SPARKY SPRACINGF3 STM32F3DISCOVERY))
47 FLASH_SIZE = 256
48 else
49 $(error FLASH_SIZE not configured for target)
50 endif
51 endif
53 REVISION := $(shell git log -1 --format="%h")
55 # Working directories
56 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
57 SRC_DIR = $(ROOT)/src/main
58 OBJECT_DIR = $(ROOT)/obj/main
59 BIN_DIR = $(ROOT)/obj
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 \
78 stm32f30x_can.c
80 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
82 DEVICE_STDPERIPH_SRC = \
83 $(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) \
97 $(USBFS_DIR)/inc \
98 $(ROOT)/src/main/vcp
100 VPATH := $(VPATH):$(USBFS_DIR)/src
102 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC)\
103 $(USBPERIPH_SRC)
105 endif
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
115 endif
117 ifeq ($(TARGET),RMDO)
118 # RMDO is a VARIANT of SPRACINGF3
119 TARGET_FLAGS := $(TARGET_FLAGS) -DSPRACINGF3
120 endif
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 \
130 stm32f10x_cec.c \
131 stm32f10x_can.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)
153 else
155 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
157 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
159 EXCLUDES = stm32f10x_crc.c \
160 stm32f10x_cec.c \
161 stm32f10x_can.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) \
179 $(USBFS_DIR)/inc \
180 $(ROOT)/src/main/vcp
182 VPATH := $(VPATH):$(USBFS_DIR)/src
184 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
185 $(USBPERIPH_SRC)
187 endif
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
195 endif
197 ifneq ($(FLASH_SIZE),)
198 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
199 endif
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
208 endif
210 INCLUDE_DIRS := $(INCLUDE_DIRS) \
211 $(TARGET_DIR)
213 VPATH := $(VPATH):$(TARGET_DIR)
215 COMMON_SRC = build_config.c \
216 debug.c \
217 version.c \
218 $(TARGET_SRC) \
219 config/config.c \
220 config/runtime_config.c \
221 common/maths.c \
222 common/printf.c \
223 common/typeconversion.c \
224 common/encoding.c \
225 common/filter.c \
226 scheduler/scheduler.c \
227 scheduler/scheduler_tasks.c \
228 main.c \
229 mw.c \
230 flight/failsafe.c \
231 flight/pid.c \
232 flight/imu.c \
233 flight/hil.c \
234 flight/mixer.c \
235 drivers/bus_i2c_soft.c \
236 drivers/serial.c \
237 drivers/sound_beeper.c \
238 drivers/system.c \
239 drivers/gps_i2cnav.c \
240 drivers/gyro_sync.c \
241 drivers/buf_writer.c \
242 io/beeper.c \
243 io/rc_controls.c \
244 io/rc_curves.c \
245 io/serial.c \
246 io/serial_1wire.c \
247 io/serial_cli.c \
248 io/serial_msp.c \
249 io/statusindicator.c \
250 rx/rx.c \
251 rx/pwm.c \
252 rx/msp.c \
253 rx/sbus.c \
254 rx/sumd.c \
255 rx/sumh.c \
256 rx/spektrum.c \
257 rx/xbus.c \
258 rx/ibus.c \
259 sensors/acceleration.c \
260 sensors/battery.c \
261 sensors/boardalignment.c \
262 sensors/compass.c \
263 sensors/gyro.c \
264 sensors/initialisation.c \
265 $(CMSIS_SRC) \
266 $(DEVICE_STDPERIPH_SRC)
268 HIGHEND_SRC = \
269 flight/gtune.c \
270 flight/navigation_rewrite.c \
271 flight/navigation_rewrite_multicopter.c \
272 flight/navigation_rewrite_fixedwing.c \
273 flight/navigation_rewrite_pos_estimator.c \
274 flight/navigation_rewrite_geo.c \
275 flight/gps_conversion.c \
276 common/colorconversion.c \
277 io/gps.c \
278 io/gps_ublox.c \
279 io/gps_nmea.c \
280 io/gps_naza.c \
281 io/gps_i2cnav.c \
282 io/ledstrip.c \
283 io/display.c \
284 telemetry/telemetry.c \
285 telemetry/frsky.c \
286 telemetry/hott.c \
287 telemetry/smartport.c \
288 telemetry/ltm.c \
289 sensors/sonar.c \
290 sensors/barometer.c \
291 blackbox/blackbox.c \
292 blackbox/blackbox_io.c
294 VCP_SRC = \
295 vcp/hw_config.c \
296 vcp/stm32_it.c \
297 vcp/usb_desc.c \
298 vcp/usb_endp.c \
299 vcp/usb_istr.c \
300 vcp/usb_prop.c \
301 vcp/usb_pwr.c \
302 drivers/serial_usb_vcp.c
304 NAZE_SRC = startup_stm32f10x_md_gcc.S \
305 drivers/accgyro_adxl345.c \
306 drivers/accgyro_bma280.c \
307 drivers/accgyro_l3g4200d.c \
308 drivers/accgyro_mma845x.c \
309 drivers/accgyro_mpu.c \
310 drivers/accgyro_mpu3050.c \
311 drivers/accgyro_mpu6050.c \
312 drivers/accgyro_mpu6500.c \
313 drivers/accgyro_spi_mpu6500.c \
314 drivers/adc.c \
315 drivers/adc_stm32f10x.c \
316 drivers/barometer_bmp085.c \
317 drivers/barometer_ms5611.c \
318 drivers/barometer_bmp280.c \
319 drivers/bus_spi.c \
320 drivers/bus_i2c_stm32f10x.c \
321 drivers/compass_hmc5883l.c \
322 drivers/compass_mag3110.c \
323 drivers/compass_ak8975.c \
324 drivers/display_ug2864hsweg01.h \
325 drivers/flash_m25p16.c \
326 drivers/gpio_stm32f10x.c \
327 drivers/inverter.c \
328 drivers/light_led_stm32f10x.c \
329 drivers/light_ws2811strip.c \
330 drivers/light_ws2811strip_stm32f10x.c \
331 drivers/sonar_hcsr04.c \
332 drivers/pwm_mapping.c \
333 drivers/pwm_output.c \
334 drivers/pwm_rx.c \
335 drivers/serial_softserial.c \
336 drivers/serial_uart.c \
337 drivers/serial_uart_stm32f10x.c \
338 drivers/sound_beeper_stm32f10x.c \
339 drivers/system_stm32f10x.c \
340 drivers/timer.c \
341 drivers/timer_stm32f10x.c \
342 io/flashfs.c \
343 hardware_revision.c \
344 $(HIGHEND_SRC) \
345 $(COMMON_SRC)
347 ALIENWIIF1_SRC = $(NAZE_SRC)
349 EUSTM32F103RC_SRC = startup_stm32f10x_hd_gcc.S \
350 drivers/accgyro_adxl345.c \
351 drivers/accgyro_bma280.c \
352 drivers/accgyro_l3g4200d.c \
353 drivers/accgyro_mma845x.c \
354 drivers/accgyro_mpu.c \
355 drivers/accgyro_mpu3050.c \
356 drivers/accgyro_mpu6050.c \
357 drivers/accgyro_spi_mpu6000.c \
358 drivers/accgyro_spi_mpu6500.c \
359 drivers/adc.c \
360 drivers/adc_stm32f10x.c \
361 drivers/barometer_bmp085.c \
362 drivers/barometer_ms5611.c \
363 drivers/bus_i2c_stm32f10x.c \
364 drivers/bus_spi.c \
365 drivers/compass_ak8975.c \
366 drivers/compass_mag3110.c \
367 drivers/compass_hmc5883l.c \
368 drivers/display_ug2864hsweg01.c \
369 drivers/flash_m25p16.c \
370 drivers/gpio_stm32f10x.c \
371 drivers/inverter.c \
372 drivers/light_led_stm32f10x.c \
373 drivers/light_ws2811strip.c \
374 drivers/light_ws2811strip_stm32f10x.c \
375 drivers/pwm_mapping.c \
376 drivers/pwm_output.c \
377 drivers/pwm_rx.c \
378 drivers/serial_softserial.c \
379 drivers/serial_uart.c \
380 drivers/serial_uart_stm32f10x.c \
381 drivers/sonar_hcsr04.c \
382 drivers/sound_beeper_stm32f10x.c \
383 drivers/system_stm32f10x.c \
384 drivers/timer.c \
385 drivers/timer_stm32f10x.c \
386 io/flashfs.c \
387 $(HIGHEND_SRC) \
388 $(COMMON_SRC)
390 PORT103R_SRC = $(EUSTM32F103RC_SRC)
392 OLIMEXINO_SRC = startup_stm32f10x_md_gcc.S \
393 drivers/accgyro_mpu.c \
394 drivers/accgyro_mpu6050.c \
395 drivers/adc.c \
396 drivers/adc_stm32f10x.c \
397 drivers/barometer_bmp085.c \
398 drivers/bus_i2c_stm32f10x.c \
399 drivers/bus_spi.c \
400 drivers/compass_hmc5883l.c \
401 drivers/compass_mag3110.c \
402 drivers/compass_ak8975.c \
403 drivers/gpio_stm32f10x.c \
404 drivers/light_led_stm32f10x.c \
405 drivers/light_ws2811strip.c \
406 drivers/light_ws2811strip_stm32f10x.c \
407 drivers/pwm_mapping.c \
408 drivers/pwm_output.c \
409 drivers/pwm_rx.c \
410 drivers/serial_softserial.c \
411 drivers/serial_uart.c \
412 drivers/serial_uart_stm32f10x.c \
413 drivers/sonar_hcsr04.c \
414 drivers/sound_beeper_stm32f10x.c \
415 drivers/system_stm32f10x.c \
416 drivers/timer.c \
417 drivers/timer_stm32f10x.c \
418 $(HIGHEND_SRC) \
419 $(COMMON_SRC)
421 CJMCU_SRC = \
422 startup_stm32f10x_md_gcc.S \
423 drivers/adc.c \
424 drivers/adc_stm32f10x.c \
425 drivers/accgyro_mpu.c \
426 drivers/accgyro_mpu6050.c \
427 drivers/bus_i2c_stm32f10x.c \
428 drivers/compass_mag3110.c \
429 drivers/compass_hmc5883l.c \
430 drivers/compass_ak8975.c \
431 drivers/gpio_stm32f10x.c \
432 drivers/light_led_stm32f10x.c \
433 drivers/pwm_mapping.c \
434 drivers/pwm_output.c \
435 drivers/pwm_rx.c \
436 drivers/serial_uart.c \
437 drivers/serial_uart_stm32f10x.c \
438 drivers/sound_beeper_stm32f10x.c \
439 drivers/system_stm32f10x.c \
440 drivers/timer.c \
441 drivers/timer_stm32f10x.c \
442 hardware_revision.c \
443 flight/gtune.c \
444 blackbox/blackbox.c \
445 blackbox/blackbox_io.c \
446 $(COMMON_SRC)
448 CC3D_SRC = \
449 startup_stm32f10x_md_gcc.S \
450 drivers/accgyro_mpu.c \
451 drivers/accgyro_spi_mpu6000.c \
452 drivers/adc.c \
453 drivers/adc_stm32f10x.c \
454 drivers/barometer_bmp085.c \
455 drivers/barometer_ms5611.c \
456 drivers/barometer_bmp280.c \
457 drivers/bus_spi.c \
458 drivers/bus_i2c_stm32f10x.c \
459 drivers/compass_mag3110.c \
460 drivers/compass_hmc5883l.c \
461 drivers/compass_ak8975.c \
462 drivers/display_ug2864hsweg01.c \
463 drivers/flash_m25p16.c \
464 drivers/gpio_stm32f10x.c \
465 drivers/inverter.c \
466 drivers/light_led_stm32f10x.c \
467 drivers/light_ws2811strip.c \
468 drivers/light_ws2811strip_stm32f10x.c \
469 drivers/pwm_mapping.c \
470 drivers/pwm_output.c \
471 drivers/pwm_rx.c \
472 drivers/serial_softserial.c \
473 drivers/serial_uart.c \
474 drivers/serial_uart_stm32f10x.c \
475 drivers/sonar_hcsr04.c \
476 drivers/sound_beeper_stm32f10x.c \
477 drivers/system_stm32f10x.c \
478 drivers/timer.c \
479 drivers/timer_stm32f10x.c \
480 io/flashfs.c \
481 $(HIGHEND_SRC) \
482 $(COMMON_SRC) \
483 $(VCP_SRC)
485 STM32F30x_COMMON_SRC = \
486 startup_stm32f30x_md_gcc.S \
487 drivers/adc.c \
488 drivers/adc_stm32f30x.c \
489 drivers/bus_i2c_stm32f30x.c \
490 drivers/bus_spi.c \
491 drivers/gpio_stm32f30x.c \
492 drivers/light_led_stm32f30x.c \
493 drivers/light_ws2811strip.c \
494 drivers/light_ws2811strip_stm32f30x.c \
495 drivers/pwm_mapping.c \
496 drivers/pwm_output.c \
497 drivers/pwm_rx.c \
498 drivers/serial_uart.c \
499 drivers/serial_uart_stm32f30x.c \
500 drivers/sound_beeper_stm32f30x.c \
501 drivers/system_stm32f30x.c \
502 drivers/timer.c \
503 drivers/timer_stm32f30x.c
505 NAZE32PRO_SRC = \
506 $(STM32F30x_COMMON_SRC) \
507 $(HIGHEND_SRC) \
508 $(COMMON_SRC) \
509 $(VCP_SRC)
511 STM32F3DISCOVERY_COMMON_SRC = \
512 $(STM32F30x_COMMON_SRC) \
513 drivers/accgyro_l3gd20.c \
514 drivers/accgyro_l3gd20.c \
515 drivers/accgyro_lsm303dlhc.c \
516 drivers/compass_mag3110.c \
517 drivers/compass_hmc5883l.c \
518 drivers/compass_ak8975.c \
519 $(VCP_SRC)
521 STM32F3DISCOVERY_SRC = \
522 $(STM32F3DISCOVERY_COMMON_SRC) \
523 drivers/accgyro_adxl345.c \
524 drivers/accgyro_bma280.c \
525 drivers/accgyro_mma845x.c \
526 drivers/accgyro_mpu.c \
527 drivers/accgyro_mpu3050.c \
528 drivers/accgyro_mpu6050.c \
529 drivers/accgyro_l3g4200d.c \
530 drivers/barometer_ms5611.c \
531 drivers/compass_mag3110.c \
532 drivers/compass_hmc5883l.c \
533 drivers/compass_ak8975.c \
534 $(HIGHEND_SRC) \
535 $(COMMON_SRC)
537 CHEBUZZF3_SRC = \
538 $(STM32F3DISCOVERY_SRC) \
539 $(HIGHEND_SRC) \
540 $(COMMON_SRC)
542 COLIBRI_RACE_SRC = \
543 $(STM32F30x_COMMON_SRC) \
544 drivers/display_ug2864hsweg01.c \
545 drivers/accgyro_mpu.c \
546 drivers/accgyro_mpu6500.c \
547 drivers/accgyro_spi_mpu6500.c \
548 drivers/accgyro_mpu6500.c \
549 drivers/barometer_ms5611.c \
550 drivers/compass_mag3110.c \
551 drivers/compass_ak8975.c \
552 drivers/compass_hmc5883l.c \
553 drivers/serial_usb_vcp.c \
554 $(HIGHEND_SRC) \
555 $(COMMON_SRC) \
556 $(VCP_SRC)
558 LUX_RACE_SRC = \
559 $(STM32F30x_COMMON_SRC) \
560 drivers/accgyro_mpu.c \
561 drivers/accgyro_mpu6500.c \
562 drivers/accgyro_spi_mpu6500.c \
563 drivers/accgyro_mpu6500.c \
564 drivers/light_ws2811strip.c \
565 drivers/light_ws2811strip_stm32f30x.c \
566 drivers/serial_usb_vcp.c \
567 $(HIGHEND_SRC) \
568 $(COMMON_SRC) \
569 $(VCP_SRC)
571 SPARKY_SRC = \
572 $(STM32F30x_COMMON_SRC) \
573 drivers/display_ug2864hsweg01.c \
574 drivers/accgyro_mpu.c \
575 drivers/accgyro_mpu6050.c \
576 drivers/barometer_bmp085.c \
577 drivers/barometer_ms5611.c \
578 drivers/barometer_bmp280.c \
579 drivers/compass_mag3110.c \
580 drivers/compass_ak8975.c \
581 drivers/compass_hmc5883l.c \
582 drivers/serial_usb_vcp.c \
583 $(HIGHEND_SRC) \
584 $(COMMON_SRC) \
585 $(VCP_SRC)
587 ALIENWIIF3_SRC = \
588 $(SPARKY_SRC)
590 RMDO_SRC = \
591 $(STM32F30x_COMMON_SRC) \
592 drivers/accgyro_mpu.c \
593 drivers/accgyro_mpu6050.c \
594 drivers/barometer_bmp085.c \
595 drivers/barometer_ms5611.c \
596 drivers/barometer_bmp280.c \
597 drivers/compass_mag3110.c \
598 drivers/compass_ak8975.c \
599 drivers/compass_hmc5883l.c \
600 drivers/display_ug2864hsweg01.h \
601 drivers/flash_m25p16.c \
602 drivers/serial_softserial.c \
603 drivers/sonar_hcsr04.c \
604 io/flashfs.c \
605 $(HIGHEND_SRC) \
606 $(COMMON_SRC)
608 SPRACINGF3_SRC = \
609 $(STM32F30x_COMMON_SRC) \
610 drivers/accgyro_mpu.c \
611 drivers/accgyro_mpu6050.c \
612 drivers/barometer_bmp085.c \
613 drivers/barometer_ms5611.c \
614 drivers/barometer_bmp280.c \
615 drivers/compass_mag3110.c \
616 drivers/compass_ak8975.c \
617 drivers/compass_hmc5883l.c \
618 drivers/display_ug2864hsweg01.h \
619 drivers/flash_m25p16.c \
620 drivers/serial_softserial.c \
621 drivers/sonar_hcsr04.c \
622 io/flashfs.c \
623 $(HIGHEND_SRC) \
624 $(COMMON_SRC)
626 MOTOLAB_SRC = \
627 $(STM32F30x_COMMON_SRC) \
628 drivers/accgyro_mpu.c \
629 drivers/accgyro_mpu6050.c \
630 drivers/barometer_ms5611.c \
631 drivers/compass_mag3110.c \
632 drivers/compass_ak8975.c \
633 drivers/compass_hmc5883l.c \
634 drivers/display_ug2864hsweg01.c \
635 drivers/serial_usb_vcp.c \
636 drivers/flash_m25p16.c \
637 io/flashfs.c \
638 $(HIGHEND_SRC) \
639 $(COMMON_SRC) \
640 $(VCP_SRC)
642 # Search path and source files for the ST stdperiph library
643 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
645 ###############################################################################
646 # Things that might need changing to use different tools
649 # Tool names
650 CC = arm-none-eabi-gcc
651 OBJCOPY = arm-none-eabi-objcopy
652 SIZE = arm-none-eabi-size
655 # Tool options.
658 ifeq ($(DEBUG),GDB)
659 OPTIMIZE = -O0
660 LTO_FLAGS = $(OPTIMIZE)
661 else
662 OPTIMIZE = -Os
663 LTO_FLAGS = -flto -fuse-linker-plugin $(OPTIMIZE)
664 endif
666 DEBUG_FLAGS = -ggdb3 -DDEBUG
668 CFLAGS = $(ARCH_FLAGS) \
669 $(LTO_FLAGS) \
670 $(addprefix -D,$(OPTIONS)) \
671 $(addprefix -I,$(INCLUDE_DIRS)) \
672 $(DEBUG_FLAGS) \
673 -std=gnu99 \
674 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
675 -ffunction-sections \
676 -fdata-sections \
677 $(DEVICE_FLAGS) \
678 -DUSE_STDPERIPH_DRIVER \
679 $(TARGET_FLAGS) \
680 -D'__FORKNAME__="$(FORKNAME)"' \
681 -D'__TARGET__="$(TARGET)"' \
682 -D'__REVISION__="$(REVISION)"' \
683 -save-temps=obj \
684 -MMD -MP
686 ASFLAGS = $(ARCH_FLAGS) \
687 -x assembler-with-cpp \
688 $(addprefix -I,$(INCLUDE_DIRS)) \
689 -MMD -MP
691 LDFLAGS = -lm \
692 -nostartfiles \
693 --specs=nano.specs \
694 -lc \
695 -lnosys \
696 $(ARCH_FLAGS) \
697 $(LTO_FLAGS) \
698 $(DEBUG_FLAGS) \
699 -static \
700 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
701 -Wl,-L$(LINKER_DIR) \
702 -Wl,--cref \
703 -T$(LD_SCRIPT)
705 ###############################################################################
706 # No user-serviceable parts below
707 ###############################################################################
709 CPPCHECK = cppcheck $(CSOURCES) --enable=all --platform=unix64 \
710 --std=c99 --inline-suppr --quiet --force \
711 $(addprefix -I,$(INCLUDE_DIRS)) \
712 -I/usr/include -I/usr/include/linux
715 # Things we will build
717 ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
718 $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS))
719 endif
721 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(TARGET).bin
722 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(TARGET).hex
723 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
724 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
725 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
726 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
728 ## Default make goal:
729 ## hex : Make filetype hex only
730 .DEFAULT_GOAL := hex
732 ## Optional make goals:
733 ## all : Make all filetypes, binary and hex
734 all: hex bin
736 ## binary : Make binary filetype
737 ## bin : Alias of 'binary'
738 ## hex : Make hex filetype
739 bin: $(TARGET_BIN)
740 binary: $(TARGET_BIN)
741 hex: $(TARGET_HEX)
743 # rule to reinvoke make with TARGET= parameter
744 # rules that should be handled in toplevel Makefile, not dependent on TARGET
745 GLOBAL_GOALS = all_targets cppcheck test
747 .PHONY: $(VALID_TARGETS)
748 $(VALID_TARGETS):
749 $(MAKE) TARGET=$@ $(filter-out $(VALID_TARGETS) $(GLOBAL_GOALS), $(MAKECMDGOALS))
751 ## all_targets : Make all TARGETs
752 .PHONY: all_targets
753 all_targets : $(VALID_TARGETS)
755 ## clean : clean up all temporary / machine-generated files
756 clean:
757 rm -f $(TARGET_BIN) $(TARGET_HEX) $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
758 rm -rf $(OBJECT_DIR)/$(TARGET)
759 cd src/test && $(MAKE) clean || true
761 flash_$(TARGET): $(TARGET_HEX)
762 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
763 echo -n 'R' >$(SERIAL_DEVICE)
764 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
766 ## flash : flash firmware (.hex) onto flight controller
767 flash: flash_$(TARGET)
769 st-flash_$(TARGET): $(TARGET_BIN)
770 st-flash --reset write $< 0x08000000
772 ## st-flash : flash firmware (.bin) onto flight controller
773 st-flash: st-flash_$(TARGET)
775 binary: $(TARGET_BIN)
777 unbrick_$(TARGET): $(TARGET_HEX)
778 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
779 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
781 ## unbrick : unbrick flight controller
782 unbrick: unbrick_$(TARGET)
784 ## cppcheck : run static analysis on C source code
785 cppcheck: $(CSOURCES)
786 $(CPPCHECK)
788 cppcheck-result.xml: $(CSOURCES)
789 $(CPPCHECK) --xml-version=2 2> cppcheck-result.xml
791 ## help : print this help message and exit
792 help: Makefile
793 @echo ""
794 @echo "Makefile for the $(FORKNAME) firmware"
795 @echo ""
796 @echo "Usage:"
797 @echo " make [TARGET=<target>] [OPTIONS=\"<options>\"]"
798 @echo ""
799 @echo "Valid TARGET values are: $(VALID_TARGETS)"
800 @echo ""
801 @sed -n 's/^## //p' $<
803 ## test : run the cleanflight test suite
804 test:
805 cd src/test && $(MAKE) test || true
807 # rebuild everything when makefile changes
808 $(TARGET_OBJS) : Makefile
810 # List of buildable ELF files and their object dependencies.
811 # It would be nice to compute these lists, but that seems to be just beyond make.
813 $(TARGET_HEX): $(TARGET_ELF)
814 $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
816 $(TARGET_BIN): $(TARGET_ELF)
817 $(OBJCOPY) -O binary $< $@
819 $(TARGET_ELF): $(TARGET_OBJS)
820 $(CC) -o $@ $^ $(LDFLAGS)
821 $(SIZE) $(TARGET_ELF)
823 # Compile
824 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
825 @mkdir -p $(dir $@)
826 @echo %% $(notdir $<)
827 @$(CC) -c -o $@ $(CFLAGS) $<
829 # Assemble
830 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
831 @mkdir -p $(dir $@)
832 @echo %% $(notdir $<)
833 @$(CC) -c -o $@ $(ASFLAGS) $<
835 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
836 @mkdir -p $(dir $@)
837 @echo %% $(notdir $<)
838 @$(CC) -c -o $@ $(ASFLAGS) $<
841 # include auto-generated dependencies
842 -include $(TARGET_DEPS)