Fixed original softserial code
[betaflight.git] / Makefile
blob3702b5c72daf282fabae0e0fb539d3dfaafee93c
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 ?= /dev/ttyUSB0
32 ###############################################################################
33 # Things that need to be maintained as the source changes
36 FORKNAME = cleanflight
38 VALID_TARGETS = NAZE NAZE32PRO OLIMEXINO STM32F3DISCOVERY CHEBUZZF3 CC3D CJMCU EUSTM32F103RC MASSIVEF3
40 # Valid targets for OP BootLoader support
41 OPBL_VALID_TARGETS = CC3D
43 REVISION = $(shell git log -1 --format="%h")
45 # Working directories
46 ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
47 SRC_DIR = $(ROOT)/src/main
48 OBJECT_DIR = $(ROOT)/obj/main
49 BIN_DIR = $(ROOT)/obj
50 CMSIS_DIR = $(ROOT)/lib/main/CMSIS
51 INCLUDE_DIRS = $(SRC_DIR)
52 LINKER_DIR = $(ROOT)/src/main/target
54 # Search path for sources
55 VPATH := $(SRC_DIR):$(SRC_DIR)/startup
57 ifeq ($(TARGET),$(filter $(TARGET),STM32F3DISCOVERY CHEBUZZF3 NAZE32PRO MASSIVEF3))
59 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver
60 USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver
62 USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c))
63 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
65 EXCLUDES = stm32f30x_crc.c \
66 stm32f30x_can.c
68 STDPERIPH_SRC := $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC))
70 DEVICE_STDPERIPH_SRC = $(USBPERIPH_SRC) \
71 $(STDPERIPH_SRC)
74 VPATH := $(VPATH):$(CMSIS_DIR)/CM1/CoreSupport:$(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x:$(USBFS_DIR)/src
75 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM1/CoreSupport/*.c \
76 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x/*.c))
78 INCLUDE_DIRS := $(INCLUDE_DIRS) \
79 $(STDPERIPH_DIR)/inc \
80 $(USBFS_DIR)/inc \
81 $(CMSIS_DIR)/CM1/CoreSupport \
82 $(CMSIS_DIR)/CM1/DeviceSupport/ST/STM32F30x \
83 $(ROOT)/src/main/vcp
85 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_256k.ld
87 ARCH_FLAGS = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
88 DEVICE_FLAGS = -DSTM32F303xC -DSTM32F303
89 TARGET_FLAGS = -D$(TARGET)
90 ifeq ($(TARGET),CHEBUZZF3)
91 # CHEBUZZ is a VARIANT of STM32F3DISCOVERY
92 TARGET_FLAGS := $(TARGET_FLAGS) -DSTM32F3DISCOVERY
93 endif
95 ifeq ($(TARGET),MASSIVEF3)
96 # MASSIVEF3 is a VARIANT of STM32F3DISCOVERY
97 TARGET_FLAGS := $(TARGET_FLAGS) -DSTM32F3DISCOVERY
98 endif
101 else ifeq ($(TARGET),$(filter $(TARGET),EUSTM32F103RC))
104 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
106 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
108 # Search path and source files for the CMSIS sources
109 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
110 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
111 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
113 INCLUDE_DIRS := $(INCLUDE_DIRS) \
114 $(STDPERIPH_DIR)/inc \
115 $(CMSIS_DIR)/CM3/CoreSupport \
116 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \
118 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_256k.ld
120 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
121 TARGET_FLAGS = -D$(TARGET) -pedantic
122 DEVICE_FLAGS = -DSTM32F10X_HD -DSTM32F10X
124 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
126 else
128 STDPERIPH_DIR = $(ROOT)/lib/main/STM32F10x_StdPeriph_Driver
130 STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c))
132 # Search path and source files for the CMSIS sources
133 VPATH := $(VPATH):$(CMSIS_DIR)/CM3/CoreSupport:$(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x
134 CMSIS_SRC = $(notdir $(wildcard $(CMSIS_DIR)/CM3/CoreSupport/*.c \
135 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x/*.c))
137 INCLUDE_DIRS := $(INCLUDE_DIRS) \
138 $(STDPERIPH_DIR)/inc \
139 $(CMSIS_DIR)/CM3/CoreSupport \
140 $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \
142 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_128k.ld
144 ARCH_FLAGS = -mthumb -mcpu=cortex-m3
145 TARGET_FLAGS = -D$(TARGET) -pedantic
146 DEVICE_FLAGS = -DSTM32F10X_MD -DSTM32F10X
148 DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC)
150 endif
152 TARGET_DIR = $(ROOT)/src/main/target/$(TARGET)
153 TARGET_SRC = $(notdir $(wildcard $(TARGET_DIR)/*.c))
155 INCLUDE_DIRS := $(INCLUDE_DIRS) \
156 $(TARGET_DIR)
158 VPATH := $(VPATH):$(TARGET_DIR)
160 COMMON_SRC = build_config.c \
161 version.c \
162 $(TARGET_SRC) \
163 config/config.c \
164 config/runtime_config.c \
165 common/maths.c \
166 common/printf.c \
167 common/typeconversion.c \
168 main.c \
169 mw.c \
170 flight/altitudehold.c \
171 flight/failsafe.c \
172 flight/flight.c \
173 flight/imu.c \
174 flight/mixer.c \
175 drivers/bus_i2c_soft.c \
176 drivers/serial.c \
177 drivers/sound_beeper.c \
178 drivers/system.c \
179 io/beeper.c \
180 io/rc_controls.c \
181 io/rc_curves.c \
182 io/serial.c \
183 io/serial_cli.c \
184 io/serial_msp.c \
185 io/statusindicator.c \
186 rx/rx.c \
187 rx/pwm.c \
188 rx/msp.c \
189 rx/sbus.c \
190 rx/sumd.c \
191 rx/sumh.c \
192 rx/spektrum.c \
193 sensors/acceleration.c \
194 sensors/battery.c \
195 sensors/boardalignment.c \
196 sensors/compass.c \
197 sensors/gyro.c \
198 sensors/initialisation.c \
199 $(CMSIS_SRC) \
200 $(DEVICE_STDPERIPH_SRC)
202 HIGHEND_SRC = flight/autotune.c \
203 flight/navigation.c \
204 flight/gps_conversion.c \
205 common/colorconversion.c \
206 io/gps.c \
207 io/ledstrip.c \
208 io/display.c \
209 telemetry/telemetry.c \
210 telemetry/frsky.c \
211 telemetry/hott.c \
212 telemetry/msp.c \
213 sensors/sonar.c \
214 sensors/barometer.c
216 NAZE_SRC = startup_stm32f10x_md_gcc.S \
217 drivers/accgyro_adxl345.c \
218 drivers/accgyro_bma280.c \
219 drivers/accgyro_l3g4200d.c \
220 drivers/accgyro_mma845x.c \
221 drivers/accgyro_mpu3050.c \
222 drivers/accgyro_mpu6050.c \
223 drivers/accgyro_spi_mpu6500.c \
224 drivers/adc.c \
225 drivers/adc_stm32f10x.c \
226 drivers/barometer_bmp085.c \
227 drivers/barometer_ms5611.c \
228 drivers/bus_spi.c \
229 drivers/bus_i2c_stm32f10x.c \
230 drivers/compass_hmc5883l.c \
231 drivers/display_ug2864hsweg01.h \
232 drivers/gpio_stm32f10x.c \
233 drivers/inverter.c \
234 drivers/light_led_stm32f10x.c \
235 drivers/light_ws2811strip.c \
236 drivers/light_ws2811strip_stm32f10x.c \
237 drivers/sonar_hcsr04.c \
238 drivers/pwm_mapping.c \
239 drivers/pwm_output.c \
240 drivers/pwm_rx.c \
241 drivers/serial_softserial.c \
242 drivers/serial_uart.c \
243 drivers/serial_uart_stm32f10x.c \
244 drivers/sound_beeper_stm32f10x.c \
245 drivers/system_stm32f10x.c \
246 drivers/timer.c \
247 drivers/timer_stm32f10x.c \
248 hardware_revision.c \
249 $(HIGHEND_SRC) \
250 $(COMMON_SRC)
252 EUSTM32F103RC_SRC = startup_stm32f10x_hd_gcc.S \
253 drivers/accgyro_adxl345.c \
254 drivers/accgyro_bma280.c \
255 drivers/accgyro_l3g4200d.c \
256 drivers/accgyro_mma845x.c \
257 drivers/accgyro_mpu3050.c \
258 drivers/accgyro_mpu6050.c \
259 drivers/accgyro_spi_mpu6000.c \
260 drivers/accgyro_spi_mpu6500.c \
261 drivers/adc.c \
262 drivers/adc_stm32f10x.c \
263 drivers/barometer_bmp085.c \
264 drivers/barometer_ms5611.c \
265 drivers/bus_i2c_stm32f10x.c \
266 drivers/bus_spi.c \
267 drivers/compass_hmc5883l.c \
268 drivers/display_ug2864hsweg01.h \
269 drivers/gpio_stm32f10x.c \
270 drivers/light_led_stm32f10x.c \
271 drivers/light_ws2811strip.c \
272 drivers/light_ws2811strip_stm32f10x.c \
273 drivers/pwm_mapping.c \
274 drivers/pwm_output.c \
275 drivers/pwm_rx.c \
276 drivers/serial_softserial.c \
277 drivers/serial_uart.c \
278 drivers/serial_uart_stm32f10x.c \
279 drivers/sonar_hcsr04.c \
280 drivers/sound_beeper_stm32f10x.c \
281 drivers/system_stm32f10x.c \
282 drivers/timer.c \
283 drivers/timer_stm32f10x.c \
284 $(HIGHEND_SRC) \
285 $(COMMON_SRC)
287 OLIMEXINO_SRC = startup_stm32f10x_md_gcc.S \
288 drivers/accgyro_mpu6050.c \
289 drivers/adc.c \
290 drivers/adc_stm32f10x.c \
291 drivers/barometer_bmp085.c \
292 drivers/bus_i2c_stm32f10x.c \
293 drivers/bus_spi.c \
294 drivers/compass_hmc5883l.c \
295 drivers/gpio_stm32f10x.c \
296 drivers/light_led_stm32f10x.c \
297 drivers/light_ws2811strip.c \
298 drivers/light_ws2811strip_stm32f10x.c \
299 drivers/pwm_mapping.c \
300 drivers/pwm_output.c \
301 drivers/pwm_rx.c \
302 drivers/serial_softserial.c \
303 drivers/serial_uart.c \
304 drivers/serial_uart_stm32f10x.c \
305 drivers/sonar_hcsr04.c \
306 drivers/sound_beeper_stm32f10x.c \
307 drivers/system_stm32f10x.c \
308 drivers/timer.c \
309 drivers/timer_stm32f10x.c \
310 $(HIGHEND_SRC) \
311 $(COMMON_SRC)
313 ifeq ($(TARGET),CJMCU)
314 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_64k.ld
315 endif
317 ifeq ($(OPBL),yes)
318 ifneq ($(filter $(TARGET),$(OPBL_VALID_TARGETS)),)
319 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_128k_opbl.ld
320 .DEFAULT_GOAL := binary
321 else
322 $(error OPBL specified with a unsupported target)
323 endif
324 endif
326 CJMCU_SRC = startup_stm32f10x_md_gcc.S \
327 drivers/adc.c \
328 drivers/adc_stm32f10x.c \
329 drivers/accgyro_mpu6050.c \
330 drivers/bus_i2c_stm32f10x.c \
331 drivers/compass_hmc5883l.c \
332 drivers/gpio_stm32f10x.c \
333 drivers/light_led_stm32f10x.c \
334 drivers/pwm_mapping.c \
335 drivers/pwm_output.c \
336 drivers/pwm_rx.c \
337 drivers/serial_uart.c \
338 drivers/serial_uart_stm32f10x.c \
339 drivers/sound_beeper_stm32f10x.c \
340 drivers/system_stm32f10x.c \
341 drivers/timer.c \
342 drivers/timer_stm32f10x.c \
343 $(COMMON_SRC)
345 CC3D_SRC = startup_stm32f10x_md_gcc.S \
346 drivers/accgyro_spi_mpu6000.c \
347 drivers/adc.c \
348 drivers/adc_stm32f10x.c \
349 drivers/bus_spi.c \
350 drivers/gpio_stm32f10x.c \
351 drivers/inverter.c \
352 drivers/light_led_stm32f10x.c \
353 drivers/light_ws2811strip.c \
354 drivers/light_ws2811strip_stm32f10x.c \
355 drivers/pwm_mapping.c \
356 drivers/pwm_output.c \
357 drivers/pwm_rx.c \
358 drivers/serial_softserial.c \
359 drivers/serial_uart.c \
360 drivers/serial_uart_stm32f10x.c \
361 drivers/sound_beeper_stm32f10x.c \
362 drivers/system_stm32f10x.c \
363 drivers/timer.c \
364 drivers/timer_stm32f10x.c \
365 $(HIGHEND_SRC) \
366 $(COMMON_SRC)
368 STM32F30x_COMMON_SRC = startup_stm32f30x_md_gcc.S \
369 drivers/adc.c \
370 drivers/adc_stm32f30x.c \
371 drivers/bus_i2c_stm32f30x.c \
372 drivers/bus_spi.c \
373 drivers/gpio_stm32f30x.c \
374 drivers/light_led_stm32f30x.c \
375 drivers/light_ws2811strip.c \
376 drivers/light_ws2811strip_stm32f30x.c \
377 drivers/pwm_mapping.c \
378 drivers/pwm_output.c \
379 drivers/pwm_rx.c \
380 drivers/serial_uart.c \
381 drivers/serial_uart_stm32f30x.c \
382 drivers/serial_usb_vcp.c \
383 drivers/sound_beeper_stm32f30x.c \
384 drivers/system_stm32f30x.c \
385 drivers/timer.c \
386 drivers/timer_stm32f30x.c \
387 vcp/hw_config.c \
388 vcp/stm32_it.c \
389 vcp/usb_desc.c \
390 vcp/usb_endp.c \
391 vcp/usb_istr.c \
392 vcp/usb_prop.c \
393 vcp/usb_pwr.c
395 NAZE32PRO_SRC = $(STM32F30x_COMMON_SRC) \
396 $(HIGHEND_SRC) \
397 $(COMMON_SRC)
399 STM32F3DISCOVERY_COMMON_SRC = $(STM32F30x_COMMON_SRC) \
400 drivers/accgyro_l3gd20.c \
401 drivers/accgyro_l3gd20.c \
402 drivers/accgyro_lsm303dlhc.c
404 STM32F3DISCOVERY_SRC = $(STM32F3DISCOVERY_COMMON_SRC) \
405 drivers/accgyro_adxl345.c \
406 drivers/accgyro_bma280.c \
407 drivers/accgyro_mma845x.c \
408 drivers/accgyro_mpu3050.c \
409 drivers/accgyro_mpu6050.c \
410 drivers/accgyro_l3g4200d.c \
411 $(HIGHEND_SRC) \
412 $(COMMON_SRC)
414 CHEBUZZF3_SRC = $(STM32F3DISCOVERY_SRC) \
415 $(HIGHEND_SRC) \
416 $(COMMON_SRC)
418 MASSIVEF3_SRC = $(STM32F3DISCOVERY_SRC) \
419 $(HIGHEND_SRC) \
420 $(COMMON_SRC)
422 ifeq ($(TARGET),MASSIVEF3)
423 LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f303_128k.ld
424 endif
426 # Search path and source files for the ST stdperiph library
427 VPATH := $(VPATH):$(STDPERIPH_DIR)/src
429 ###############################################################################
430 # Things that might need changing to use different tools
433 # Tool names
434 CC = arm-none-eabi-gcc
435 OBJCOPY = arm-none-eabi-objcopy
436 SIZE = arm-none-eabi-size
439 # Tool options.
442 ifeq ($(DEBUG),GDB)
443 OPTIMIZE = -O0
444 LTO_FLAGS = $(OPTIMIZE)
445 else
446 OPTIMIZE = -Os
447 LTO_FLAGS = -flto -fuse-linker-plugin $(OPTIMIZE)
448 endif
450 DEBUG_FLAGS = -ggdb3
452 CFLAGS = $(ARCH_FLAGS) \
453 $(LTO_FLAGS) \
454 $(addprefix -D,$(OPTIONS)) \
455 $(addprefix -I,$(INCLUDE_DIRS)) \
456 $(DEBUG_FLAGS) \
457 -std=gnu99 \
458 -Wall -Wextra -Wunsafe-loop-optimizations \
459 -ffunction-sections \
460 -fdata-sections \
461 $(DEVICE_FLAGS) \
462 -DUSE_STDPERIPH_DRIVER \
463 $(TARGET_FLAGS) \
464 -D'__FORKNAME__="$(FORKNAME)"' \
465 -D'__TARGET__="$(TARGET)"' \
466 -D'__REVISION__="$(REVISION)"' \
467 -save-temps=obj \
468 -MMD
470 ASFLAGS = $(ARCH_FLAGS) \
471 -x assembler-with-cpp \
472 $(addprefix -I,$(INCLUDE_DIRS)) \
473 -MMD
475 LDFLAGS = -lm \
476 -nostartfiles \
477 --specs=nano.specs \
478 -lc \
479 -lnosys \
480 $(ARCH_FLAGS) \
481 $(LTO_FLAGS) \
482 $(DEBUG_FLAGS) \
483 -static \
484 -Wl,-gc-sections,-Map,$(TARGET_MAP) \
485 -T$(LD_SCRIPT)
487 ###############################################################################
488 # No user-serviceable parts below
489 ###############################################################################
492 # Things we will build
494 ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
495 $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS))
496 endif
498 TARGET_BIN = $(BIN_DIR)/$(FORKNAME)_$(TARGET).bin
499 TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(TARGET).hex
500 TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf
501 TARGET_OBJS = $(addsuffix .o,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
502 TARGET_DEPS = $(addsuffix .d,$(addprefix $(OBJECT_DIR)/$(TARGET)/,$(basename $($(TARGET)_SRC))))
503 TARGET_MAP = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).map
505 # List of buildable ELF files and their object dependencies.
506 # It would be nice to compute these lists, but that seems to be just beyond make.
508 $(TARGET_HEX): $(TARGET_ELF)
509 $(OBJCOPY) -O ihex --set-start 0x8000000 $< $@
511 $(TARGET_BIN): $(TARGET_ELF)
512 $(OBJCOPY) -O binary $< $@
514 $(TARGET_ELF): $(TARGET_OBJS)
515 $(CC) -o $@ $^ $(LDFLAGS)
516 $(SIZE) $(TARGET_ELF)
518 # Compile
519 $(OBJECT_DIR)/$(TARGET)/%.o: %.c
520 @mkdir -p $(dir $@)
521 @echo %% $(notdir $<)
522 @$(CC) -c -o $@ $(CFLAGS) $<
524 # Assemble
525 $(OBJECT_DIR)/$(TARGET)/%.o: %.s
526 @mkdir -p $(dir $@)
527 @echo %% $(notdir $<)
528 @$(CC) -c -o $@ $(ASFLAGS) $<
530 $(OBJECT_DIR)/$(TARGET)/%.o: %.S
531 @mkdir -p $(dir $@)
532 @echo %% $(notdir $<)
533 @$(CC) -c -o $@ $(ASFLAGS) $<
535 clean:
536 rm -f $(TARGET_BIN) $(TARGET_HEX) $(TARGET_ELF) $(TARGET_OBJS) $(TARGET_MAP)
537 rm -rf $(OBJECT_DIR)/$(TARGET)
539 flash_$(TARGET): $(TARGET_HEX)
540 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
541 echo -n 'R' >$(SERIAL_DEVICE)
542 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
544 flash: flash_$(TARGET)
546 binary: $(TARGET_BIN)
548 unbrick_$(TARGET): $(TARGET_HEX)
549 stty -F $(SERIAL_DEVICE) raw speed 115200 -crtscts cs8 -parenb -cstopb -ixon
550 stm32flash -w $(TARGET_HEX) -v -g 0x0 -b 115200 $(SERIAL_DEVICE)
552 unbrick: unbrick_$(TARGET)
554 help:
555 @echo ""
556 @echo "Makefile for the $(FORKNAME) firmware"
557 @echo ""
558 @echo "Usage:"
559 @echo " make [TARGET=<target>] [OPTIONS=\"<options>\"]"
560 @echo ""
561 @echo "Valid TARGET values are: $(VALID_TARGETS)"
562 @echo ""
564 # rebuild everything when makefile changes
565 $(TARGET_OBJS) : Makefile
567 # include auto-generated dependencies
568 -include $(TARGET_DEPS)