Skip to content

Commit 2ccfc78

Browse files
committed
ci(stm32variant): enhance series managements
- dynamically manage ignores series (i.e. the one not supported by the core) - allow to update one or several series based on a pattern. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent b19931a commit 2ccfc78

File tree

1 file changed

+50
-39
lines changed

1 file changed

+50
-39
lines changed

CI/update/stm32variant.py

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@
1414

1515
script_path = Path(__file__).parent.resolve()
1616
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+
)
1824

25+
stm32_list = [] # series
26+
ignored_stm32_list = [] # series
27+
aggregate_serie_list = [] # series
1928
mcu_list = [] # 'name'
2029
io_list = [] # 'PIN','name'
2130
alt_list = [] # 'PIN','name'
@@ -158,6 +167,12 @@ def parse_mcu_file():
158167

159168
mcu_node = xml_mcu.getElementsByTagName("Mcu")[0]
160169
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+
161176
if mcu_family.endswith("+"):
162177
mcu_family = mcu_family[:-1]
163178
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)
22712286
def aggregate_dir():
22722287
# Get mcu_family directories
22732288
out_temp_path = tmp_dir
2274-
mcu_families = sorted(out_temp_path.glob("STM32*/"))
22752289

22762290
group_mcu_dir = []
22772291
mcu_dir1_files_list = []
22782292
mcu_dir2_files_list = []
22792293

22802294
# 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"
22852297
out_family_path = root_dir / "variants" / mcu_family.name
22862298
# Get all mcu_dir
22872299
mcu_dirs = sorted(mcu_family.glob("*/"))
@@ -2525,14 +2537,7 @@ def manage_repo():
25252537
system_path = root_dir / "system"
25262538
templates_dir = script_path / "templates"
25272539
mcu_family_dir = ""
2528-
filtered_family = ""
2529-
refname_filter = [
2530-
"STM32H7R",
2531-
"STM32H7S",
2532-
"STM32MP13",
2533-
"STM32MP2",
2534-
"STM32WB0",
2535-
]
2540+
filtered_serie = ""
25362541
periph_c_filename = "PeripheralPins.c"
25372542
pinvar_h_filename = "PinNamesVar.h"
25382543
config_filename = script_path / "update_config.json"
@@ -2582,15 +2587,15 @@ def manage_repo():
25822587
group.add_argument(
25832588
"-l",
25842589
"--list",
2585-
help="list available xml files description in database",
2590+
help="list available xml files description in database.",
25862591
action="store_true",
25872592
)
25882593

25892594
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.",
25942599
)
25952600

25962601
parser.add_argument(
@@ -2604,7 +2609,6 @@ def manage_repo():
26042609
action="store_true",
26052610
)
26062611
parser.add_argument(
2607-
"-s",
26082612
"--skip",
26092613
help=f"Skip {repo_name} clone/fetch",
26102614
action="store_true",
@@ -2656,13 +2660,9 @@ def manage_repo():
26562660
print(f"{stm32targets_file} does not exits!")
26572661
exit(1)
26582662

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)
26662666
# Get all xml files
26672667
mcu_list = sorted(dirMCU.glob("STM32*.xml"))
26682668

@@ -2672,6 +2672,11 @@ def manage_repo():
26722672
print(f.name)
26732673
quit()
26742674

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+
26752680
# Create the jinja2 environment.
26762681
j2_env = Environment(
26772682
loader=FileSystemLoader(str(templates_dir)), trim_blocks=True, lstrip_blocks=True
@@ -2687,23 +2692,22 @@ def manage_repo():
26872692
# Open input file
26882693
xml_mcu = parse(str(mcu_file))
26892694
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
26922697
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
26962701
):
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)
27042704
xml_mcu.unlink()
27052705
continue
27062706

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+
27072711
print(f"Generating files for '{mcu_file.name}'...")
27082712
if not gpiofile:
27092713
print("Could not find GPIO file")
@@ -2771,3 +2775,10 @@ def manage_repo():
27712775

27722776
# Clean temporary dir
27732777
deleteFolder(tmp_dir)
2778+
2779+
# Display ignored families
2780+
if ignored_stm32_list:
2781+
print("\nIgnored 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

Comments
 (0)