-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
70 lines (52 loc) · 1.71 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
PREFIX?=arm-none-eabi-
CC=$(PREFIX)gcc
OBJCOPY=$(PREFIX)objcopy
BINDIR=bin
SRCDIR=src
BINARY=rkclock
OPENCM3_DIR=libopencm3
OPENCM3_LIBDIR=$(OPENCM3_DIR)/lib
OPENCM3_BIN=$(OPENCM3_LIBDIR)/libopencm3_stm32l0.a
CFLAGS= -std=c17 -Wall
#CFLAGS+= -O0
CFLAGS+= -Os
CFLAGS+= -g3
CFLAGS+= -fno-common -ffunction-sections -fdata-sections
CFLAGS+= -I$(OPENCM3_DIR)/include
CFLAGS+= -mcpu=cortex-m0plus -mthumb -msoft-float
# STM32L0 starts up with MSI at 2.1MHz
CFLAGS+= -DSTM32L0
LDSCRIPT=$(SRCDIR)/stm32l011k4.ld
LDFLAGS+=-L$(OPENCM3_LIBDIR) -Wl,--start-group -lc -lgcc -lnosys -mcpu=cortex-m0plus -Wl,--end-group --static -nostartfiles -T $(LDSCRIPT)
##
BINARY_ELF+=$(BINDIR)/$(BINARY).elf
BINARY_BIN+=$(BINDIR)/$(BINARY).bin
#BINARY_HEX+=$(BINDIR)/$(BINARY).hex
OBJS=$(BINDIR)/main.o $(BINDIR)/tm1637.o $(BINDIR)/key.o $(BINDIR)/rtc.o $(BINDIR)/bcd.o
#OBJS+=$(BINDIR)/usart.o
all: outdir $(BINARY_ELF) $(BINARY_BIN) #$(BINARY_HEX)
libopencm3/Makefile:
@echo "Initializing libopencm3 submodule"
git submodule update --init
$(OPENCM3_BIN): $(OPENCM3_DIR)/Makefile
$(MAKE) V=1 TARGETS='stm32/l0' -C $(OPENCM3_DIR)
%.bin: %.elf
$(OBJCOPY) -Obinary $(*).elf $(*).bin
#%.hex: %.elf
# $(OBJCOPY) -Oihex $(*).elf $(*).hex
$(BINDIR)/main.o : $(SRCDIR)/main.c
$(CC) -c $(CFLAGS) $< -o $@
$(BINDIR)/%.o : $(SRCDIR)/%.c $(SRCDIR)/%.h
$(CC) -c $(CFLAGS) $< -o $@
$(BINDIR)/$(BINARY).elf: $(OBJS) $(OPENCM3_BIN)
$(CC) $(LDFLAGS) $(OBJS) $(OPENCM3_BIN) -o $@
outdir:
mkdir -p $(BINDIR)
flash:
openocd -f st_nucleo_l011k4.cfg -c "program $(BINARY_ELF) verify reset exit"
serial-console:
cu -s 9600 -l /dev/ttyACM0
clean:
$(RM) $(BINDIR)/*.o $(BINARY_ELF) $(BINARY_BIN) #$(BINARY_HEX)
.PHONY: outdir clean flash serial-console all
#$(V).SILENT: