use ellcc cross-compiler, BMP flasher, core board definition

This commit is contained in:
King Kévin 2017-04-03 13:06:28 +02:00
parent 0a7ed77094
commit 4d66ad2e7d
1 changed files with 34 additions and 45 deletions

View File

@ -25,38 +25,39 @@ endif
BINARY = firmware BINARY = firmware
# which development board is used # which development board is used
# supported are: SYSTEM_BOARD, MAPLE_MINI, BLUE_PILL # supported are: SYSTEM_BOARD, MAPLE_MINI, BLUE_PILL, CORE_BOARD
BOARD = BLUE_PILL BOARD = CORE_BOARD
# source files # source files
CSRC = $(wildcard *.c) CSRC = $(wildcard *.c)
CHDR = $(wildcard *.h) CHDR = $(wildcard *.h)
OBJ = $(patsubst %.c,%.o,$(CSRC)) OBJ = $(patsubst %.c,%.o,$(CSRC))
# figure out based on the includes which library files are used in the main CSRC files
DEPENDENCIES = $(patsubst %.c,%.inc,$(CSRC))
# my library collection # my library collection
LIB = lib LIB = lib
# the library files to use # the library files to use (this will be populated using includes based DEPENDENCIES)
# this will be populated using includes based DEPENDENCIES
LIB_CSRC = LIB_CSRC =
LIB_CHDR = $(patsubst %.c,%.h,$(LIB_CSRC)) LIB_CHDR = $(patsubst %.c,%.h,$(LIB_CSRC))
LIB_OBJ = $(patsubst %.c,%.o,$(LIB_CSRC)) LIB_OBJ = $(patsubst %.c,%.o,$(LIB_CSRC))
# figure out based on the includes which library files are used in the main CSRC files
DEPENDENCIES = $(patsubst %.c,%.inc,$(CSRC))
# populates LIB_CSRC based on the library files used # populates LIB_CSRC based on the library files used
-include $(DEPENDENCIES) -include $(DEPENDENCIES)
# executables for linking, compiling, debugging, ... # executables for linking, compiling, debugging, ...
PREFIX ?= arm-none-eabi # use ELLCC cross-compiling chain (based on clang/llvm + musl)
# use gcc as compiler ELLCC := /opt/ellcc/
CC := $(PREFIX)-gcc # use ELLCC as compile
# use clang as compiler CC := $(ELLCC)bin/ecc -target arm-none-eabi
#CC := clang -target $(PREFIX)
LD := $(PREFIX)-ld LD := $(PREFIX)-ld
AR := $(PREFIX)-ar LD := $(ELLCC)bin/ecc-ld -m armelf
AS := $(PREFIX)-as AR := $(ELLCC)bin/ecc-ar
OBJCOPY := $(PREFIX)-objcopy AS := $(ELLCC)bin/ecc-as
OBJDUMP := $(PREFIX)-objdump OBJCOPY := $(ELLCC)bin/ecc-objcopy
GDB := $(PREFIX)-gdb OBJDUMP := $(ELLCC)bin/ecc-objdump
# ecc-gdb is buggy and crashes on "kill"
GDB := gdb
# opencm3 libraries # opencm3 libraries
OPENCM3_DIR := libopencm3 OPENCM3_DIR := libopencm3
@ -70,6 +71,8 @@ ifeq ($(BOARD),SYSTEM_BOARD)
LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103x8.ld LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103x8.ld
else ifeq ($(BOARD),BLUE_PILL) else ifeq ($(BOARD),BLUE_PILL)
LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103x8.ld LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103x8.ld
else ifeq ($(BOARD),CORE_BOARD)
LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103x8.ld
else ifeq ($(BOARD),MAPLE_MINI) else ifeq ($(BOARD),MAPLE_MINI)
LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103xb.ld LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103xb.ld
endif endif
@ -81,7 +84,7 @@ DEFS += -DSTM32F1 -D$(BOARD)
# optimize for size # optimize for size
CFLAGS += -Os CFLAGS += -Os
# add debug symbols (remove for smaller release) # add debug symbols (remove for smaller release)
CFLAGS += -g CFLAGS += -ggdb
# use C99 (supported by most an sufficient) # use C99 (supported by most an sufficient)
CFLAGS += -std=c99 CFLAGS += -std=c99
# have strict warning (for better code) # have strict warning (for better code)
@ -90,18 +93,14 @@ CFLAGS += -Wpedantic -Wall -Werror -Wundef -Wextra -Wshadow -Wredundant-decls -W
CFLAGS += -fno-common -ffunction-sections -fdata-sections CFLAGS += -fno-common -ffunction-sections -fdata-sections
# use variable size enum (opencm3, gcc, and compiler-rt do) # use variable size enum (opencm3, gcc, and compiler-rt do)
CFLAGS += -fshort-enums CFLAGS += -fshort-enums
# use no variable size enum (musl does not) # use no variable size enum (ELLCC/musl does not)
#CFLAGS += -fno-short-enums CFLAGS += -fno-short-enums
# don't use system main definition (the starting point) # don't use system main definition (the starting point)
CFLAGS += -ffreestanding CFLAGS += -ffreestanding
# don't use the standard library # don't use the standard library
#CFLAGS += -nostdlib -nostdinc CFLAGS += -nostdlib -nostdinc
# include musl libc # include ELLCC libraries
#CFLAGS += -I /media/data/tmp/arm-linux-musleabi/arm-linux-musleabi/include CFLAGS += -I$(ELLCC)libecc/include/ -I$(ELLCC)libecc/include/arm/
# include newlib libc
#CFLAGS += -I/usr/arm-none-eabi/include/
# include gcc standard library (for printf)
#CFLAGS += -I/usr/lib/gcc/arm-none-eabi/6.1.1/include/
# include own libraries # include own libraries
CFLAGS += -I . $(patsubst %,-I%,$(LIB)) CFLAGS += -I . $(patsubst %,-I%,$(LIB))
# include opencm3 libraries # include opencm3 libraries
@ -117,32 +116,22 @@ LDFLAGS += -nostartfiles
# only keep used sections # only keep used sections
LDFLAGS += --gc-sections LDFLAGS += --gc-sections
# don't use system libraries # don't use system libraries
#LDFLAGS += -nostdlib -nostdinc LDFLAGS += -nostdlib -nostdinc
# add musl libraries (for libc, libm) # add ELLCC standard libraries (for libc, libm, libgcc)
#LDFLAGS += --library-path /media/data/tmp/arm-linux-musleabi/arm-linux-musleabi/lib LDFLAGS += --library-path $(ELLCC)libecc/lib/cortex-m3-linux/
# add system libraries (for libc, libm, libnosys)
LDFLAGS += --library-path /usr/arm-none-eabi/lib/armv7-m/
# add gcc library (for ARM ABI to be used by gcc)
LDFLAGS += --library-path /usr/lib/gcc/arm-none-eabi/*/armv7-m/
# add compiler-rt library (for ARM ABI to be used by clang)
#LDFLAGS += --library-path /usr/arm-none-eabi/lib/armv7-m/
# opencm3 libraries # opencm3 libraries
LDFLAGS += --library-path $(OPENCM3_LIB) LDFLAGS += --library-path $(OPENCM3_LIB)
# linker script with definitions for micro-controller # linker script with definitions for micro-controller
LDFLAGS += --script $(LDSCRIPT) LDFLAGS += --script $(LDSCRIPT)
# used libraries (gcc provides the ARM ABI, not sure how to replace with compiler-rt)
# used libraries when using gcc (must be provided after objects) LDLIBS += --library $(STM32F1_LIB) --library c --library m --library gcc
LDLIBS += --library $(STM32F1_LIB) --library c --library gcc --library nosys --library m
# used libraries when using clang (must be provided after objects)
#LDLIBS += --library $(STM32F1_LIB) --library c --library m --library clang_rt.builtins
# target micro-controller information (ARM Cortex-M3 supports thumb and thumnb2, but does not include a floating point unit) # target micro-controller information (ARM Cortex-M3 supports thumb and thumnb2, but does not include a floating point unit)
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float
# SWD adapter used # SWD adapter used
# supported are : st-link v2 (STLINKV2), black magic probe (BMP) # supported are : st-link v2 (STLINKV2), black magic probe (BMP)
SWD_ADAPTER ?= STLINKV2 SWD_ADAPTER ?= BMP
ifeq ($(SWD_ADAPTER),STLINKV2) ifeq ($(SWD_ADAPTER),STLINKV2)
# OpenOCD configuration # OpenOCD configuration
OOCD ?= openocd OOCD ?= openocd
@ -192,14 +181,14 @@ list: $(BINARY).list
# figure out which library source files are used for later inclusion # figure out which library source files are used for later inclusion
%.inc: %.d %.inc: %.d
$(Q)grep -o -e " ${LIB}\/[^ ]*\.h" $(<) | sed -e 's/\.h$$/.c/g' -e 's/^/LIB_CSRC +=/' > $(@) $(Q)grep -o -e " ${LIB}\/[^ ]*\.h" $(<) | sed -e 's|\(.*\)\.h$$|LIB_CSRC +=\1.c\n-include\1.inc|g' -e 's|.*${*}.*||g' > $(@)
# doxygen documentation # doxygen documentation
doc: Doxyfile README.md $(CSRC) $(CHDR) $(LIB_CSRC) $(LIB_CHDR) doc: Doxyfile README.md $(CSRC) $(CHDR) $(LIB_CSRC) $(LIB_CHDR)
$(Q)doxygen $(<) $(Q)doxygen $(<)
clean: clean:
$(Q)$(RM) $(BINARY).elf $(BINARY).bin $(BINARY).hex $(BINARY).map $(OBJ) $(LIB_OBJ) $(LIB)/*.o $(DEPENDENCIES) $(Q)$(RM) $(BINARY).elf $(BINARY).bin $(BINARY).hex $(BINARY).map $(OBJ) $(LIB_OBJ) $(LIB)/*.o $(DEPENDENCIES) $(LIB)/*.inc
# make libopencm3 if library for STM32F1 is not yet existing # make libopencm3 if library for STM32F1 is not yet existing
$(OPENCM3_LIB)/lib$(STM32F1_LIB).a: $(OPENCM3_LIB)/lib$(STM32F1_LIB).a:
@ -213,7 +202,7 @@ flash: $(BINARY).hex
ifeq ($(SWD_ADAPTER),STLINKV2) ifeq ($(SWD_ADAPTER),STLINKV2)
$(Q)$(OOCD) --file interface/$(OOCD_INTERFACE).cfg --file target/$(OOCD_TARGET).cfg --command "init" --command "reset init" --command "flash write_image erase $(<)" --command "reset" --command "shutdown" $(NULL) $(Q)$(OOCD) --file interface/$(OOCD_INTERFACE).cfg --file target/$(OOCD_TARGET).cfg --command "init" --command "reset init" --command "flash write_image erase $(<)" --command "reset" --command "shutdown" $(NULL)
else ifeq ($(SWD_ADAPTER),BMP) else ifeq ($(SWD_ADAPTER),BMP)
$(Q)$(GDB) --eval-command="target extended-remote $(BMPPORT)" --eval-command="monitor version" --eval-command="monitor swdp_scan" --eval-command="attach 1" --eval-command="load" --eval-command="detach" --eval-command="kill" --eval-command="quit" $(<) $(Q)$(GDB) --eval-command="target extended-remote $(BMPPORT)" --eval-command="set confirm off" --eval-command="kill" --eval-command="monitor swdp_scan" --eval-command="attach 1" --eval-command="load" --eval-command="kill" --eval-command="detach" --eval-command="quit" $(<)
endif endif
# reset device by setting the data width to 5 bis on the USB CDC ACM port # reset device by setting the data width to 5 bis on the USB CDC ACM port