Permalink
Find file
18837e1 Jul 25, 2016
@kcuzner @insom
100 lines (72 sloc) 2.08 KB
# Makefile for the STM32F103C8 blink program
#
# Kevin Cuzner
#
PROJECT = blink
# Project Structure
SRCDIR = src
COMDIR = common
BINDIR = bin
OBJDIR = obj
INCDIR = include
# Project target
CPU = cortex-m3
# Sources
SRC = $(wildcard $(SRCDIR)/*.c) $(wildcard $(COMDIR)/*.c)
ASM = $(wildcard $(SRCDIR)/*.s) $(wildcard $(COMDIR)/*.s)
# Include directories
INCLUDE = -I$(INCDIR) -Icmsis
# Linker
LSCRIPT = STM32F103X8_FLASH.ld
# C Flags
GCFLAGS = -std=c99 -Wall -fno-common -mthumb -mcpu=$(CPU) -DSTM32F103xB --specs=nosys.specs -g -Wa,-ahlms=$(addprefix $(OBJDIR)/,$(notdir $(<:.c=.lst)))
GCFLAGS += $(INCLUDE)
LDFLAGS += -T$(LSCRIPT) -mthumb -mcpu=$(CPU) --specs=nosys.specs
ASFLAGS += -mcpu=$(CPU)
# Flashing
OCDFLAGS = -f openocd.cfg
# Tools
CC = arm-none-eabi-gcc
AS = arm-none-eabi-as
AR = arm-none-eabi-ar
LD = arm-none-eabi-ld
OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size
OBJDUMP = arm-none-eabi-objdump
OCD = openocd
RM = rm -rf
## Build process
OBJ := $(addprefix $(OBJDIR)/,$(notdir $(SRC:.c=.o)))
OBJ += $(addprefix $(OBJDIR)/,$(notdir $(ASM:.s=.o)))
all:: $(BINDIR)/$(PROJECT).bin
Build: $(BINDIR)/$(PROJECT).bin
install: $(BINDIR)/$(PROJECT).bin
$(OCD) $(OCDFLAGS)
$(BINDIR)/$(PROJECT).hex: $(BINDIR)/$(PROJECT).elf
$(OBJCOPY) -R .stack -O ihex $(BINDIR)/$(PROJECT).elf $(BINDIR)/$(PROJECT).hex
$(BINDIR)/$(PROJECT).bin: $(BINDIR)/$(PROJECT).elf
$(OBJCOPY) -R .stack -O binary $(BINDIR)/$(PROJECT).elf $(BINDIR)/$(PROJECT).bin
$(BINDIR)/$(PROJECT).elf: $(OBJ)
@mkdir -p $(dir $@)
$(CC) $(OBJ) $(LDFLAGS) -o $(BINDIR)/$(PROJECT).elf
$(OBJDUMP) -D $(BINDIR)/$(PROJECT).elf > $(BINDIR)/$(PROJECT).lst
$(SIZE) $(BINDIR)/$(PROJECT).elf
macros:
$(CC) $(GCFLAGS) -dM -E - < /dev/null
cleanBuild: clean
clean:
$(RM) $(BINDIR)
$(RM) $(OBJDIR)
# Compilation
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(GCFLAGS) -c $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.s
@mkdir -p $(dir $@)
$(AS) $(ASFLAGS) -o $@ $<
$(OBJDIR)/%.o: $(COMDIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(GCFLAGS) -c $< -o $@
$(OBJDIR)/%.o: $(COMDIR)/%.s
@mkdir -p $(dir $@)
$(AS) $(ASFLAGS) -o $@ $<