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 iNav firmware.
10 # Invoke this with 'make help' to see the list of supported targets.
12 ###############################################################################
15 # Things that the user might override on the commandline
18 # The target to build, see VALID_TARGETS below
21 # Compile-time options
24 # compile for OpenPilot BootLoader support
27 # Debugger optons, must be empty or GDB
30 # Insert the debugging hardfault debugger
31 # releases should not be built with this flag as it does not disable pwm output
34 # Serial port/Device for flashing
35 SERIAL_DEVICE ?
= $(firstword $(wildcard /dev
/ttyUSB
*) no-port-found
)
37 # Flash size (KB). Some low-end chips actually have more flash than advertised, use this to override.
40 ###############################################################################
41 # Things that need to be maintained as the source changes
47 ROOT
:= $(patsubst %/,%,$(dir $(lastword
$(MAKEFILE_LIST
))))
48 SRC_DIR
= $(ROOT
)/src
/main
49 OBJECT_DIR
= $(ROOT
)/obj
/main
51 CMSIS_DIR
= $(ROOT
)/lib
/main
/CMSIS
52 INCLUDE_DIRS
= $(SRC_DIR
) \
53 $(ROOT
)/src
/main
/target
54 LINKER_DIR
= $(ROOT
)/src
/main
/target
56 # default xtal value for F4 targets
59 # used for turning on features like VCP and SDCARD
62 ALT_TARGETS
= $(sort $(filter-out target
, $(basename $(notdir $(wildcard $(ROOT
)/src
/main
/target
/*/*.mk
)))))
63 OPBL_TARGETS
= $(filter %_OPBL
, $(ALT_TARGETS
))
65 #VALID_TARGETS = $(F1_TARGETS) $(F3_TARGETS) $(F4_TARGETS)
66 VALID_TARGETS
= $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/target.mk
))
67 VALID_TARGETS
:= $(subst /,, $(subst .
/src
/main
/target
/,, $(VALID_TARGETS
)))
68 VALID_TARGETS
:= $(VALID_TARGETS
) $(ALT_TARGETS
)
69 VALID_TARGETS
:= $(sort $(VALID_TARGETS
))
71 ifeq ($(filter $(TARGET
),$(ALT_TARGETS
)), $(TARGET
))
72 BASE_TARGET
:= $(firstword $(subst /,, $(subst .
/src
/main
/target
/,, $(dir $(wildcard $(ROOT
)/src
/main
/target
/*/$(TARGET
).mk
)))))
73 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/$(TARGET
).mk
75 BASE_TARGET
:= $(TARGET
)
78 ifeq ($(filter $(TARGET
),$(OPBL_TARGETS
)), $(TARGET
))
82 # silently ignore if the file is not present. Allows for target specific.
83 -include $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)/target.mk
85 F4_TARGETS
= $(F405_TARGETS
) $(F411_TARGETS
)
87 ifeq ($(filter $(TARGET
),$(VALID_TARGETS
)),)
88 $(error Target
'$(TARGET)' is not valid
, must be one of
$(VALID_TARGETS
). Have you prepared a valid target.mk?
)
91 ifeq ($(filter $(TARGET
),$(F1_TARGETS
) $(F3_TARGETS
) $(F4_TARGETS
)),)
92 $(error Target
'$(TARGET)' has not specified a valid STM group
, must be one of F1
, F3
, F405
, or F411. Have you prepared a valid target.mk?
)
95 128K_TARGETS
= $(F1_TARGETS
)
96 256K_TARGETS
= $(F3_TARGETS
)
97 512K_TARGETS
= $(F411_TARGETS
)
98 1024K_TARGETS
= $(F405_TARGETS
)
100 # Configure default flash sizes for the targets (largest size specified gets hit first) if flash not specified already.
101 ifeq ($(FLASH_SIZE
),)
102 ifeq ($(TARGET
),$(filter $(TARGET
),$(1024K_TARGETS
)))
104 else ifeq ($(TARGET
),$(filter $(TARGET
),$(512K_TARGETS
)))
106 else ifeq ($(TARGET
),$(filter $(TARGET
),$(256K_TARGETS
)))
108 else ifeq ($(TARGET
),$(filter $(TARGET
),$(128K_TARGETS
)))
111 $(error FLASH_SIZE not configured for target
$(TARGET
))
115 # note that there is no hardfault debugging startup file assembly handler for other platforms
116 ifeq ($(DEBUG_HARDFAULTS
),F3
)
117 CFLAGS
+= -DDEBUG_HARDFAULTS
118 STM32F30x_COMMON_SRC
= startup_stm32f3_debug_hardfault_handler.S
120 STM32F30x_COMMON_SRC
= startup_stm32f30x_md_gcc.S
123 REVISION
= $(shell git log
-1 --format
="%h")
125 FC_VER_MAJOR
:= $(shell grep
" FC_VERSION_MAJOR" src
/main
/build
/version.h | awk
'{print $$3}' )
126 FC_VER_MINOR
:= $(shell grep
" FC_VERSION_MINOR" src
/main
/build
/version.h | awk
'{print $$3}' )
127 FC_VER_PATCH
:= $(shell grep
" FC_VERSION_PATCH" src
/main
/build
/version.h | awk
'{print $$3}' )
129 FC_VER
:= $(FC_VER_MAJOR
).
$(FC_VER_MINOR
).
$(FC_VER_PATCH
)
131 # Search path for sources
132 VPATH
:= $(SRC_DIR
):$(SRC_DIR
)/startup
133 USBFS_DIR
= $(ROOT
)/lib
/main
/STM32_USB-FS-Device_Driver
134 USBPERIPH_SRC
= $(notdir $(wildcard $(USBFS_DIR
)/src
/*.c
))
135 FATFS_DIR
= $(ROOT
)/lib
/main
/FatFS
136 FATFS_SRC
= $(notdir $(wildcard $(FATFS_DIR
)/*.c
))
138 CSOURCES
:= $(shell find
$(SRC_DIR
) -name
'*.c')
140 ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
143 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F30x_StdPeriph_Driver
144 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
145 EXCLUDES
= stm32f30x_crc.c \
148 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
149 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
151 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM1
/CoreSupport
:$(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
152 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM1
/CoreSupport
/*.c \
153 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
/*.c
))
155 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
156 $(STDPERIPH_DIR
)/inc \
157 $(CMSIS_DIR
)/CM1
/CoreSupport \
158 $(CMSIS_DIR
)/CM1
/DeviceSupport
/ST
/STM32F30x
160 ifneq ($(filter VCP
, $(FEATURES
)),)
161 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
165 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
167 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
)\
171 ifneq ($(filter SDCARD
, $(FEATURES
)),)
172 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
175 VPATH
:= $(VPATH
):$(FATFS_DIR
)
178 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k.
ld
180 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
181 DEVICE_FLAGS
= -DSTM32F303xC
-DSTM32F303
182 TARGET_FLAGS
= -D
$(TARGET
)
186 else ifeq ($(TARGET
),$(filter $(TARGET
), $(F4_TARGETS
)))
189 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F4xx_StdPeriph_Driver
190 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
191 EXCLUDES
= stm32f4xx_crc.c \
197 stm32f4xx_flash_ramfunc.c \
201 stm32f4xx_spdifrx.c \
203 stm32f4xx_cryp_aes.c \
204 stm32f4xx_hash_md5.c \
205 stm32f4xx_cryp_des.c \
209 stm32f4xx_cryp_tdes.c \
210 stm32f4xx_hash_sha1.c
213 ifeq ($(TARGET
),$(filter $(TARGET
), $(F411_TARGETS
)))
214 EXCLUDES
+= stm32f4xx_fsmc.c
217 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
220 USBCORE_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Core
221 USBCORE_SRC
= $(notdir $(wildcard $(USBCORE_DIR
)/src
/*.c
))
222 USBOTG_DIR
= $(ROOT
)/lib
/main
/STM32_USB_OTG_Driver
223 USBOTG_SRC
= $(notdir $(wildcard $(USBOTG_DIR
)/src
/*.c
))
224 EXCLUDES
= usb_bsp_template.c \
225 usb_conf_template.c \
230 USBOTG_SRC
:= $(filter-out ${EXCLUDES}, $(USBOTG_SRC
))
231 USBCDC_DIR
= $(ROOT
)/lib
/main
/STM32_USB_Device_Library
/Class
/cdc
232 USBCDC_SRC
= $(notdir $(wildcard $(USBCDC_DIR
)/src
/*.c
))
233 EXCLUDES
= usbd_cdc_if_template.c
234 USBCDC_SRC
:= $(filter-out ${EXCLUDES}, $(USBCDC_SRC
))
235 VPATH
:= $(VPATH
):$(USBOTG_DIR
)/src
:$(USBCORE_DIR
)/src
:$(USBCDC_DIR
)/src
237 DEVICE_STDPERIPH_SRC
:= $(STDPERIPH_SRC
) \
243 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM4
/CoreSupport
:$(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
244 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM4
/CoreSupport
/*.c \
245 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx
/*.c
))
246 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
247 $(STDPERIPH_DIR
)/inc \
252 $(CMSIS_DIR
)/CM4
/CoreSupport \
253 $(CMSIS_DIR
)/CM4
/DeviceSupport
/ST
/STM32F4xx \
254 $(ROOT
)/src
/main
/vcpf4
256 ifneq ($(filter SDCARD
,$(FEATURES
)),)
257 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
259 VPATH
:= $(VPATH
):$(FATFS_DIR
)
263 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m4
-march
=armv7e-m
-mfloat-abi
=hard
-mfpu
=fpv4-sp-d16
-fsingle-precision-constant
-Wdouble-promotion
265 ifeq ($(TARGET
),$(filter $(TARGET
),$(F411_TARGETS
)))
266 DEVICE_FLAGS
= -DSTM32F411xE
267 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411.
ld
268 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F405_TARGETS
)))
269 DEVICE_FLAGS
= -DSTM32F40_41xxx
270 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405.
ld
272 $(error Unknown MCU for F4 target
)
274 DEVICE_FLAGS
+= -DHSE_VALUE
=$(HSE_VALUE
)
276 TARGET_FLAGS
= -D
$(TARGET
)
282 STDPERIPH_DIR
= $(ROOT
)/lib
/main
/STM32F10x_StdPeriph_Driver
283 STDPERIPH_SRC
= $(notdir $(wildcard $(STDPERIPH_DIR
)/src
/*.c
))
284 EXCLUDES
= stm32f10x_crc.c \
288 STDPERIPH_SRC
:= $(filter-out ${EXCLUDES}, $(STDPERIPH_SRC
))
290 # Search path and source files for the CMSIS sources
291 VPATH
:= $(VPATH
):$(CMSIS_DIR
)/CM3
/CoreSupport
:$(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
292 CMSIS_SRC
= $(notdir $(wildcard $(CMSIS_DIR
)/CM3
/CoreSupport
/*.c \
293 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x
/*.c
))
295 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
296 $(STDPERIPH_DIR
)/inc \
297 $(CMSIS_DIR
)/CM3
/CoreSupport \
298 $(CMSIS_DIR
)/CM3
/DeviceSupport
/ST
/STM32F10x \
300 DEVICE_STDPERIPH_SRC
= $(STDPERIPH_SRC
)
302 ifneq ($(filter VCP
, $(FEATURES
)),)
303 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
307 VPATH
:= $(VPATH
):$(USBFS_DIR
)/src
309 DEVICE_STDPERIPH_SRC
:= $(DEVICE_STDPERIPH_SRC
) \
314 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k.
ld
315 ARCH_FLAGS
= -mthumb
-mcpu
=cortex-m3
316 TARGET_FLAGS
:= -D
$(TARGET
) -pedantic
$(TARGET_FLAGS
)
318 ifeq ($(DEVICE_FLAGS
),)
319 DEVICE_FLAGS
= -DSTM32F10X_MD
321 DEVICE_FLAGS
+= -DSTM32F10X
327 ifneq ($(BASE_TARGET
), $(TARGET
))
328 TARGET_FLAGS
:= $(TARGET_FLAGS
) -D
$(BASE_TARGET
)
331 ifneq ($(FLASH_SIZE
),)
332 DEVICE_FLAGS
:= $(DEVICE_FLAGS
) -DFLASH_SIZE
=$(FLASH_SIZE
)
335 TARGET_DIR
= $(ROOT
)/src
/main
/target
/$(BASE_TARGET
)
336 TARGET_DIR_SRC
= $(notdir $(wildcard $(TARGET_DIR
)/*.c
))
339 TARGET_FLAGS
:= -DOPBL
$(TARGET_FLAGS
)
340 ifeq ($(TARGET
), $(filter $(TARGET
),$(F405_TARGETS
)))
341 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f405_opbl.
ld
342 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F411_TARGETS
)))
343 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f411_opbl.
ld
344 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F3_TARGETS
)))
345 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f303_
$(FLASH_SIZE
)k_opbl.
ld
346 else ifeq ($(TARGET
), $(filter $(TARGET
),$(F1_TARGETS
)))
347 LD_SCRIPT
= $(LINKER_DIR
)/stm32_flash_f103_
$(FLASH_SIZE
)k_opbl.
ld
349 .DEFAULT_GOAL
:= binary
354 INCLUDE_DIRS
:= $(INCLUDE_DIRS
) \
357 VPATH
:= $(VPATH
):$(TARGET_DIR
)
360 build
/build_config.c \
370 common
/typeconversion.c \
373 fc/runtime_config.c \
375 drivers
/buf_writer.c \
376 drivers
/bus_i2c_soft.c \
378 drivers
/bus_spi_soft.c \
380 drivers
/gps_i2cnav.c \
381 drivers
/gyro_sync.c \
383 drivers
/light_led.c \
384 drivers
/rx_nrf24l01.c \
386 drivers
/pwm_mapping.c \
387 drivers
/pwm_output.c \
391 drivers
/serial_uart.c \
392 drivers
/sound_beeper.c \
405 io
/serial_4way_avrootloader.c \
406 io
/serial_4way_stk500v2.c \
409 io
/statusindicator.c \
426 scheduler
/scheduler.c \
427 scheduler
/scheduler_tasks.c \
428 sensors
/acceleration.c \
430 sensors
/boardalignment.c \
433 sensors
/initialisation.c \
435 $(DEVICE_STDPERIPH_SRC
)
438 blackbox
/blackbox.c \
439 blackbox
/blackbox_io.c \
440 common
/colorconversion.c \
441 drivers
/display_ug2864hsweg01.c \
442 flight
/navigation_rewrite.c \
443 flight
/navigation_rewrite_multicopter.c \
444 flight
/navigation_rewrite_fixedwing.c \
445 flight
/navigation_rewrite_pos_estimator.c \
446 flight
/navigation_rewrite_geo.c \
447 flight
/gps_conversion.c \
455 sensors
/rangefinder.c \
456 sensors
/barometer.c \
457 telemetry
/telemetry.c \
460 telemetry
/smartport.c \
461 telemetry
/mavlink.c \
464 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
466 vcpf4
/stm32f4xx_it.c \
470 vcpf4
/usbd_cdc_vcp.c \
471 drivers
/serial_usb_vcp.c
481 drivers
/serial_usb_vcp.c \
485 STM32F10x_COMMON_SRC
= \
486 startup_stm32f10x_md_gcc.S \
487 drivers
/adc_stm32f10x.c \
488 drivers
/bus_i2c_stm32f10x.c \
490 drivers
/gpio_stm32f10x.c \
492 drivers
/serial_softserial.c \
493 drivers
/serial_uart_stm32f10x.c \
494 drivers
/system_stm32f10x.c \
495 drivers
/timer_stm32f10x.c
497 STM32F30x_COMMON_SRC
= \
498 startup_stm32f30x_md_gcc.S \
499 target
/system_stm32f30x.c \
500 drivers
/adc_stm32f30x.c \
501 drivers
/bus_i2c_stm32f30x.c \
503 drivers
/gpio_stm32f30x.c \
504 drivers
/light_ws2811strip_stm32f30x.c \
505 drivers
/serial_uart_stm32f30x.c \
506 drivers
/system_stm32f30x.c \
507 drivers
/timer_stm32f30x.c
509 STM32F4xx_COMMON_SRC
= \
510 startup_stm32f40xx.s \
511 target
/system_stm32f4xx.c \
512 drivers
/accgyro_mpu.c \
513 drivers
/adc_stm32f4xx.c \
514 drivers
/adc_stm32f4xx.c \
515 drivers
/bus_i2c_stm32f10x.c \
516 drivers
/gpio_stm32f4xx.c \
518 drivers
/serial_softserial.c \
519 drivers
/serial_uart_stm32f4xx.c \
520 drivers
/system_stm32f4xx.c \
521 drivers
/timer_stm32f4xx.c \
522 drivers
/dma_stm32f4xx.c
524 # check if target.mk supplied
525 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
)))
526 TARGET_SRC
:= $(STM32F4xx_COMMON_SRC
) $(TARGET_SRC
)
527 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F3_TARGETS
)))
528 TARGET_SRC
:= $(STM32F30x_COMMON_SRC
) $(TARGET_SRC
)
529 else ifeq ($(TARGET
),$(filter $(TARGET
),$(F1_TARGETS
)))
530 TARGET_SRC
:= $(STM32F10x_COMMON_SRC
) $(TARGET_SRC
)
533 ifneq ($(filter ONBOARDFLASH
,$(FEATURES
)),)
535 drivers
/flash_m25p16.c \
539 ifeq ($(TARGET
),$(filter $(TARGET
),$(F4_TARGETS
) $(F3_TARGETS
)))
540 TARGET_SRC
+= $(HIGHEND_SRC
)
541 else ifneq ($(filter HIGHEND
,$(FEATURES
)),)
542 TARGET_SRC
+= $(HIGHEND_SRC
)
545 TARGET_SRC
+= $(COMMON_SRC
)
547 ifneq ($(filter SDCARD
,$(FEATURES
)),)
550 drivers
/sdcard_standard.c \
551 io
/asyncfatfs
/asyncfatfs.c \
552 io
/asyncfatfs
/fat_standard.c
555 ifneq ($(filter VCP
,$(FEATURES
)),)
556 TARGET_SRC
+= $(VCP_SRC
)
558 # end target specific make file checks
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
569 CC
= arm-none-eabi-gcc
570 OBJCOPY
= arm-none-eabi-objcopy
571 SIZE
= arm-none-eabi-size
579 LTO_FLAGS
= $(OPTIMIZE
)
582 LTO_FLAGS
= -flto
-fuse-linker-plugin
$(OPTIMIZE
)
585 DEBUG_FLAGS
= -ggdb3
-DDEBUG
587 CFLAGS
+= $(ARCH_FLAGS
) \
589 $(addprefix -D
,$(OPTIONS
)) \
590 $(addprefix -I
,$(INCLUDE_DIRS
)) \
593 -Wall
-Wextra
-Wunsafe-loop-optimizations
-Wdouble-promotion \
594 -ffunction-sections \
597 -DUSE_STDPERIPH_DRIVER \
599 -D
'__FORKNAME__="$(FORKNAME)"' \
600 -D
'__TARGET__="$(TARGET)"' \
601 -D
'__REVISION__="$(REVISION)"' \
605 ASFLAGS
= $(ARCH_FLAGS
) \
606 -x assembler-with-cpp \
607 $(addprefix -I
,$(INCLUDE_DIRS
)) \
619 -Wl
,-gc-sections
,-Map
,$(TARGET_MAP
) \
620 -Wl
,-L
$(LINKER_DIR
) \
622 -Wl
,--no-wchar-size-warning \
625 ###############################################################################
626 # No user-serviceable parts below
627 ###############################################################################
629 CPPCHECK
= cppcheck
$(CSOURCES
) --enable
=all --platform
=unix64 \
630 --std
=c99
--inline-suppr
--quiet
--force \
631 $(addprefix -I
,$(INCLUDE_DIRS
)) \
632 -I
/usr
/include -I
/usr
/include/linux
635 # Things we will build
637 TARGET_BIN
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).bin
638 TARGET_HEX
= $(BIN_DIR
)/$(FORKNAME
)_
$(FC_VER
)_
$(TARGET
).hex
639 TARGET_ELF
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).elf
640 TARGET_OBJS
= $(addsuffix .o
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
641 TARGET_DEPS
= $(addsuffix .d
,$(addprefix $(OBJECT_DIR
)/$(TARGET
)/,$(basename $(TARGET_SRC
))))
642 TARGET_MAP
= $(OBJECT_DIR
)/$(FORKNAME
)_
$(TARGET
).map
645 CLEAN_ARTIFACTS
:= $(TARGET_BIN
)
646 CLEAN_ARTIFACTS
+= $(TARGET_HEX
)
647 CLEAN_ARTIFACTS
+= $(TARGET_ELF
) $(TARGET_OBJS
) $(TARGET_MAP
)
649 # List of buildable ELF files and their object dependencies.
650 # It would be nice to compute these lists, but that seems to be just beyond make.
652 $(TARGET_HEX
): $(TARGET_ELF
)
653 $(OBJCOPY
) -O ihex
--set-start
0x8000000 $< $@
655 $(TARGET_BIN
): $(TARGET_ELF
)
656 $(OBJCOPY
) -O binary
$< $@
658 $(TARGET_ELF
): $(TARGET_OBJS
)
659 @echo LD
$(notdir $@
)
660 @
$(CC
) -o
$@
$^
$(LDFLAGS
)
661 $(SIZE
) $(TARGET_ELF
)
664 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.c
666 @echo
%% $(notdir $<)
667 @
$(CC
) -c
-o
$@
$(CFLAGS
) $<
670 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.s
672 @echo
%% $(notdir $<)
673 @
$(CC
) -c
-o
$@
$(ASFLAGS
) $<
675 $(OBJECT_DIR
)/$(TARGET
)/%.o
: %.S
677 @echo
%% $(notdir $<)
678 @
$(CC
) -c
-o
$@
$(ASFLAGS
) $<
681 ## all : Build all valid targets
682 all: $(VALID_TARGETS
)
686 echo
"Building $@" && \
687 $(MAKE
) -j binary hex TARGET
=$@
&& \
688 echo
"Building $@ succeeded."
690 ## clean : clean up all temporary / machine-generated files
692 rm -f
$(CLEAN_ARTIFACTS
)
693 rm -rf
$(OBJECT_DIR
)/$(TARGET
)
695 ## clean_test : clean up all temporary / machine-generated files (tests)
697 cd src
/test && $(MAKE
) clean || true
699 ## clean_all_targets : clean all valid target platforms
701 for clean_target in
$(VALID_TARGETS
); do \
703 echo
"Cleaning $$clean_target" && \
704 $(MAKE
) -j TARGET
=$$clean_target clean || \
706 echo
"Cleaning $$clean_target succeeded."; \
709 flash_
$(TARGET
): $(TARGET_HEX
)
710 stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
711 echo
-n
'R' >$(SERIAL_DEVICE
)
712 stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
714 ## flash : flash firmware (.hex) onto flight controller
715 flash
: flash_
$(TARGET
)
717 st-flash_
$(TARGET
): $(TARGET_BIN
)
718 st-flash
--reset write
$< 0x08000000
720 ## st-flash : flash firmware (.bin) onto flight controller
721 st-flash
: st-flash_
$(TARGET
)
723 binary
: $(TARGET_BIN
)
726 unbrick_
$(TARGET
): $(TARGET_HEX
)
727 stty
-F
$(SERIAL_DEVICE
) raw speed
115200 -crtscts cs8
-parenb
-cstopb
-ixon
728 stm32flash
-w
$(TARGET_HEX
) -v
-g
0x0 -b
115200 $(SERIAL_DEVICE
)
730 ## unbrick : unbrick flight controller
731 unbrick
: unbrick_
$(TARGET
)
733 ## cppcheck : run static analysis on C source code
734 cppcheck
: $(CSOURCES
)
737 cppcheck-result.xml
: $(CSOURCES
)
738 $(CPPCHECK
) --xml-version
=2 2> cppcheck-result.xml
740 ## help : print this help message and exit
743 @echo
"Makefile for the $(FORKNAME) firmware"
746 @echo
" make [TARGET=<target>] [OPTIONS=\"<options>\"]"
748 @echo
" make <target> [OPTIONS=\"<options>\"]"
750 @echo
"Valid TARGET values are: $(VALID_TARGETS)"
752 @sed
-n
's/^## //p' $<
754 ## targets : print a list of all valid target platforms (for consumption by scripts)
756 @echo
"Valid targets: $(VALID_TARGETS)"
757 @echo
"Target: $(TARGET)"
758 @echo
"Base target: $(BASE_TARGET)"
760 ## test : run the cleanflight test suite
762 cd src
/test && $(MAKE
) test || true
764 # rebuild everything when makefile changes
765 $(TARGET_OBJS
) : Makefile
767 # include auto-generated dependencies
768 -include $(TARGET_DEPS
)