4949md_CMSIS_path = "STM32YYxx_CMSIS_version.md"
5050md_HAL_path = "STM32YYxx_HAL_Driver_version.md"
5151
52+ # stm32 def file to update
53+ stm32_def = "stm32_def.h"
54+
5255# Templating
5356templates_dir = script_path / "templates"
5457stm32yyxx_hal_conf_file = "stm32yyxx_hal_conf.h"
@@ -99,6 +102,8 @@ def checkConfig():
99102 global system_dest_path
100103 global md_HAL_path
101104 global md_CMSIS_path
105+ global stm32_def
106+
102107 config_file_path = script_path / path_config_filename
103108 if config_file_path .is_file ():
104109 try :
@@ -112,13 +117,50 @@ def checkConfig():
112117 cmsis_dest_path = repo_local_path / repo_core_name / cmsis_dest_path
113118 system_dest_path = repo_local_path / repo_core_name / system_dest_path
114119 md_CMSIS_path = cmsis_dest_path / md_CMSIS_path
120+ stm32_def = (
121+ repo_local_path
122+ / repo_core_name
123+ / "cores"
124+ / "arduino"
125+ / "stm32"
126+ / stm32_def
127+ )
115128 except IOError :
116129 print ("Failed to open {}!" .format (config_file ))
117130 else :
118131 create_config ()
119132 createFolder (repo_local_path )
120133
121134
135+ def updateStm32Def (serie ):
136+ print ("Adding top HAL include for {}..." .format (serie ))
137+ regex_serie = re .compile (r"defined\(STM32(\w+)xx\)" )
138+ # Add the new STM32YY entry
139+ added = False
140+ serie_found = ""
141+ nb_serie = 0
142+ for line in fileinput .input (stm32_def , inplace = True ):
143+ m = regex_serie .search (line )
144+ if m :
145+ serie_found = m .group (1 )
146+ nb_serie += 1
147+ if (
148+ not added
149+ and serie_found
150+ and ((serie_found > serie ) or (not m and "include" not in line ))
151+ ):
152+ if nb_serie == 1 :
153+ pcond = "if"
154+ else :
155+ pcond = "elif"
156+ print ("#{} defined(STM32{}xx)" .format (pcond , serie ))
157+ print (' #include "stm32{}xx.h"' .format (serie .lower ()))
158+ print (line .replace ("if" , "elif" ), end = "" )
159+ added = True
160+ else :
161+ print (line , end = "" )
162+
163+
122164def updateHalConfDefault (serie ):
123165 system_serie = system_dest_path / ("STM32{}xx" .format (serie ))
124166 hal_conf_base = "stm32{}xx_hal_conf" .format (serie .lower ())
@@ -531,7 +573,7 @@ def updateMDFile(md_file, serie, version):
531573 serie_found = m .group (1 )
532574 if not new_line :
533575 new_line = regexmd_add .sub (rf"\g<1>{ serie } \g<2>{ version } " , line )
534- if not added and serie_found and (serie_found > serie . upper () or not m ):
576+ if not added and serie_found and (serie_found > serie or not m ):
535577 print (new_line , end = "" )
536578 added = True
537579 print (line , end = "" )
@@ -620,17 +662,24 @@ def updateCore():
620662 update_hal_conf_commit_msg = (
621663 "system: {0}: update STM32{0}xx hal default config" .format (serie )
622664 )
665+ update_stm32_def_commit_msg = "core: {0}: add top HAL include" .format (serie )
623666 # Create system files
624667 createSystemFiles (serie )
625- # Commit all sytem files
668+ # Commit all system files
626669 commitFiles (core_path , system_commit_msg )
670+ # Update default HAL configuration
627671 updateHalConfDefault (serie )
628672 commitFiles (core_path , update_hal_conf_commit_msg )
629- print ("Please , review carefully all the system files added!" )
630- print ("Add #ifndef/#endif to all definitions which should be" )
673+ print ("\t Please , review carefully all the system files added!" )
674+ print ("\t Add #ifndef/#endif to all definitions which should be" )
631675 print (
632- "redefinable in the stm32{}xx_hal_conf_default.h" .format (serie .lower ())
676+ "\t redefinable in the stm32{}xx_hal_conf_default.h" .format (
677+ serie .lower ()
678+ )
633679 )
680+ # Update stm32_def to add top HAL include
681+ updateStm32Def (serie )
682+ commitFiles (core_path , update_stm32_def_commit_msg )
634683
635684 if HAL_updated or CMSIS_updated :
636685 # Generate all wrapper files
0 commit comments