Skip to content

Commit d856484

Browse files
FRASTMfpistm
andcommitted
Update script to add new STM32Cube serie to the core
use: -a <new_serie_to_add ex: l5> Signed-off-by: Francois Ramu <francois.ramu@st.com> Co-authored-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 5f95b95 commit d856484

File tree

1 file changed

+65
-23
lines changed

1 file changed

+65
-23
lines changed

CI/utils/stm32update.py

+65-23
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,16 @@ def checkVersion(serie, repo_path):
232232
"stm32{}xx_hal.c".format(lserie),
233233
)
234234
cube_HAL_versions[serie] = parseVersion(HAL_file)
235-
HAL_file = os.path.join(
236-
hal_dest_path,
237-
"STM32{}xx_HAL_Driver".format(userie),
238-
"Src",
239-
"stm32{}xx_hal.c".format(lserie),
240-
)
241-
core_HAL_versions[serie] = parseVersion(HAL_file)
235+
if upargs.add:
236+
core_HAL_versions[serie] = "0.0.0"
237+
else:
238+
HAL_file = os.path.join(
239+
hal_dest_path,
240+
"STM32{}xx_HAL_Driver".format(userie),
241+
"Src",
242+
"stm32{}xx_hal.c".format(lserie),
243+
)
244+
core_HAL_versions[serie] = parseVersion(HAL_file)
242245

243246
CMSIS_file = os.path.join(
244247
repo_path,
@@ -248,13 +251,16 @@ def checkVersion(serie, repo_path):
248251
"stm32{}xx.h".format(lserie),
249252
)
250253
cube_CMSIS_versions[serie] = parseVersion(CMSIS_file)
251-
CMSIS_file = os.path.join(
252-
cmsis_dest_path,
253-
"STM32{}xx".format(userie),
254-
"Include",
255-
"stm32{}xx.h".format(lserie),
256-
)
257-
core_CMSIS_versions[serie] = parseVersion(CMSIS_file)
254+
if upargs.add:
255+
core_CMSIS_versions[serie] = "0.0.0"
256+
else:
257+
CMSIS_file = os.path.join(
258+
cmsis_dest_path,
259+
"STM32{}xx".format(userie),
260+
"Include",
261+
"stm32{}xx.h".format(lserie),
262+
)
263+
core_CMSIS_versions[serie] = parseVersion(CMSIS_file)
258264

259265
# print("STM32Cube" + serie + " HAL version: " + cube_HAL_versions[serie])
260266
# print("STM32Core " + serie + " HAL version: " + core_HAL_versions[serie])
@@ -417,7 +423,9 @@ def updateCore():
417423
core_CMSIS_version = core_CMSIS_versions[serie]
418424
cube_CMSIS_version = cube_CMSIS_versions[serie]
419425
cube_version = cube_versions[serie]
420-
regexmd = re.compile(rf"(STM32{serie}:\s+)\d+.\d+.\d+")
426+
regexmd_up = re.compile(rf"(STM32{serie}:\s+)\d+.\d+.\d+")
427+
regexmd_serie = re.compile(r"STM32(\w+):\s+\d+.\d+.\d+")
428+
regexmd_add = re.compile(r"(STM32)\w+(:\s+)\d+.\d+.\d+")
421429
HAL_updated = False
422430
CMSIS_updated = False
423431
hal_commit_msg = """[{0}] Update STM32{0}xx HAL Drivers to v{1}
@@ -453,9 +461,22 @@ def updateCore():
453461
)
454462
copyFolder(HAL_serie_cube_path, HAL_serie_core_path, {"*.chm"})
455463
# Update MD file
456-
for line in fileinput.input(md_HAL_path, inplace=True):
457-
line = regexmd.sub(rf"\g<1>{cube_HAL_version}", line)
458-
print(line, end="")
464+
if upargs.add: # Add the new STM32YY entry
465+
added = False
466+
for line in fileinput.input(md_HAL_path, inplace=True):
467+
m = regexmd_serie.search(line)
468+
if not added and m and m.group(1) > serie.upper():
469+
print(
470+
regexmd_add.sub(
471+
rf"\g<1>{serie}\g<2>{cube_HAL_version}", line
472+
),
473+
end="",
474+
)
475+
added = True
476+
print(line, end="")
477+
else: # Update the version
478+
for line in fileinput.input(md_HAL_path, inplace=True):
479+
print(regexmd_up.sub(rf"\g<1>{cube_HAL_version}", line), end="")
459480
# Commit all HAL files
460481
commitFiles(core_path, hal_commit_msg)
461482
HAL_updated = True
@@ -480,9 +501,22 @@ def updateCore():
480501
)
481502
copyFolder(CMSIS_serie_cube_path, CMSIS_serie_dest_path, {"iar", "arm"})
482503
# Update MD file
483-
for line in fileinput.input(md_CMSIS_path, inplace=True):
484-
line = regexmd.sub(rf"\g<1>{cube_CMSIS_version}", line)
485-
print(line, end="")
504+
if upargs.add: # Add the new STM32YY entry
505+
added = False
506+
for line in fileinput.input(md_CMSIS_path, inplace=True):
507+
m = regexmd_serie.search(line)
508+
if not added and m and m.group(1) > serie.upper():
509+
print(
510+
regexmd_add.sub(
511+
rf"\g<1>{serie}\g<2>{cube_CMSIS_version}", line
512+
),
513+
end="",
514+
)
515+
added = True
516+
print(line, end="")
517+
else: # Update the version
518+
for line in fileinput.input(md_CMSIS_path, inplace=True):
519+
print(regexmd_up.sub(rf"\g<1>{cube_CMSIS_version}", line), end="")
486520
# Commit all CMSIS files
487521
commitFiles(core_path, cmsis_commit_msg)
488522
CMSIS_updated = True
@@ -506,9 +540,13 @@ def updateCore():
506540
upparser.add_argument(
507541
"-c", "--check", help="Check versions. Default all.", action="store_true"
508542
)
509-
upparser.add_argument(
543+
group = upparser.add_mutually_exclusive_group()
544+
group.add_argument(
510545
"-s", "--serie", metavar="pattern", help="Pattern of the STM32 serie(s) to update"
511546
)
547+
group.add_argument(
548+
"-a", "--add", metavar="name", help="STM32 serie name to add. Ex: 'F1'"
549+
)
512550

513551
upargs = upparser.parse_args()
514552

@@ -519,8 +557,12 @@ def main():
519557
checkConfig()
520558
updateCoreRepo()
521559
stm32_list = genSTM32List(hal_dest_path, upargs.serie)
560+
if upargs.add:
561+
if upargs.add.upper() not in stm32_list:
562+
stm32_list = [upargs.add.upper()]
563+
else:
564+
print(upargs.add + " can't be added as it already exists!")
522565
updateSTRepo()
523-
524566
if upargs.check:
525567
printVersion()
526568
else:

0 commit comments

Comments
 (0)