This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
forked from andysworkshop/stm32plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
273 lines (213 loc) · 7.89 KB
/
SConstruct
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
# Top level SConstruct file for stm32plus and all the examples.
"""
Usage: scons mode=<MODE> mcu=<MCU> (hse=<HSE> / hsi=<HSI>) [float=hard] [examples=no]
<MODE>: debug/fast/small.
debug = -O0
fast = -O3
small = -Os
<MCU>: f1hd/f1cle/f1mdvl/f042/f051/f030/f4.
f030 = STM32F030 series.
f042 = STM32F042 series.
f051 = STM32F051 series.
f1hd = STM32F103HD series.
f1cle = STM32F107 series.
f1md = STM32100 medium density series.
f1mdvl = STM32100 medium density value line series.
f4 = STM32F407/f417 series (maintained for backwards compatibility)
f405 = STM32F405
f407 = STM32F407
f415 = STM32F417
f417 = STM32F417
f427 = STM32F427
f437 = STM32F437
f429 = STM32F429
f439 = STM32F439
<HSE or HSI>:
Your external (HSE) or internal (HSI) oscillator speed in Hz. Some of the ST standard
peripheral library code uses the HSE_VALUE / HSI_VALUE #define that we set here. Select
either the 'hse' or 'hsi' option, not both.
[float=hard]:
Optional flag for an F4 build that will cause the hardware FPU to be
used for floating point operations. Requires the "GNU Tools for ARM Embedded
Processors" toolchain. Will not work with Code Sourcery Lite.
[examples=no]:
Optional flag that allows you to build just the library without the examples. The
default is to build the library and the examples.
[lto=yes]:
Use link-time optimization, GCC feature that can substantially reduce binary size
Examples:
scons mode=debug mcu=f1hd hse=8000000 // debug / f1hd / 8MHz
scons mode=debug mcu=f1cle hse=25000000 // debug / f1cle / 25MHz
scons mode=debug mcu=f1mdvl hse=8000000 // debug / f1mdvl / 8MHz
scons mode=fast mcu=f1hd hse=8000000 install // fast / f1hd / 8MHz
scons mode=small mcu=f4 hse=8000000 -j4 float=hard install // small / f407 or f417 / 8Mhz
scons mode=debug mcu=f4 hse=8000000 -j4 install // debug / f407 or f417 / 8Mhz
scons mode=debug mcu=f051 hse=8000000 -j4 install // debug / f051 / 8Mhz
Additional Notes:
The -j<N> option can be passed to scons to do a parallel build. On a multicore
CPU this can greatly accelerate the build. Set <N> to approximately the number
of cores that you have.
The built library will be placed in the stm32plus/build subdirectory.
If you specify the install command-line option then that library will be installed
into the location given by INSTALLDIR, which defaults to /usr/local/arm-none-eabi.
The library, headers, and examples will be installed respectively, to the lib,
include, and bin subdirectories of INSTALLDIR.
It is safe to compile multiple combinations of mode/mcu/hse as the compiled object
code and library are placed in a unique directory name underneath stm32plus/build.
It is likewise safe to install multiple versions of the library and examples.
"""
import os
import platform
#
# set CCFLAGS/ASFLAGS/LINKFLAGS
#
def setFlags(cpu,libdef):
cpuopt="-mcpu=cortex-"+cpu;
libopt="-DSTM32PLUS_"+libdef;
env.Append(CCFLAGS=[cpuopt,libopt])
env.Append(ASFLAGS=cpuopt)
env.Append(LINKFLAGS=cpuopt)
#
# set the F4-specific hard float option
#
def floatOpt():
global float
float=ARGUMENTS.get('float')
if float=="hard":
env.Append(CCFLAGS=["-mfloat-abi=hard"])
env.Append(LINKFLAGS=["-mfloat-abi=hard","-mfpu=fpv4-sp-d16"]);
else:
float=None
return
# set the installation root. you can customise this. the default attempts to read the
# current release version from the stm32plus.h configuration header file.
VERSION=os.popen('egrep "#define\s+STM32PLUS_BUILD" lib/include/config/stm32plus.h | sed "s/^.*0x//g"').read()
VERSION=VERSION.rstrip()
if len(VERSION) != 6:
print("Unexpected error getting the library version")
Exit(1)
INSTALLDIR=ARGUMENTS.get('INSTALLDIR') or "/usr/local/arm-none-eabi"
INSTALLDIR_PREFIX=ARGUMENTS.get('INSTALLDIR_PREFIX') or "stm32plus-"+VERSION
# get the required args and validate
mode = ARGUMENTS.get('mode')
mcu = ARGUMENTS.get('mcu')
# hse or hsi
osc = ARGUMENTS.get('hse')
if osc:
osc_type = "e"
osc_def = "HSE_VALUE"
else:
osc = ARGUMENTS.get('hsi')
if osc:
osc_type = "i"
osc_def = "HSI_VALUE"
else:
print(__doc__)
Exit(1)
if not osc.isdigit():
print(__doc__)
Exit(1)
# examples off?
build_examples = ARGUMENTS.get('examples')
# use LTO ?
lto = ARGUMENTS.get('lto')
float = None
# set up build environment and pull in OS environment variables
env=Environment(ENV=os.environ)
# replace the compiler values in the environment
env.Replace(CC="arm-none-eabi-gcc")
env.Replace(CXX="arm-none-eabi-g++")
env.Replace(AS="arm-none-eabi-as")
env.Replace(AR="arm-none-eabi-ar")
env.Replace(RANLIB="arm-none-eabi-ranlib")
# set the include directories
env.Append(CPPPATH=["#lib/include","#lib/include/stl","#lib"])
# create the C and C++ flags that are needed. We can't use the extra or pedantic errors on the ST library code.
env.Replace(CCFLAGS=["-Wall","-Werror","-Wno-implicit-fallthrough","-ffunction-sections","-fdata-sections","-fno-exceptions","-mthumb","-gdwarf-2","-pipe"])
env.Replace(CXXFLAGS=["-Wextra","-pedantic-errors","-fno-rtti","-std=gnu++14","-fno-threadsafe-statics"])
env.Append(CCFLAGS="-D"+osc_def+"="+osc)
env.Append(LINKFLAGS=["-Xlinker","--gc-sections","-mthumb","-g3","-gdwarf-2"])
# add on the MCU-specific definitions
if mcu=="f1hd":
setFlags("m3","F1_HD")
elif mcu=="f1cle":
setFlags("m3","F1_CL_E")
elif mcu=="f1mdvl":
setFlags("m3","F1_MD_VL")
elif mcu=="f1md":
setFlags("m3","F1_MD")
elif mcu=="f4" or mcu=="f407":
setFlags("m4","F407")
floatOpt()
elif mcu=="f405":
setFlags("m4","F405")
floatOpt()
elif mcu=="f415":
setFlags("m4","F415")
floatOpt()
elif mcu=="f417":
setFlags("m4","F417")
floatOpt()
elif mcu=="f427":
setFlags("m4","F427")
floatOpt()
floatOpt()
elif mcu=="f437":
setFlags("m4","F437")
floatOpt()
elif mcu=="f429":
setFlags("m4","F429")
floatOpt()
elif mcu=="f439":
setFlags("m4","F439")
floatOpt()
elif mcu=="f051":
setFlags("m0","F0_51")
elif mcu=="f030":
setFlags("m0","F0_30")
elif mcu=="f042":
setFlags("m0","F0_42")
else:
print(__doc__)
Exit(1)
# add on the mode=specific optimisation definitions
if mode=="debug":
env.Append(CCFLAGS=["-O0","-g3"])
elif mode=="fast":
env.Append(CCFLAGS=["-O3"])
elif mode=="small":
env.Append(CCFLAGS=["-Os"])
else:
print(__doc__)
Exit(1)
# modify build flags and plugin location for using LTO
if lto=="yes":
if "cygwin" in platform.system().lower():
lto_plugin="liblto_plugin-0.dll"
else:
lto_plugin="liblto_plugin.so"
import subprocess
opts=subprocess.check_output("arm-none-eabi-gcc --print-file-name="+lto_plugin,shell=True).strip()
env.Append(CFLAGS=["-flto"])
env.Append(CXXFLAGS=["-flto"])
env.Append(CPPFLAGS=["-flto"])
env.Append(LINKFLAGS=["-flto"])
env.Append(ARFLAGS=["--plugin="+opts])
env.Append(RANLIBFLAGS=["--plugin="+opts])
print("stm32plus build version is "+VERSION)
systemprefix=mode+"-"+mcu+"-"+osc+osc_type
if float:
systemprefix += "-"+float
# launch SConscript for the main library
libstm32plus=SConscript("lib/SConscript",
exports=["mode","mcu","osc","osc_type","osc_def","env","systemprefix","INSTALLDIR","INSTALLDIR_PREFIX","VERSION"],
variant_dir="lib/build/"+systemprefix,
duplicate=0)
env.Append(LIBS=[libstm32plus])
# launch SConscript for the examples
if build_examples!="no":
SConscript("examples/SConscript",exports=["mode","mcu","osc","osc_type","osc_def","env","systemprefix","INSTALLDIR","INSTALLDIR_PREFIX","VERSION"])
# build the CMake helper
SConscript("cmake/SConscript",
exports=["env","systemprefix","libstm32plus","INSTALLDIR","INSTALLDIR_PREFIX","VERSION"],
variant_dir="lib/build/"+systemprefix+"/cmake")