• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 in either of:
24# - For older releases, the README.md of each hal_driver, e.g.:
25# https://github.com/STMicroelectronics/stm32f4xx_hal_driver/blob/v1.8.0/README.md
26# - For newer releases, the Release_Notes.html file in STM32Cube release, e.g.:
27# https://github.com/STMicroelectronics/STM32CubeF4/blob/v1.27.1/Release_Notes.html
28_STM32CUBE_VERSIONS = {
29    "f0": {
30        "hal_driver_tag": "v1.7.6",
31        "cmsis_device_tag": "v2.3.6",
32        "cmsis_core_tag": "v5.4.0_cm0",
33    },
34    "f1": {
35        "hal_driver_tag": "v1.1.8",
36        "cmsis_device_tag": "v4.3.3",
37        "cmsis_core_tag": "v5.4.0_cm3",
38    },
39    "f2": {
40        "hal_driver_tag": "v1.2.7",
41        "cmsis_device_tag": "v2.2.5",
42        "cmsis_core_tag": "v5.4.0_cm3",
43    },
44    "f3": {
45        "hal_driver_tag": "v1.5.6",
46        "cmsis_device_tag": "v2.3.6",
47        "cmsis_core_tag": "v5.4.0_cm4",
48    },
49    "f4": {
50        "hal_driver_tag": "v1.8.0",
51        "cmsis_device_tag": "v2.6.8",
52        "cmsis_core_tag": "v5.4.0_cm4",
53    },
54    "f7": {
55        "hal_driver_tag": "v1.3.0",
56        "cmsis_device_tag": "v1.2.8",
57        "cmsis_core_tag": "v5.4.0_cm7",
58    },
59    "g0": {
60        "hal_driver_tag": "v1.4.5",
61        "cmsis_device_tag": "v1.4.3",
62        "cmsis_core_tag": "v5.6.0_cm0",
63    },
64    "g4": {
65        "hal_driver_tag": "v1.2.2",
66        "cmsis_device_tag": "v1.2.2",
67        "cmsis_core_tag": "v5.6.0_cm4",
68    },
69    "h7": {
70        "hal_driver_tag": "v1.11.0",
71        "cmsis_device_tag": "v1.10.2",
72        "cmsis_core_tag": "v5.6.0",
73    },
74    "l0": {
75        "hal_driver_tag": "v1.10.5",
76        "cmsis_device_tag": "v1.9.2",
77        "cmsis_core_tag": "v5.4.0_cm0",
78    },
79    "l1": {
80        "hal_driver_tag": "v1.4.4",
81        "cmsis_device_tag": "v2.3.2",
82        "cmsis_core_tag": "v5.4.0_cm3",
83    },
84    "l4": {
85        "hal_driver_tag": "v1.13.3",
86        "cmsis_device_tag": "v1.7.2",
87        "cmsis_core_tag": "v5.6.0_cm4",
88    },
89    "l5": {
90        "hal_driver_tag": "v1.0.4",
91        "cmsis_device_tag": "v1.0.4",
92        "cmsis_core_tag": "v5.6.0_cm33",
93    },
94    "wb": {
95        "hal_driver_tag": "v1.11.0",
96        "cmsis_device_tag": "v1.11.0",
97        "cmsis_core_tag": "v5.6.0_cm4",
98    },
99    "wl": {
100        "hal_driver_tag": "v1.1.0",
101        "cmsis_device_tag": "v1.1.0",
102        "cmsis_core_tag": "v5.6.0_cm4",
103    },
104}
105
106
107class Stm32Cube(pw_package.package_manager.Package):
108    """Install and check status of stm32cube."""
109
110    def __init__(self, family, tags, *args, **kwargs):
111        super().__init__(*args, name=f'stm32cube_{family}', **kwargs)
112
113        st_github_url = 'https://github.com/STMicroelectronics'
114
115        self._hal_driver = pw_package.git_repo.GitRepo(
116            name='hal_driver',
117            url=f'{st_github_url}/stm32{family}xx_hal_driver.git',
118            tag=tags['hal_driver_tag'],
119        )
120
121        self._cmsis_core = pw_package.git_repo.GitRepo(
122            name='cmsis_core',
123            url=f'{st_github_url}/cmsis_core.git',
124            tag=tags['cmsis_core_tag'],
125        )
126
127        self._cmsis_device = pw_package.git_repo.GitRepo(
128            name='cmsis_device',
129            url=f'{st_github_url}/cmsis_device_{family}.git',
130            tag=tags['cmsis_device_tag'],
131        )
132
133    def install(self, path: pathlib.Path) -> None:
134        self._hal_driver.install(path / self._hal_driver.name)
135        self._cmsis_core.install(path / self._cmsis_core.name)
136        self._cmsis_device.install(path / self._cmsis_device.name)
137
138        pw_stm32cube_build.gen_file_list.gen_file_list(path)
139
140    def status(self, path: pathlib.Path) -> bool:
141        return all(
142            [
143                self._hal_driver.status(path / self._hal_driver.name),
144                self._cmsis_core.status(path / self._cmsis_core.name),
145                self._cmsis_device.status(path / self._cmsis_device.name),
146                (path / "files.txt").is_file(),
147            ]
148        )
149
150    def info(self, path: pathlib.Path) -> Sequence[str]:
151        return (
152            f'{self.name} installed in: {path}',
153            "Enable by running 'gn args out' and adding this line:",
154            f'  dir_pw_third_party_{self.name} = "{path}"',
155        )
156
157
158for st_family, st_tags in _STM32CUBE_VERSIONS.items():
159    pw_package.package_manager.register(Stm32Cube, st_family, st_tags)
160