forked from akospasztor/stm32-bootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConscript
More file actions
205 lines (167 loc) · 6.16 KB
/
Copy pathSConscript
File metadata and controls
205 lines (167 loc) · 6.16 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
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
import os
# Import build configuration
Import('build_config')
# Get project path: this is the path of the SConscript file
project_path = Dir('#').rel_path(Dir('.'))
# >>> Project Configuration ---------------------------------------------------
# Specify the build directory and its subfolders
build_dir = os.path.join('build', build_config['name'])
obj_subdir = 'obj'
# Specify the target outputs
target_name = 'stm32-bootloader'
target_exe = os.path.join(build_dir, target_name)
target_hex = os.path.join(build_dir, target_name) + '.hex'
target_bin = os.path.join(build_dir, target_name) + '.bin'
# Microcontroller flags
mcu_flags = [
'-mcpu=cortex-m4',
'-mthumb',
'-mfpu=fpv4-sp-d16',
'-mfloat-abi=hard',
]
# Common compiler flags
common_flags = [
'-Wall',
'-pedantic',
'-fdata-sections',
'-ffunction-sections',
]
# Assembler flags
a_flags = [
'-c',
]
# C/C++ compiler flags
cc_flags = [
'-MMD',
'-MP',
]
# Linker flags
link_flags = [
'-T{}'.format('bsp/stm32l496-discovery/gcc-arm/stm32l496xx_flash.ld'),
'-specs=nano.specs',
'-specs=nosys.specs',
'-lc',
'-lm',
'-lnosys',
'-Wl,-Map={}.map,--cref'.format(os.path.join(project_path, target_exe)),
'-Wl,--gc-sections',
'-Wl,--print-memory-usage',
]
# Defines
defines = [
'USE_HAL_DRIVER',
'STM32L496xx',
]
# Include locations
includes = [
'#/bootloader/include',
'#/bsp/stm32l496-discovery/include',
'#/lib/FatFs',
'#/lib/CMSIS/Include',
'#/lib/CMSIS/Device/ST/STM32L4xx/Include',
'#/lib/STM32L4xx_HAL_Driver/Inc',
]
# Source files
sources = Glob('#/bootloader/source/*.c')
sources += Glob('#/bsp/stm32l496-discovery/gcc-arm/startup_stm32l496xx.s')
sources += Glob('#/bsp/stm32l496-discovery/source/*.c')
sources += Glob('#/lib/FatFs/*.c')
sources += Glob('#/lib/FatFs/option/unicode.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc_ex.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_sd_ex.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_sd.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c')
sources += Glob('#/lib/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_sdmmc.c')
# <<< End of configuration ----------------------------------------------------
# Create environment
env = Environment(
ENV={'PATH': os.environ['PATH']}
)
# Specify the cross compiler toolchain
cross_compiler = 'arm-none-eabi-'
for (tool, name) in [
('AS', 'gcc -x assembler-with-cpp'),
('CC', 'gcc'),
('CXX', 'g++'),
('LINK', 'g++'),
('OBJCOPY', 'objcopy'),
('SIZE', 'size'),
]:
# Use the specified GCC_PATH if defined; otherwise use the GCC from PATH
if 'GCC_PATH' in os.environ:
env[tool] = os.path.join(os.environ['GCC_PATH'], cross_compiler + name)
else:
env[tool] = cross_compiler + name
# Overwrite the default assembler command variables
env['ASCOMSTR'] = 'Assembling static object $TARGET'
# Overwrite the default compiler command variables
env['CCCOMSTR'] = 'Compiling static object $TARGET'
# Overwrite the default linker command variables
env['LINKCOM'] = '$LINK $LINKFLAGS -o $TARGET $SOURCES'
env['LINKCOMSTR'] = 'Linking $TARGET'
# Overwrite the default objcopy command string
env['OBJCOPYCOMSTR'] = 'Generating $TARGET'
# Overwrite the default size command string
env['SIZECOMSTR'] = 'Generating size information'
# Clear all COMSTR variables if verbose mode is requested
if GetOption('verbose'):
for key, value in env.items():
if key.endswith('COMSTR'):
env[key] = ''
# Set the executable file suffix
env['PROGSUFFIX'] = ".elf"
# Set the object file suffix
env['OBJSUFFIX'] = ".o"
# Set the assembler flags
env['ASFLAGS'] = a_flags + mcu_flags + common_flags + build_config['optimization_flags']
# Set the C/C++ compiler flags
env['CCFLAGS'] = cc_flags + mcu_flags + common_flags + build_config['optimization_flags']
# Set the linker flags
env['LINKFLAGS'] = mcu_flags + link_flags
# Set the defines
env['CPPDEFINES'] = defines
# Set the include locations
env['CPPPATH'] = includes
# Build object files
obj_list = []
for src in sources:
filename = (os.path.splitext(os.path.basename(str(src)))[0])
obj = os.path.join(build_dir, obj_subdir, (filename + '.o'))
extra_flags = [
'-Wa,-a,-ad,-alms={}.lst'.format(
os.path.join(project_path, build_dir, obj_subdir, filename)),
]
env.Object(target=obj, source=src, CCFLAGS=(env['CCFLAGS'] + extra_flags))
obj_list.append(obj)
# Build executable
program = env.Program(target_exe, obj_list)
# Create hex output
hexfile = env.Command(target_hex, program, Action(
'$OBJCOPY -O ihex $SOURCE $TARGET', env['OBJCOPYCOMSTR']))
# Create binary output
binary = env.Command(target_bin, program, Action(
'$OBJCOPY -O binary -S $SOURCE $TARGET', env['OBJCOPYCOMSTR']))
# Generate size information
size = env.Command(None, program, Action('$SIZE $SOURCE', env['SIZECOMSTR']))
# Define build targets
build_targets = [program, hexfile, binary, size]
# Specify additional files and directories that should be removed during clean
env.Clean(build_targets, 'build')
# Define default target
env.Default(build_targets)
# Define target aliases
env.Alias('build', build_targets)