3434
3535# Out startup files
3636CMSIS_Startupfile = ""
37+ CMSIS_Startupfile_source = ""
3738
3839# Out system stm32 files
3940system_stm32_outfile = ""
4849ll_h_file = "stm32yyxx_ll_ppp.h"
4950c_file = "stm32yyxx_feat.c"
5051stm32_def_build_file = "stm32_def_build.h"
52+ startup_stm32yyxx_file = "startup_stm32yyxx.c"
5153system_stm32_file = "system_stm32yyxx.c"
5254
5355# Create the jinja2 environment.
6062c_file_template = j2_env .get_template (c_file )
6163dsp_file_template = Template ('#include "../Source/{{ dsp_dir }}/{{ dsp_name }}"\n \n ' )
6264stm32_def_build_template = j2_env .get_template (stm32_def_build_file )
65+ startup_stm32yyxx_template = j2_env .get_template (startup_stm32yyxx_file )
6366system_stm32_template = j2_env .get_template (system_stm32_file )
6467
6568# re
@@ -79,6 +82,7 @@ def checkConfig(arg_core, arg_cmsis):
7982 global CMSIS_DSP_lib_path
8083 global CMSIS_DSP_outSrc_path
8184 global CMSIS_Startupfile
85+ global CMSIS_Startupfile_source
8286 global system_path
8387 global system_stm32_outfile
8488 global HALoutSrc_path
@@ -100,6 +104,9 @@ def checkConfig(arg_core, arg_cmsis):
100104 CMSIS_DSP_lib_path = core_path / "libraries" / "CMSIS_DSP"
101105 CMSIS_DSP_outSrc_path = CMSIS_DSP_lib_path / "src"
102106 CMSIS_Startupfile = core_path / "cores" / "arduino" / "stm32" / stm32_def_build_file
107+ CMSIS_Startupfile_source = (
108+ core_path / "cores" / "arduino" / "stm32" / startup_stm32yyxx_file
109+ )
103110 system_stm32_outfile = SrcWrapper_path / "src" / "stm32" / system_stm32_file
104111
105112 HALoutSrc_path = SrcWrapper_path / "src" / "HAL"
@@ -149,6 +156,36 @@ def printCMSISStartup(log):
149156 else :
150157 if log :
151158 print ("No startup files found!" )
159+ # v2
160+ filelist = sorted (CMSIS_Device_ST_path .glob ("**/startup_*.c" ))
161+ filelist = [pth .name for pth in filelist ]
162+ if len (filelist ):
163+ if log :
164+ print (f"Number of source startup files: { len (filelist )} " )
165+ # Some mcu have two startup files
166+ # Ex: WL one for cm0plus and one for cm4
167+ # In that case this is the same value line so add an extra defined
168+ # to use the correct one.
169+ group_startup_list = [
170+ list (g ) for _ , g in groupby (filelist , lambda x : re .split ("_|\\ ." , x )[1 ])
171+ ]
172+ cmsis_list = []
173+ for fn_list in group_startup_list :
174+ if len (fn_list ) == 1 :
175+ valueline = re .split ("_|\\ ." , fn_list [0 ])
176+ vline = valueline [1 ].upper ().replace ("X" , "x" )
177+ cmsis_list .append ({"vline" : vline , "fn" : fn_list [0 ], "cm" : "" })
178+ else :
179+ for fn in fn_list :
180+ valueline = re .split ("_|\\ ." , fn )
181+ vline = valueline [1 ].upper ().replace ("X" , "x" )
182+ cm = valueline [2 ].upper ()
183+ cmsis_list .append ({"vline" : vline , "fn" : fn , "cm" : cm })
184+ with open (CMSIS_Startupfile_source , "w" , newline = "\n " ) as out_file :
185+ out_file .write (startup_stm32yyxx_template .render (cmsis_list = cmsis_list ))
186+ else :
187+ if log :
188+ print ("No startup files found!" )
152189
153190
154191def printSystemSTM32 (log ):
@@ -181,6 +218,8 @@ def wrap(arg_core, arg_cmsis, log):
181218 createFolder (LLoutInc_path )
182219 if CMSIS_Startupfile .is_file ():
183220 CMSIS_Startupfile .unlink ()
221+ if CMSIS_Startupfile_source .is_file ():
222+ CMSIS_Startupfile_source .unlink ()
184223 all_ll_h_list = []
185224 # key: peripheral, value: series list
186225 ll_h_dict = {}
0 commit comments