@@ -382,9 +382,8 @@ def get_gpio_af_numF1_default(pintofind, iptofind):
382
382
# return "AFIO_" + iptofind .split("_")[0] + "_DISABLE"
383
383
ip = iptofind .split ("_" )[0 ]
384
384
afio_default = "AFIO_NONE"
385
- if pintofind in default_afio_f1 :
386
- if ip in default_afio_f1 [pintofind ]:
387
- afio_default = default_afio_f1 [pintofind ][ip ]
385
+ if pintofind in default_afio_f1 and ip in default_afio_f1 [pintofind ]:
386
+ afio_default = default_afio_f1 [pintofind ][ip ]
388
387
return afio_default
389
388
390
389
@@ -559,10 +558,9 @@ def store_xspi(pin, name, signal):
559
558
560
559
# Store SYS pins
561
560
def store_sys (pin , name , signal ):
562
- if "_WKUP" in signal :
563
- if not any (pin .replace ("_C" , "" ) in i for i in syswkup_list ):
564
- signal = signal .replace ("PWR" , "SYS" )
565
- syswkup_list .append ([pin , name , signal ])
561
+ if "_WKUP" in signal and not any (pin .replace ("_C" , "" ) in i for i in syswkup_list ):
562
+ signal = signal .replace ("PWR" , "SYS" )
563
+ syswkup_list .append ([pin , name , signal ])
566
564
567
565
568
566
# Store USB pins
@@ -1341,7 +1339,7 @@ def print_pinamevar():
1341
1339
alt_syswkup_list = []
1342
1340
for idx , syswkup_list in enumerate (syswkup_pins_list , start = 1 ):
1343
1341
if len (syswkup_list ) > 1 :
1344
- for idx2 , lst in enumerate (syswkup_list [1 :], start = 1 ):
1342
+ for idx2 , _lst in enumerate (syswkup_list [1 :], start = 1 ):
1345
1343
alt_syswkup_list .append (f"{ idx } _{ idx2 } " )
1346
1344
return alt_syswkup_list
1347
1345
@@ -1375,13 +1373,13 @@ def spi_pins_variant():
1375
1373
for ss in spissel_list :
1376
1374
ss_inst = ss [2 ].split ("_" , 1 )[0 ]
1377
1375
if mosi_inst == ss_inst :
1378
- if "PNUM_NOT_DEFINED" == ss_pin :
1376
+ if ss_pin == "PNUM_NOT_DEFINED" :
1379
1377
ss_pin = ss [0 ].replace ("_" , "" , 1 )
1380
- elif "PNUM_NOT_DEFINED" == ss1_pin :
1378
+ elif ss1_pin == "PNUM_NOT_DEFINED" :
1381
1379
ss1_pin = ss [0 ].replace ("_" , "" , 1 )
1382
- elif "PNUM_NOT_DEFINED" == ss2_pin :
1380
+ elif ss2_pin == "PNUM_NOT_DEFINED" :
1383
1381
ss2_pin = ss [0 ].replace ("_" , "" , 1 )
1384
- elif "PNUM_NOT_DEFINED" == ss3_pin :
1382
+ elif ss3_pin == "PNUM_NOT_DEFINED" :
1385
1383
ss3_pin = ss [0 ].replace ("_" , "" , 1 )
1386
1384
break
1387
1385
break
@@ -1449,7 +1447,7 @@ def serial_pins_variant():
1449
1447
print ("No serial instance number found!" )
1450
1448
serialnum = "-1"
1451
1449
else :
1452
- serialtx_pin = serialtx_pin = "PNUM_NOT_DEFINED"
1450
+ serialtx_pin = "PNUM_NOT_DEFINED"
1453
1451
serialnum = "-1"
1454
1452
print ("No serial found!" )
1455
1453
return dict (instance = serialnum , rx = serialrx_pin , tx = serialtx_pin )
@@ -1653,10 +1651,13 @@ def search_product_line(valueline: str, extra: str) -> str:
1653
1651
else :
1654
1652
break
1655
1653
if pline >= vline :
1656
- if extra and len (product_line_list ) > idx_pline + 1 :
1657
- if product_line_list [idx_pline + 1 ] == (product_line + extra ):
1658
- # Look for the next product line if contains the extra
1659
- product_line = product_line_list [idx_pline + 1 ]
1654
+ if (
1655
+ extra
1656
+ and len (product_line_list ) > idx_pline + 1
1657
+ and product_line_list [idx_pline + 1 ] == (product_line + extra )
1658
+ ):
1659
+ # Look for the next product line if contains the extra
1660
+ product_line = product_line_list [idx_pline + 1 ]
1660
1661
break
1661
1662
else :
1662
1663
# In case of CMSIS device does not exist
@@ -1700,9 +1701,7 @@ def parse_stm32targets():
1700
1701
1701
1702
1702
1703
def search_svdfile (mcu_name ):
1703
- svd_file = ""
1704
- if mcu_name in svd_dict :
1705
- svd_file = svd_dict [mcu_name ]
1704
+ svd_file = svd_dict .get (mcu_name , "" )
1706
1705
return svd_file
1707
1706
1708
1707
@@ -2275,7 +2274,7 @@ def merge_dir(out_temp_path, group_mcu_dir, mcu_family, periph_xml, variant_exp)
2275
2274
# Save board entry
2276
2275
skip = False
2277
2276
with open (dir_name / boards_entry_filename ) as fp :
2278
- for index , line in enumerate (fp ):
2277
+ for _index , line in enumerate (fp ):
2279
2278
# Skip until next empty line (included)
2280
2279
if skip :
2281
2280
if line == "\n " :
@@ -2391,24 +2390,23 @@ def aggregate_dir():
2391
2390
periph_xml_tmp = []
2392
2391
variant_exp_tmp = []
2393
2392
for index2 , fname in enumerate (mcu_dir1_files_list ):
2394
- with open (fname , "r" ) as f1 :
2395
- with open (mcu_dir2_files_list [index2 ], "r" ) as f2 :
2396
- diff = set (f1 ).symmetric_difference (f2 )
2397
- diff .discard ("\n " )
2398
- if not diff or len (diff ) == 2 :
2399
- if index2 == 0 :
2400
- for line in diff :
2401
- periph_xml_tmp += periperalpins_regex .findall (
2402
- line
2403
- )
2404
- elif index2 == 2 :
2405
- for line in diff :
2406
- variant_exp_tmp += variant_regex .findall (line )
2407
- continue
2408
- else :
2409
- # Not the same directory compare with the next one
2410
- index += 1
2411
- break
2393
+ with open (fname , "r" ) as f1 , open (
2394
+ mcu_dir2_files_list [index2 ], "r"
2395
+ ) as f2 :
2396
+ diff = set (f1 ).symmetric_difference (f2 )
2397
+ diff .discard ("\n " )
2398
+ if not diff or len (diff ) == 2 :
2399
+ if index2 == 0 :
2400
+ for line in diff :
2401
+ periph_xml_tmp += periperalpins_regex .findall (line )
2402
+ elif index2 == 2 :
2403
+ for line in diff :
2404
+ variant_exp_tmp += variant_regex .findall (line )
2405
+ continue
2406
+ else :
2407
+ # Not the same directory compare with the next one
2408
+ index += 1
2409
+ break
2412
2410
# All files compared and matched
2413
2411
else :
2414
2412
# Concatenate lists without duplicate
@@ -2505,10 +2503,11 @@ def checkConfig():
2505
2503
default_cubemxdir ()
2506
2504
if config_filename .is_file ():
2507
2505
try :
2508
- config_file = open (config_filename , "r" )
2509
- path_config = json .load (config_file )
2510
- config_file .close ()
2511
-
2506
+ # config_file = open(config_filename, "r")
2507
+ # path_config = json.load(config_file)
2508
+ # config_file.close()
2509
+ with open (config_filename , "r" ) as config_file :
2510
+ path_config = json .load (config_file )
2512
2511
if "REPO_LOCAL_PATH" not in path_config :
2513
2512
path_config ["REPO_LOCAL_PATH" ] = str (repo_local_path )
2514
2513
defaultConfig (config_filename , path_config )
@@ -2779,21 +2778,21 @@ def manage_repo():
2779
2778
generic_clock_filepath = out_temp_path / generic_clock_filename
2780
2779
out_temp_path .mkdir (parents = True , exist_ok = True )
2781
2780
2782
- # open output file
2783
- periph_c_file = open (periph_c_filepath , "w" , newline = "\n " )
2784
- pinvar_h_file = open (pinvar_h_filepath , "w" , newline = "\n " )
2785
- variant_cpp_file = open (variant_cpp_filepath , "w" , newline = "\n " )
2786
- variant_h_file = open (variant_h_filepath , "w" , newline = "\n " )
2787
- boards_entry_file = open (boards_entry_filepath , "w" , newline = "\n " )
2788
- generic_clock_file = open (generic_clock_filepath , "w" , newline = "\n " )
2789
2781
parse_pins ()
2790
2782
manage_af_and_alternate ()
2791
2783
2792
- generic_list = print_boards_entry ()
2793
- print_general_clock (generic_list )
2794
- print_peripheral ()
2795
- alt_syswkup_list = print_pinamevar ()
2796
- print_variant (generic_list , alt_syswkup_list )
2784
+ with open (boards_entry_filepath , "w" , newline = "\n " ) as boards_entry_file :
2785
+ generic_list = print_boards_entry ()
2786
+ with open (generic_clock_filepath , "w" , newline = "\n " ) as generic_clock_file :
2787
+ print_general_clock (generic_list )
2788
+ with open (periph_c_filepath , "w" , newline = "\n " ) as periph_c_file :
2789
+ print_peripheral ()
2790
+ with open (pinvar_h_filepath , "w" , newline = "\n " ) as pinvar_h_file :
2791
+ alt_syswkup_list = print_pinamevar ()
2792
+ with open (variant_cpp_filepath , "w" , newline = "\n " ) as variant_cpp_file , open (
2793
+ variant_h_filepath , "w" , newline = "\n "
2794
+ ) as variant_h_file :
2795
+ print_variant (generic_list , alt_syswkup_list )
2797
2796
del alt_syswkup_list [:]
2798
2797
del generic_list [:]
2799
2798
sum_io = len (io_list ) + len (alt_list ) + len (dualpad_list ) + len (remap_list )
@@ -2810,12 +2809,6 @@ def manage_repo():
2810
2809
2811
2810
clean_all_lists ()
2812
2811
2813
- periph_c_file .close ()
2814
- pinvar_h_file .close ()
2815
- variant_h_file .close ()
2816
- variant_cpp_file .close ()
2817
- boards_entry_file .close ()
2818
- generic_clock_file .close ()
2819
2812
xml_mcu .unlink ()
2820
2813
xml_gpio .unlink ()
2821
2814
0 commit comments