14
14
15
15
script_path = Path (__file__ ).parent .resolve ()
16
16
sys .path .append (str (script_path .parent ))
17
- from utils import defaultConfig , deleteFolder , execute_cmd , getRepoBranchName
17
+ from utils import (
18
+ defaultConfig ,
19
+ deleteFolder ,
20
+ execute_cmd ,
21
+ getRepoBranchName ,
22
+ genSTM32List ,
23
+ )
18
24
25
+ stm32_list = [] # series
26
+ ignored_stm32_list = [] # series
27
+ aggregate_serie_list = [] # series
19
28
mcu_list = [] # 'name'
20
29
io_list = [] # 'PIN','name'
21
30
alt_list = [] # 'PIN','name'
@@ -158,6 +167,12 @@ def parse_mcu_file():
158
167
159
168
mcu_node = xml_mcu .getElementsByTagName ("Mcu" )[0 ]
160
169
mcu_family = mcu_node .attributes ["Family" ].value
170
+ # Check if FwLibrary is present in the attributes
171
+ if "FwLibrary" in mcu_node .attributes :
172
+ mcu_family = mcu_node .attributes ["FwLibrary" ].value
173
+ # split using '_' and kept the lasy part
174
+ mcu_family = f"STM32{ mcu_family .split ('_' )[- 1 ]} "
175
+
161
176
if mcu_family .endswith ("+" ):
162
177
mcu_family = mcu_family [:- 1 ]
163
178
mcu_refname = mcu_node .attributes ["RefName" ].value
@@ -2271,17 +2286,14 @@ def merge_dir(out_temp_path, group_mcu_dir, mcu_family, periph_xml, variant_exp)
2271
2286
def aggregate_dir ():
2272
2287
# Get mcu_family directories
2273
2288
out_temp_path = tmp_dir
2274
- mcu_families = sorted (out_temp_path .glob ("STM32*/" ))
2275
2289
2276
2290
group_mcu_dir = []
2277
2291
mcu_dir1_files_list = []
2278
2292
mcu_dir2_files_list = []
2279
2293
2280
2294
# Compare per family
2281
- for mcu_family in mcu_families :
2282
- # Generate only for one family
2283
- if filtered_family and filtered_family not in mcu_family .name :
2284
- continue
2295
+ for mcu_family_name in aggregate_serie_list :
2296
+ mcu_family = out_temp_path / f"{ mcu_family_name } xx"
2285
2297
out_family_path = root_dir / "variants" / mcu_family .name
2286
2298
# Get all mcu_dir
2287
2299
mcu_dirs = sorted (mcu_family .glob ("*/" ))
@@ -2525,14 +2537,7 @@ def manage_repo():
2525
2537
system_path = root_dir / "system"
2526
2538
templates_dir = script_path / "templates"
2527
2539
mcu_family_dir = ""
2528
- filtered_family = ""
2529
- refname_filter = [
2530
- "STM32H7R" ,
2531
- "STM32H7S" ,
2532
- "STM32MP13" ,
2533
- "STM32MP2" ,
2534
- "STM32WB0" ,
2535
- ]
2540
+ filtered_serie = ""
2536
2541
periph_c_filename = "PeripheralPins.c"
2537
2542
pinvar_h_filename = "PinNamesVar.h"
2538
2543
config_filename = script_path / "update_config.json"
@@ -2582,15 +2587,15 @@ def manage_repo():
2582
2587
group .add_argument (
2583
2588
"-l" ,
2584
2589
"--list" ,
2585
- help = "list available xml files description in database" ,
2590
+ help = "list available xml files description in database. " ,
2586
2591
action = "store_true" ,
2587
2592
)
2588
2593
2589
2594
group .add_argument (
2590
- "-f " ,
2591
- "--family " ,
2592
- metavar = "name " ,
2593
- help = "Generate all files for specified mcu family ." ,
2595
+ "-s " ,
2596
+ "--serie " ,
2597
+ metavar = "pattern " ,
2598
+ help = "Generate all files for specified STM32 serie(s) pattern ." ,
2594
2599
)
2595
2600
2596
2601
parser .add_argument (
@@ -2604,7 +2609,6 @@ def manage_repo():
2604
2609
action = "store_true" ,
2605
2610
)
2606
2611
parser .add_argument (
2607
- "-s" ,
2608
2612
"--skip" ,
2609
2613
help = f"Skip { repo_name } clone/fetch" ,
2610
2614
action = "store_true" ,
@@ -2656,13 +2660,9 @@ def manage_repo():
2656
2660
print (f"{ stm32targets_file } does not exits!" )
2657
2661
exit (1 )
2658
2662
2659
- if args .family :
2660
- filtered_family = args .family .upper ()
2661
- filtered_family = filtered_family .removeprefix ("STM32" )
2662
- while filtered_family .endswith ("X" ):
2663
- filtered_family = filtered_family .rstrip ("X" )
2664
- filtered_family = f"STM32{ filtered_family } "
2665
-
2663
+ if args .serie :
2664
+ serie = args .serie .upper ()
2665
+ serie_pattern = re .compile (rf"STM32({ serie } )$" , re .IGNORECASE )
2666
2666
# Get all xml files
2667
2667
mcu_list = sorted (dirMCU .glob ("STM32*.xml" ))
2668
2668
@@ -2672,6 +2672,11 @@ def manage_repo():
2672
2672
print (f .name )
2673
2673
quit ()
2674
2674
2675
+ stm32_list = [f"STM32{ stm32 } " for stm32 in genSTM32List (system_path / "Drivers" )]
2676
+ if not stm32_list :
2677
+ print (f"No STM32 series found in { system_path } /Drivers" )
2678
+ quit ()
2679
+
2675
2680
# Create the jinja2 environment.
2676
2681
j2_env = Environment (
2677
2682
loader = FileSystemLoader (str (templates_dir )), trim_blocks = True , lstrip_blocks = True
@@ -2687,23 +2692,22 @@ def manage_repo():
2687
2692
# Open input file
2688
2693
xml_mcu = parse (str (mcu_file ))
2689
2694
parse_mcu_file ()
2690
-
2691
- # Generate only for one family or supported reference
2695
+ # Generate only for specified pattern series or supported one
2696
+ # Check if mcu_family is supported by the core
2692
2697
if (
2693
- filtered_family
2694
- and filtered_family not in mcu_family
2695
- or any ( skp in mcu_refname for skp in refname_filter )
2698
+ mcu_family not in stm32_list
2699
+ or args . serie
2700
+ and serie_pattern . search ( mcu_family ) is None
2696
2701
):
2697
- # Add a warning if filtered family is requested
2698
- if filtered_family and filtered_family not in refname_filter :
2699
- for skp in refname_filter :
2700
- if skp == filtered_family :
2701
- print (f"Requested family { filtered_family } is filtered!" )
2702
- print ("Please update the refname_filter list." )
2703
- quit ()
2702
+ if mcu_family not in ignored_stm32_list and mcu_family not in stm32_list :
2703
+ ignored_stm32_list .append (mcu_family )
2704
2704
xml_mcu .unlink ()
2705
2705
continue
2706
2706
2707
+ # Add mcu family to the list of directory to aggregate
2708
+ if mcu_family not in aggregate_serie_list :
2709
+ aggregate_serie_list .append (mcu_family )
2710
+
2707
2711
print (f"Generating files for '{ mcu_file .name } '..." )
2708
2712
if not gpiofile :
2709
2713
print ("Could not find GPIO file" )
@@ -2771,3 +2775,10 @@ def manage_repo():
2771
2775
2772
2776
# Clean temporary dir
2773
2777
deleteFolder (tmp_dir )
2778
+
2779
+ # Display ignored families
2780
+ if ignored_stm32_list :
2781
+ print ("\n Ignored families:" )
2782
+ for family in ignored_stm32_list :
2783
+ print (f" - { family } " )
2784
+ print ("To be supported, series must first be supported by the core." )
0 commit comments