@@ -369,41 +369,23 @@ def latestTag(serie, repo_name, repo_path):
369
369
# print(f"Latest tagged version available for {repo_name} is {version_tag}")
370
370
371
371
372
- def parseVersion (path ):
372
+ def parseVersion (path , patterns ):
373
373
main_found = False
374
374
sub1_found = False
375
375
sub2_found = False
376
376
rc_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
- )
395
377
396
378
for 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 ):
398
380
VERSION_MAIN = int (match .group (1 ), 16 )
399
381
main_found = True
400
- for match in re .finditer (sub1_pattern , line ):
382
+ for match in re .finditer (patterns [ 1 ] , line ):
401
383
VERSION_SUB1 = int (match .group (1 ), 16 )
402
384
sub1_found = True
403
- for match in re .finditer (sub2_pattern , line ):
385
+ for match in re .finditer (patterns [ 2 ] , line ):
404
386
VERSION_SUB2 = int (match .group (1 ), 16 )
405
387
sub2_found = True
406
- for match in re .finditer (rc_pattern , line ):
388
+ for match in re .finditer (patterns [ 3 ] , line ):
407
389
VERSION_RC = int (match .group (1 ), 16 )
408
390
rc_found = True
409
391
if main_found and sub1_found and sub2_found and rc_found :
@@ -434,14 +416,30 @@ def parseVersion(path):
434
416
def checkVersion (serie , repo_path ):
435
417
lserie = serie .lower ()
436
418
userie = 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
+
437
425
HAL_file = (
438
426
repo_path
439
427
/ hal_src_path
440
428
/ f"STM32{ userie } xx_HAL_Driver"
441
429
/ "Src"
442
430
/ f"stm32{ lserie } xx_hal.c"
443
431
)
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 )
445
443
if upargs .add :
446
444
core_HAL_versions [serie ] = "0.0.0"
447
445
else :
@@ -451,23 +449,35 @@ def checkVersion(serie, repo_path):
451
449
/ "Src"
452
450
/ f"stm32{ lserie } xx_hal.c"
453
451
)
454
- core_HAL_versions [serie ] = parseVersion (HAL_file )
452
+ core_HAL_versions [serie ] = parseVersion (HAL_file , patterns )
455
453
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
+ )
456
466
CMSIS_file = (
457
467
repo_path
458
468
/ cmsis_src_path
459
469
/ f"STM32{ userie } xx"
460
470
/ "Include"
461
471
/ f"stm32{ lserie } xx.h"
462
472
)
463
- cube_CMSIS_versions [serie ] = parseVersion (CMSIS_file )
473
+ cube_CMSIS_versions [serie ] = parseVersion (CMSIS_file , patterns )
464
474
if upargs .add :
465
475
core_CMSIS_versions [serie ] = "0.0.0"
466
476
else :
467
477
CMSIS_file = (
468
478
cmsis_dest_path / f"STM32{ userie } xx" / "Include" / f"stm32{ lserie } xx.h"
469
479
)
470
- core_CMSIS_versions [serie ] = parseVersion (CMSIS_file )
480
+ core_CMSIS_versions [serie ] = parseVersion (CMSIS_file , patterns )
471
481
472
482
# print(f"STM32Cube{serie} HAL version: {cube_HAL_versions[serie]}")
473
483
# print(f"STM32Core{serie} HAL version: {core_HAL_versions[serie]}")
0 commit comments