Skip to content

Commit 2f2f041

Browse files
committed
ci(stm32svd): script to manage svd files from STM32CubeCLT
This script will update the stm32_svd repository: https://github.com/stm32duino/stm32_svd Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 28ac456 commit 2f2f041

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

CI/update/stm32svd.py

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import json
2+
import sys
3+
from pathlib import Path
4+
5+
script_path = Path(__file__).parent.resolve()
6+
sys.path.append(str(script_path.parent))
7+
from utils import copyFile, copyFolder, createFolder, deleteFolder
8+
from utils import defaultConfig, genSTM32List
9+
10+
stm32_list = [] # series
11+
root_path = script_path.parent.parent.resolve()
12+
hal_path = root_path / "system" / "Drivers"
13+
cubeclt_path = Path("")
14+
cubeclt_svd_path = Path("")
15+
stm32_svd_repo = Path("")
16+
stm32_svd_dir = Path("")
17+
18+
19+
def checkConfig():
20+
global cubeclt_path
21+
global cubeclt_svd_path
22+
global stm32_svd_repo
23+
global stm32_svd_dir
24+
config_file_path = script_path / "update_config.json"
25+
if config_file_path.is_file():
26+
try:
27+
config_file = open(config_file_path, "r")
28+
path_config = json.load(config_file)
29+
config_file.close()
30+
31+
if "STM32CUBECLT_PATH" not in path_config:
32+
path_config["STM32CUBECLT_PATH"] = str(
33+
"Path to STM32CubeCLT installation directory"
34+
)
35+
defaultConfig(config_file_path, path_config)
36+
else:
37+
cubeclt_path = Path(path_config["STM32CUBECLT_PATH"])
38+
if not cubeclt_path.is_dir():
39+
print(f"{cubeclt_path} does not exist!")
40+
exit(1)
41+
else:
42+
cubeclt_svd_path = cubeclt_path / "STMicroelectronics_CMSIS_SVD"
43+
if not cubeclt_svd_path.is_dir():
44+
print(f"{cubeclt_svd_path} does not exist!")
45+
exit(1)
46+
if "STM32_SVD_PATH" not in path_config:
47+
path_config["STM32_SVD_PATH"] = str("Path to stm32_svd repository")
48+
defaultConfig(config_file_path, path_config)
49+
else:
50+
stm32_svd_repo = Path(path_config["STM32_SVD_PATH"])
51+
if not stm32_svd_repo.is_dir():
52+
print(f"{stm32_svd_repo} does not exist!")
53+
exit(1)
54+
else:
55+
stm32_svd_dir = stm32_svd_repo / "svd"
56+
except IOError:
57+
print(f"Failed to open {config_file}!")
58+
else:
59+
defaultConfig(
60+
config_file_path,
61+
{"STM32CUBECLT_PATH": "Path to STM32CubeCLT installation directory"},
62+
)
63+
64+
65+
def main():
66+
global stm32_list
67+
# check config have to be done first
68+
checkConfig()
69+
stm32_list = genSTM32List(hal_path, None)
70+
# Reverse order to get WBA before WB to ease svd sorting
71+
stm32_list.sort(reverse=True)
72+
# Clean up core svd folder
73+
deleteFolder(stm32_svd_dir)
74+
createFolder(stm32_svd_dir)
75+
# Update the Core folder
76+
copyFolder(cubeclt_svd_path / "Core", stm32_svd_dir / "Core")
77+
# Update the license
78+
copyFile(cubeclt_svd_path / "about.html", stm32_svd_dir)
79+
# Copy the version
80+
copyFile(cubeclt_path / ".version", stm32_svd_dir / "STM32CubeCLT.version")
81+
# Create all directories
82+
for serie in stm32_list:
83+
createFolder(stm32_svd_dir / f"STM32{serie}xx")
84+
# Get all xml files
85+
svd_list = sorted(cubeclt_svd_path.glob("STM32*.svd"))
86+
87+
# Copy all svd files per series
88+
for svd_file in svd_list:
89+
svd_name = svd_file.name
90+
for serie in stm32_list:
91+
if svd_name.find(f"STM32{serie}") != -1:
92+
copyFile(svd_file, stm32_svd_dir / f"STM32{serie}xx")
93+
break
94+
95+
96+
if __name__ == "__main__":
97+
main()

0 commit comments

Comments
 (0)