Fix CJMCU build, broken by df92691410cf8cf2b4639c09b14abd1cf4fe6ac7
[betaflight.git] / Makefile
blobc4940a086ad7b362590ceaf0fce3a79c50d14801
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 = cleanflight
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 main.c \
225 mw.c \
226 flight/altitudehold.c \
227 flight/failsafe.c \
228 flight/pid.c \
229 flight/imu.c \
230 flight/mixer.c \
231 flight/lowpass.c \
232 flight/filter.c \
233 drivers/bus_i2c_soft.c \
234 drivers/serial.c \
235 drivers/sound_beeper.c \
236 drivers/system.c \
237 io/beeper.c \
238 io/rc_controls.c \
239 io/rc_curves.c \
240 io/serial.c \
241 io/serial_cli.c \
242 io/serial_msp.c \
243 io/statusindicator.c \
244 rx/rx.c \
245 rx/pwm.c \
246 rx/msp.c \
247 rx/sbus.c \
248 rx/sumd.c \
249 rx/sumh.c \
250 rx/spektrum.c \
251 rx/xbus.c \
252 sensors/acceleration.c \
253 sensors/battery.c \
254 sensors/boardalignment.c \
255 sensors/compass.c \
256 sensors/gyro.c \
257 sensors/initialisation.c \
258 $(CMSIS_SRC) \
259 $(DEVICE_STDPERIPH_SRC)
261 HIGHEND_SRC = flight/autotune.c \
262 flight/navigation.c \
263 flight/gps_conversion.c \
264 common/colorconversion.c \
265 io/gps.c \
266 io/ledstrip.c \
267 io/display.c \
268 telemetry/telemetry.c \
269 telemetry/frsky.c \
270 telemetry/hott.c \
271 telemetry/msp.c \
272 telemetry/smartport.c \
273 sensors/sonar.c \
274 sensors/barometer.c \
275 blackbox/blackbox.c \
276 blackbox/blackbox_io.c
278 VCP_SRC = \
279 vcp/hw_config.c \
280 vcp/stm32_it.c \
281 vcp/usb_desc.c \
282 vcp/usb_endp.c \
283 vcp/usb_istr.c \
284 vcp/usb_prop.c \
285 vcp/usb_pwr.c \
286 drivers/serial_usb_vcp.c
288 NAZE_SRC = startup_stm32f10x_md_gcc.S \
289 drivers/accgyro_adxl345.c \
290 drivers/accgyro_bma280.c \
291 drivers/accgyro_l3g4200d.c \
292 drivers/accgyro_mma845x.c \
293 drivers/accgyro_mpu3050.c \
294 drivers/accgyro_mpu6050.c \
295 drivers/accgyro_spi_mpu6500.c \
296 drivers/adc.c \
297 drivers/adc_stm32f10x.c \
298 drivers/barometer_bmp085.c \
299 drivers/barometer_ms5611.c \
300 drivers/bus_spi.c \
301 drivers/bus_i2c_stm32f10x.c \
302 drivers/compass_hmc5883l.c \
303 drivers/display_ug2864hsweg01.h \
304 drivers/flash_m25p16.c \
305 drivers/gpio_stm32f10x.c \
306 drivers/inverter.c \
307 drivers/light_led_stm32f10x.c \
308 drivers/light_ws2811strip.c \
309 drivers/light_ws2811strip_stm32f10x.c \
310 drivers/sonar_hcsr04.c \
311 drivers/pwm_mapping.c \
312 drivers/pwm_output.c \
313 drivers/pwm_rx.c \
314 drivers/serial_softserial.c \
315 drivers/serial_uart.c \
316 drivers/serial_uart_stm32f10x.c \
317 drivers/sound_beeper_stm32f10x.c \
318 drivers/system_stm32f10x.c \
319 drivers/timer.c \
320 drivers/timer_stm32f10x.c \
321 io/flashfs.c \
322 hardware_revision.c \
323 $(HIGHEND_SRC) \
324 $(COMMON_SRC)
326 ALIENWIIF1_SRC = $(NAZE_SRC)
328 EUSTM32F103RC_SRC = startup_stm32f10x_hd_gcc.S \
329 drivers/accgyro_adxl345.c \
330 drivers/accgyro_bma280.c \
331 drivers/accgyro_l3g4200d.c \
332 drivers/accgyro_mma845x.c \
333 drivers/accgyro_mpu3050.c \
334 drivers/accgyro_mpu6050.c \
335 drivers/accgyro_spi_mpu6000.c \
336 drivers/accgyro_spi_mpu6500.c \
337 drivers/adc.c \
338 drivers/adc_stm32f10x.c \
339 drivers/barometer_bmp085.c \
340 drivers/barometer_ms5611.c \
341 drivers/bus_i2c_stm32f10x.c \
342 drivers/bus_spi.c \
343 drivers/compass_ak8975.c \
344 drivers/compass_hmc5883l.c \
345 drivers/display_ug2864hsweg01.c \
346 drivers/flash_m25p16.c \
347 drivers/gpio_stm32f10x.c \
348 drivers/inverter.c \
349 drivers/light_led_stm32f10x.c \
350 drivers/light_ws2811strip.c \
351 drivers/light_ws2811strip_stm32f10x.c \
352 drivers/pwm_mapping.c \
353 drivers/pwm_output.c \
354 drivers/pwm_rx.c \
355 drivers/serial_softserial.c \
356 drivers/serial_uart.c \
357 drivers/serial_uart_stm32f10x.c \
358 drivers/sonar_hcsr04.c \
359 drivers/sound_beeper_stm32f10x.c \
360 drivers/system_stm32f10x.c \
361 drivers/timer.c \
362 drivers/timer_stm32f10x.c \
363 io/flashfs.c \
364 $(HIGHEND_SRC) \
365 $(COMMON_SRC)
367 PORT103R_SRC = $(EUSTM32F103RC_SRC)
369 OLIMEXINO_SRC = startup_stm32f10x_md_gcc.S \
370 drivers/accgyro_mpu6050.c \
371 drivers/adc.c \
372 drivers/adc_stm32f10x.c \
373 drivers/barometer_bmp085.c \
374 drivers/bus_i2c_stm32f10x.c \
375 drivers/bus_spi.c \
376 drivers/compass_hmc5883l.c \
377 drivers/gpio_stm32f10x.c \
378 drivers/light_led_stm32f10x.c \
379 drivers/light_ws2811strip.c \
380 drivers/light_ws2811strip_stm32f10x.c \
381 drivers/pwm_mapping.c \
382 drivers/pwm_output.c \
383 drivers/pwm_rx.c \
384 drivers/serial_softserial.c \
385 drivers/serial_uart.c \
386 drivers/serial_uart_stm32f10x.c \
387 drivers/sonar_hcsr04.c \
388 drivers/sound_beeper_stm32f10x.c \
389 drivers/system_stm32f10x.c \
390 drivers/timer.c \
391 drivers/timer_stm32f10x.c \
392 $(HIGHEND_SRC) \
393 $(COMMON_SRC)
395 ifeq ($(OPBL),yes)
396 ifneq ($(filter $(TARGET),$(OPBL_VALID_TARGETS)),)
397 TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
398 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k_opbl.ld
399 .DEFAULT_GOAL := binary
400 else
401 $(error OPBL specified with a unsupported target)
402 endif
403 endif
405 CJMCU_SRC = \
406 startup_stm32f10x_md_gcc.S \
407 drivers/adc.c \
408 drivers/adc_stm32f10x.c \
409 drivers/accgyro_mpu6050.c \
410 drivers/bus_i2c_stm32f10x.c \
411 drivers/compass_hmc5883l.c \
412 drivers/gpio_stm32f10x.c \
413 drivers/light_led_stm32f10x.c \
414 drivers/pwm_mapping.c \
415 drivers/pwm_output.c \
416 drivers/pwm_rx.c \
417 drivers/serial_uart.c \
418 drivers/serial_uart_stm32f10x.c \
419 drivers/sound_beeper_stm32f10x.c \
420 drivers/system_stm32f10x.c \
421 drivers/timer.c \
422 drivers/timer_stm32f10x.c \
423 hardware_revision.c \
424 blackbox/blackbox.c \
425 blackbox/blackbox_io.c \
426 $(COMMON_SRC)
428 CC3D_SRC = \
429 startup_stm32f10x_md_gcc.S \
430 drivers/accgyro_spi_mpu6000.c \
431 drivers/adc.c \
432 drivers/adc_stm32f10x.c \
433 drivers/barometer_bmp085.c \
434 drivers/barometer_ms5611.c \
435 drivers/bus_spi.c \
436 drivers/bus_i2c_stm32f10x.c \
437 drivers/compass_hmc5883l.c \
438 drivers/display_ug2864hsweg01.c \
439 drivers/flash_m25p16.c \
440 drivers/gpio_stm32f10x.c \
441 drivers/inverter.c \
442 drivers/light_led_stm32f10x.c \
443 drivers/light_ws2811strip.c \
444 drivers/light_ws2811strip_stm32f10x.c \
445 drivers/pwm_mapping.c \
446 drivers/pwm_output.c \
447 drivers/pwm_rx.c \
448 drivers/serial_softserial.c \
449 drivers/serial_uart.c \
450 drivers/serial_uart_stm32f10x.c \
451 drivers/sonar_hcsr04.c \
452 drivers/sound_beeper_stm32f10x.c \
453 drivers/system_stm32f10x.c \
454 drivers/timer.c \
455 drivers/timer_stm32f10x.c \
456 io/flashfs.c \
457 $(HIGHEND_SRC) \
458 $(COMMON_SRC) \
459 $(VCP_SRC)
461 STM32F30x_COMMON_SRC = \
462 startup_stm32f30x_md_gcc.S \
463 drivers/adc.c \
464 drivers/adc_stm32f30x.c \
465 drivers/bus_i2c_stm32f30x.c \
466 drivers/bus_spi.c \
467 drivers/gpio_stm32f30x.c \
468 drivers/light_led_stm32f30x.c \
469 drivers/light_ws2811strip.c \
470 drivers/light_ws2811strip_stm32f30x.c \
471 drivers/pwm_mapping.c \
472 drivers/pwm_output.c \
473 drivers/pwm_rx.c \
474 drivers/serial_uart.c \
475 drivers/serial_uart_stm32f30x.c \
476 drivers/sound_beeper_stm32f30x.c \
477 drivers/system_stm32f30x.c \
478 drivers/timer.c \
479 drivers/timer_stm32f30x.c
481 NAZE32PRO_SRC = \
482 $(STM32F30x_COMMON_SRC) \
483 $(HIGHEND_SRC) \
484 $(COMMON_SRC) \
485 $(VCP_SRC)
487 STM32F3DISCOVERY_COMMON_SRC = \
488 $(STM32F30x_COMMON_SRC) \
489 drivers/accgyro_l3gd20.c \
490 drivers/accgyro_l3gd20.c \
491 drivers/accgyro_lsm303dlhc.c \
492 drivers/compass_hmc5883l.c \
493 $(VCP_SRC)
495 STM32F3DISCOVERY_SRC = \
496 $(STM32F3DISCOVERY_COMMON_SRC) \
497 drivers/accgyro_adxl345.c \
498 drivers/accgyro_bma280.c \
499 drivers/accgyro_mma845x.c \
500 drivers/accgyro_mpu3050.c \
501 drivers/accgyro_mpu6050.c \
502 drivers/accgyro_l3g4200d.c \
503 drivers/barometer_ms5611.c \
504 drivers/compass_ak8975.c \
505 $(HIGHEND_SRC) \
506 $(COMMON_SRC)
508 CHEBUZZF3_SRC = \
509 $(STM32F3DISCOVERY_SRC) \
510 $(HIGHEND_SRC) \
511 $(COMMON_SRC)
513 COLIBRI_RACE_SRC = \
514 $(STM32F30x_COMMON_SRC) \
515 drivers/display_ug2864hsweg01.c \
516 drivers/accgyro_spi_mpu6500.c \
517 drivers/barometer_ms5611.c \
518 drivers/compass_ak8975.c \
519 drivers/compass_hmc5883l.c \
520 drivers/serial_usb_vcp.c \
521 $(HIGHEND_SRC) \
522 $(COMMON_SRC) \
523 $(VCP_SRC)
525 SPARKY_SRC = \
526 $(STM32F30x_COMMON_SRC) \
527 drivers/display_ug2864hsweg01.c \
528 drivers/accgyro_mpu6050.c \
529 drivers/barometer_ms5611.c \
530 drivers/compass_ak8975.c \
531 drivers/serial_usb_vcp.c \
532 $(HIGHEND_SRC) \
533 $(COMMON_SRC) \
534 $(VCP_SRC)
536 ALIENWIIF3_SRC = $(SPARKY_SRC)
538 SPRACINGF3_SRC = \
539 $(STM32F30x_COMMON_SRC) \
540 drivers/accgyro_mpu6050.c \
541 drivers/barometer_ms5611.c \
542 drivers/compass_ak8975.c \
543 drivers/compass_hmc5883l.c \
544 drivers/display_ug2864hsweg01.h \
545 drivers/flash_m25p16.c \
546 drivers/serial_softserial.c \
547 drivers/sonar_hcsr04.c \
548 io/flashfs.c \
549 $(HIGHEND_SRC) \
550 $(COMMON_SRC)
552 # Search path and source files for the ST stdperiph library
553 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
555 ###############################################################################
556 # Things that might need changing to use different tools
559 # Tool names
560 CC = arm-none-eabi-gcc
561 OBJCOPY = arm-none-eabi-objcopy
562 SIZE = arm-none-eabi-size
565 # Tool options.
568 ifeq ($(DEBUG),GDB)
569 OPTIMIZE = -O0
570 LTO_FLAGS = $(OPTIMIZE)
571 else
572 OPTIMIZE = -Os
573 LTO_FLAGS = -flto -fuse-linker-plugin $(OPTIMIZE)
574 endif
576 DEBUG_FLAGS = -ggdb3
578 CFLAGS = $(ARCH_FLAGS) \
579 $(LTO_FLAGS) \
580 $(addprefix -D,$(OPTIONS)) \
581 $(addprefix -I,$(INCLUDE_DIRS)) \
582 $(DEBUG_FLAGS) \
583 -std=gnu99 \
584 -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
585 -ffunction-sections \
586 -fdata-sections \
587 $(DEVICE_FLAGS) \
588 -DUSE_STDPERIPH_DRIVER \
589 $(TARGET_FLAGS) \
590 -D'__FORKNAME__="$(FORKNAME)"' \
591 -D'__TARGET__="$(TARGET)"' \
592 -D'__REVISION__="$(REVISION)"' \
593 -save-temps=obj \
594 -MMD -MP
596 ASFLAGS = $(ARCH_FLAGS) \
597 -x assembler-with-cpp \
598 $(addprefix -I,$(INCLUDE_DIRS)) \
599 -MMD -MP
601 LDFLAGS = -lm \
602 -nostartfiles \
603 --specs=nano.specs \
604 -lc \
605 -lnosys \
606 $(ARCH_FLAGS) \
607 $(LTO_FLAGS) \
608 $(DEBUG_FLAGS) \
609 -static \
610 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
611 -Wl,-L$(LINKER_DIR) \
612 -T$(LD_SCRIPT)
614 ###############################################################################
615 # No user-serviceable parts below
616 ###############################################################################
619 # Things we will build
621 ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
622 $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS))
623 endif
625 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(TARGET).bin
626 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(TARGET).hex
627 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
628 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
629 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
630 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
632 # List of buildable ELF files and their object dependencies.
633 # It would be nice to compute these lists, but that seems to be just beyond make.
635 $(TARGET_HEX): $(TARGET_ELF)
636 $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
638 $(TARGET_BIN): $(TARGET_ELF)
639 $(OBJCOPY) -O binary $< $@
641 $(TARGET_ELF): $(TARGET_OBJS)
642 $(CC) -o $@ $^ $(LDFLAGS)
643 $(SIZE) $(TARGET_ELF)
645 # Compile
646 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
647 @mkdir -p $(dir $@)
648 @echo %% $(notdir $<)
649 @$(CC) -c -o $@ $(CFLAGS) $<
651 # Assemble
652 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
653 @mkdir -p $(dir $@)
654 @echo %% $(notdir $<)
655 @$(CC) -c -o $@ $(ASFLAGS) $<
657 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
658 @mkdir -p $(dir $@)
659 @echo %% $(notdir $<)
660 @$(CC) -c -o $@ $(ASFLAGS) $<
662 clean:
663 rm -f $(TARGET_BIN) $(TARGET_HEX) $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
664 rm -rf $(OBJECT_DIR)/$(TARGET)
665 cd src/test && $(MAKE) clean || true
667 flash_$(TARGET): $(TARGET_HEX)
668 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
669 echo -n 'R' >$(SERIAL_DEVICE)
670 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
672 flash: flash_$(TARGET)
674 st-flash_$(TARGET): $(TARGET_BIN)
675 st-flash --reset write $< 0x08000000
677 st-flash: st-flash_$(TARGET)
679 binary: $(TARGET_BIN)
681 unbrick_$(TARGET): $(TARGET_HEX)
682 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
683 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
685 unbrick: unbrick_$(TARGET)
687 help:
688 @echo ""
689 @echo "Makefile for the $(FORKNAME) firmware"
690 @echo ""
691 @echo "Usage:"
692 @echo " make [TARGET=<target>] [OPTIONS=\"<options>\"]"
693 @echo ""
694 @echo "Valid TARGET values are: $(VALID_TARGETS)"
695 @echo ""
697 ## test : run the cleanflight test suite
698 test:
699 cd src/test && $(MAKE) test || true
701 # rebuild everything when makefile changes
702 $(TARGET_OBJS) : Makefile
704 # include auto-generated dependencies
705 -include $(TARGET_DEPS)