Makefile 18.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
###############################################################################
# "THE BEER-WARE LICENSE" (Revision 42):
# <msmith@FreeBSD.ORG> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return
###############################################################################
#
# Makefile for building the cleanflight firmware.
#
# Invoke this with 'make help' to see the list of supported targets.
Petr Ledvina's avatar
Petr Ledvina committed
11
#
12
13
14
15
16
17
18
19
20
21
22

###############################################################################
# Things that the user might override on the commandline
#

# The target to build, see VALID_TARGETS below
TARGET		?= NAZE

# Compile-time options
OPTIONS		?=

23
24
25
# compile for OpenPilot BootLoader support
OPBL ?=no

26
27
28
29
30
31
# Debugger optons, must be empty or GDB
DEBUG ?=

# Serial port/Device for flashing
SERIAL_DEVICE	?= /dev/ttyUSB0

32
33
34
# Flash size (KB).  Some low-end chips actually have more flash than advertised, use this to override.
FLASH_SIZE ?=

35
36
37
38
39
40
###############################################################################
# Things that need to be maintained as the source changes
#

FORKNAME			 = cleanflight

41
VALID_TARGETS	 = NAZE NAZE32PRO OLIMEXINO STM32F3DISCOVERY CHEBUZZF3 CC3D CJMCU EUSTM32F103RC SPRACINGF3 PORT103R SPARKY ALIENWIIF1 ALIENWIIF3
42

43
44
45
# Valid targets for OP BootLoader support
OPBL_VALID_TARGETS = CC3D

46
47
48
49
50
51
52
53
54
55
56
57
58
# Configure default flash sizes for the targets
ifeq ($(FLASH_SIZE),)
ifeq ($(TARGET),$(filter $(TARGET),CJMCU))
FLASH_SIZE = 64
else ifeq ($(TARGET),$(filter $(TARGET),NAZE CC3D ALIENWIIF1 SPRACINGF3 OLIMEXINO))
FLASH_SIZE = 128
else ifeq ($(TARGET),$(filter $(TARGET),EUSTM32F103RC PORT103R STM32F3DISCOVERY CHEBUZZF3 NAZE32PRO SPARKY ALIENWIIF3))
FLASH_SIZE = 256
else
$(error FLASH_SIZE not configured for target)
endif
endif

59
60
REVISION = $(shell git log -1 --format="%h")

61
# Working directories
Petr Ledvina's avatar
Petr Ledvina committed
62
ROOT		 := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
63
64
65
66
SRC_DIR		 = $(ROOT)/src/main
OBJECT_DIR	 = $(ROOT)/obj/main
BIN_DIR		 = $(ROOT)/obj
CMSIS_DIR	 = $(ROOT)/lib/main/CMSIS
Petr Ledvina's avatar
Petr Ledvina committed
67
68
INCLUDE_DIRS	 = $(SRC_DIR)
LINKER_DIR	 = $(ROOT)/src/main/target
69
70
71

# Search path for sources
VPATH		:= $(SRC_DIR):$(SRC_DIR)/startup
72
73
USBFS_DIR	= $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
74

75
ifeq ($(TARGET),$(filter $(TARGET),STM32F3DISCOVERY CHEBUZZF3 NAZE32PRO SPRACINGF3 SPARKY ALIENWIIF3))
76
77
78
79
80

STDPERIPH_DIR	= $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver

STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))

81
EXCLUDES	= stm32f30x_crc.c \
82
83
84
85
		stm32f30x_can.c

STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))

86
DEVICE_STDPERIPH_SRC = \
87
88
89
		$(STDPERIPH_SRC)


