-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
105 lines (77 loc) · 2.53 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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) -DSTM32F10X_MD --specs=nosys.specs -g -Wa,-ahlms=$(addprefix $(OBJDIR)/,$(notdir $(<:.c=.lst)))
GCFLAGS = -std=c99 -Wall -fno-common -mthumb -mcpu=$(CPU) -DSTM32F10X_MD -DUSE_STDPERIPH_DRIVER --specs=nosys.specs -g -Wa,-ahlms=$(addprefix $(OBJDIR)/,$(notdir $(<:.c=.lst)))
#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
flash:
@echo "Please install stm32flash tool - is in ubuntu repo"
stm32flash -g 0x8000000 -b 115200 -w bin/blink.bin /dev/ttyUSB0
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 $@ $<