@@ -232,13 +232,16 @@ def checkVersion(serie, repo_path):
232
232
"stm32{}xx_hal.c" .format (lserie ),
233
233
)
234
234
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 )
242
245
243
246
CMSIS_file = os .path .join (
244
247
repo_path ,
@@ -248,13 +251,16 @@ def checkVersion(serie, repo_path):
248
251
"stm32{}xx.h" .format (lserie ),
249
252
)
250
253
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 )
258
264
259
265
# print("STM32Cube" + serie + " HAL version: " + cube_HAL_versions[serie])
260
266
# print("STM32Core " + serie + " HAL version: " + core_HAL_versions[serie])
@@ -417,7 +423,9 @@ def updateCore():
417
423
core_CMSIS_version = core_CMSIS_versions [serie ]
418
424
cube_CMSIS_version = cube_CMSIS_versions [serie ]
419
425
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+" )
421
429
HAL_updated = False
422
430
CMSIS_updated = False
423
431
hal_commit_msg = """[{0}] Update STM32{0}xx HAL Drivers to v{1}
@@ -453,9 +461,22 @@ def updateCore():
453
461
)
454
462
copyFolder (HAL_serie_cube_path , HAL_serie_core_path , {"*.chm" })
455
463
# 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 = "" )
459
480
# Commit all HAL files
460
481
commitFiles (core_path , hal_commit_msg )
461
482
HAL_updated = True
@@ -480,9 +501,22 @@ def updateCore():
480
501
)
481
502
copyFolder (CMSIS_serie_cube_path , CMSIS_serie_dest_path , {"iar" , "arm" })
482
503
# 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 = "" )
486
520
# Commit all CMSIS files
487
521
commitFiles (core_path , cmsis_commit_msg )
488
522
CMSIS_updated = True
@@ -506,9 +540,13 @@ def updateCore():
506
540
upparser .add_argument (
507
541
"-c" , "--check" , help = "Check versions. Default all." , action = "store_true"
508
542
)
509
- upparser .add_argument (
543
+ group = upparser .add_mutually_exclusive_group ()
544
+ group .add_argument (
510
545
"-s" , "--serie" , metavar = "pattern" , help = "Pattern of the STM32 serie(s) to update"
511
546
)
547
+ group .add_argument (
548
+ "-a" , "--add" , metavar = "name" , help = "STM32 serie name to add. Ex: 'F1'"
549
+ )
512
550
513
551
upargs = upparser .parse_args ()
514
552
@@ -519,8 +557,13 @@ def main():
519
557
checkConfig ()
520
558
updateCoreRepo ()
521
559
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!" )
565
+ exit (1 )
522
566
updateSTRepo ()
523
-
524
567
if upargs .check :
525
568
printVersion ()
526
569
else :
0 commit comments