90
VPATH		:= $(VPATH):$(CMSIS_DIR)/CM1/CoreSupport:$(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x
91
92
93
94
95
96
CMSIS_SRC	 = $(notdir $(wildcard $(CMSIS_DIR)/CM1/CoreSupport/*.c \
			   $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x/*.c))

INCLUDE_DIRS := $(INCLUDE_DIRS) \
		   $(STDPERIPH_DIR)/inc \
		   $(CMSIS_DIR)/CM1/CoreSupport \
97
98
99
100
101
		   $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x

ifneq ($(TARGET),SPRACINGF3)
INCLUDE_DIRS := $(INCLUDE_DIRS) \
		   $(USBFS_DIR)/inc \
102
103
		   $(ROOT)/src/main/vcp

104
105
106
107
108
109
110
VPATH := $(VPATH):$(USBFS_DIR)/src

DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC)\
		   $(USBPERIPH_SRC) 

endif

111
LD_SCRIPT	 = $(LINKER_DIR)/stm32_flash_f303_$(FLASH_SIZE)k.ld
112

113
ARCH_FLAGS	 = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
114
DEVICE_FLAGS = -DSTM32F303xC -DSTM32F303
115
116
117
118
119
120
TARGET_FLAGS = -D$(TARGET)
ifeq ($(TARGET),CHEBUZZF3)
# CHEBUZZ is a VARIANT of STM32F3DISCOVERY
TARGET_FLAGS := $(TARGET_FLAGS) -DSTM32F3DISCOVERY
endif

121
else ifeq ($(TARGET),$(filter $(TARGET),EUSTM32F103RC PORT103R))
122
123
124
125
126
127


STDPERIPH_DIR	 = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver

STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))

128
129
130
131
132
133
EXCLUDES	= stm32f10x_crc.c \
		stm32f10x_cec.c \
		stm32f10x_can.c

STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))

134
135
136
137
138
139
140
141
142
143
# Search path and source files for the CMSIS sources
VPATH		:= $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
CMSIS_SRC	 = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
			   $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))

INCLUDE_DIRS := $(INCLUDE_DIRS) \
		   $(STDPERIPH_DIR)/inc \
		   $(CMSIS_DIR)/CM3/CoreSupport \
		   $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \

144
LD_SCRIPT	 = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
145
146
147
148
149
150
151

ARCH_FLAGS	 = -mthumb -mcpu=cortex-m3
TARGET_FLAGS = -D$(TARGET) -pedantic
DEVICE_FLAGS = -DSTM32F10X_HD -DSTM32F10X

DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)

152
153
154
155
156
157
else

STDPERIPH_DIR	 = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver

STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))

158
159
160
161
162
163
EXCLUDES	= stm32f10x_crc.c \
		stm32f10x_cec.c \
		stm32f10x_can.c

STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))

164
165
166
167
168
169
170
171
172
173
# Search path and source files for the CMSIS sources
VPATH		:= $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
CMSIS_SRC	 = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
			   $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))

INCLUDE_DIRS := $(INCLUDE_DIRS) \
		   $(STDPERIPH_DIR)/inc \
		   $(CMSIS_DIR)/CM3/CoreSupport \
		   $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \

174
175
176
177
178
179
180
181
182
183
184
185
186
187
DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)

ifeq ($(TARGET),CC3D)
INCLUDE_DIRS := $(INCLUDE_DIRS) \
		   $(USBFS_DIR)/inc \
		   $(ROOT)/src/main/vcp

VPATH := $(VPATH):$(USBFS_DIR)/src

DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \
		   $(USBPERIPH_SRC) 

endif

188
LD_SCRIPT	 = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k.ld
189
190

ARCH_FLAGS	 = -mthumb -mcpu=cortex-m3
191
TARGET_FLAGS = -D$(TARGET) -pedantic
192
DEVICE_FLAGS = -DSTM32F10X_MD -DSTM32F10X
193
194
195

endif

196
197
198
199
ifneq ($(FLASH_SIZE),)
DEVICE_FLAGS := $(DEVICE_FLAGS) -DFLASH_SIZE=$(FLASH_SIZE)
endif

200
201
202
TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
TARGET_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))

203
204
205
206
207
208
ifeq ($(TARGET),ALIENWIIF1)
# ALIENWIIF1 is a VARIANT of NAZE
TARGET_FLAGS := $(TARGET_FLAGS) -DNAZE -DALIENWII32
TARGET_DIR = $(ROOT)/src/main/target/NAZE
endif

209
210
211
212
213
214
INCLUDE_DIRS := $(INCLUDE_DIRS) \
		    $(TARGET_DIR)

VPATH		:= $(VPATH):$(TARGET_DIR)

COMMON_SRC	 = build_config.c \
Dominic Clifton's avatar
Dominic Clifton committed
215
		   debug.c \
216
		   version.c \
217
218
219
220
221
222
		   $(TARGET_SRC) \
		   config/config.c \
		   config/runtime_config.c \
		   common/maths.c \
		   common/printf.c \
		   common/typeconversion.c \
223
		   common/encoding.c \
224
225
226
227
		   main.c \
		   mw.c \
		   flight/altitudehold.c \
		   flight/failsafe.c \
228
		   flight/pid.c \
229
230
		   flight/imu.c \
		   flight/mixer.c \
231
		   flight/lowpass.c \
232
233
234
235
236
237
238
239
240
241
242
243
244
245
		   drivers/bus_i2c_soft.c \
		   drivers/serial.c \
		   drivers/sound_beeper.c \
		   drivers/system.c \
		   io/beeper.c \
		   io/rc_controls.c \
		   io/rc_curves.c \
		   io/serial.c \
		   io/serial_cli.c \
		   io/serial_msp.c \
		   io/statusindicator.c \
		   rx/rx.c \
		   rx/pwm.c \
		   rx/msp.c \
246
247
		   rx/sbus.c \
		   rx/sumd.c \
248
		   rx/sumh.c \
249
		   rx/spektrum.c \
250
		   rx/xbus.c \
251
252
253
254
255
256
257
258
259
260
		   sensors/acceleration.c \
		   sensors/battery.c \
		   sensors/boardalignment.c \
		   sensors/compass.c \
		   sensors/gyro.c \
		   sensors/initialisation.c \
		   $(CMSIS_SRC) \
		   $(DEVICE_STDPERIPH_SRC)

HIGHEND_SRC  = flight/autotune.c \
261
262
		   flight/navigation.c \
		   flight/gps_conversion.c \
263
		   common/colorconversion.c \
264
265
		   io/gps.c \
		   io/ledstrip.c \
Dominic Clifton's avatar
Dominic Clifton committed
266
		   io/display.c \
267
268
269
270
		   telemetry/telemetry.c \
		   telemetry/frsky.c \
		   telemetry/hott.c \
		   telemetry/msp.c \
271
		   telemetry/smartport.c \
272
		   sensors/sonar.c \
Nicholas Sherlock's avatar
Nicholas Sherlock committed
273
		   sensors/barometer.c \
274
275
		   blackbox/blackbox.c \
		   blackbox/blackbox_io.c
276

277
278
279
280
281
282
283
284
285
286
VCP_SRC	 = \
		   vcp/hw_config.c \
		   vcp/stm32_it.c \
		   vcp/usb_desc.c \
		   vcp/usb_endp.c \
		   vcp/usb_istr.c \
		   vcp/usb_prop.c \
		   vcp/usb_pwr.c \
		   drivers/serial_usb_vcp.c

287
288
289
290
291
292
293
NAZE_SRC	 = startup_stm32f10x_md_gcc.S \
		   drivers/accgyro_adxl345.c \
		   drivers/accgyro_bma280.c \
		   drivers/accgyro_l3g4200d.c \
		   drivers/accgyro_mma845x.c \
		   drivers/accgyro_mpu3050.c \
		   drivers/accgyro_mpu6050.c \
294
		   drivers/accgyro_spi_mpu6500.c \
295
296
297
298
299
300
301
		   drivers/adc.c \
		   drivers/adc_stm32f10x.c \
		   drivers/barometer_bmp085.c \
		   drivers/barometer_ms5611.c \
		   drivers/bus_spi.c \
		   drivers/bus_i2c_stm32f10x.c \
		   drivers/compass_hmc5883l.c \
302
		   drivers/display_ug2864hsweg01.h \
303
		   drivers/gpio_stm32f10x.c \
304
		   drivers/inverter.c \
305
306
307
308
309
310
311
312
313
314
315
316
317
		   drivers/light_led_stm32f10x.c \
		   drivers/light_ws2811strip.c \
		   drivers/light_ws2811strip_stm32f10x.c \
		   drivers/sonar_hcsr04.c \
		   drivers/pwm_mapping.c \
		   drivers/pwm_output.c \
		   drivers/pwm_rx.c \
		   drivers/serial_softserial.c \
		   drivers/serial_uart.c \
		   drivers/serial_uart_stm32f10x.c \
		   drivers/sound_beeper_stm32f10x.c \
		   drivers/system_stm32f10x.c \
		   drivers/timer.c \
Petr Ledvina's avatar
Petr Ledvina committed
318
		   drivers/timer_stm32f10x.c \
319
320
		   drivers/flash_m25p16.c \
		   io/flashfs.c \
321
		   hardware_revision.c \
322
323
324
		   $(HIGHEND_SRC) \
		   $(COMMON_SRC)

325
ALIENWIIF1_SRC	 = $(NAZE_SRC)
326

327
EUSTM32F103RC_SRC	 = startup_stm32f10x_hd_gcc.S \
328
329
		   drivers/accgyro_adxl345.c \
		   drivers/accgyro_bma280.c \
Dominic Clifton's avatar
Dominic Clifton committed
330
		   drivers/accgyro_l3g4200d.c \
331
332
333
334
335
		   drivers/accgyro_mma845x.c \
		   drivers/accgyro_mpu3050.c \
		   drivers/accgyro_mpu6050.c \
		   drivers/accgyro_spi_mpu6000.c \
		   drivers/accgyro_spi_mpu6500.c \
336
337
338
		   drivers/adc.c \
		   drivers/adc_stm32f10x.c \
		   drivers/barometer_bmp085.c \
339
		   drivers/barometer_ms5611.c \
340
341
		   drivers/bus_i2c_stm32f10x.c \
		   drivers/bus_spi.c \
342
		   drivers/compass_ak8975.c \
343
		   drivers/compass_hmc5883l.c \
344
		   drivers/display_ug2864hsweg01.c \
345
		   drivers/gpio_stm32f10x.c \
346
		   drivers/inverter.c \
347
348
349
350
351
352
353
354
355
356
357
358
359
		   drivers/light_led_stm32f10x.c \
		   drivers/light_ws2811strip.c \
		   drivers/light_ws2811strip_stm32f10x.c \
		   drivers/pwm_mapping.c \
		   drivers/pwm_output.c \
		   drivers/pwm_rx.c \
		   drivers/serial_softserial.c \
		   drivers/serial_uart.c \
		   drivers/serial_uart_stm32f10x.c \
		   drivers/sonar_hcsr04.c \
		   drivers/sound_beeper_stm32f10x.c \
		   drivers/system_stm32f10x.c \
		   drivers/timer.c \
Petr Ledvina's avatar
Petr Ledvina committed
360
		   drivers/timer_stm32f10x.c \
361
362
363
		   $(HIGHEND_SRC) \
		   $(COMMON_SRC)

364
365
PORT103R_SRC = $(EUSTM32F103RC_SRC)

366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
OLIMEXINO_SRC	 = startup_stm32f10x_md_gcc.S \
		   drivers/accgyro_mpu6050.c \
		   drivers/adc.c \
		   drivers/adc_stm32f10x.c \
		   drivers/barometer_bmp085.c \
		   drivers/bus_i2c_stm32f10x.c \
		   drivers/bus_spi.c \
		   drivers/compass_hmc5883l.c \
		   drivers/gpio_stm32f10x.c \
		   drivers/light_led_stm32f10x.c \
		   drivers/light_ws2811strip.c \
		   drivers/light_ws2811strip_stm32f10x.c \
		   drivers/pwm_mapping.c \
		   drivers/pwm_output.c \
		   drivers/pwm_rx.c \
		   drivers/serial_softserial.c \
		   drivers/serial_uart.c \
		   drivers/serial_uart_stm32f10x.c \
384
		   drivers/sonar_hcsr04.c \
385
386
387
		   drivers/sound_beeper_stm32f10x.c \
		   drivers/system_stm32f10x.c \
		   drivers/timer.c \
Petr Ledvina's avatar
Petr Ledvina committed
388
		   drivers/timer_stm32f10x.c \
389
390
391
		   $(HIGHEND_SRC) \
		   $(COMMON_SRC)

392
393
ifeq ($(OPBL),yes)
ifneq ($(filter $(TARGET),$(OPBL_VALID_TARGETS)),)
394
TARGET_FLAGS := -DOPBL $(TARGET_FLAGS)
395
LD_SCRIPT	 = $(LINKER_DIR)/stm32_flash_f103_$(FLASH_SIZE)k_opbl.ld
396
397
398
399
400
401
.DEFAULT_GOAL := binary
else
$(error OPBL specified with a unsupported target)
endif
endif

402
403
CJMCU_SRC	 = \
		   startup_stm32f10x_md_gcc.S \
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
		   drivers/adc.c \
		   drivers/adc_stm32f10x.c \
		   drivers/accgyro_mpu6050.c \
		   drivers/bus_i2c_stm32f10x.c \
		   drivers/compass_hmc5883l.c \
		   drivers/gpio_stm32f10x.c \
		   drivers/light_led_stm32f10x.c \
		   drivers/pwm_mapping.c \
		   drivers/pwm_output.c \
		   drivers/pwm_rx.c \
		   drivers/serial_uart.c \
		   drivers/serial_uart_stm32f10x.c \
		   drivers/sound_beeper_stm32f10x.c \
		   drivers/system_stm32f10x.c \
		   drivers/timer.c \
Petr Ledvina's avatar
Petr Ledvina committed
419
		   drivers/timer_stm32f10x.c \
420
		   hardware_revision.c \
421
422
		   blackbox/blackbox.c \
		   blackbox/blackbox_io.c \
423
424
		   $(COMMON_SRC)

425
426
CC3D_SRC	 = \
		   startup_stm32f10x_md_gcc.S \
427
428
429
		   drivers/accgyro_spi_mpu6000.c \
		   drivers/adc.c \
		   drivers/adc_stm32f10x.c \
430
431
		   drivers/barometer_bmp085.c \
		   drivers/barometer_ms5611.c \
432
		   drivers/bus_spi.c \
433
434
435
		   drivers/bus_i2c_stm32f10x.c \
		   drivers/compass_hmc5883l.c \
		   drivers/display_ug2864hsweg01.c \
436
		   drivers/gpio_stm32f10x.c \
437
		   drivers/inverter.c \
438
439
440
441
442
443
444
445
446
		   drivers/light_led_stm32f10x.c \
		   drivers/light_ws2811strip.c \
		   drivers/light_ws2811strip_stm32f10x.c \
		   drivers/pwm_mapping.c \
		   drivers/pwm_output.c \
		   drivers/pwm_rx.c \
		   drivers/serial_softserial.c \
		   drivers/serial_uart.c \
		   drivers/serial_uart_stm32f10x.c \
Dominic Clifton's avatar
Dominic Clifton committed
447
		   drivers/sonar_hcsr04.c \
448
449
450
		   drivers/sound_beeper_stm32f10x.c \
		   drivers/system_stm32f10x.c \
		   drivers/timer.c \
Petr Ledvina's avatar
Petr Ledvina committed
451
		   drivers/timer_stm32f10x.c \
452
453
		   drivers/flash_m25p16.c \
		   io/flashfs.c \
454
		   $(HIGHEND_SRC) \
455
456
		   $(COMMON_SRC) \
		   $(VCP_SRC)
457

458
459
STM32F30x_COMMON_SRC	 = \
		   startup_stm32f30x_md_gcc.S \
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
		   drivers/adc.c \
		   drivers/adc_stm32f30x.c \
		   drivers/bus_i2c_stm32f30x.c \
		   drivers/bus_spi.c \
		   drivers/gpio_stm32f30x.c \
		   drivers/light_led_stm32f30x.c \
		   drivers/light_ws2811strip.c \
		   drivers/light_ws2811strip_stm32f30x.c \
		   drivers/pwm_mapping.c \
		   drivers/pwm_output.c \
		   drivers/pwm_rx.c \
		   drivers/serial_uart.c \
		   drivers/serial_uart_stm32f30x.c \
		   drivers/sound_beeper_stm32f30x.c \
		   drivers/system_stm32f30x.c \
		   drivers/timer.c \
476
477
478
479
		   drivers/timer_stm32f30x.c

NAZE32PRO_SRC	 = \
		   $(STM32F30x_COMMON_SRC) \
480
		   $(HIGHEND_SRC) \
481
482
		   $(COMMON_SRC) \
		   $(VCP_SRC)
483

484
485
STM32F3DISCOVERY_COMMON_SRC	 = \
		   $(STM32F30x_COMMON_SRC) \
486
487
		   drivers/accgyro_l3gd20.c \
		   drivers/accgyro_l3gd20.c \
488
		   drivers/accgyro_lsm303dlhc.c \
489
		   drivers/compass_hmc5883l.c \
490
		   $(VCP_SRC)
491

492
493
STM32F3DISCOVERY_SRC	 = \
		   $(STM32F3DISCOVERY_COMMON_SRC) \
494
495
496
497
498
499
		   drivers/accgyro_adxl345.c \
		   drivers/accgyro_bma280.c \
		   drivers/accgyro_mma845x.c \
		   drivers/accgyro_mpu3050.c \
		   drivers/accgyro_mpu6050.c \
		   drivers/accgyro_l3g4200d.c \
500
501
		   drivers/barometer_ms5611.c \
		   drivers/compass_ak8975.c \
502
503
504
		   $(HIGHEND_SRC) \
		   $(COMMON_SRC)

505
506
CHEBUZZF3_SRC	 = \
		   $(STM32F3DISCOVERY_SRC) \
Dominic Clifton's avatar
Dominic Clifton committed
507
508
		   $(HIGHEND_SRC) \
		   $(COMMON_SRC)
Petr Ledvina's avatar
Petr Ledvina committed
509

510
511
SPARKY_SRC	 = \
		   $(STM32F30x_COMMON_SRC) \
512
		   drivers/display_ug2864hsweg01.c \
Dominic Clifton's avatar
Dominic Clifton committed
513
		   drivers/accgyro_mpu6050.c \
514
		   drivers/barometer_ms5611.c \
515
		   drivers/compass_ak8975.c \
516
517
518
519
520
		   drivers/serial_usb_vcp.c \
		   $(HIGHEND_SRC) \
		   $(COMMON_SRC) \
		   $(VCP_SRC)

521
522
ALIENWIIF3_SRC	 = $(SPARKY_SRC)

523
524
525
526
SPRACINGF3_SRC	 = \
		   $(STM32F30x_COMMON_SRC) \
		   drivers/accgyro_mpu6050.c \
		   drivers/barometer_ms5611.c \
527
		   drivers/compass_ak8975.c \
528
		   drivers/compass_hmc5883l.c \
529
		   drivers/display_ug2864hsweg01.h \
530
		   drivers/flash_m25p16.c \
531
		   drivers/sonar_hcsr04.c \
532
		   io/flashfs.c \
533
534
535
		   $(HIGHEND_SRC) \
		   $(COMMON_SRC)

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# Search path and source files for the ST stdperiph library
VPATH		:= $(VPATH):$(STDPERIPH_DIR)/src

###############################################################################
# Things that might need changing to use different tools
#

# Tool names
CC		 = arm-none-eabi-gcc
OBJCOPY		 = arm-none-eabi-objcopy
SIZE		 = arm-none-eabi-size

#
# Tool options.
#

ifeq ($(DEBUG),GDB)
OPTIMIZE	 = -O0
LTO_FLAGS	 = $(OPTIMIZE)
else
OPTIMIZE	 = -Os
557
LTO_FLAGS	 = -flto -fuse-linker-plugin $(OPTIMIZE)
558
559
560
561
562
endif

DEBUG_FLAGS	 = -ggdb3

CFLAGS		 = $(ARCH_FLAGS) \
563
		   $(LTO_FLAGS) \
564
565
566
567
		   $(addprefix -D,$(OPTIONS)) \
		   $(addprefix -I,$(INCLUDE_DIRS)) \
		   $(DEBUG_FLAGS) \
		   -std=gnu99 \
Petr Ledvina's avatar
Petr Ledvina committed
568
		   -Wall -Wextra -Wunsafe-loop-optimizations -Wdouble-promotion \
569
570
571
572
573
574
		   -ffunction-sections \
		   -fdata-sections \
		   $(DEVICE_FLAGS) \
		   -DUSE_STDPERIPH_DRIVER \
		   $(TARGET_FLAGS) \
		   -D'__FORKNAME__="$(FORKNAME)"' \
575
		   -D'__TARGET__="$(TARGET)"' \
576
		   -D'__REVISION__="$(REVISION)"' \
Petr Ledvina's avatar
Petr Ledvina committed
577
		   -save-temps=obj \
578
		   -MMD -MP
579
580
581

ASFLAGS		 = $(ARCH_FLAGS) \
		   -x assembler-with-cpp \
Petr Ledvina's avatar
Petr Ledvina committed
582
		   $(addprefix -I,$(INCLUDE_DIRS)) \
583
		  -MMD -MP
584

585
586
587
588
589
LDFLAGS		 = -lm \
		   -nostartfiles \
		   --specs=nano.specs \
		   -lc \
		   -lnosys \
590
		   $(ARCH_FLAGS) \
591
		   $(LTO_FLAGS) \
592
593
594
		   $(DEBUG_FLAGS) \
		   -static \
		   -Wl,-gc-sections,-Map,$(TARGET_MAP) \
595
		   -Wl,-L$(LINKER_DIR) \
596
		   -T$(LD_SCRIPT)
597
598
599
600
601
602
603
604
605
606
607
608

###############################################################################
# No user-serviceable parts below
###############################################################################

#
# Things we will build
#
ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
$(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS))
endif

609
TARGET_BIN	 = $(BIN_DIR)/$(FORKNAME)_$(TARGET).bin
610
611
612
TARGET_HEX	 = $(BIN_DIR)/$(FORKNAME)_$(TARGET).hex
TARGET_ELF	 = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
TARGET_OBJS	 = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
Petr Ledvina's avatar
Petr Ledvina committed
613
614
TARGET_DEPS	 = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
TARGET_MAP	 = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
615
616
617
618
619
620
621

# List of buildable ELF files and their object dependencies.
# It would be nice to compute these lists, but that seems to be just beyond make.

$(TARGET_HEX): $(TARGET_ELF)
	$(OBJCOPY) -O ihex --set-start 0x8000000 $< $@

622
623
624
$(TARGET_BIN): $(TARGET_ELF)
	$(OBJCOPY) -O binary $< $@

625
626
627
628
629
630
631
632
633
634
635
636
637
638
$(TARGET_ELF):  $(TARGET_OBJS)
	$(CC) -o $@ $^ $(LDFLAGS)
	$(SIZE) $(TARGET_ELF) 

# Compile
$(OBJECT_DIR)/$(TARGET)/%.o: %.c
	@mkdir -p $(dir $@)
	@echo %% $(notdir $<)
	@$(CC) -c -o $@ $(CFLAGS) $<

# Assemble
$(OBJECT_DIR)/$(TARGET)/%.o: %.s
	@mkdir -p $(dir $@)
	@echo %% $(notdir $<)
Petr Ledvina's avatar
Petr Ledvina committed
639
640
	@$(CC) -c -o $@ $(ASFLAGS) $<

goebish's avatar
goebish committed
641
$(OBJECT_DIR)/$(TARGET)/%.o: %.S
642
643
	@mkdir -p $(dir $@)
	@echo %% $(notdir $<)
Petr Ledvina's avatar
Petr Ledvina committed
644
	@$(CC) -c -o $@ $(ASFLAGS) $<
645
646

clean:
647
	rm -f $(TARGET_BIN) $(TARGET_HEX) $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
648
649
650
651
652
653
654
655
656
	rm -rf $(OBJECT_DIR)/$(TARGET)

flash_$(TARGET): $(TARGET_HEX)
	stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
	echo -n 'R' >$(SERIAL_DEVICE)
	stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)

flash: flash_$(TARGET)

657
binary: $(TARGET_BIN)
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673

unbrick_$(TARGET): $(TARGET_HEX)
	stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
	stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)

unbrick: unbrick_$(TARGET)

help:
	@echo ""
	@echo "Makefile for the $(FORKNAME) firmware"
	@echo ""
	@echo "Usage:"
	@echo "        make [TARGET=<target>] [OPTIONS=\"<options>\"]"
	@echo ""
	@echo "Valid TARGET values are: $(VALID_TARGETS)"
	@echo ""
Petr Ledvina's avatar
Petr Ledvina committed
674
675
676
677
678
679

# rebuild everything when makefile changes
$(TARGET_OBJS) : Makefile

# include auto-generated dependencies
-include $(TARGET_DEPS)