-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (69 loc) · 2.89 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
PROJ_NAME=stdemojtag
################################################################################
# SETUP TOOLS #
################################################################################
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
AS = arm-none-eabi-as
##### Preprocessor options
# directories to be searched for header files
INCLUDE = $(addprefix -I,$(INC_DIRS))
# #defines needed when working with the STM peripherals library
DEFS = -DUSE_HAL_DRIVER -DSTM32L476xx -DUSE_STM32L476G_DISCO_REVB
##### Assembler options
AFLAGS = -mcpu=cortex-m4
AFLAGS += -mthumb
AFLAGS += -mthumb-interwork
AFLAGS += -mlittle-endian
AFLAGS += -mfloat-abi=hard
AFLAGS += -mfpu=fpv4-sp-d16
##### Compiler options
CFLAGS = -ggdb
CFLAGS += -Os
CFLAGS += -Wall -Wextra -Warray-bounds -ffunction-sections -fdata-sections
CFLAGS += $(AFLAGS)
##### Linker options
# tell ld which linker file to use
# (this file is in the current directory)
LFLAGS = -Tsrc/STM32L476VGTx_FLASH.ld --specs=rdimon.specs -Wl,--gc-sections
################################################################################
# SOURCE FILES DIRECTORIES #
################################################################################
STM_SRC_DIR += src
vpath %.c $(STM_SRC_DIR)
vpath %.s $(STM_SRC_DIR)
################################################################################
# HEADER FILES DIRECTORIES #
################################################################################
# The header files we use are located here
INC_DIRS += src
################################################################################
# SOURCE FILES TO COMPILE #
################################################################################
SRCS += $(wildcard src/[^~]*.c)
# startup file, calls main
ASRC = src/startup_stm32l476xx.s
OBJS = $(patsubst src/%.c,build/%.o,$(SRCS))
OBJS += $(patsubst src/%.s,build/%.o,$(ASRC))
######################################################################
# SETUP TARGETS #
######################################################################
.PHONY: all
all: $(PROJ_NAME).elf
build/%.o : src/%.c
@mkdir -p build
@echo "[Compiling ] $^"
@$(CC) -c -o $@ $(INCLUDE) $(DEFS) $(CFLAGS) $^
build/%.o : src/%.s
@mkdir -p build
@echo "[Assembling ]" $^
@$(AS) $(AFLAGS) $< -o $@
$(PROJ_NAME).elf: $(OBJS)
@echo "[Linking ] $@"
@$(CC) $(CFLAGS) $(LFLAGS) $^ -o $@
@$(OBJCOPY) -O ihex $(PROJ_NAME).elf $(PROJ_NAME).hex
@$(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin
clean:
rm -f *.o $(PROJ_NAME).elf $(PROJ_NAME).hex $(PROJ_NAME).bin -r build
flash: all
st-flash write $(PROJ_NAME).bin 0x8000000