-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
174 lines (151 loc) · 4.3 KB
/
Makefile
File metadata and controls
174 lines (151 loc) · 4.3 KB
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
#Output file name
OUTFILE = BlueOS
#Linker script
LDSCRIPT = BlueOS_linker.ld
#Map File
MAPFILE = BlueOS_linker.map
#Directories to find included files
INCLUDE = -I./inc -I./config
#Additional link libraries
LDLIBS =
#-lm
BLDIR = obj
SRCDIR = src
CFGDIR = config
OUTDIR = bin
TARGET = $(OUTDIR)/$(OUTFILE)
#Tool Names
CROSS_COMPILE = arm-none-eabi-
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
AR=$(CROSS_COMPILE)ar
AS=$(CROSS_COMPILE)as
OC=$(CROSS_COMPILE)objcopy
OD=$(CROSS_COMPILE)objdump
SZ=$(CROSS_COMPILE)size
FL=$(shell which st-flash)
SR=$(shell which minicom)
#Compiler Flags
CFLAGS = -c -fno-common \
-ffunction-sections \
-fdata-sections \
-Os \
-mcpu=cortex-m3 -Wall \
-mthumb \
-std=gnu99 \
-DSTM32F103CB \
-DSTM32F10X_MD \
-DBLUE_PILL
#-DMAPLE_MINI
#Linker Flags
LDFLAGS = -O, --gc-sections \
-T $(LDSCRIPT) \
-Map $(BLDIR)/$(MAPFILE) \
-no-startup -nostdlib
#Object Copy Flags
OCFLAGS = -Obinary
#Object Dump Flags
ODFLAGS = -S
#Generate list of source files
SRCS := $(notdir $(wildcard src/*.c src/*.S src/*.s config/*.c))
#Generate list of object files
OBJS = $(addsuffix .o, $(basename $(SRCS)))
.PHONY : clean all
all: $(TARGET).bin $(TARGET).hex $(TARGET).list
$(SZ) $(TARGET).elf
clean:
ifeq ($(OS),Windows_NT)
del *.o
del *.elf
del *.lst
del *.out
del *.bin
del *.hex
del *.map
del $(BLDIR)\*.o
del $(BLDIR)\*.elf
del $(BLDIR)\*.lst
del $(BLDIR)\*.out
del $(BLDIR)\*.bin
del $(BLDIR)\*.hex
del $(BLDIR)\*.map
del $(SRCDIR)\*.o
del $(SRCDIR)\*.elf
del $(SRCDIR)\*.lst
del $(SRCDIR)\*.out
del $(SRCDIR)\*.bin
del $(SRCDIR)\*.hex
del $(SRCDIR)\*.map
del $(OUTDIR)\*.o
del $(OUTDIR)\*.elf
del $(OUTDIR)\*.lst
del $(OUTDIR)\*.out
del $(OUTDIR)\*.bin
del $(OUTDIR)\*.hex
del $(OUTDIR)\*.map
else
-find . -name '*.o' -exec rm {} \;
-find . -name '*.elf' -exec rm {} \;
-find . -name '*.lst' -exec rm {} \;
-find . -name '*.out' -exec rm {} \;
-find . -name '*.bin' -exec rm {} \;
-find . -name '*.hex' -exec rm {} \;
-find . -name '*.map' -exec rm {} \;
-find . -name '$(BLDIR)\*.o' -exec rm {} \;
-find . -name '$(BLDIR)\*.elf' -exec rm {} \;
-find . -name '$(BLDIR)\*.lst' -exec rm {} \;
-find . -name '$(BLDIR)\*.out' -exec rm {} \;
-find . -name '$(BLDIR)\*.bin' -exec rm {} \;
-find . -name '$(BLDIR)\*.hex' -exec rm {} \;
-find . -name '$(BLDIR)\*.map' -exec rm {} \;
-find . -name '$(SRCDIR)\*.o' -exec rm {} \;
-find . -name '$(SRCDIR)\*.elf' -exec rm {} \;
-find . -name '$(SRCDIR)\*.lst' -exec rm {} \;
-find . -name '$(SRCDIR)\*.out' -exec rm {} \;
-find . -name '$(SRCDIR)\*.bin' -exec rm {} \;
-find . -name '$(SRCDIR)\*.hex' -exec rm {} \;
-find . -name '$(SRCDIR)\*.map' -exec rm {} \;
-find . -name '$(OUTDIR)\*.o' -exec rm {} \;
-find . -name '$(OUTDIR)\*.elf' -exec rm {} \;
-find . -name '$(OUTDIR)\*.lst' -exec rm {} \;
-find . -name '$(OUTDIR)\*.out' -exec rm {} \;
-find . -name '$(OUTDIR)\*.bin' -exec rm {} \;
-find . -name '$(OUTDIR)\*.hex' -exec rm {} \;
-find . -name '$(OUTDIR)\*.map' -exec rm {} \;
endif
$(TARGET).list: $(TARGET).elf
@echo " Dump $(TARGET).elf to $(TARGET).lst"
@$(OD) $(ODFLAGS) $< > $(TARGET).lst
$(TARGET).bin: $(TARGET).elf
@echo " Copy $(TARGET).elf to $(TARGET).bin"
@$(OC) $(OCFLAGS) $(TARGET).elf $(TARGET).bin
$(TARGET).hex: $(TARGET).elf
@echo " Copy $(TARGET).elf to $(TARGET).hex"
@$(OC) $(OCFLAGS) $(TARGET).elf $(TARGET).hex
$(TARGET).elf: $(addprefix $(BLDIR)/, $(OBJS))
@echo " LD $<"
@$(LD) $(LDFLAGS) -o $(TARGET).elf $(addprefix $(BLDIR)/, $(OBJS)) $(LDLIBS)
# Make object files (.o) out of various sources
$(BLDIR)/%.o: $(SRCDIR)/%.c
@echo " CC $<"
@$(CC) $(INCLUDE) $(CFLAGS) $< -o $@
$(BLDIR)/%.o: $(CFGDIR)/%.c
@echo " CC $<"
@$(CC) $(INCLUDE) $(CFLAGS) $< -o $@
$(BLDIR)/%.o: $(SRCDIR)/%.S
@echo " CC $<"
@$(CC) $(INCLUDE) $(CFLAGS) $< -o $@
$(BLDIR)/%.o: $(SRCDIR)/%.s
@echo " CC $<"
@$(CC) $(INCLUDE) $(CFLAGS) $< -o $@
# $(TARGET).bin
flash: clean all
@printf " FLASH $<\n"
$(FL) --reset write $(TARGET).bin 0x08000000
serial:
@printf " SERIAL $<\n"
$(SR) -D /dev/ttyUSB0 -b 115200
#Dump some of Flash into file
#st-flash --reset read Flash_Dump.hex 0x08000000 0x08000800
# Dissasembly of .bin file (or Flash dump?)
# arm-none-eabi-objdump -D -bbinary -marm bin/BlueOS.bin -Mforce-thumb > bin/BlueOS.S