better handle libopencm3 dependency
This commit is contained in:
parent
f79f16b88f
commit
30c2e473ee
43
Makefile
43
Makefile
|
@ -30,6 +30,14 @@ FIRMWARE = $(APPLICATION) $(BOOTLOADER)
|
||||||
# supported are: SYSTEM_BOARD, MAPLE_MINI, BLUE_PILL, CORE_BOARD
|
# supported are: SYSTEM_BOARD, MAPLE_MINI, BLUE_PILL, CORE_BOARD
|
||||||
BOARD = SYSTEM_BOARD
|
BOARD = SYSTEM_BOARD
|
||||||
|
|
||||||
|
# opencm3 libraries
|
||||||
|
OPENCM3_DIR := libopencm3
|
||||||
|
OPENCM3_INC = $(OPENCM3_DIR)/include
|
||||||
|
OPENCM3_LIB = $(OPENCM3_DIR)/lib
|
||||||
|
|
||||||
|
# library for the STM32F1 (provided by opencm3)
|
||||||
|
STM32F1_LIB = opencm3_stm32f1
|
||||||
|
|
||||||
# source files (this will be populated using includes based DEPENDENCIES)
|
# source files (this will be populated using includes based DEPENDENCIES)
|
||||||
CSRC = global.c
|
CSRC = global.c
|
||||||
# headers corresponding to source files
|
# headers corresponding to source files
|
||||||
|
@ -56,13 +64,6 @@ GDB := $(ELLCC)bin/ecc-gdb
|
||||||
# ecc-gdb (0.13.3) is buggy (crash on kill, can't load elf)
|
# ecc-gdb (0.13.3) is buggy (crash on kill, can't load elf)
|
||||||
GDB := arm-none-eabi-gdb
|
GDB := arm-none-eabi-gdb
|
||||||
|
|
||||||
# opencm3 libraries
|
|
||||||
OPENCM3_DIR := libopencm3
|
|
||||||
OPENCM3_INC = $(OPENCM3_DIR)/include
|
|
||||||
OPENCM3_LIB = $(OPENCM3_DIR)/lib
|
|
||||||
# library for the STM32F1 (provided by opencm3)
|
|
||||||
STM32F1_LIB = opencm3_stm32f1
|
|
||||||
|
|
||||||
# device micro-controller and board
|
# device micro-controller and board
|
||||||
DEFS += -DSTM32F1 -D$(BOARD)
|
DEFS += -DSTM32F1 -D$(BOARD)
|
||||||
|
|
||||||
|
@ -107,8 +108,6 @@ LDFLAGS += -nostdlib -nostdinc
|
||||||
LDFLAGS += --library-path $(ELLCC)libecc/lib/cortex-m3-linux/
|
LDFLAGS += --library-path $(ELLCC)libecc/lib/cortex-m3-linux/
|
||||||
# opencm3 libraries
|
# opencm3 libraries
|
||||||
LDFLAGS += --library-path $(OPENCM3_LIB)
|
LDFLAGS += --library-path $(OPENCM3_LIB)
|
||||||
# linker script with definitions for micro-controller
|
|
||||||
#LDFLAGS += --script $(LDSCRIPT)
|
|
||||||
# used libraries (gcc provides the ARM ABI, not sure how to replace with compiler-rt)
|
# 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
|
LDLIBS += --library $(STM32F1_LIB) --library c --library m --library gcc
|
||||||
|
|
||||||
|
@ -129,7 +128,7 @@ BMP_PORT ?= /dev/ttyACM0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# compile target rules
|
# compile target rules
|
||||||
all: $(OPENCM3_LIB)/lib$(STM32F1_LIB).a elf hex bin
|
all: elf hex bin
|
||||||
|
|
||||||
elf: $(patsubst %,%.elf,$(FIRMWARE))
|
elf: $(patsubst %,%.elf,$(FIRMWARE))
|
||||||
bin: $(patsubst %,%.bin,$(FIRMWARE))
|
bin: $(patsubst %,%.bin,$(FIRMWARE))
|
||||||
|
@ -149,12 +148,12 @@ hex: $(patsubst %,%.hex,$(FIRMWARE))
|
||||||
$(Q)$(LD) $(LDFLAGS) --script $(*).ld $(<) $(OBJ) $(LDLIBS) -o $(@)
|
$(Q)$(LD) $(LDFLAGS) --script $(*).ld $(<) $(OBJ) $(LDLIBS) -o $(@)
|
||||||
$(Q)size $(@)
|
$(Q)size $(@)
|
||||||
|
|
||||||
%.o: %.c $(CHDR)
|
%.o: %.c $(CHDR) $(OPENCM3_LIB)/lib$(STM32F1_LIB).a
|
||||||
$(info compiling $(@))
|
$(info compiling $(@))
|
||||||
$(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -o $(@) -c $(<)
|
$(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -o $(@) -c $(<)
|
||||||
|
|
||||||
# generate dependencies
|
# generate dependencies (requires libopencm3 to be built to generate all libraries)
|
||||||
%.d: %.c
|
%.d: %.c $(OPENCM3_LIB)/lib$(STM32F1_LIB).a
|
||||||
@# check which libraries are used
|
@# check which libraries are used
|
||||||
$(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -MM -MF $(@) -o /dev/null -c $(<)
|
$(Q)$(CC) $(CFLAGS) $(ARCH_FLAGS) -MM -MF $(@) -o /dev/null -c $(<)
|
||||||
|
|
||||||
|
@ -162,6 +161,17 @@ hex: $(patsubst %,%.hex,$(FIRMWARE))
|
||||||
%.inc: %.d
|
%.inc: %.d
|
||||||
$(Q)grep -o -e " lib\/[^ ]*\.h" $(<) | sed -e 's|\(.*\)\.h$$|CSRC +=\1.c\n-include\1.inc|g' -e 's|.*${*}.*||g' > $(@)
|
$(Q)grep -o -e " lib\/[^ ]*\.h" $(<) | sed -e 's|\(.*\)\.h$$|CSRC +=\1.c\n-include\1.inc|g' -e 's|.*${*}.*||g' > $(@)
|
||||||
|
|
||||||
|
# get libopencm3
|
||||||
|
$(OPENCM3_DIR)/Makefile:
|
||||||
|
$(info checking out libopencm3 submodule)
|
||||||
|
$(Q)git submodule init
|
||||||
|
$(Q)git submodule update
|
||||||
|
|
||||||
|
# compile libopencm3
|
||||||
|
$(OPENCM3_LIB)/lib$(STM32F1_LIB).a: $(OPENCM3_DIR)/Makefile
|
||||||
|
$(info compiling libopencm3 submodule)
|
||||||
|
$(Q)CFLAGS=-fno-short-enums $(MAKE) --directory $(OPENCM3_DIR)
|
||||||
|
|
||||||
# doxygen documentation
|
# doxygen documentation
|
||||||
doc: Doxyfile README.md $(patsubst %,%.c,$(FIRMWARE)) $(CSRC) $(CHDR)
|
doc: Doxyfile README.md $(patsubst %,%.c,$(FIRMWARE)) $(CSRC) $(CHDR)
|
||||||
$(Q)doxygen $(<)
|
$(Q)doxygen $(<)
|
||||||
|
@ -169,13 +179,6 @@ doc: Doxyfile README.md $(patsubst %,%.c,$(FIRMWARE)) $(CSRC) $(CHDR)
|
||||||
clean:
|
clean:
|
||||||
$(Q)$(RM) $(BOOTLOADER).elf $(BOOTLOADER).bin $(BOOTLOADER).hex $(APPLICATION).elf $(APPLICATION).bin $(APPLICATION).hex $(OBJ) $(DEPENDENCIES) *.inc lib/*.inc
|
$(Q)$(RM) $(BOOTLOADER).elf $(BOOTLOADER).bin $(BOOTLOADER).hex $(APPLICATION).elf $(APPLICATION).bin $(APPLICATION).hex $(OBJ) $(DEPENDENCIES) *.inc lib/*.inc
|
||||||
|
|
||||||
# make libopencm3 if library for STM32F1 is not yet existing
|
|
||||||
$(OPENCM3_LIB)/lib$(STM32F1_LIB).a:
|
|
||||||
$(info compiling libopencm3 library)
|
|
||||||
git submodule init
|
|
||||||
git submodule update
|
|
||||||
$(Q)$(MAKE) CFLAGS=-fno-short-enums -C $(OPENCM3_DIR)
|
|
||||||
|
|
||||||
# flash application using DFU
|
# flash application using DFU
|
||||||
flash: $(APPLICATION).bin
|
flash: $(APPLICATION).bin
|
||||||
$(Q)dfu-util -d c440:0d00 -D $(<)
|
$(Q)dfu-util -d c440:0d00 -D $(<)
|
||||||
|
|
Loading…
Reference in New Issue