-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
124 lines (107 loc) · 2.66 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
123
124
TARGET = main
# Default target chip.
#MCU ?= STM32F103C8
MCU ?= STM32L432KC
# Define target chip information.
ifeq ($(MCU), STM32L432KC)
MCU_FILES = STM32L432KC
ST_MCU_DEF = STM32L432xx
MCU_CLASS = L4
else ifeq($(MCU), STM32F103C8)
MCU_FILES = STM32F103C8
ST_MCU_DEF = STM32F103xB
MCU_CLASS = F1
endif
#
# Generic STM32 makefile:
#
ifeq ($(MCU_CLASS), F0)
MCU_SPEC = cortex-m0
else ifeq ($(MCU_CLASS), $(filter $(MCU_CLASS), L0 G0))
MCU_SPEC = cortex-m0plus
else ifeq ($(MCU_CLASS), $(filter $(MCU_CLASS), F1 L1))
MCU_SPEC = cortex-m3
else ifeq ($(MCU_CLASS), $(filter $(MCU_CLASS), L4 G4 WB))
MCU_SPEC = cortex-m4
endif
# Toolchain definitions (ARM bare metal defaults)
TOOLCHAIN = /usr
CC = $(TOOLCHAIN)/bin/arm-none-eabi-gcc
AS = $(TOOLCHAIN)/bin/arm-none-eabi-as
LD = $(TOOLCHAIN)/bin/arm-none-eabi-ld
OC = $(TOOLCHAIN)/bin/arm-none-eabi-objcopy
OD = $(TOOLCHAIN)/bin/arm-none-eabi-objdump
OS = $(TOOLCHAIN)/bin/arm-none-eabi-size
# Assembly directives.
ASFLAGS += -c
ASFLAGS += -O0
ASFLAGS += -mcpu=$(MCU_SPEC)
ASFLAGS += -mthumb
ASFLAGS += -Wall
# (Set error messages to appear on a single line.)
ASFLAGS += -fmessage-length=0
ASFLAGS += -DVVC_$(MCU_CLASS)
# C compilation directives
CFLAGS += -mcpu=$(MCU_SPEC)
CFLAGS += -mthumb
ifeq ($(MCU_CLASS), $(filter $(MCU_CLASS), F0 F1 L0 L1 G0))
CFLAGS += -msoft-float
CFLAGS += -mfloat-abi=soft
else
CFLAGS += -mhard-float
CFLAGS += -mfloat-abi=hard
CFLAGS += -mfpu=fpv4-sp-d16
endif
CFLAGS += -Wall
CFLAGS += -g
CFLAGS += -fmessage-length=0
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += --specs=nosys.specs
CFLAGS += -D$(ST_MCU_DEF)
CFLAGS += -D$(MCU_FILES)
CFLAGS += -DVVC_$(MCU_CLASS)
# Linker directives.
LSCRIPT = ./ld/$(MCU_FILES).ld
LFLAGS += -mcpu=$(MCU_SPEC)
LFLAGS += -mthumb
ifeq ($(MCU_CLASS), $(filter $(MCU_CLASS), F0 F1 L0 L1 G0))
LFLAGS += -msoft-float
LFLAGS += -mfloat-abi=soft
else
LFLAGS += -mhard-float
LFLAGS += -mfloat-abi=hard
LFLAGS += -mfpu=fpv4-sp-d16
endif
LFLAGS += -Wall
LFLAGS += --specs=nosys.specs
LFLAGS += -lgcc
LFLAGS += -Wl,--gc-sections
LFLAGS += -Wl,-L./ld
LFLAGS += -T$(LSCRIPT)
AS_SRC = ./$(ST_MCU_DEF)_vt.S
C_SRC = ./src/main.c
INCLUDE = -I./
INCLUDE += -I./src
INCLUDE += -I./device_headers
OBJS = $(AS_SRC:.S=.o)
OBJS += $(C_SRC:.c=.o)
.PHONY: all
all: $(TARGET).bin
./$(ST_MCU_DEF)_vt.S:
python generate_vt.py $(ST_MCU_DEF) $(MCU_SPEC)
%.o: %.S
$(CC) -x assembler-with-cpp $(ASFLAGS) $< -o $@
%.o: %.c
$(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@
$(TARGET).elf: $(OBJS)
$(CC) $^ $(LFLAGS) -o $@
$(TARGET).bin: $(TARGET).elf
$(OC) -S -O binary $< $@
$(OS) $<
.PHONY: clean
clean:
rm -f $(OBJS)
rm -f $(ST_MCU_DEF)_vt.S
rm -f $(TARGET).elf
rm -f $(TARGET).bin