@@ -369,41 +369,23 @@ def latestTag(serie, repo_name, repo_path):
369369# print(f"Latest tagged version available for {repo_name} is {version_tag}")
370370
371371
372- def parseVersion (path ):
372+ def parseVersion (path , patterns ):
373373main_found = False
374374sub1_found = False
375375sub2_found = False
376376rc_found = False
377- if "HAL" in str (path ):
378- main_pattern = re .compile (r"HAL_VERSION_MAIN.*0x([\dA-Fa-f]+)" )
379- sub1_pattern = re .compile (r"HAL_VERSION_SUB1.*0x([\dA-Fa-f]+)" )
380- sub2_pattern = re .compile (r"HAL_VERSION_SUB2.*0x([\dA-Fa-f]+)" )
381- rc_pattern = re .compile (r"HAL_VERSION_RC.*0x([\dA-Fa-f]+)" )
382- else :
383- main_pattern = re .compile (
384- r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_MAIN.*0x([\dA-Fa-f]+)"
385- )
386- sub1_pattern = re .compile (
387- r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_SUB1.*0x([\dA-Fa-f]+)"
388- )
389- sub2_pattern = re .compile (
390- r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_SUB2.*0x([\dA-Fa-f]+)"
391- )
392- rc_pattern = re .compile (
393- r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_RC.*0x([\dA-Fa-f]+)"
394- )
395377
396378for i ,line in enumerate (open (path ,encoding = "utf8" ,errors = "ignore" )):
397- for match in re .finditer (main_pattern ,line ):
379+ for match in re .finditer (patterns [ 0 ] ,line ):
398380VERSION_MAIN = int (match .group (1 ),16 )
399381main_found = True
400- for match in re .finditer (sub1_pattern ,line ):
382+ for match in re .finditer (patterns [ 1 ] ,line ):
401383VERSION_SUB1 = int (match .group (1 ),16 )
402384sub1_found = True
403- for match in re .finditer (sub2_pattern ,line ):
385+ for match in re .finditer (patterns [ 2 ] ,line ):
404386VERSION_SUB2 = int (match .group (1 ),16 )
405387sub2_found = True
406- for match in re .finditer (rc_pattern ,line ):
388+ for match in re .finditer (patterns [ 3 ] ,line ):
407389VERSION_RC = int (match .group (1 ),16 )
408390rc_found = True
409391if main_found and sub1_found and sub2_found and rc_found :
@@ -434,14 +416,30 @@ def parseVersion(path):
434416def checkVersion (serie ,repo_path ):
435417lserie = serie .lower ()
436418userie = serie .upper ()
419+
420+ patterns = [re .compile (r"HAL_VERSION_MAIN.*0x([\dA-Fa-f]+)" )]
421+ patterns .append (re .compile (r"HAL_VERSION_SUB1.*0x([\dA-Fa-f]+)" ))
422+ patterns .append (re .compile (r"HAL_VERSION_SUB2.*0x([\dA-Fa-f]+)" ))
423+ patterns .append (re .compile (r"HAL_VERSION_RC.*0x([\dA-Fa-f]+)" ))
424+
437425HAL_file = (
438426repo_path
439427/ hal_src_path
440428/ f"STM32{ userie } xx_HAL_Driver"
441429/ "Src"
442430/ f"stm32{ lserie } xx_hal.c"
443431 )
444- cube_HAL_versions [serie ]= parseVersion (HAL_file )
432+ with open (HAL_file ,"r" )as fp :
433+ data = fp .read ()
434+ if "HAL_VERSION_MAIN" not in data :
435+ HAL_file = (
436+ repo_path
437+ / hal_src_path
438+ / f"STM32{ userie } xx_HAL_Driver"
439+ / "Inc"
440+ / f"stm32{ lserie } xx_hal.h"
441+ )
442+ cube_HAL_versions [serie ]= parseVersion (HAL_file ,patterns )
445443if upargs .add :
446444core_HAL_versions [serie ]= "0.0.0"
447445else :
@@ -451,23 +449,35 @@ def checkVersion(serie, repo_path):
451449/ "Src"
452450/ f"stm32{ lserie } xx_hal.c"
453451 )
454- core_HAL_versions [serie ]= parseVersion (HAL_file )
452+ core_HAL_versions [serie ]= parseVersion (HAL_file , patterns )
455453
454+ patterns = [
455+ re .compile (r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_MAIN.*0x([\dA-Fa-f]+)" )
456+ ]
457+ patterns .append (
458+ re .compile (r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_SUB1.*0x([\dA-Fa-f]+)" )
459+ )
460+ patterns .append (
461+ re .compile (r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_SUB2.*0x([\dA-Fa-f]+)" )
462+ )
463+ patterns .append (
464+ re .compile (r"(?:CMSIS|DEVICE|CMSIS_DEVICE)_VERSION_RC.*0x([\dA-Fa-f]+)" )
465+ )
456466CMSIS_file = (
457467repo_path
458468/ cmsis_src_path
459469/ f"STM32{ userie } xx"
460470/ "Include"
461471/ f"stm32{ lserie } xx.h"
462472 )
463- cube_CMSIS_versions [serie ]= parseVersion (CMSIS_file )
473+ cube_CMSIS_versions [serie ]= parseVersion (CMSIS_file , patterns )
464474if upargs .add :
465475core_CMSIS_versions [serie ]= "0.0.0"
466476else :
467477CMSIS_file = (
468478cmsis_dest_path / f"STM32{ userie } xx" / "Include" / f"stm32{ lserie } xx.h"
469479 )
470- core_CMSIS_versions [serie ]= parseVersion (CMSIS_file )
480+ core_CMSIS_versions [serie ]= parseVersion (CMSIS_file , patterns )
471481
472482# print(f"STM32Cube{serie} HAL version: {cube_HAL_versions[serie]}")
473483# print(f"STM32Core{serie} HAL version: {core_HAL_versions[serie]}")