23
23
"""
24
24
25
25
import json
26
+ import sys
26
27
from os .path import isfile , isdir , join
27
28
28
- from platformio .util import get_systype
29
-
30
29
from SCons .Script import COMMAND_LINE_TARGETS , DefaultEnvironment
31
30
32
31
env = DefaultEnvironment ()
33
32
platform = env .PioPlatform ()
34
33
board_config = env .BoardConfig ()
35
34
35
+ IS_WINDOWS = sys .platform .startswith ("win" )
36
36
FRAMEWORK_DIR = platform .get_package_dir ("framework-arduinoststm32" )
37
37
CMSIS_DIR = join (platform .get_package_dir ("framework-cmsis" ), "CMSIS" )
38
38
assert isdir (FRAMEWORK_DIR )
52
52
)
53
53
variant_dir = join (variants_dir , variant )
54
54
inc_variant_dir = variant_dir
55
- if "windows" not in get_systype (). lower () and not (
55
+ if not IS_WINDOWS and not (
56
56
set (["_idedata" , "idedata" ]) & set (COMMAND_LINE_TARGETS ) and " " not in variant_dir
57
57
):
58
58
inc_variant_dir = variant_dir .replace ("(" , r"\(" ).replace (")" , r"\)" )
@@ -116,15 +116,14 @@ def process_usb_configuration(cpp_defines):
116
116
117
117
118
118
def get_arm_math_lib (cpu ):
119
- core = board_config .get ("build.cpu" )
120
- if "m33" in core :
119
+ if "m33" in cpu :
121
120
return "arm_ARMv8MMLlfsp_math"
122
- elif "m4" in core :
121
+ elif "m4" in cpu :
123
122
return "arm_cortexM4lf_math"
124
- elif "m7" in core :
123
+ elif "m7" in cpu :
125
124
return "arm_cortexM7lfsp_math"
126
125
127
- return "arm_cortex%sl_math" % core [7 :9 ].upper ()
126
+ return "arm_cortex%sl_math" % cpu [7 :9 ].upper ()
128
127
129
128
130
129
def configure_application_offset (mcu , upload_protocol ):
@@ -157,16 +156,6 @@ def configure_application_offset(mcu, upload_protocol):
157
156
env .Append (LINKFLAGS = ["-Wl,--defsym=LD_FLASH_OFFSET=%s" % hex (offset )])
158
157
159
158
160
- if (
161
- any (cpu in board_config .get ("build.cpu" ) for cpu in ("cortex-m33" , "cortex-m4" , "cortex-m7" ))
162
- and "stm32wl" not in mcu
163
- ):
164
- env .Append (
165
- CCFLAGS = ["-mfpu=fpv4-sp-d16" , "-mfloat-abi=hard" ],
166
- LINKFLAGS = ["-mfpu=fpv4-sp-d16" , "-mfloat-abi=hard" ],
167
- )
168
-
169
-
170
159
def load_boards_remap ():
171
160
remap_file = join (FRAMEWORK_DIR , "tools" , "platformio" , "boards_remap.json" )
172
161
if not isfile (remap_file ):
@@ -212,11 +201,23 @@ def get_arduino_board_id(board_config, mcu):
212
201
213
202
return board_id .upper ()
214
203
215
-
216
204
board_id = get_arduino_board_id (board_config , mcu )
205
+ machine_flags = [
206
+ "-mcpu=%s" % board_config .get ("build.cpu" ),
207
+ "-mthumb" ,
208
+ ]
209
+
210
+ if (
211
+ any (cpu in board_config .get ("build.cpu" ) for cpu in ("cortex-m33" , "cortex-m4" , "cortex-m7" ))
212
+ and "stm32wl" not in mcu
213
+ ):
214
+ machine_flags .extend (["-mfpu=fpv4-sp-d16" , "-mfloat-abi=hard" ])
217
215
218
216
env .Append (
219
- ASFLAGS = ["-x" , "assembler-with-cpp" ],
217
+ ASFLAGS = machine_flags ,
218
+ ASPPFLAGS = [
219
+ "-x" , "assembler-with-cpp" ,
220
+ ],
220
221
CFLAGS = ["-std=gnu11" ],
221
222
CXXFLAGS = [
222
223
"-std=gnu++14" ,
@@ -225,15 +226,12 @@ def get_arduino_board_id(board_config, mcu):
225
226
"-fno-exceptions" ,
226
227
"-fno-use-cxa-atexit" ,
227
228
],
228
- CCFLAGS = [
229
+ CCFLAGS = machine_flags + [
229
230
"-Os" , # optimize for size
230
- "-mcpu=%s" % board_config .get ("build.cpu" ),
231
- "-mthumb" ,
232
231
"-ffunction-sections" , # place each function in its own section
233
232
"-fdata-sections" ,
234
233
"-nostdlib" ,
235
- "--param" ,
236
- "max-inline-insns-single=500" ,
234
+ "--param" , "max-inline-insns-single=500" ,
237
235
],
238
236
CPPDEFINES = [
239
237
series ,
@@ -329,10 +327,8 @@ def get_arduino_board_id(board_config, mcu):
329
327
join (CMSIS_DIR , "DSP" , "PrivateInclude" ),
330
328
join (FRAMEWORK_DIR , "cores" , "arduino" ),
331
329
],
332
- LINKFLAGS = [
330
+ LINKFLAGS = machine_flags + [
333
331
"-Os" ,
334
- "-mthumb" ,
335
- "-mcpu=%s" % board_config .get ("build.cpu" ),
336
332
"--specs=nano.specs" ,
337
333
"-Wl,--gc-sections,--relax" ,
338
334
"-Wl,--check-sections" ,
@@ -388,9 +384,6 @@ def get_arduino_board_id(board_config, mcu):
388
384
process_usb_speed_configuration (cpp_defines )
389
385
process_usart_configuration (cpp_defines )
390
386
391
- # copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode)
392
- env .Append (ASFLAGS = env .get ("CCFLAGS" , [])[:])
393
-
394
387
env .Append (
395
388
LIBSOURCE_DIRS = [
396
389
join (FRAMEWORK_DIR , "libraries" , "__cores__" , "arduino" ),
0 commit comments