2323"""
2424
2525import json
26+ import sys
2627from os .path import isfile , isdir , join
2728
28- from platformio .util import get_systype
29-
3029from SCons .Script import COMMAND_LINE_TARGETS , DefaultEnvironment
3130
3231env = DefaultEnvironment ()
3332platform = env .PioPlatform ()
3433board_config = env .BoardConfig ()
3534
35+ IS_WINDOWS = sys .platform .startswith ("win" )
3636FRAMEWORK_DIR = platform .get_package_dir ("framework-arduinoststm32" )
3737CMSIS_DIR = join (platform .get_package_dir ("framework-cmsis" ), "CMSIS" )
3838assert isdir (FRAMEWORK_DIR )
5252)
5353variant_dir = join (variants_dir , variant )
5454inc_variant_dir = variant_dir
55- if "windows" not in get_systype (). lower () and not (
55+ if not IS_WINDOWS and not (
5656 set (["_idedata" , "idedata" ]) & set (COMMAND_LINE_TARGETS ) and " " not in variant_dir
5757):
5858 inc_variant_dir = variant_dir .replace ("(" , r"\(" ).replace (")" , r"\)" )
@@ -116,15 +116,14 @@ def process_usb_configuration(cpp_defines):
116116
117117
118118def get_arm_math_lib (cpu ):
119- core = board_config .get ("build.cpu" )
120- if "m33" in core :
119+ if "m33" in cpu :
121120 return "arm_ARMv8MMLlfsp_math"
122- elif "m4" in core :
121+ elif "m4" in cpu :
123122 return "arm_cortexM4lf_math"
124- elif "m7" in core :
123+ elif "m7" in cpu :
125124 return "arm_cortexM7lfsp_math"
126125
127- return "arm_cortex%sl_math" % core [7 :9 ].upper ()
126+ return "arm_cortex%sl_math" % cpu [7 :9 ].upper ()
128127
129128
130129def configure_application_offset (mcu , upload_protocol ):
@@ -157,16 +156,6 @@ def configure_application_offset(mcu, upload_protocol):
157156 env .Append (LINKFLAGS = ["-Wl,--defsym=LD_FLASH_OFFSET=%s" % hex (offset )])
158157
159158
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-
170159def load_boards_remap ():
171160 remap_file = join (FRAMEWORK_DIR , "tools" , "platformio" , "boards_remap.json" )
172161 if not isfile (remap_file ):
@@ -212,11 +201,23 @@ def get_arduino_board_id(board_config, mcu):
212201
213202 return board_id .upper ()
214203
215-
216204board_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" ])
217215
218216env .Append (
219- ASFLAGS = ["-x" , "assembler-with-cpp" ],
217+ ASFLAGS = machine_flags ,
218+ ASPPFLAGS = [
219+ "-x" , "assembler-with-cpp" ,
220+ ],
220221 CFLAGS = ["-std=gnu11" ],
221222 CXXFLAGS = [
222223 "-std=gnu++14" ,
@@ -225,15 +226,12 @@ def get_arduino_board_id(board_config, mcu):
225226 "-fno-exceptions" ,
226227 "-fno-use-cxa-atexit" ,
227228 ],
228- CCFLAGS = [
229+ CCFLAGS = machine_flags + [
229230 "-Os" , # optimize for size
230- "-mcpu=%s" % board_config .get ("build.cpu" ),
231- "-mthumb" ,
232231 "-ffunction-sections" , # place each function in its own section
233232 "-fdata-sections" ,
234233 "-nostdlib" ,
235- "--param" ,
236- "max-inline-insns-single=500" ,
234+ "--param" , "max-inline-insns-single=500" ,
237235 ],
238236 CPPDEFINES = [
239237 series ,
@@ -329,10 +327,8 @@ def get_arduino_board_id(board_config, mcu):
329327 join (CMSIS_DIR , "DSP" , "PrivateInclude" ),
330328 join (FRAMEWORK_DIR , "cores" , "arduino" ),
331329 ],
332- LINKFLAGS = [
330+ LINKFLAGS = machine_flags + [
333331 "-Os" ,
334- "-mthumb" ,
335- "-mcpu=%s" % board_config .get ("build.cpu" ),
336332 "--specs=nano.specs" ,
337333 "-Wl,--gc-sections,--relax" ,
338334 "-Wl,--check-sections" ,
@@ -388,9 +384,6 @@ def get_arduino_board_id(board_config, mcu):
388384process_usb_speed_configuration (cpp_defines )
389385process_usart_configuration (cpp_defines )
390386
391- # copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode)
392- env .Append (ASFLAGS = env .get ("CCFLAGS" , [])[:])
393-
394387env .Append (
395388 LIBSOURCE_DIRS = [
396389 join (FRAMEWORK_DIR , "libraries" , "__cores__" , "arduino" ),
0 commit comments