-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
122 lines (86 loc) · 3.1 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# This makefile is for libopencm3 based STM32 projects
# To use HAL/LL, see the HAL based project's makefile
TARGET=main
TOOLCHAIN_PREFIX=~/Toolchains/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi
CC=$(TOOLCHAIN_PREFIX)-gcc
LD=$(TOOLCHAIN_PREFIX)-gcc
AS=$(TOOLCHAIN_PREFIX)-as
CP=$(TOOLCHAIN_PREFIX)-objcopy
OD=$(TOOLCHAIN_PREFIX)-objdump
# Microcontroller family
DEFS = -DSTM32F1
# Cortex core
MCU = cortex-m3
MCFLAGS = -mcpu=$(MCU)
################## User Sources ####################
SRCS = main.c
SRCS += ../st7789_stm32_spi.c
SRCS += ../libopencm3/lib/cm3/vector.c
################## Includes ########################
INCLS = -I..
INCLS += -I../libopencm3/include
INCLS += -I../fonts
################## Libs ########################
LIBS = -L../libopencm3/lib
LIBS += -lopencm3_stm32f1
################ Compiler Flags ######################
CFLAGS = -ggdb
CFLAGS += -Wall -Wextra -Warray-bounds
CFLAGS += -mlittle-endian -mthumb -mthumb-interwork
CFLAGS += -mfloat-abi=soft
CFLAGS += --specs=nano.specs
CFLAGS += $(MCFLAGS)
############# CFLAGS for Optimization ##################
CFLAGS += -O0
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
################### Linker Flags #####################
LFLAGS = -Tstm32f103xb.ld
LFLAGS += --specs=nosys.specs
LFLAGS += -Wl,--gc-sections -static
LFLAGS += -Wl,--Map=$(TARGET).map
LFLAGS += -Wl,--cref
LFLAGS += --static
LFLAGS += -nostartfiles #We're using no start file. Without this flag, get linker error
################### Recipe to make all (build and burn) ####################
.PHONY: all
all: build
################### Recipe to build ####################
.PHONY: build
build: $(TARGET).bin $(TARGET).hex $(TARGET).lst $(TARGET).size
################### Recipe to burn ####################
.PHONY: burn
burn:
@echo "[Flashing] $(TARGET).bin in 0x8000000 address"
@st-flash write $(TARGET).bin 0x8000000
################### Recipe to debug ####################
.PHONY: debug
debug:
@echo "[Debugging] $(TARGET).elf
# Need to run st-util first for starting the gdb server
@st-util &
@$(GDB) -iex "add-auto-load-safe-path ./.gdbinit" $(TARGET).elf
################### Recipe to make .elf ####################
$(TARGET).elf: $(SRCS)
@echo "[Compiling] $(SRCS)"
@$(CC) $(INCLS) $(DEFS) $(CFLAGS) $(LFLAGS) $^ $(LIBS) -o $@
################### Recipe to make .bin ####################
$(TARGET).bin: $(TARGET).elf
@echo "[Building] $@"
@$(CP) -O binary $^ $@
################### Recipe to make .hex ####################
$(TARGET).hex: $(TARGET).elf
@echo "[Building] $@"
@$(CP) -O ihex $^ $@
################### Recipe to make .lst ####################
$(TARGET).lst: $(TARGET).elf
@echo "[Building] $@"
@$(OD) -S $^ > $(TARGET).lst
################### Recipe to make size ####################
$(TARGET).size: $(TARGET).elf
@$(PREFIX)-size -B -d $^
################### Recipe to clean all ####################
.PHONY: clean
clean:
@echo "[Cleaning] $(TARGET).hex $(TARGET).bin $(TARGET).elf $(TARGET).lst $(TARGET).map"
@rm -f $(TARGET).hex $(TARGET).bin $(TARGET).elf $(TARGET).lst $(TARGET).map