49
49
md_CMSIS_path = "STM32YYxx_CMSIS_version.md"
50
50
md_HAL_path = "STM32YYxx_HAL_Driver_version.md"
51
51
52
+ # stm32 def file to update
53
+ stm32_def = "stm32_def.h"
54
+
52
55
# Templating
53
56
templates_dir = script_path / "templates"
54
57
stm32yyxx_hal_conf_file = "stm32yyxx_hal_conf.h"
@@ -99,6 +102,8 @@ def checkConfig():
99
102
global system_dest_path
100
103
global md_HAL_path
101
104
global md_CMSIS_path
105
+ global stm32_def
106
+
102
107
config_file_path = script_path / path_config_filename
103
108
if config_file_path .is_file ():
104
109
try :
@@ -112,13 +117,50 @@ def checkConfig():
112
117
cmsis_dest_path = repo_local_path / repo_core_name / cmsis_dest_path
113
118
system_dest_path = repo_local_path / repo_core_name / system_dest_path
114
119
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
+ )
115
128
except IOError :
116
129
print ("Failed to open {}!" .format (config_file ))
117
130
else :
118
131
create_config ()
119
132
createFolder (repo_local_path )
120
133
121
134
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
+
122
164
def updateHalConfDefault (serie ):
123
165
system_serie = system_dest_path / ("STM32{}xx" .format (serie ))
124
166
hal_conf_base = "stm32{}xx_hal_conf" .format (serie .lower ())
@@ -531,7 +573,7 @@ def updateMDFile(md_file, serie, version):
531
573
serie_found = m .group (1 )
532
574
if not new_line :
533
575
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 ):
535
577
print (new_line , end = "" )
536
578
added = True
537
579
print (line , end = "" )
@@ -620,17 +662,24 @@ def updateCore():
620
662
update_hal_conf_commit_msg = (
621
663
"system: {0}: update STM32{0}xx hal default config" .format (serie )
622
664
)
665
+ update_stm32_def_commit_msg = "core: {0}: add top HAL include" .format (serie )
623
666
# Create system files
624
667
createSystemFiles (serie )
625
- # Commit all sytem files
668
+ # Commit all system files
626
669
commitFiles (core_path , system_commit_msg )
670
+ # Update default HAL configuration
627
671
updateHalConfDefault (serie )
628
672
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" )
631
675
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
+ )
633
679
)
680
+ # Update stm32_def to add top HAL include
681
+ updateStm32Def (serie )
682
+ commitFiles (core_path , update_stm32_def_commit_msg )
634
683
635
684
if HAL_updated or CMSIS_updated :
636
685
# Generate all wrapper files
0 commit comments