|
| 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 | +core_svd_dir = root_path / "svd" |
| 16 | + |
| 17 | + |
| 18 | +def checkConfig(): |
| 19 | + global cubeclt_path |
| 20 | + global cubeclt_svd_path |
| 21 | + |
| 22 | + config_file_path = script_path / "update_config.json" |
| 23 | + if config_file_path.is_file(): |
| 24 | + try: |
| 25 | + config_file = open(config_file_path, "r") |
| 26 | + path_config = json.load(config_file) |
| 27 | + config_file.close() |
| 28 | + # Common path |
| 29 | + if "STM32CUBECLT_PATH" not in path_config: |
| 30 | + path_config["STM32CUBECLT_PATH"] = str( |
| 31 | + "Path to STM32CubeCLT installation directory" |
| 32 | + ) |
| 33 | + defaultConfig(config_file_path, path_config) |
| 34 | + else: |
| 35 | + cubeclt_path = Path(path_config["STM32CUBECLT_PATH"]) |
| 36 | + if not cubeclt_path.is_dir(): |
| 37 | + print(f"{cubeclt_path} does not exist!") |
| 38 | + exit(1) |
| 39 | + else: |
| 40 | + cubeclt_svd_path = cubeclt_path / "STMicroelectronics_CMSIS_SVD" |
| 41 | + if not cubeclt_svd_path.is_dir(): |
| 42 | + print(f"{cubeclt_svd_path} does not exist!") |
| 43 | + exit(1) |
| 44 | + except IOError: |
| 45 | + print(f"Failed to open {config_file}!") |
| 46 | + else: |
| 47 | + defaultConfig( |
| 48 | + config_file_path, |
| 49 | + {"STM32CUBECLT_PATH": "Path to STM32CubeCLT installation directory"}, |
| 50 | + ) |
| 51 | + |
| 52 | + |
| 53 | +def main(): |
| 54 | + global stm32_list |
| 55 | + # check config have to be done first |
| 56 | + checkConfig() |
| 57 | + stm32_list = genSTM32List(hal_path, None) |
| 58 | + # Reverse order to get WBA before WB to ease svd sorting |
| 59 | + stm32_list.sort(reverse=True) |
| 60 | + # Clean up core svd folder |
| 61 | + deleteFolder(core_svd_dir) |
| 62 | + createFolder(core_svd_dir) |
| 63 | + # Update the Core folder |
| 64 | + copyFolder(cubeclt_svd_path / "Core", core_svd_dir / "Core") |
| 65 | + # Update the license |
| 66 | + copyFile(cubeclt_svd_path / "about.html", core_svd_dir) |
| 67 | + # Copy the version |
| 68 | + copyFile(cubeclt_path / ".version", core_svd_dir / "STM32CubeCLT.version") |
| 69 | + # Create all directories |
| 70 | + for serie in stm32_list: |
| 71 | + createFolder(core_svd_dir / f"STM32{serie}xx") |
| 72 | + # Get all xml files |
| 73 | + svd_list = sorted(cubeclt_svd_path.glob("STM32*.svd")) |
| 74 | + |
| 75 | + # Copy all svd files per series |
| 76 | + for svd_file in svd_list: |
| 77 | + svd_name = svd_file.name |
| 78 | + for serie in stm32_list: |
| 79 | + if svd_name.find(f"STM32{serie}") != -1: |
| 80 | + copyFile(svd_file, core_svd_dir / f"STM32{serie}xx") |
| 81 | + break |
| 82 | + |
| 83 | + |
| 84 | +if __name__ == "__main__": |
| 85 | + main() |
0 commit comments