original dT back
[betaflight.git] / Makefile
blobc0e5f781f2265508f29ed4044c651e921388c053
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
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))
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))
77 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver
79 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
81 EXCLUDES = stm32f30x_crc.c \
82 stm32f30x_can.c
84 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
86 DEVICE_STDPERIPH_SRC = \
87 $(STDPERIPH_SRC)
90 VPATH := $(VPATH):$(CMSIS_DIR)/CM1/CoreSupport:$(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
91 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM1/CoreSupport/*.c \
92 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x/*.c))
94 INCLUDE_DIRS := $(INCLUDE_DIRS) \
95 $(STDPERIPH_DIR)/inc \
96 $(CMSIS_DIR)/CM1/CoreSupport \
97 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
99 ifneq ($(TARGET),SPRACINGF3)
100 INCLUDE_DIRS := $(INCLUDE_DIRS) \
101 $(USBFS_DIR)/inc \
102 $(ROOT)/src/main/vcp
104 VPATH := $(VPATH):$(USBFS_DIR)/src
106 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC)\
107 $(USBPERIPH_SRC)
109 endif
111 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k.ld
113 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
114 DEVICE_FLAGS = -DSTM32F303xC -DSTM32F303
115 TARGET_FLAGS = -D$(TARGET)
116 ifeq ($(TARGET),CHEBUZZF3)
117 # CHEBUZZ is a VARIANT of STM32F3DISCOVERY
118 TARGET_FLAGS := $(TARGET_FLAGS) -DSTM32F3DISCOVERY
119 endif
121 else ifeq ($(TARGET),$(filter $(TARGET),EUSTM32F103RC PORT103R))
124 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
126 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
128 EXCLUDES = stm32f10x_crc.c \
129 stm32f10x_cec.c \
130 stm32f10x_can.c
132 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
134 # Search path and source files for the CMSIS sources
135 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
136 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
137 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
139 INCLUDE_DIRS := $(INCLUDE_DIRS) \
140 $(STDPERIPH_DIR)/inc \
141 $(CMSIS_DIR)/CM3/CoreSupport \
142 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \
144 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
146 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
147 TARGET_FLAGS = -D$(TARGET) -pedantic
148 DEVICE_FLAGS = -DSTM32F10X_HD -DSTM32F10X
150 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
152 else
154 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
156 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
158 EXCLUDES = stm32f10x_crc.c \
159 stm32f10x_cec.c \
160 stm32f10x_can.c
162 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
164 # Search path and source files for the CMSIS sources
165 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
166 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
167 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
169 INCLUDE_DIRS := $(INCLUDE_DIRS) \
170 $(STDPERIPH_DIR)/inc \
171 $(CMSIS_DIR)/CM3/CoreSupport \
172 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \
174 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
176 ifeq ($(TARGET),CC3D)
177 INCLUDE_DIRS := $(INCLUDE_DIRS) \
178 $(USBFS_DIR)/inc \
179 $(ROOT)/src/main/vcp
181 VPATH := $(VPATH):$(USBFS_DIR)/src
183 DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
184 $(USBPERIPH_SRC)
186 endif
188 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
190 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
191 TARGET_FLAGS = -D$(TARGET) -pedantic
192 DEVICE_FLAGS = -DSTM32F10X_MD -DSTM32F10X
194 endif
196 ifneq ($(FLASH_SIZE),)
197 DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
198 endif
200 TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
201 TARGET_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
203 ifeq ($(TARGET),ALIENWIIF1)
204 # ALIENWIIF1 is a VARIANT of NAZE
205 TARGET_FLAGS := $(TARGET_FLAGS) -DNAZE -DALIENWII32
206 TARGET_DIR = $(ROOT)/src/main/target/NAZE
207 endif
209 INCLUDE_DIRS := $(INCLUDE_DIRS) \
210 $(TARGET_DIR)
212 VPATH := $(VPATH):$(TARGET_DIR)
214 COMMON_SRC = build_config.c \
215 debug.c \
216 version.c \
217 $(TARGET_SRC) \
218 config/config.c \
219 config/runtime_config.c \
220 common/maths.c \
221 common/printf.c \
222 common/typeconversion.c \
223 common/encoding.c \
224 common/filter.c \
225 main.c \
226 mw.c \
227 flight/altitudehold.c \
228 flight/failsafe.c \
229 flight/pid.c \
230 flight/imu.c \
231 flight/mixer.c \
232 flight/lowpass.c \
233 drivers/bus_i2c_soft.c \
234 drivers/serial.c \
235 drivers/sound_beeper.c \
236 drivers/system.c \
237 drivers/gyro_sync.c \
238 io/beeper.c \
239 io/rc_controls.c \
240 io/rc_curves.c \
241 io/serial.c \
242 io/serial_1wire.c \
243 io/serial_cli.c \
244 io/serial_msp.c \
245 io/statusindicator.c \
246 rx/rx.c \
247 rx/pwm.c \
248 rx/msp.c \
249 rx/sbus.c \
250 rx/sumd.c \
251 rx/sumh.c \
252 rx/spektrum.c \
253 rx/xbus.c \
254 sensors/acceleration.c \
255 sensors/battery.c \
256 sensors/boardalignment.c \
257 sensors/compass.c \
258 sensors/gyro.c \
259 sensors/initialisation.c \
260 $(CMSIS_SRC) \
261 $(DEVICE_STDPERIPH_SRC)
263 HIGHEND_SRC = flight/autotune.c \
264 flight/navigation.c \
265 flight/gps_conversion.c \
266 common/colorconversion.c \
267 io/gps.c \
268 io/ledstrip.c \
269 io/display.c \
270 telemetry/telemetry.c \
271 telemetry/frsky.c \
272 telemetry/hott.c \
273 telemetry/msp.c \
274 telemetry/smartport.c \
275 sensors/sonar.c \
276 sensors/barometer.c \
277 blackbox/blackbox.c \
278 blackbox/blackbox_io.c
280 VCP_SRC = \
281 vcp/hw_config.c \
282 vcp/stm32_it.c \
283 vcp/usb_desc.c \
284 vcp/usb_endp.c \
285 vcp/usb_istr.c \
286 vcp/usb_prop.c \
287 vcp/usb_pwr.c \
288 drivers/serial_usb_vcp.c
290 NAZE_SRC = startup_stm32f10x_md_gcc.S \
291 drivers/accgyro_adxl345.c \
292 drivers/accgyro_bma280.c \
293 drivers/accgyro_l3g4200d.c \
294 drivers/accgyro_mma845x.c \
295 drivers/accgyro_mpu3050.c \
296 drivers/accgyro_mpu6050.c \
297 drivers/accgyro_spi_mpu6500.c \
298 drivers/adc.c \
299 drivers/adc_stm32f10x.c \
300 drivers/barometer_bmp085.c \
301 drivers/barometer_bmp280.c \
302 drivers/barometer_ms5611.c \
303 drivers/bus_spi.c \
304 drivers/bus_i2c_stm32f10x.c \
305 drivers/compass_hmc5883l.c \
306 drivers/display_ug2864hsweg01.h \
307 drivers/flash_m25p16.c \
308 drivers/gpio_stm32f10x.c \
309 drivers/inverter.c \
310 drivers/light_led_stm32f10x.c \
311 drivers/light_ws2811strip.c \
312 drivers/light_ws2811strip_stm32f10x.c \
313 drivers/sonar_hcsr04.c \
314 drivers/pwm_mapping.c \
315 drivers/pwm_output.c \
316 drivers/pwm_rx.c \
317 drivers/serial_softserial.c \
318 drivers/serial_uart.c \
319 drivers/serial_uart_stm32f10x.c \
320 drivers/sound_beeper_stm32f10x.c \
321 drivers/system_stm32f10x.c \
322 drivers/timer.c \
323 drivers/timer_stm32f10x.c \
324 io/flashfs.c \
325 hardware_revision.c \
326 $(HIGHEND_SRC) \
327 $(COMMON_SRC)
329 ALIENWIIF1_SRC = $(NAZE_SRC)
331 EUSTM32F103RC_SRC = startup_stm32f10x_hd_gcc.S \
332 drivers/accgyro_adxl345.c \
333 drivers/accgyro_bma280.c \
334 drivers/accgyro_l3g4200d.c \
335 drivers/accgyro_mma845x.c \
336 drivers/accgyro_mpu3050.c \
337 drivers/accgyro_mpu6050.c \
338 drivers/accgyro_spi_mpu6000.c \
339 drivers/accgyro_spi_mpu6500.c \
340 drivers/adc.c \
341 drivers/adc_stm32f10x.c \
342 drivers/barometer_bmp085.c \
343 drivers/barometer_bmp280.c \
344 drivers/barometer_ms5611.c \
345 drivers/bus_i2c_stm32f10x.c \
346 drivers/bus_spi.c \
347 drivers/compass_ak8975.c \
348 drivers/compass_hmc5883l.c \
349 drivers/display_ug2864hsweg01.c \
350 drivers/flash_m25p16.c \
351 drivers/gpio_stm32f10x.c \
352 drivers/inverter.c \
353 drivers/light_led_stm32f10x.c \
354 drivers/light_ws2811strip.c \
355 drivers/light_ws2811strip_stm32f10x.c \
356 drivers/pwm_mapping.c \
357 drivers/pwm_output.c \
358 drivers/pwm_rx.c \
359 drivers/serial_softserial.c \
360 drivers/serial_uart.c \
361 drivers/serial_uart_stm32f10x.c \
362 drivers/sonar_hcsr04.c \
363 drivers/sound_beeper_stm32f10x.c \
364 drivers/system_stm32f10x.c \
365 drivers/timer.c \
366 drivers/timer_stm32f10x.c \
367 io/flashfs.c \
368 $(HIGHEND_SRC) \
369 $(COMMON_SRC)
371 PORT103R_SRC = $(EUSTM32F103RC_SRC)
373 OLIMEXINO_SRC = startup_stm32f10x_md_gcc.S \
374 drivers/accgyro_mpu6050.c \
375 drivers/adc.c \
376 drivers/adc_stm32f10x.c \
377 drivers/barometer_bmp085.c \
378 drivers/barometer_bmp280.c \
379 drivers/bus_i2c_stm32f10x.c \
380 drivers/bus_spi.c \
381 drivers/compass_hmc5883l.c \
382 drivers/gpio_stm32f10x.c \
383 drivers/light_led_stm32f10x.c \
384 drivers/light_ws2811strip.c \
385 drivers/light_ws2811strip_stm32f10x.c \
386 drivers/pwm_mapping.c \
387 drivers/pwm_output.c \
388 drivers/pwm_rx.c \
389 drivers/serial_softserial.c \
390 drivers/serial_uart.c \
391 drivers/serial_uart_stm32f10x.c \
392 drivers/sonar_hcsr04.c \
393 drivers/sound_beeper_stm32f10x.c \
394 drivers/system_stm32f10x.c \
395 drivers/timer.c \
396 drivers/timer_stm32f10x.c \
397 $(HIGHEND_SRC) \
398 $(COMMON_SRC)
400 ifeq ($(OPBL),yes)
401 ifneq ($(filter $(TARGET),$(OPBL_VALID_TARGETS)),)
402 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
403 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k_opbl.ld
404 .DEFAULT_GOAL := binary
405 else
406 $(error OPBL specified with a unsupported target)
407 endif
408 endif
410 CJMCU_SRC = \
411 startup_stm32f10x_md_gcc.S \
412 drivers/adc.c \
413 drivers/adc_stm32f10x.c \
414 drivers/accgyro_mpu6050.c \
415 drivers/bus_i2c_stm32f10x.c \
416 drivers/compass_hmc5883l.c \
417 drivers/gpio_stm32f10x.c \
418 drivers/light_led_stm32f10x.c \
419 drivers/pwm_mapping.c \
420 drivers/pwm_output.c \
421 drivers/pwm_rx.c \
422 drivers/serial_uart.c \
423 drivers/serial_uart_stm32f10x.c \
424 drivers/sound_beeper_stm32f10x.c \
425 drivers/system_stm32f10x.c \
426 drivers/timer.c \
427 drivers/timer_stm32f10x.c \
428 hardware_revision.c \
429 blackbox/blackbox.c \
430 blackbox/blackbox_io.c \
431 $(COMMON_SRC)
433 CC3D_SRC = \
434 startup_stm32f10x_md_gcc.S \
435 drivers/accgyro_spi_mpu6000.c \
436 drivers/adc.c \
437 drivers/adc_stm32f10x.c \
438 drivers/barometer_bmp085.c \
439 drivers/barometer_bmp280.c \
440 drivers/barometer_ms5611.c \
441 drivers/bus_spi.c \
442 drivers/bus_i2c_stm32f10x.c \
443 drivers/compass_hmc5883l.c \
444 drivers/display_ug2864hsweg01.c \
445 drivers/flash_m25p16.c \
446 drivers/gpio_stm32f10x.c \
447 drivers/inverter.c \
448 drivers/light_led_stm32f10x.c \
449 drivers/light_ws2811strip.c \
450 drivers/light_ws2811strip_stm32f10x.c \
451 drivers/pwm_mapping.c \
452 drivers/pwm_output.c \
453 drivers/pwm_rx.c \
454 drivers/serial_softserial.c \
455 drivers/serial_uart.c \
456 drivers/serial_uart_stm32f10x.c \
457 drivers/sonar_hcsr04.c \
458 drivers/sound_beeper_stm32f10x.c \
459 drivers/system_stm32f10x.c \
460 drivers/timer.c \
461 drivers/timer_stm32f10x.c \
462 io/flashfs.c \
463 $(HIGHEND_SRC) \
464 $(COMMON_SRC) \
465 $(VCP_SRC)
467 STM32F30x_COMMON_SRC = \
468 startup_stm32f30x_md_gcc.S \
469 drivers/adc.c \
470 drivers/adc_stm32f30x.c \
471 drivers/bus_i2c_stm32f30x.c \
472 drivers/bus_spi.c \
473 drivers/gpio_stm32f30x.c \
474 drivers/light_led_stm32f30x.c \
475 drivers/light_ws2811strip.c \
476 drivers/light_ws2811strip_stm32f30x.c \
477 drivers/pwm_mapping.c \
478 drivers/pwm_output.c \
479 drivers/pwm_rx.c \
480 drivers/serial_uart.c \
481 drivers/serial_uart_stm32f30x.c \
482 drivers/sound_beeper_stm32f30x.c \
483 drivers/system_stm32f30x.c \
484 drivers/timer.c \
485 drivers/timer_stm32f30x.c
487 NAZE32PRO_SRC = \
488 $(STM32F30x_COMMON_SRC) \
489 $(HIGHEND_SRC) \
490 $(COMMON_SRC) \
491 $(VCP_SRC)
493 STM32F3DISCOVERY_COMMON_SRC = \
494 $(STM32F30x_COMMON_SRC) \
495 drivers/accgyro_l3gd20.c \
496 drivers/accgyro_l3gd20.c \
497 drivers/accgyro_lsm303dlhc.c \
498 drivers/compass_hmc5883l.c \
499 $(VCP_SRC)
501 STM32F3DISCOVERY_SRC = \
502 $(STM32F3DISCOVERY_COMMON_SRC) \
503 drivers/accgyro_adxl345.c \
504 drivers/accgyro_bma280.c \
505 drivers/accgyro_mma845x.c \
506 drivers/accgyro_mpu3050.c \
507 drivers/accgyro_mpu6050.c \
508 drivers/accgyro_l3g4200d.c \
509 drivers/barometer_ms5611.c \
510 drivers/barometer_bmp280.c \
511 drivers/compass_ak8975.c \
512 $(HIGHEND_SRC) \
513 $(COMMON_SRC)
515 CHEBUZZF3_SRC = \
516 $(STM32F3DISCOVERY_SRC) \
517 $(HIGHEND_SRC) \
518 $(COMMON_SRC)
520 COLIBRI_RACE_SRC = \
521 $(STM32F30x_COMMON_SRC) \
522 drivers/display_ug2864hsweg01.c \
523 drivers/accgyro_spi_mpu6500.c \
524 drivers/barometer_ms5611.c \
525 drivers/compass_ak8975.c \
526 drivers/compass_hmc5883l.c \
527 drivers/serial_usb_vcp.c \
528 $(HIGHEND_SRC) \
529 $(COMMON_SRC) \
530 $(VCP_SRC)
532 SPARKY_SRC = \
533 $(STM32F30x_COMMON_SRC) \
534 drivers/display_ug2864hsweg01.c \
535 drivers/accgyro_mpu6050.c \
536 drivers/barometer_ms5611.c \
537 drivers/barometer_bmp280.c \
538 drivers/compass_ak8975.c \
539 drivers/serial_usb_vcp.c \
540 $(HIGHEND_SRC) \
541 $(COMMON_SRC) \
542 $(VCP_SRC)
544 ALIENWIIF3_SRC = $(SPARKY_SRC)
546 SPRACINGF3_SRC = \
547 $(STM32F30x_COMMON_SRC) \
548 drivers/accgyro_mpu6050.c \
549 drivers/barometer_ms5611.c \
550 drivers/compass_ak8975.c \
551 drivers/barometer_bmp280.c \
552 drivers/compass_hmc5883l.c \
553 drivers/display_ug2864hsweg01.h \
554 drivers/flash_m25p16.c \
555 drivers/serial_softserial.c \
556 drivers/sonar_hcsr04.c \
557 io/flashfs.c \
558 $(HIGHEND_SRC) \
559 $(COMMON_SRC)
561 # Search path and source files for the ST stdperiph library
562 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
564 ###############################################################################
565 # Things that might need changing to use different tools
568 # Tool names
569 CC = arm-none-eabi-gcc
570 OBJCOPY = arm-none-eabi-objcopy
571 SIZE = arm-none-eabi-size
574 # Tool options.
577 ifeq ($(DEBUG),GDB)
578 OPTIMIZE = -O0
579 LTO_FLAGS = $(OPTIMIZE)
580 else
581 OPTIMIZE = -Os
582 LTO_FLAGS = -flto -fuse-linker-plugin $(OPTIMIZE)
583 endif
585 DEBUG_FLAGS = -ggdb3
587 CFLAGS = $(ARCH_FLAGS) \
588 $(LTO_FLAGS) \
589 $(addprefix -D,$(OPTIONS)) \
590 $(addprefix -I,$(INCLUDE_DIRS)) \
591 $(DEBUG_FLAGS) \
592 -std=gnu99 \
593 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
594 -ffunction-sections \
595 -fdata-sections \
596 $(DEVICE_FLAGS) \
597 -DUSE_STDPERIPH_DRIVER \
598 $(TARGET_FLAGS) \
599 -D'__FORKNAME__="$(FORKNAME)"' \
600 -D'__TARGET__="$(TARGET)"' \
601 -D'__REVISION__="$(REVISION)"' \
602 -save-temps=obj \
603 -MMD -MP
605 ASFLAGS = $(ARCH_FLAGS) \
606 -x assembler-with-cpp \
607 $(addprefix -I,$(INCLUDE_DIRS)) \
608 -MMD -MP
610 LDFLAGS = -lm \
611 -nostartfiles \
612 --specs=nano.specs \
613 -lc \
614 -lnosys \
615 $(ARCH_FLAGS) \
616 $(LTO_FLAGS) \
617 $(DEBUG_FLAGS) \
618 -static \
619 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
620 -Wl,-L$(LINKER_DIR) \
621 -T$(LD_SCRIPT)
623 ###############################################################################
624 # No user-serviceable parts below
625 ###############################################################################
628 # Things we will build
630 ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
631 $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS))
632 endif
634 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(TARGET).bin
635 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(TARGET).hex
636 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
637 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
638 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
639 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
641 # List of buildable ELF files and their object dependencies.
642 # It would be nice to compute these lists, but that seems to be just beyond make.
644 $(TARGET_HEX): $(TARGET_ELF)
645 $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
647 $(TARGET_BIN): $(TARGET_ELF)
648 $(OBJCOPY) -O binary $< $@
650 $(TARGET_ELF): $(TARGET_OBJS)
651 $(CC) -o $@ $^ $(LDFLAGS)
652 $(SIZE) $(TARGET_ELF)
654 # Compile
655 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
656 @mkdir -p $(dir $@)
657 @echo %% $(notdir $<)
658 @$(CC) -c -o $@ $(CFLAGS) $<
660 # Assemble
661 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
662 @mkdir -p $(dir $@)
663 @echo %% $(notdir $<)
664 @$(CC) -c -o $@ $(ASFLAGS) $<
666 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
667 @mkdir -p $(dir $@)
668 @echo %% $(notdir $<)
669 @$(CC) -c -o $@ $(ASFLAGS) $<
671 clean:
672 rm -f $(TARGET_BIN) $(TARGET_HEX) $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
673 rm -rf $(OBJECT_DIR)/$(TARGET)
674 cd src/test && $(MAKE) clean || true
676 flash_$(TARGET): $(TARGET_HEX)
677 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
678 echo -n 'R' >$(SERIAL_DEVICE)
679 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
681 flash: flash_$(TARGET)
683 st-flash_$(TARGET): $(TARGET_BIN)
684 st-flash --reset write $< 0x08000000
686 st-flash: st-flash_$(TARGET)
688 binary: $(TARGET_BIN)
690 unbrick_$(TARGET): $(TARGET_HEX)
691 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
692 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
694 unbrick: unbrick_$(TARGET)
696 help:
697 @echo ""
698 @echo "Makefile for the $(FORKNAME) firmware"
699 @echo ""
700 @echo "Usage:"
701 @echo " make [TARGET=<target>] [OPTIONS=\"<options>\"]"
702 @echo ""
703 @echo "Valid TARGET values are: $(VALID_TARGETS)"
704 @echo ""
706 ## test : run the cleanflight test suite
707 test:
708 cd src/test && $(MAKE) test || true
710 # rebuild everything when makefile changes
711 $(TARGET_OBJS) : Makefile
713 # include auto-generated dependencies
714 -include $(TARGET_DEPS)