2016-07-28 02:14:03 +02:00
|
|
|
# --- START OF CONFIG ---------------------------------------------------
|
|
|
|
# Edit the following variables for your own needs
|
|
|
|
|
|
|
|
# toolchain configuration
|
|
|
|
PREFIX ?= arm-none-eabi-
|
|
|
|
CC = $(PREFIX)gcc
|
|
|
|
LD = $(PREFIX)gcc
|
|
|
|
OBJCOPY = $(PREFIX)objcopy
|
|
|
|
OBJDUMP = $(PREFIX)objdump
|
|
|
|
GDB = $(PREFIX)gdb
|
|
|
|
SIZE = $(PREFIX)size
|
|
|
|
|
|
|
|
OOCD = openocd
|
|
|
|
#OOCD_CFG = board/stm32f4discovery.cfg
|
|
|
|
OOCD_CFG = ./oocd/solarlader.cfg
|
|
|
|
|
|
|
|
TOOLCHAIN_DIR ?= /usr/arm-none-eabi
|
|
|
|
OPENCM3_DIR ?= ../../libopencm3
|
|
|
|
|
|
|
|
# default build configuration
|
|
|
|
# "make BUILD=release" does a release build
|
|
|
|
BUILD:=debug
|
|
|
|
|
|
|
|
# basic build flags configuration
|
|
|
|
CFLAGS+=-Wall -std=c99 -pedantic -Wextra -Wimplicit-function-declaration \
|
|
|
|
-Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes \
|
|
|
|
-Wundef -Wshadow \
|
|
|
|
-fno-common -ffunction-sections -fdata-sections -mcpu=cortex-m0 -mthumb \
|
|
|
|
-mfloat-abi=soft -MD -DSTM32F0
|
|
|
|
|
|
|
|
LDFLAGS+=--static \
|
|
|
|
-L$(OPENCM3_DIR)/lib \
|
|
|
|
-nostartfiles -Wl,--gc-sections \
|
|
|
|
-mthumb -mcpu=cortex-m0 -mthumb -mfloat-abi=soft
|
|
|
|
|
|
|
|
# the LD script
|
|
|
|
#LDFLAGS+=-Tldscripts/solarlader-$(BUILD).ld
|
|
|
|
LDFLAGS+=-Tldscripts/solarlader-release.ld
|
|
|
|
|
|
|
|
# Flags for libopencm3
|
|
|
|
CFLAGS+=-I$(OPENCM3_DIR)/include
|
|
|
|
LDFLAGS+=-L$(OPENCM3_DIR)/lib -lopencm3_stm32f0
|
|
|
|
|
|
|
|
# Flags for fxplib
|
2016-09-04 14:37:08 +02:00
|
|
|
CFLAGS+=-Ifxplib/include -DPOINTPOS=16
|
2016-07-28 02:14:03 +02:00
|
|
|
LDFLAGS+=-Lfxplib/lib/$(BUILD) -lfxp_stm32f0
|
|
|
|
|
|
|
|
# generic linking
|
|
|
|
LDFLAGS+=-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
|
|
|
|
|
|
|
|
# build type specific flags
|
2016-08-17 22:04:04 +02:00
|
|
|
CFLAGS_debug=-O0 -ggdb -DDEBUG
|
2016-07-28 02:14:03 +02:00
|
|
|
LDFLAGS_debug=
|
|
|
|
|
2016-08-13 01:12:33 +02:00
|
|
|
CFLAGS_release=-Os -ggdb
|
2016-07-28 02:14:03 +02:00
|
|
|
LDFLAGS_release=
|
|
|
|
|
|
|
|
# target configuration
|
|
|
|
TARGET := test
|
|
|
|
VERSION := 0.0.0
|
|
|
|
VCSVERSION := $(shell git rev-parse --short HEAD)
|
|
|
|
|
|
|
|
# source files for the project
|
|
|
|
SOURCE := $(shell find src/ -name '*.c')
|
|
|
|
INCLUDES := $(shell find src/ -name '*.h')
|
|
|
|
|
|
|
|
# additional dependencies for build (proper targets must be specified by user)
|
|
|
|
DEPS := build_libfxp
|
|
|
|
|
|
|
|
# default target
|
|
|
|
all: $(TARGET)
|
|
|
|
|
|
|
|
# user-specific targets
|
|
|
|
export CFLAGS
|
|
|
|
export BUILD
|
|
|
|
export PREFIX
|
|
|
|
export POSTFIX = stm32f0
|
|
|
|
build_libfxp:
|
|
|
|
cd fxplib && $(MAKE)
|
|
|
|
|
|
|
|
# --- END OF CONFIG -----------------------------------------------------
|
|
|
|
|
|
|
|
OBJ1=$(patsubst %.c, %.o, $(SOURCE))
|
|
|
|
OBJ=$(patsubst src/%, obj/$(BUILD)/%, $(OBJ1))
|
|
|
|
|
|
|
|
VERSIONSTR="\"$(VERSION)-$(VCSVERSION)\""
|
|
|
|
|
|
|
|
CFLAGS+=-DVERSION=$(VERSIONSTR)
|
|
|
|
|
|
|
|
TARGET_BASE := bin/$(BUILD)/$(TARGET)
|
|
|
|
|
|
|
|
CFLAGS+=$(CFLAGS_$(BUILD))
|
|
|
|
LDFLAGS+=$(LDFLAGS_$(BUILD))
|
|
|
|
|
|
|
|
.PHONY show_cflags:
|
|
|
|
@echo --- Build parameters: ------------------------------------------
|
|
|
|
@echo CFLAGS\=$(CFLAGS)
|
|
|
|
@echo LDFLAGS\=$(LDFLAGS)
|
|
|
|
@echo SOURCE\=$(SOURCE)
|
|
|
|
@echo -----------------------------------------------------------------
|
|
|
|
|
|
|
|
$(TARGET): show_cflags $(TARGET_BASE).elf $(TARGET_BASE).hex \
|
|
|
|
$(TARGET_BASE).lss $(TARGET_BASE).bin
|
|
|
|
@$(SIZE) $(TARGET_BASE).elf
|
|
|
|
@echo ">>> $(BUILD) build complete."
|
|
|
|
|
|
|
|
$(TARGET_BASE).elf: $(DEPS) $(OBJ) $(INCLUDES) Makefile
|
|
|
|
@echo Linking $@ ...
|
|
|
|
@mkdir -p $(shell dirname $@)
|
|
|
|
@$(LD) -o $(TARGET_BASE).elf $(OBJ) $(LDFLAGS)
|
|
|
|
|
|
|
|
$(TARGET_BASE).hex: $(TARGET_BASE).elf
|
|
|
|
@echo "Generating $@ ..."
|
|
|
|
@$(OBJCOPY) -Oihex $< $@
|
|
|
|
|
|
|
|
$(TARGET_BASE).bin: $(TARGET_BASE).elf
|
|
|
|
@echo "Generating $@ ..."
|
|
|
|
@$(OBJCOPY) -Obinary $< $@
|
|
|
|
|
|
|
|
$(TARGET_BASE).lss: $(TARGET_BASE).elf
|
|
|
|
@echo "Generating $@ ..."
|
|
|
|
@$(OBJDUMP) -S $< > $@
|
|
|
|
|
|
|
|
obj/$(BUILD)/%.o: src/%.c $(INCLUDES) Makefile
|
|
|
|
@echo "Compiling $< ..."
|
|
|
|
@mkdir -p $(shell dirname $@)
|
|
|
|
@$(CC) -c $(CFLAGS) -o $@ $<
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f $(TARGET_BASE).elf
|
|
|
|
rm -f $(TARGET_BASE).hex
|
|
|
|
rm -f $(TARGET_BASE).lss
|
|
|
|
rm -f $(TARGET_BASE).bin
|
|
|
|
rm -f $(OBJ)
|
|
|
|
|
|
|
|
program: program_release #$(BUILD)
|
|
|
|
|
|
|
|
program_release: $(TARGET_BASE).hex
|
|
|
|
$(OOCD) -f $(OOCD_CFG) \
|
|
|
|
-c "init" \
|
|
|
|
-c "reset halt" \
|
|
|
|
-c "flash write_image erase $(TARGET_BASE).hex" \
|
|
|
|
-c "reset" \
|
|
|
|
-c "shutdown"
|
|
|
|
|
|
|
|
program_debug: $(TARGET_BASE).hex
|
|
|
|
$(OOCD) -f $(OOCD_CFG) \
|
|
|
|
-c "init" \
|
|
|
|
-c "reset halt" \
|
|
|
|
-c "load_image $(TARGET_BASE).hex" \
|
|
|
|
-c "resume `arm-none-eabi-readelf -h bin/debug/test.elf | awk '/Entry/{print $$4;}'`" \
|
|
|
|
-c "shutdown"
|
|
|
|
|
|
|
|
debug: $(TARGET_BASE).hex
|
|
|
|
$(OOCD) -f $(OOCD_CFG) \
|
|
|
|
-c "init"
|