This repository has been archived by the owner on May 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.stm32
263 lines (214 loc) · 6.37 KB
/
Makefile.stm32
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
# Hey Emacs, this is a -*- makefile -*-
#
# Copyright (C) 2009 Antoine Drouin
#
# This file is part of paparazzi.
#
# paparazzi is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# paparazzi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with paparazzi; see the file COPYING. If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
#
# This is the common Makefile for the stm32-target.
#
SRC_ARCH = arch/stm32
# Pretty Printer
# Call with "make Q=''" to get full command display
Q=@
#
# find compiler toolchain
#
include $(PAPARAZZI_SRC)/conf/Makefile.arm-embedded-toolchain
ifeq ($(ARCH_L),f4)
MCU = cortex-m4
else
MCU = cortex-m3
endif
OPT ?= s
# Slightly bigger .elf files but gains the ability to decode macros
DEBUG_FLAGS ?= -ggdb3
CSTANDARD ?= -std=gnu99
CXXSTANDARD ?= -std=c++98
# input files
SRCS = $($(TARGET).srcs)
#ASRC =
# object files
COBJ = $(SRCS:%.c=$(OBJDIR)/%.o)
OBJS = $(COBJ:%.cpp=$(OBJDIR)/%.o)
AOBJ = $(ASRC:%.S=$(OBJDIR)/%.o)
# linker script :
# if LDSCRIPT is defined in the airframe use that independantly of TARGET
# if not, and a TARGET.LDSCRIPT is defined, use that
# if not, use the default STM32f103re_flash.ld
ifndef LDSCRIPT
ifndef $(TARGET).LDSCRIPT
$(warning Linker script for target "$(TARGET)" on board "$(BOARD)" not defined. Using stm32default.ld.)
LDSCRIPT = $(SRC_ARCH)/stm32default.ld
else
LDSCRIPT = $($(TARGET).LDSCRIPT)
$(info Using "$($(TARGET).LDSCRIPT)" as ldscript for target "$(TARGET)".)
endif
endif
ifeq ($(ARCH_L), )
FLOAT_ABI ?= -msoft-float
else ifeq ($(ARCH_L),f4)
ifndef HARD_FLOAT
FLOAT_ABI ?= -msoft-float
else
FLOAT_ABI ?= -mfloat-abi=softfp -mfpu=fpv4-sp-d16
endif
endif
ARCH_FLAGS ?= -mcpu=$(MCU) -mthumb
# flags for warnings (C and C++)
WARN_FLAGS += -Wall -Wextra -Wunused
#WARN_FLAGS += -Wcast-qual
WARN_FLAGS += -Wcast-align
WARN_FLAGS += -Wpointer-arith
WARN_FLAGS += -Wswitch-default
WARN_FLAGS += -Wredundant-decls -Wmissing-declarations
WARN_FLAGS += -Wshadow
# common flags
CFLAGS += -O$(OPT)
CFLAGS += $(DEBUG_FLAGS)
CFLAGS += $(FLOAT_ABI)
CFLAGS += $(ARCH_FLAGS)
CFLAGS += $(USER_CFLAGS)
CFLAGS += $(WARN_FLAGS)
CXXFLAGS += -O$(OPT)
CXXFLAGS += $(DEBUG_FLAGS)
CXXFLAGS += $(FLOAT_ABI)
CXXFLAGS += $(ARCH_FLAGS)
CXXFLAGS += $(USER_CFLAGS)
CXXFLAGS += $(WARN_FLAGS)
CFLAGS += -I. -I./$(ARCH) -I../ext/libopencm3/include $(INCLUDES)
CFLAGS += -D__thumb2__
CFLAGS += -Wl,--gc-sections
CFLAGS += -mfix-cortex-m3-ldrd
CFLAGS += $(CSTANDARD)
#CFLAGS += -malignment-traps
CFLAGS += -fno-common
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(notdir $(subst $(suffix $<),.lst,$<))
CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
CFLAGS += -Wnested-externs
CFLAGS += $($(TARGET).CFLAGS)
CFLAGS += $(BOARD_CFLAGS)
#CFLAGS += -fno-diagnostics-show-caret
ifneq ($(ARCH_L), )
ifeq ($(ARCH_L),f4)
CFLAGS += -DSTM32F4
endif
else
CFLAGS += -DSTM32F1
endif
# with cortex-m3 and m4 unaligned data can still be read
CFLAGS += -DPPRZLINK_UNALIGNED_ACCESS=1
# C++ only flags
CXXFLAGS += $(CXXSTANDARD)
CXXFLAGS += -pipe -fshow-column -ffast-math
CXXFLAGS += -ffunction-sections -fdata-sections
CXXFLAGS += $($(TARGET).CXXFLAGS)
AFLAGS = -ahls -mapcs-32
AFLAGS += -mcpu=$(MCU) -mthumb
AFLAGS += -x assembler-with-cpp -Wa,-adhlns=$(OBJDIR)/$(<:.S=.lst)
LDFLAGS += -L../ext/libopencm3/lib
LDFLAGS += -T$(LDSCRIPT) -nostartfiles -O$(OPT) -mthumb -mcpu=$(MCU)
LDFLAGS += $(BOARD_LDFLAGS)
ifeq ($(ARCH_L), )
LDFLAGS += -mfix-cortex-m3-ldrd -msoft-float
else ifeq ($(ARCH_L),f4)
ifndef HARD_FLOAT
LDFLAGS += -mfix-cortex-m3-ldrd -msoft-float
else
LDFLAGS += -lnosys -D__thumb2__\
-mfloat-abi=softfp -mfpu=fpv4-sp-d16
endif
endif
LDFLAGS += -Wl,-Map=$(OBJDIR)/$(TARGET).map,--cref,--gc-sections
ifneq ($(ARCH_L), )
LDLIBS += -lopencm3_stm32$(ARCH_L)
else
LDLIBS += -lopencm3_stm32f1
endif
LDLIBS += -lc -lm -lgcc
CPFLAGS = -j .isr_vector -j .text -j .data
CPFLAGS_BIN = -Obinary
CPFLAGS_HEX = -Oihex
ODFLAGS = -S
# some common informative targets
include $(PAPARAZZI_SRC)/conf/Makefile.arm-embedded-common
# Default target.
all: printcommands sizebefore build sizeafter
# depend order only for parallel make
sizebefore: | printcommands
build: | printcommands sizebefore
sizeafter: | build
build: $(OBJDIR) elf bin hex
# lss sym
$(OBJDIR):
@echo CREATING object dir $(OBJDIR)
@test -d $(OBJDIR) || mkdir -p $(OBJDIR)
elf: $(OBJDIR)/$(TARGET).elf
bin: $(OBJDIR)/$(TARGET).bin
hex: $(OBJDIR)/$(TARGET).hex
lss: $(OBJDIR)/$(TARGET).lss
sym: $(OBJDIR)/$(TARGET).sym
%.bin: %.elf
@echo OBJCB $@
$(Q)$(CP) $(CPFLAGS) $(CPFLAGS_BIN) $< $@
%.hex: %.elf
@echo OBJCH $@
$(Q)$(CP) $(CPFLAGS) $(CPFLAGS_HEX) $< $@
# Create extended listing file from ELF output file.
# testing: option -C
%.lss: %.elf
@echo OBJD $@
$(Q)$(DMP) -h -S -C $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo NM $@
$(Q)$(NM) -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(OBJDIR)/$(TARGET).elf
.PRECIOUS : $(OBJS) $(AOBJ)
%.elf: $(OBJS) $(AOBJ) | $(OBJDIR)
@echo LD $@
$(Q)$(LD) $(LDFLAGS) $($(TARGET).LDFLAGS) -o $@ $(COBJ) $(AOBJ) $(LDLIBS)
# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c $(OBJDIR)/../Makefile.ac
@echo CC $@
$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
$(Q)$(CC) -MMD -c $(CFLAGS) $< -o $@
# Compile: create object files from C++ source files
$(OBJDIR)/%.o : %.cpp $(OBJDIR)/../Makefile.ac
@echo CXX $@
$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
$(Q)$(CXX) -MMD -c $(CXXFLAGS) $< -o $@
# Assemble: create object files from assembler source files. ARM/Thumb
$(AOBJ) : $(OBJDIR)/%.o : %.S
@echo AS $@
$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
$(Q)$(CC) -c $(AFLAGS) $< -o $@
# Load upload rules
include $(PAPARAZZI_SRC)/conf/Makefile.stm32-upload
# Listing of phony targets.
.PHONY : all build elf bin lss sym
#
# Dependencies
#
ifneq ($(MAKECMDGOALS),clean)
DEPS = $(addprefix $(OBJDIR)/,$($(TARGET).srcs:.c=.d))
DEPS += $(addprefix $(OBJDIR)/,$($(TARGET).srcs:.cpp=.d))
-include $(DEPS)
endif