-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
73 lines (55 loc) · 1.61 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
TTY ?= /dev/ttyUSB0
BAUD ?= 19200
# Folders
SRC = src/
LPC = LPC11xx/
C_FILES = $(wildcard $(SRC)*.c) $(wildcard $(LPC)*.c)
S_FILES = $(wildcard $(SRC)*.S)
OBJ = $(C_FILES:.c=.o) $(S_FILES:.S=.o)
ASM = $(C_FILES:.c=.asm)
DEP = $(C_FILES:.c=.d)
# File names
BIN = $(SRC)LPC1114FN28.bin
ELF = $(SRC)LPC1114FN28.elf
HEX = $(SRC)LPC1114FN28.hex
LD = $(SRC)LPC1114FN28.ld
MAP = $(SRC)LPC1114FN28.map
# C compiler flags
C_FLAGS = -mcpu=cortex-m0 -mthumb
C_FLAGS += -Wall -Wextra -Werror -pedantic
C_FLAGS += -std=c11 -O0 -ffreestanding -fno-tree-loop-distribute-patterns
C_FLAGS += -ffunction-sections -fdata-sections
C_FLAGS += $(if $(DEBUG), -g) -I$(LPC) -D BAUD_RATE=$(BAUD)
# Linker flags
LD_FLAGS = -mcpu=cortex-m0 -mthumb -nostdlib
LD_FLAGS += -Wl,-gc-sections
all: $(HEX) $(BIN)
asm: $(ASM)
size: $(OBJ) $(ELF)
@size $(OBJ) $(ELF)
$(HEX): $(ELF)
@echo "Creating" $@
@arm-none-eabi-objcopy -O ihex $(ELF) $(HEX)
$(BIN): $(ELF)
@echo "Creating" $@
@arm-none-eabi-objcopy -O binary $(ELF) $(BIN)
$(ELF): $(LD) $(OBJ)
@echo "Linking into" $@
@arm-none-eabi-gcc $(LD_FLAGS) -T $(LD) -Wl,-Map,$(MAP) -o $@ $(OBJ) -lgcc
%.o: %.c
@echo "Building" $@
@arm-none-eabi-gcc -MMD -MF $(<:.c=.d) $(C_FLAGS) -o $@ -c $<
%.o: %.S
@echo "Building" $@
@arm-none-eabi-gcc $(C_FLAGS) -o $@ -c $<
%.asm: %.c
@echo "Building" $@
@arm-none-eabi-gcc $(C_FLAGS) -fverbose-asm -o $@ -S $<
clean:
@rm -rf $(OBJ) $(ASM) $(DEP)
@rm -rf $(BIN) $(ELF) $(HEX) $(MAP)
@echo "Cleaned project"
-include $(DEP)
upload: $(BIN)
lpc21isp -control -verify -term -bin $(BIN) $(TTY) $(BAUD) 12000
# lpc21isp -termonly $(TTY) $(BAUD) 12000