-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
321 lines (257 loc) · 7.21 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# Optimization options
# -flto use link-time optimization
#
OPT = -O2 -flto
# OPT = -O1 # for debugging
# Object files directory
# Warning: this will be removed by make clean!
#
OBJDIR = obj_app
# Target file name (without extension)
#
TARGET = $(OBJDIR)/nucular_kb
# Define all C source files (dependencies are generated automatically)
#
INCDIRS += Source
SOURCES += Source/main.c
SOURCES += Source/keyboard.c
SOURCES += Source/kb_driver.c
SOURCES += Source/hid_debug.c
SOURCES += Source/trackpoint.c
SOURCES += Source/ps2_host.c
SOURCES += Source/ustime.c
SOURCES += Source/util.c
SOURCES += Source/small_printf.c
SOURCES += Source/usbd_conf.c
SOURCES += Source/usbd_desc.c
SOURCES += Source/usbd_hid.c
# USB middleware library
#
USB_DIR = Libraries/STM32_USB_Device_Library-2.2.0
INCDIRS += $(USB_DIR)/Core/Inc
SOURCES += $(USB_DIR)/Core/Src/usbd_core.c
SOURCES += $(USB_DIR)/Core/Src/usbd_ctlreq.c
SOURCES += $(USB_DIR)/Core/Src/usbd_ioreq.c
# HAL driver library
#
CPPFLAGS += -DSTM32L052xx
CPPFLAGS += -DUSE_HAL_DRIVER
CPPFLAGS += -DUSE_FULL_ASSERT
HAL_DIR = Libraries/STM32L0xx_HAL_Driver-1.1.0
INCDIRS += $(HAL_DIR)/Inc
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_iwdg.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_tim.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_tim_ex.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_uart.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_uart_ex.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_usart.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_pcd.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_pcd_ex.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_gpio.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_dma.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_rcc.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_rcc_ex.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_rtc.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_rtc_ex.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_flash.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_flash_ex.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_flash_ramfunc.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_pwr.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_pwr_ex.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_cortex.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_i2c.c
SOURCES += $(HAL_DIR)/Src/stm32l0xx_hal_i2c_ex.c
# CMSIS-Library
#
CMSIS_DIR = Libraries/CMSIS-3.2.0
INCDIRS += $(CMSIS_DIR)/Include
INCDIRS += $(CMSIS_DIR)/Device/ST/STM32L0xx/Include
SOURCES += $(CMSIS_DIR)/Device/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l052xx.s
SOURCES += $(CMSIS_DIR)/Device/ST/STM32L0xx/Source/Templates/system_stm32l0xx.c
LDSCRIPT = Source/STM32L052R8_FLASH.ld
#============================================================================
#
OBJECTS += $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SOURCES))))
CPPFLAGS += $(addprefix -I,$(INCDIRS))
#---------------- Preprocessor and common options ----------------
# Optimization options
CPPFLAGS += $(OPT)
CPPFLAGS += -fsingle-precision-constant
# Use a friendly C dialect
CPPFLAGS += -fno-strict-aliasing
CPPFLAGS += -fwrapv
# Generate debugging information
CPPFLAGS += -g
# preserve .s and .i-files
CPPFLAGS += -save-temps=obj
# Use individual sections to enable linker garbage collection
CPPFLAGS += -ffunction-sections
CPPFLAGS += -fdata-sections
# Warning options
CPPFLAGS += -Wall
CPPFLAGS += -Wundef
CPPFLAGS += -Wstrict-prototypes
#CPPFLAGS += -Wextra
#CPPFLAGS += -Wpointer-arith
#CPPFLAGS += -Winline
#CPPFLAGS += -Wunreachable-code
#---------------- C Compiler Options ----------------
#
CFLAGS += -std=gnu11
#---------------- C++ Compiler Options ----------------
#
#---------------- Assembler Options ----------------
#
#---------------- Linker Options ----------------
#
LDFLAGS += $(OPT) -g
LDFLAGS += -specs=nano.specs
# LDFLAGS += -u _printf_float -u _scanf_float
# Link math library
# LDFLAGS += -lm
# Create a map file with cross references
LDFLAGS += -Wl,-Map=$(TARGET).map,--cref
# Garbage collect unused sections (see above)
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -T$(LDSCRIPT)
#============================================================================
# Define programs and commands
#
TOOLCHAIN = arm-none-eabi-
CC = $(TOOLCHAIN)gcc
OBJCOPY = $(TOOLCHAIN)objcopy
OBJDUMP = $(TOOLCHAIN)objdump
SIZE = $(TOOLCHAIN)size
NM = $(TOOLCHAIN)nm
MKDIR = mkdir
DOXYGEN = doxygen
STLINK = Tools/st-link/ST-LINK_CLI.exe
HEX2DFU = Tools/hex2dfu/hex2dfu.py
# Compiler flags to generate dependency files
#
GENDEPFLAGS = -MMD -MP
# Combine all necessary flags and optional flags
# Add target processor to flags.
#
# CPU = -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
# CPU = -mcpu=cortex-m4 -mthumb -mfloat-abi=softfp -mfpu=fpv4-sp-d16
CPU = -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft
CFLAGS += $(CPU)
CXXFLAGS += $(CPU)
ASFLAGS += $(CPU)
LDFLAGS += $(CPU)
# Default target
#
all: gccversion build showsize
build: elf hex bin dfu lss sym
elf: $(TARGET).elf
hex: $(TARGET).hex
bin: $(TARGET).bin
dfu: $(TARGET).dfu
lss: $(TARGET).lss
sym: $(TARGET).sym
doxygen:
@echo
@echo Creating Doxygen documentation
@$(DOXYGEN)
boot:
$(MAKE) -f Bootloader/Makefile
boot_clean:
$(MAKE) -f Bootloader/Makefile clean
boot_flash:
$(MAKE) -f Bootloader/Makefile flash
# Display compiler version information
#
gccversion:
@$(CC) --version
# Show the final program size
#
showsize: build
@echo
@$(SIZE) $(TARGET).elf
# @echo
# @$(NM) $(TARGET).elf --size-sort -r | grep " [DdBb] "
# Flash the device
#
flash: build showsize
$(STLINK) -c SWD -P $(TARGET).hex -Run
# Target: clean project
#
clean:
@echo Cleaning project:
rm -rf $(OBJDIR)
rm -f Source/version.c
# Link: create ELF output file from object files
#
$(TARGET).elf: $(OBJECTS) $(LDSCRIPT)
@echo
@echo Linking: $@
@$(MKDIR) -p $(dir $@)
$(CC) $(OBJECTS) $(LDFLAGS) --output $@
# Create extended listing file from ELF output file
#
%.lss: %.elf
@echo
@echo Creating Extended Listing: $@
@$(MKDIR) -p $(dir $@)
$(OBJDUMP) -h -S -z $< > $@
# Create a symbol table from ELF output file
#
%.sym: %.elf
@echo
@echo Creating Symbol Table: $@
@$(MKDIR) -p $(dir $@)
$(NM) -n $< > $@
# Create final output files from ELF output file.
#
%.hex: %.elf
@echo
@echo Creating hex file: $@
@$(MKDIR) -p $(dir $@)
$(OBJCOPY) -O ihex $< $@
# Create binary output file from ELF output file.
#
%.bin: %.elf
@echo
@echo Creating bin file: $@
@$(MKDIR) -p $(dir $@)
$(OBJCOPY) -O binary $< $@
# Create DfuSe file from hex files
#
%.dfu: %.hex
@echo
@echo Creating dfu file: $@
@$(MKDIR) -p $(dir $@)
$(HEX2DFU) $< $@
# Compile: create object files from C source files
#
$(OBJDIR)/%.o : %.c
@echo
@echo Compiling C: $<
@$(MKDIR) -p $(dir $@)
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(GENDEPFLAGS) $< -o $@
$(OBJDIR)/%.o : %.cpp
@echo
@echo Compiling C++: $<
@$(MKDIR) -p $(dir $@)
$(CC) -c $(CPPFLAGS) $(CXXFLAGS) $(GENDEPFLAGS) $< -o $@
# Assemble: create object files from assembler source files
#
$(OBJDIR)/%.o : %.s
@echo
@echo Assembling: $<
@$(MKDIR) -p $(dir $@)
$(CC) -c $(CPPFLAGS) $(ASFLAGS) $(GENDEPFLAGS) $< -o $@
# Make everything depend on the makefile
#
# $(OBJECTS): $(MAKEFILE_LIST)
# Include the dependency files
#
-include $(OBJECTS:.o=.d)
# Listing of phony targets
#
.PHONY: all build flash clean \
boot boot_clean boot_flash \
elf hex bin dfu lss sym \
doxygen showsize gccversion