1# Copyright 2021 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Install and check status of stm32cube.""" 15 16import pathlib 17from typing import Sequence 18 19import pw_stm32cube_build.gen_file_list 20import pw_package.git_repo 21import pw_package.package_manager 22 23# Compatible versions are listed on the README.md of each hal_driver repo 24_STM32CUBE_VERSIONS = { 25 "f0": { 26 "hal_driver_tag": "v1.7.5", 27 "cmsis_device_tag": "v2.3.5", 28 "cmsis_core_tag": "v5.4.0_cm0", 29 }, 30 "f1": { 31 "hal_driver_tag": "v1.1.7", 32 "cmsis_device_tag": "v4.3.2", 33 "cmsis_core_tag": "v5.4.0_cm3", 34 }, 35 "f2": { 36 "hal_driver_tag": "v1.2.6", 37 "cmsis_device_tag": "v2.2.4", 38 "cmsis_core_tag": "v5.4.0_cm3", 39 }, 40 "f3": { 41 "hal_driver_tag": "v1.5.5", 42 "cmsis_device_tag": "v2.3.5", 43 "cmsis_core_tag": "v5.4.0_cm4", 44 }, 45 "f4": { 46 "hal_driver_tag": "v1.7.12", 47 "cmsis_device_tag": "v2.6.6", 48 "cmsis_core_tag": "v5.4.0_cm4", 49 }, 50 "f7": { 51 "hal_driver_tag": "v1.2.9", 52 "cmsis_device_tag": "v1.2.6", 53 "cmsis_core_tag": "v5.4.0_cm7", 54 }, 55 "g0": { 56 "hal_driver_tag": "v1.4.1", 57 "cmsis_device_tag": "v1.4.0", 58 "cmsis_core_tag": "v5.6.0_cm0", 59 }, 60 "g4": { 61 "hal_driver_tag": "v1.2.1", 62 "cmsis_device_tag": "v1.2.1", 63 "cmsis_core_tag": "v5.6.0_cm4", 64 }, 65 "h7": { 66 "hal_driver_tag": "v1.10.0", 67 "cmsis_device_tag": "v1.10.0", 68 "cmsis_core_tag": "v5.6.0", 69 }, 70 "l0": { 71 "hal_driver_tag": "v1.10.4", 72 "cmsis_device_tag": "v1.9.1", 73 "cmsis_core_tag": "v4.5_cm0", 74 }, 75 "l1": { 76 "hal_driver_tag": "v1.4.3", 77 "cmsis_device_tag": "v2.3.1", 78 "cmsis_core_tag": "v5.4.0_cm3", 79 }, 80 "l4": { 81 "hal_driver_tag": "v1.13.0", 82 "cmsis_device_tag": "v1.7.1", 83 "cmsis_core_tag": "v5.6.0_cm4", 84 }, 85 "l5": { 86 "hal_driver_tag": "v1.0.4", 87 "cmsis_device_tag": "v1.0.4", 88 "cmsis_core_tag": "v5.6.0_cm33", 89 }, 90 "wb": { 91 "hal_driver_tag": "v1.8.0", 92 "cmsis_device_tag": "v1.8.0", 93 "cmsis_core_tag": "v5.4.0_cm4", 94 }, 95 "wl": { 96 "hal_driver_tag": "v1.0.0", 97 "cmsis_device_tag": "v1.0.0", 98 "cmsis_core_tag": "v5.6.0_cm4", 99 }, 100} 101 102 103class Stm32Cube(pw_package.package_manager.Package): 104 """Install and check status of stm32cube.""" 105 def __init__(self, family, tags, *args, **kwargs): 106 super().__init__(*args, name=f'stm32cube_{family}', **kwargs) 107 108 st_github_url = 'https://github.com/STMicroelectronics' 109 110 self._hal_driver = pw_package.git_repo.GitRepo( 111 name='hal_driver', 112 url=f'{st_github_url}/stm32{family}xx_hal_driver.git', 113 tag=tags['hal_driver_tag'], 114 ) 115 116 self._cmsis_core = pw_package.git_repo.GitRepo( 117 name='cmsis_core', 118 url=f'{st_github_url}/cmsis_core.git', 119 tag=tags['cmsis_core_tag'], 120 ) 121 122 self._cmsis_device = pw_package.git_repo.GitRepo( 123 name='cmsis_device', 124 url=f'{st_github_url}/cmsis_device_{family}.git', 125 tag=tags['cmsis_device_tag'], 126 ) 127 128 def install(self, path: pathlib.Path) -> None: 129 self._hal_driver.install(path / self._hal_driver.name) 130 self._cmsis_core.install(path / self._cmsis_core.name) 131 self._cmsis_device.install(path / self._cmsis_device.name) 132 133 pw_stm32cube_build.gen_file_list.gen_file_list(path) 134 135 def status(self, path: pathlib.Path) -> bool: 136 return all([ 137 self._hal_driver.status(path / self._hal_driver.name), 138 self._cmsis_core.status(path / self._cmsis_core.name), 139 self._cmsis_device.status(path / self._cmsis_device.name), 140 (path / "files.txt").is_file(), 141 ]) 142 143 def info(self, path: pathlib.Path) -> Sequence[str]: 144 return ( 145 f'{self.name} installed in: {path}', 146 "Enable by running 'gn args out' and adding this line:", 147 f' dir_pw_third_party_{self.name} = "{path}"', 148 ) 149 150 151for st_family, st_tags in _STM32CUBE_VERSIONS.items(): 152 pw_package.package_manager.register(Stm32Cube, st_family, st_tags) 153