@@ -382,9 +382,8 @@ def get_gpio_af_numF1_default(pintofind, iptofind):
382382 # return "AFIO_" + iptofind .split("_")[0] + "_DISABLE"
383383 ip = iptofind .split ("_" )[0 ]
384384 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 ]
388387 return afio_default
389388
390389
@@ -559,10 +558,9 @@ def store_xspi(pin, name, signal):
559558
560559# Store SYS pins
561560def 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 ])
566564
567565
568566# Store USB pins
@@ -1341,7 +1339,7 @@ def print_pinamevar():
13411339 alt_syswkup_list = []
13421340 for idx , syswkup_list in enumerate (syswkup_pins_list , start = 1 ):
13431341 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 ):
13451343 alt_syswkup_list .append (f"{ idx } _{ idx2 } " )
13461344 return alt_syswkup_list
13471345
@@ -1375,13 +1373,13 @@ def spi_pins_variant():
13751373 for ss in spissel_list :
13761374 ss_inst = ss [2 ].split ("_" , 1 )[0 ]
13771375 if mosi_inst == ss_inst :
1378- if "PNUM_NOT_DEFINED" == ss_pin :
1376+ if ss_pin == "PNUM_NOT_DEFINED" :
13791377 ss_pin = ss [0 ].replace ("_" , "" , 1 )
1380- elif "PNUM_NOT_DEFINED" == ss1_pin :
1378+ elif ss1_pin == "PNUM_NOT_DEFINED" :
13811379 ss1_pin = ss [0 ].replace ("_" , "" , 1 )
1382- elif "PNUM_NOT_DEFINED" == ss2_pin :
1380+ elif ss2_pin == "PNUM_NOT_DEFINED" :
13831381 ss2_pin = ss [0 ].replace ("_" , "" , 1 )
1384- elif "PNUM_NOT_DEFINED" == ss3_pin :
1382+ elif ss3_pin == "PNUM_NOT_DEFINED" :
13851383 ss3_pin = ss [0 ].replace ("_" , "" , 1 )
13861384 break
13871385 break
@@ -1449,7 +1447,7 @@ def serial_pins_variant():
14491447 print ("No serial instance number found!" )
14501448 serialnum = "-1"
14511449 else :
1452- serialtx_pin = serialtx_pin = "PNUM_NOT_DEFINED"
1450+ serialtx_pin = "PNUM_NOT_DEFINED"
14531451 serialnum = "-1"
14541452 print ("No serial found!" )
14551453 return dict (instance = serialnum , rx = serialrx_pin , tx = serialtx_pin )
@@ -1653,10 +1651,13 @@ def search_product_line(valueline: str, extra: str) -> str:
16531651 else :
16541652 break
16551653 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 ]
16601661 break
16611662 else :
16621663 # In case of CMSIS device does not exist
@@ -1700,9 +1701,7 @@ def parse_stm32targets():
17001701
17011702
17021703def 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 , "" )
17061705 return svd_file
17071706
17081707
@@ -2275,7 +2274,7 @@ def merge_dir(out_temp_path, group_mcu_dir, mcu_family, periph_xml, variant_exp)
22752274 # Save board entry
22762275 skip = False
22772276 with open (dir_name / boards_entry_filename ) as fp :
2278- for index , line in enumerate (fp ):
2277+ for _index , line in enumerate (fp ):
22792278 # Skip until next empty line (included)
22802279 if skip :
22812280 if line == "\n " :
@@ -2391,24 +2390,23 @@ def aggregate_dir():
23912390 periph_xml_tmp = []
23922391 variant_exp_tmp = []
23932392 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
24122410 # All files compared and matched
24132411 else :
24142412 # Concatenate lists without duplicate
@@ -2505,10 +2503,11 @@ def checkConfig():
25052503 default_cubemxdir ()
25062504 if config_filename .is_file ():
25072505 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 )
25122511 if "REPO_LOCAL_PATH" not in path_config :
25132512 path_config ["REPO_LOCAL_PATH" ] = str (repo_local_path )
25142513 defaultConfig (config_filename , path_config )
@@ -2779,21 +2778,21 @@ def manage_repo():
27792778 generic_clock_filepath = out_temp_path / generic_clock_filename
27802779 out_temp_path .mkdir (parents = True , exist_ok = True )
27812780
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 " )
27892781 parse_pins ()
27902782 manage_af_and_alternate ()
27912783
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 )
27972796 del alt_syswkup_list [:]
27982797 del generic_list [:]
27992798 sum_io = len (io_list ) + len (alt_list ) + len (dualpad_list ) + len (remap_list )
@@ -2810,12 +2809,6 @@ def manage_repo():
28102809
28112810 clean_all_lists ()
28122811
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 ()
28192812 xml_mcu .unlink ()
28202813 xml_gpio .unlink ()
28212814
0 commit comments