mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-02-28 11:54:30 +03:00
change F303's Makefile to version control; fixed bugs in F303 usb ringbuffer, add two buffers like in F0x2
This commit is contained in:
@@ -9,12 +9,8 @@ MCU ?= F303xb
|
||||
ARMARCH = __ARM_ARCH_7M__
|
||||
# change this linking script depending on particular MCU model,
|
||||
LDSCRIPT ?= stm32f303xB.ld
|
||||
# debug
|
||||
#DEFS = -DEBUG
|
||||
|
||||
INDEPENDENT_HEADERS=
|
||||
|
||||
FP_FLAGS ?= -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -fsingle-precision-constant -mlittle-endian -DARM_MATH_CM4
|
||||
FP_FLAGS ?= -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -mlittle-endian -DARM_MATH_CM4
|
||||
ASM_FLAGS ?= -mthumb -mcpu=cortex-m4
|
||||
ARCH_FLAGS = $(ASM_FLAGS) $(FP_FLAGS) -D $(ARMARCH)
|
||||
|
||||
@@ -42,6 +38,10 @@ DFUUTIL := $(shell which dfu-util)
|
||||
###############################################################################
|
||||
# Source files
|
||||
OBJDIR := mk
|
||||
# target (debug/release)
|
||||
TARGFILE := $(OBJDIR)/TARGET
|
||||
# autoincremental version & build date
|
||||
VERSION_FILE = version.inc
|
||||
SRC := $(wildcard *.c)
|
||||
OBJS := $(addprefix $(OBJDIR)/, $(SRC:%.c=%.o))
|
||||
STARTUP := $(OBJDIR)/startup.o
|
||||
@@ -59,16 +59,15 @@ LIB_DIR := $(INC_DIR)/ld
|
||||
# C flags
|
||||
CFLAGS += -g -gdwarf-2 # debuggin symbols in listing
|
||||
CFLAGS += -O2 -D__thumb2__=1 -MD
|
||||
CFLAGS += -Wall -Werror -Wextra -Wshadow
|
||||
CFLAGS += -Wall -Wextra -Wshadow
|
||||
CFLAGS += -fshort-enums -ffunction-sections -fdata-sections
|
||||
#CFLAGS += -fno-common -ffunction-sections -fdata-sections -fno-stack-protector
|
||||
#CFLAGS += -fno-common -fno-stack-protector
|
||||
CFLAGS += $(ARCH_FLAGS)
|
||||
|
||||
###############################################################################
|
||||
# Linker flags
|
||||
#LDFLAGS += -nostartfiles --static -nostdlib -specs=nosys.specs -specs=nano.specs
|
||||
LDFLAGS += -nostartfiles --static -specs=nosys.specs -specs=nano.specs
|
||||
LDFLAGS += $(ARCH_FLAGS)
|
||||
LDFLAGS += -specs=nano.specs -specs=nosys.specs
|
||||
LDFLAGS += -L$(LIB_DIR)
|
||||
#-L$(TOOLCHLIB)
|
||||
LDFLAGS += -T$(LDSCRIPT)
|
||||
@@ -76,7 +75,7 @@ LDFLAGS += -Wl,-Map=$(MAP),--cref -Wl,--gc-sections -Wl,--print-memory-usage
|
||||
|
||||
###############################################################################
|
||||
# Used libraries
|
||||
#LDLIBS += -lc $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
||||
LDLIBS += -lm -lc $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
||||
|
||||
DEFS += -DSTM32$(FAMILY) -DSTM32$(MCU)
|
||||
|
||||
@@ -85,7 +84,36 @@ LIST := $(OBJDIR)/$(BINARY).list
|
||||
BIN := $(BINARY).bin
|
||||
HEX := $(BINARY).hex
|
||||
|
||||
all: bin list size
|
||||
ifeq ($(shell test -e $(TARGFILE) && echo -n yes),yes)
|
||||
TARGET := $(file < $(TARGFILE))
|
||||
else
|
||||
TARGET := RELEASE
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET), DEBUG)
|
||||
.DEFAULT_GOAL := debug
|
||||
endif
|
||||
|
||||
ifeq ($(shell test -e $(VERSION_FILE) && echo -n yes), yes)
|
||||
NEXTVER := $(shell expr $$(awk '/#define BUILD_NUMBER/' $(VERSION_FILE) | tr -cd "[0-9]") + 1)
|
||||
else
|
||||
NEXTVER := "1"
|
||||
endif
|
||||
BUILDDATE := $(shell date +%Y-%m-%d)
|
||||
|
||||
# release: add LTO
|
||||
release: CFLAGS += -flto
|
||||
release: LDFLAGS += -flto
|
||||
release: $(TARGFILE) bin list size
|
||||
|
||||
#debug: add debug flags
|
||||
debug: CFLAGS += -DEBUG -Werror -g3
|
||||
debug: TARGET := DEBUG
|
||||
debug: $(TARGFILE) bin list size
|
||||
|
||||
$(TARGFILE): $(OBJDIR)
|
||||
@echo -e "\t\tTARGET: $(TARGET)"
|
||||
@echo "$(TARGET)" > $(TARGFILE)
|
||||
|
||||
elf: $(ELF)
|
||||
bin: $(BIN)
|
||||
@@ -102,6 +130,14 @@ $(OBJDIR):
|
||||
$(STARTUP): $(INC_DIR)/startup/vector.c
|
||||
$(CC) $(CFLAGS) $(DEFS) $(INCLUDE) -o $@ -c $<
|
||||
|
||||
$(VERSION_FILE): *.[ch]
|
||||
@[ -f $(VERSION_FILE) ] || echo -e "#define BUILD_NUMBER \"0\"\n#define BUILD_DATE \"none\"" > $(VERSION_FILE)
|
||||
@echo " Generate version: $(NEXTVER) for date $(BUILDDATE)"
|
||||
@sed -i "s/#define BUILD_NUMBER.*/#define BUILD_NUMBER \"$(NEXTVER)\"/" $(VERSION_FILE)
|
||||
@sed -i "s/#define BUILD_DATE.*/#define BUILD_DATE \"$(BUILDDATE)\"/" $(VERSION_FILE)
|
||||
|
||||
$(OBJDIR)/proto.o: proto.c $(VERSION_FILE)
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
@echo " CC $<"
|
||||
$(CC) $(CFLAGS) $(DEFS) $(INCLUDE) -o $@ -c $<
|
||||
@@ -127,8 +163,7 @@ size: $(ELF)
|
||||
|
||||
clean:
|
||||
@echo " CLEAN"
|
||||
$(RM) $(OBJS) $(DEPS) $(ELF) $(HEX) $(LIST) $(MAP)
|
||||
@rmdir $(OBJDIR) 2>/dev/null || true
|
||||
@rm -rf $(OBJDIR) 2>/dev/null || true
|
||||
|
||||
|
||||
flash: $(BIN)
|
||||
@@ -143,4 +178,10 @@ dfuboot: $(BIN)
|
||||
@echo " LOAD $(BIN) THROUGH DFU"
|
||||
$(DFUUTIL) -a0 -D $(BIN) -s 0x08000000
|
||||
|
||||
.PHONY: clean flash boot
|
||||
openocd:
|
||||
openocd -f openocd.cfg
|
||||
|
||||
dbg:
|
||||
arm-none-eabi-gdb $(ELF) -ex 'target remote localhost:3333' -ex 'monitor reset halt'
|
||||
|
||||
.PHONY: size clean flash boot dfuboot openocd dbg
|
||||
|
||||
Reference in New Issue
Block a user