Skip to content

Commit 130a67c

Browse files
committed
ci(variant): add openocd generation to stm32variant script
Add the generation of openocd scripts for all currently available variants when using the stm32variant python script. Signed-off-by: Guillaume Gautier <[email protected]>
1 parent 4fab426 commit 130a67c

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

CI/update/stm32variant.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,30 @@
6161
mcu_refname = ""
6262
mcu_flash = []
6363
mcu_ram = []
64-
legacy_hal = {"CAN": ["F0", "F1", "F2", "F3", "F4", "F7", "L4"], "ETH": ["F4", "F7", "H7"]}
64+
legacy_hal = {
65+
"CAN": ["F0", "F1", "F2", "F3", "F4", "F7", "L4"],
66+
"ETH": ["F4", "F7", "H7"],
67+
}
68+
openocd_list = {
69+
"STM32F0": "stm32f0x",
70+
"STM32F1": "stm32f1x",
71+
"STM32F2": "stm32f2x",
72+
"STM32F3": "stm32f3x",
73+
"STM32F4": "stm32f4x",
74+
"STM32F7": "stm32f7x",
75+
"STM32G0": "stm32g0x",
76+
"STM32G4": "stm32g4x",
77+
"STM32H7": "stm32h7x",
78+
"STM32L0": "stm32l0",
79+
"STM32L1": "stm32l1",
80+
"STM32L4": "stm32l4x",
81+
"STM32L5": "stm32l5x",
82+
"STM32MP13": "stm32mp13x",
83+
"STM32MP15": "stm32mp15x",
84+
"STM32U5": "stm32u5x",
85+
"STM32WB": "stm32wbx",
86+
"STM32WL": "stm32wlx",
87+
}
6588
# Cube information
6689
product_line_dict = {}
6790

@@ -1547,6 +1570,7 @@ def print_boards_entry():
15471570
mcu_dir=mcu_refname.replace("STM32", ""),
15481571
mcu_family_dir=mcu_family_dir,
15491572
product_line=product_line,
1573+
openocd_filename=openocd_filename,
15501574
)
15511575
)
15521576
return generic_list
@@ -1561,6 +1585,15 @@ def print_general_clock(generic_list):
15611585
)
15621586

15631587

1588+
def print_openocd(openocd_target):
1589+
openocd_template = j2_env.get_template(openocd_filename)
1590+
openocd_file.write(
1591+
openocd_template.render(
1592+
openocd_target=openocd_target,
1593+
)
1594+
)
1595+
1596+
15641597
# List management
15651598
tokenize = re.compile(r"(\d+)|(\D+)").findall
15661599

@@ -2289,6 +2322,7 @@ def manage_repo():
22892322
templates_dir = cur_dir / "templates"
22902323
mcu_family_dir = ""
22912324
filtered_family = ""
2325+
openocd_target = ""
22922326
# filtered_mcu_file = ""
22932327
periph_c_filename = "PeripheralPins.c"
22942328
pinvar_h_filename = "PinNamesVar.h"
@@ -2297,6 +2331,7 @@ def manage_repo():
22972331
variant_cpp_filename = "variant_generic.cpp"
22982332
boards_entry_filename = "boards_entry.txt"
22992333
generic_clock_filename = "generic_clock.c"
2334+
openocd_filename = "openocd.cfg"
23002335
repo_local_path = cur_dir / "repo"
23012336
cubemxdir = Path()
23022337
gh_url = "https://github.com/STMicroelectronics/STM32_open_pin_data"
@@ -2315,8 +2350,9 @@ def manage_repo():
23152350
- {pinvar_h_filename},
23162351
- {variant_cpp_filename},
23172352
- {variant_h_filename},
2318-
- {boards_entry_filename}
2319-
- {generic_clock_filename}
2353+
- {boards_entry_filename},
2354+
- {generic_clock_filename},
2355+
- {openocd_filename}
23202356
for all xml files description available in STM32CubeMX internal database.
23212357
Internal database path must be defined in {config_filename}.
23222358
It can be the one from STM32CubeMX directory if defined:
@@ -2462,6 +2498,23 @@ def manage_repo():
24622498
quit()
24632499
xml_gpio = parse(str(dirIP / f"GPIO-{gpiofile}_Modes.xml"))
24642500

2501+
if mcu_family == "STM32MP1":
2502+
if mcu_refname.startswith("STM32MP13"):
2503+
openocd_target = openocd_list.get("STM32MP13")
2504+
elif mcu_refname.startswith("STM32MP15"):
2505+
openocd_target = openocd_list.get("STM32MP15")
2506+
else:
2507+
openocd_target = openocd_list.get(mcu_family, "")
2508+
if openocd_target == "":
2509+
print(
2510+
"""
2511+
--> Could not find appropriate openocd target for this family.
2512+
- If a script for this family is available in openocd/scripts/target
2513+
please add it to the openocd_list
2514+
- Please also update boards.txt to add the openocdscript variable for this
2515+
family: {new_family}.build.openocdscript=openocd.cfg
2516+
"""
2517+
)
24652518
mcu_family_dir = mcu_family + "xx"
24662519
out_temp_path = tmp_dir / mcu_family_dir / mcu_file.stem.replace("STM32", "")
24672520
periph_c_filepath = out_temp_path / periph_c_filename
@@ -2470,6 +2523,7 @@ def manage_repo():
24702523
variant_h_filepath = out_temp_path / variant_h_filename
24712524
boards_entry_filepath = out_temp_path / boards_entry_filename
24722525
generic_clock_filepath = out_temp_path / generic_clock_filename
2526+
openocd_filepath = out_temp_path / openocd_filename
24732527
out_temp_path.mkdir(parents=True, exist_ok=True)
24742528

24752529
# open output file
@@ -2479,11 +2533,13 @@ def manage_repo():
24792533
variant_h_file = open(variant_h_filepath, "w", newline="\n")
24802534
boards_entry_file = open(boards_entry_filepath, "w", newline="\n")
24812535
generic_clock_file = open(generic_clock_filepath, "w", newline="\n")
2536+
openocd_file = open(openocd_filepath, "w", newline="\n")
24822537
parse_pins()
24832538
manage_af_and_alternate()
24842539

24852540
generic_list = print_boards_entry()
24862541
print_general_clock(generic_list)
2542+
print_openocd(openocd_target)
24872543
print_peripheral()
24882544
alt_syswkup_list = print_pinamevar()
24892545
print_variant(generic_list, alt_syswkup_list)
@@ -2509,6 +2565,7 @@ def manage_repo():
25092565
variant_cpp_file.close()
25102566
boards_entry_file.close()
25112567
generic_clock_file.close()
2568+
openocd_file.close()
25122569
xml_mcu.unlink()
25132570
xml_gpio.unlink()
25142571

CI/update/templates/openocd.cfg

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (c) 2023, STMicroelectronics
3+
# All rights reserved.
4+
#
5+
# This software component is licensed by ST under BSD 3-Clause license,
6+
# the "License"; You may not use this file except in compliance with the
7+
# License. You may obtain a copy of the License at:
8+
# opensource.org/licenses/BSD-3-Clause
9+
#
10+
11+
source [find interface/stlink.cfg]
12+
13+
transport select hla_swd
14+
15+
source [find target/{{openocd_target}}.cfg]
16+
17+
reset_config srst_only
18+

0 commit comments

Comments
 (0)