diff --git a/Makefile b/Makefile index 5985440..fb3f88c 100644 --- a/Makefile +++ b/Makefile @@ -25,38 +25,39 @@ endif BINARY = firmware # which development board is used -# supported are: SYSTEM_BOARD, MAPLE_MINI, BLUE_PILL -BOARD = BLUE_PILL +# supported are: SYSTEM_BOARD, MAPLE_MINI, BLUE_PILL, CORE_BOARD +BOARD = CORE_BOARD # source files CSRC = $(wildcard *.c) CHDR = $(wildcard *.h) 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 LIB = lib -# the library files to use -# this will be populated using includes based DEPENDENCIES +# the library files to use (this will be populated using includes based DEPENDENCIES) LIB_CSRC = LIB_CHDR = $(patsubst %.c,%.h,$(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 -include $(DEPENDENCIES) # executables for linking, compiling, debugging, ... -PREFIX ?= arm-none-eabi -# use gcc as compiler -CC := $(PREFIX)-gcc -# use clang as compiler -#CC := clang -target $(PREFIX) +# use ELLCC cross-compiling chain (based on clang/llvm + musl) +ELLCC := /opt/ellcc/ +# use ELLCC as compile +CC := $(ELLCC)bin/ecc -target arm-none-eabi LD := $(PREFIX)-ld -AR := $(PREFIX)-ar -AS := $(PREFIX)-as -OBJCOPY := $(PREFIX)-objcopy -OBJDUMP := $(PREFIX)-objdump -GDB := $(PREFIX)-gdb +LD := $(ELLCC)bin/ecc-ld -m armelf +AR := $(ELLCC)bin/ecc-ar +AS := $(ELLCC)bin/ecc-as +OBJCOPY := $(ELLCC)bin/ecc-objcopy +OBJDUMP := $(ELLCC)bin/ecc-objdump +# ecc-gdb is buggy and crashes on "kill" +GDB := gdb # opencm3 libraries OPENCM3_DIR := libopencm3 @@ -70,6 +71,8 @@ ifeq ($(BOARD),SYSTEM_BOARD) LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103x8.ld else ifeq ($(BOARD),BLUE_PILL) 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) LDSCRIPT = $(OPENCM3_DIR)/lib/stm32/f1/stm32f103xb.ld endif @@ -81,7 +84,7 @@ DEFS += -DSTM32F1 -D$(BOARD) # optimize for size CFLAGS += -Os # add debug symbols (remove for smaller release) -CFLAGS += -g +CFLAGS += -ggdb # use C99 (supported by most an sufficient) CFLAGS += -std=c99 # 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 # use variable size enum (opencm3, gcc, and compiler-rt do) CFLAGS += -fshort-enums -# use no variable size enum (musl does not) -#CFLAGS += -fno-short-enums +# use no variable size enum (ELLCC/musl does not) +CFLAGS += -fno-short-enums # don't use system main definition (the starting point) CFLAGS += -ffreestanding # don't use the standard library -#CFLAGS += -nostdlib -nostdinc -# include musl libc -#CFLAGS += -I /media/data/tmp/arm-linux-musleabi/arm-linux-musleabi/include -# 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/ +CFLAGS += -nostdlib -nostdinc +# include ELLCC libraries +CFLAGS += -I$(ELLCC)libecc/include/ -I$(ELLCC)libecc/include/arm/ # include own libraries CFLAGS += -I . $(patsubst %,-I%,$(LIB)) # include opencm3 libraries @@ -117,32 +116,22 @@ LDFLAGS += -nostartfiles # only keep used sections LDFLAGS += --gc-sections # don't use system libraries -#LDFLAGS += -nostdlib -nostdinc -# add musl libraries (for libc, libm) -#LDFLAGS += --library-path /media/data/tmp/arm-linux-musleabi/arm-linux-musleabi/lib -# 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/ +LDFLAGS += -nostdlib -nostdinc +# add ELLCC standard libraries (for libc, libm, libgcc) +LDFLAGS += --library-path $(ELLCC)libecc/lib/cortex-m3-linux/ # opencm3 libraries LDFLAGS += --library-path $(OPENCM3_LIB) - # linker script with definitions for micro-controller LDFLAGS += --script $(LDSCRIPT) - -# used libraries when using gcc (must be provided after objects) -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 +# used libraries (gcc provides the ARM ABI, not sure how to replace with compiler-rt) +LDLIBS += --library $(STM32F1_LIB) --library c --library m --library gcc # 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 # SWD adapter used # supported are : st-link v2 (STLINKV2), black magic probe (BMP) -SWD_ADAPTER ?= STLINKV2 +SWD_ADAPTER ?= BMP ifeq ($(SWD_ADAPTER),STLINKV2) # OpenOCD configuration OOCD ?= openocd @@ -192,14 +181,14 @@ list: $(BINARY).list # figure out which library source files are used for later inclusion %.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 doc: Doxyfile README.md $(CSRC) $(CHDR) $(LIB_CSRC) $(LIB_CHDR) $(Q)doxygen $(<) 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 $(OPENCM3_LIB)/lib$(STM32F1_LIB).a: @@ -213,7 +202,7 @@ flash: $(BINARY).hex 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) 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 # reset device by setting the data width to 5 bis on the USB CDC ACM port