-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile.stm32l1
139 lines (106 loc) · 4.14 KB
/
makefile.stm32l1
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# output name images
ELFIMAGE = hd44780.elf
BINIMAGE = $(ELFIMAGE:.elf=.bin)
MAPFILE = $(ELFIMAGE:.elf=.map)
# user source code
C_DIR = code
C_SOURCE = test.c hd44780.c
A_DIR = code
A_SOURCE =
# optimisation level
# 0 - reduce compilation time and make debugging work (default)
# 1 - tries to reduce code size and execution time, without extremely extending compilation time
# 2 - optimise more than 1. Enables all optimisations that don't have a speed-space tradeoff
# 3 - optimise even more than 2. Very aggressive
# s - optimise for speed, enables all level 2 (with some exceptions) and a few others
# fast - optimise for speed, disregards strict standards compliance and enables level 3
OPTIM = 0
# debugging mode (1 enabled, 0 disabled)
DEBUG_MODE = 1
# work directory - hold all the .obj files
WORK_DIR = work
# library dir
LIB_DIR = ../libs
# location of the cmsis library
CMSIS_INC = $(LIB_DIR)/CMSIS/Include
# stm specific
STM32_GEN_INC = $(LIB_DIR)/CMSIS/Device/ST/STM32L1xx/Include
STM32_PERIPH_INC = $(LIB_DIR)/STM32L1xx_StdPeriph_Driver/inc
STM32_PERIPH_LIB = $(LIB_DIR)/STM32L1xx_StdPeriph_Driver/STM32L1xx_StdPeriph_Driver.a
# startup code
START_SRC = $(LIB_DIR)/CMSIS/Device/ST/STM32L1xx/Source/Templates/gcc_ride7/startup_stm32l1xx_md.s
START_OBJ = $(WORK_DIR)/startup_stm32l1xx.o
SYSTEM_SRC = $(LIB_DIR)/CMSIS/Device/ST/STM32L1xx/Source/Templates/system_stm32l1xx.c
SYSTEM_OBJ = $(WORK_DIR)/system_stm32l1xx.o
# linker script
LINK_SCRIPT = $(LIB_DIR)/stm32l1xx_md_flash.ld
# gcc
AS = arm-none-eabi-as
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
CODESIZE = arm-none-eabi-size
# target arch
CPU = cortex-m3
# user source code objs
WORK_OBJS = $(addprefix $(WORK_DIR)/,$(C_SOURCE:.c=.o))
ASM_OBJS = $(addprefix $(WORK_DIR)/,$(A_SOURCE:.s=.os))
# assembler flags
AFLAGS = -mcpu=$(CPU) -mthumb -mlittle-endian -mthumb-interwork
AFLAGS += -I$(CMSIS_INC) -I$(STM32_GEN_INC) -I$(STM32_PERIPH_INC) -I$(LIB_DIR)
# compiler flags
CFLAGS = -c -mcpu=$(CPU) -mthumb -Wall -O$(OPTIM) -mlittle-endian -mthumb-interwork -mtune=$(CPU)
CFLAGS += -I$(CMSIS_INC) -I$(STM32_GEN_INC) -I$(STM32_PERIPH_INC) -I$(LIB_DIR)
CFLAGS += -DSTM32L1XX -DHSE_VALUE=\(\(uint32_t\)8000000\)
# linker flags
LK = -static -mcpu=$(CPU) -mthumb -mlitle-endian -mthumb-interwork -nostartfiles
MAP = -Xlinker -Map -Xlinker
LDESC = -Xlinker -T
# strip debug if debug not enabled
ifeq ($(DEBUG_MODE),1)
# In order to generate the application code with DEBUG function
# All debug information will be remained (Un-strip)
ELFSTRIP = $(OBJCOPY) -O elf32-littlearm
ELFTOBIN = $(OBJCOPY) -I elf32-little -O binary
BINTOELF = $(OBJCOPY) -I binary -O elf32-little
CFLAGS += -ggdb
else
# In order to generate the final application code without DEBUG
# All debug information will be remove (strip)
ELFSTRIP = $(OBJCOPY) -O elf32-littlearm --strip-all
ELFTOBIN = $(OBJCOPY) -I elf32-little -O binary --strip-debug --strip-unneeded
BINTOELF = $(OBJCOPY) -I elf32-little -O elf32-little --strip-all
endif
# ==========================================================================================
# make rules
# ==========================================================================================
default: rom
rom: dirs $(ASM_OBJS) $(WORK_OBJS) $(START_OBJ) $(SYSTEM_OBJ)
@echo Linking ...
@$(CC) $(ASM_OBJS) $(WORK_OBJS) $(START_OBJ) $(SYSTEM_OBJ) $(STM32_PERIPH_LIB) \
$(LK) $(MAP) $(MAPFILE) $(LDESC) $(LINK_SCRIPT) -o $(ELFIMAGE)
@echo Converting to bin ...
@$(ELFTOBIN) $(ELFIMAGE) $(BINIMAGE)
@echo Code stats
@$(CODESIZE) $(ELFIMAGE)
.PHONY: dirs clean rom
dirs:
@echo Creating work folder structure
@test -d $(WORK_DIR) || mkdir $(subst /,\,$(WORK_DIR))
clean:
@echo Removing work folder structure
@if [ -d work ]; then rm -r work; fi
@if [ -f $(ELFIMAGE) ]; then rm $(ELFIMAGE); fi
@if [ -f $(BINIMAGE) ]; then rm $(BINIMAGE); fi
@if [ -f $(MAPFILE) ]; then rm $(MAPFILE); fi
$(addprefix $(WORK_DIR)/,%.o):$(addprefix $(C_DIR)/,%.c)
@echo $<
@$(CC) $(CFLAGS) -c $< -o $@
$(addprefix $(WORK_DIR)/,%.os):$(addprefix $(A_DIR)/,%.s)
@echo $<
@$(AS) $(AFLAGS) $< -o $@
$(START_OBJ):$(START_SRC)
@echo $<
@$(AS) $(AFLAGS) $< -o $@
$(SYSTEM_OBJ):$(SYSTEM_SRC)
@echo $<
@$(CC) $(CFLAGS) -c $< -o $@