xref: /aosp_15_r20/external/pigweed/third_party/stm32cube/stm32_hal_driver.BUILD.bazel (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2023 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
15# BUILD.bazel file for stm32xxx_hal_driver.
16
17# buildifier: disable=module-docstring
18# Must point to a cc_library exposing a header named stm32f4xx_hal_conf.h (or
19# similar for other families) that contains the HAL configuration
20label_flag(
21    name = "hal_config",
22    build_setting_default = ":unspecified",
23)
24
25# May point to a non-default implementation of timebase.
26label_flag(
27    name = "timebase",
28    build_setting_default = ":default_timebase",
29)
30
31# Should point to the corresponding cmsis_device library. Hidden behind a label
32# flag so that it can be overriden in projects that build for more than one
33# family of STM processors.
34label_flag(
35    name = "cmsis_device",
36    build_setting_default = ":unspecified",
37)
38
39label_flag(
40    name = "cmsis_init",
41    build_setting_default = ":unspecified",
42)
43
44# Special target used as a default value of the label_flags. It's not
45# compatible with any platform: To use Pigweed's STM32Cube integration, you
46# must configure these label flags.
47cc_library(
48    name = "unspecified",
49    target_compatible_with = ["@platforms//:incompatible"],
50)
51
52_DISABLED_WARNINGS = [
53    "-Wno-unused-parameter",
54    "-Wno-redundant-decls",
55    "-Wno-sign-compare",
56    "-Wno-undef",
57    "-Wno-implicit-function-declaration",
58    "-Wno-switch-enum",
59]
60
61cc_library(
62    name = "default_timebase",
63    srcs = glob(["Src/*_hal_timebase_tim_template.c"]),
64    copts = _DISABLED_WARNINGS,
65    deps = [":hal_driver_without_timebase"],
66)
67
68cc_library(
69    name = "hal_driver",
70    copts = _DISABLED_WARNINGS,
71    deps = [
72        ":hal_driver_without_timebase",
73        ":timebase",
74    ],
75)
76
77cc_library(
78    name = "hal_driver_without_timebase",
79    srcs = glob(
80        [
81            "Src/*.c",
82            "Src/Legacy/*.c",
83        ],
84        exclude = ["Src/*_template.c"],
85    ),
86    copts = _DISABLED_WARNINGS,
87    deps = [
88        ":cmsis_device",
89        ":cmsis_init",
90        ":hal_headers",
91    ],
92)
93
94cc_library(
95    name = "hal_headers",
96    hdrs = glob(
97        [
98            "Inc/*.h",
99            "Inc/Legacy/*.h",
100        ],
101        exclude = [
102            # Excluded because implementers may want to override this template.
103            "Inc/*_hal_conf_template.h",
104        ],
105    ),
106    copts = _DISABLED_WARNINGS,
107    defines = [
108        "USE_HAL_DRIVER",
109    ],
110    includes = [
111        "Inc",
112        "Inc/Legacy",
113    ],
114    deps = [
115        ":cmsis_device",
116        ":hal_config",
117    ],
118)
119