aboutsummaryrefslogtreecommitdiff
path: root/third_party/stm32cube
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/stm32cube')
-rw-r--r--third_party/stm32cube/BUILD.bazel14
-rw-r--r--third_party/stm32cube/BUILD.gn15
-rw-r--r--third_party/stm32cube/cmsis_core.BUILD.bazel30
-rw-r--r--third_party/stm32cube/cmsis_device.BUILD.bazel46
-rw-r--r--third_party/stm32cube/stm32_hal_driver.BUILD.bazel117
5 files changed, 220 insertions, 2 deletions
diff --git a/third_party/stm32cube/BUILD.bazel b/third_party/stm32cube/BUILD.bazel
index 81a3ff78c..94e3537f4 100644
--- a/third_party/stm32cube/BUILD.bazel
+++ b/third_party/stm32cube/BUILD.bazel
@@ -21,10 +21,24 @@ package(default_visibility = ["//visibility:public"])
licenses(["notice"])
+# NOTE: To depend on this target, you must set the STM32CUBE_HEADER
+# preprocessor variable, perhaps using copts associated with the target
+# platform. See the module documentation for details.
pw_cc_library(
name = "stm32cube",
hdrs = [
"public/stm32cube/init.h",
"public/stm32cube/stm32cube.h",
],
+ includes = ["public"],
+ deps = [
+ ":hal_driver",
+ ],
+)
+
+# This label_flag introduces a layer of indirection useful when building a
+# project that requires more than one STM32Cube MCU Package.
+label_flag(
+ name = "hal_driver",
+ build_setting_default = "@hal_driver",
)
diff --git a/third_party/stm32cube/BUILD.gn b/third_party/stm32cube/BUILD.gn
index da8c1373e..cdfde7393 100644
--- a/third_party/stm32cube/BUILD.gn
+++ b/third_party/stm32cube/BUILD.gn
@@ -117,7 +117,7 @@ if (dir_pw_third_party_stm32cube == "") {
inputs = [ "$dir_pw_third_party_stm32cube/hal_driver/Inc/${files.family}_hal_conf_template.h" ]
}
- config("flags") {
+ config("header_flags") {
cflags = [ "-Wno-unused-parameter" ]
cflags_c = [
"-Wno-redundant-decls",
@@ -126,6 +126,8 @@ if (dir_pw_third_party_stm32cube == "") {
"-Wno-implicit-function-declaration",
"-Wno-switch-enum",
]
+
+ # TODO: b/301262374 - Provide a better way to detect the compiler type.
if (get_path_info(pw_toolchain_SCOPE.cc, "file") == "clang") {
cflags += [ "-Wno-deprecated-volatile" ]
cflags_c += [ "-Wno-parentheses-equality" ]
@@ -146,6 +148,14 @@ if (dir_pw_third_party_stm32cube == "") {
visibility = [ ":*" ]
}
+ config("sources_flags") {
+ if (get_path_info(pw_toolchain_SCOPE.cc, "file") == "clang") {
+ cflags_c = [ "-Wno-unused-but-set-variable" ]
+ }
+
+ visibility = [ ":*" ]
+ }
+
config("public_include_paths") {
include_dirs = files.include_dirs
include_dirs += [ "public" ]
@@ -156,7 +166,7 @@ if (dir_pw_third_party_stm32cube == "") {
# this. If you just want to depend on the hal, depend on stm32cube directly.
pw_source_set("stm32cube_headers") {
public_configs = [
- ":flags",
+ ":header_flags",
":public_include_paths",
]
public = [
@@ -172,6 +182,7 @@ if (dir_pw_third_party_stm32cube == "") {
}
pw_source_set("stm32cube") {
+ configs = [ ":sources_flags" ]
public_deps = [ ":stm32cube_headers" ]
sources = files.sources
deps = [
diff --git a/third_party/stm32cube/cmsis_core.BUILD.bazel b/third_party/stm32cube/cmsis_core.BUILD.bazel
new file mode 100644
index 000000000..083434f80
--- /dev/null
+++ b/third_party/stm32cube/cmsis_core.BUILD.bazel
@@ -0,0 +1,30 @@
+# Copyright 2023 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+# BUILD.bazel file for cmsis_core.
+
+# buildifier: disable=module-docstring
+cc_library(
+ name = "cmsis_core",
+ hdrs = glob(
+ [
+ "Include/*.h",
+ "Include/DSP/Include/*.h",
+ ],
+ ),
+ includes = [
+ "Include",
+ "Include/DSP/Include",
+ ],
+)
diff --git a/third_party/stm32cube/cmsis_device.BUILD.bazel b/third_party/stm32cube/cmsis_device.BUILD.bazel
new file mode 100644
index 000000000..9911787cf
--- /dev/null
+++ b/third_party/stm32cube/cmsis_device.BUILD.bazel
@@ -0,0 +1,46 @@
+# Copyright 2023 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+# BUILD.bazel file for cmsis_device_xxx.
+
+# buildifier: disable=module-docstring
+# Should point to the corresponding cmsis_core library. Hidden behind a label
+# flag so that it can be overriden in projects that build for more than one
+# family of STM processors.
+label_flag(
+ name = "cmsis_core",
+ build_setting_default = "@cmsis_core",
+)
+
+cc_library(
+ name = "default_cmsis_init",
+ srcs = glob(["Source/Templates/system_*.c"]),
+ deps = [":cmsis_device"],
+)
+
+cc_library(
+ name = "cmsis_device",
+ hdrs = glob(
+ [
+ "Include/*.h",
+ ],
+ ),
+ includes = ["Include"],
+ defines = [
+ "__ARMCC_VERSION=0",
+ ],
+ deps = [
+ ":cmsis_core",
+ ],
+)
diff --git a/third_party/stm32cube/stm32_hal_driver.BUILD.bazel b/third_party/stm32cube/stm32_hal_driver.BUILD.bazel
new file mode 100644
index 000000000..8bceedfce
--- /dev/null
+++ b/third_party/stm32cube/stm32_hal_driver.BUILD.bazel
@@ -0,0 +1,117 @@
+# Copyright 2023 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+# BUILD.bazel file for stm32xxx_hal_driver.
+
+# buildifier: disable=module-docstring
+# Must point to a cc_library exposing a header named stm32f4xx_hal_conf.h (or
+# similar for other families) that contains the HAL configuration
+label_flag(
+ name = "hal_config",
+ build_setting_default = ":unspecified",
+)
+
+# May point to a non-default implementation of timebase.
+label_flag(
+ name = "timebase",
+ build_setting_default = ":default_timebase",
+)
+
+# Should point to the corresponding cmsis_device library. Hidden behind a label
+# flag so that it can be overriden in projects that build for more than one
+# family of STM processors.
+label_flag(
+ name = "cmsis_device",
+ build_setting_default = "@cmsis_device",
+)
+
+label_flag(
+ name = "cmsis_init",
+ build_setting_default = "@cmsis_device//:default_cmsis_init",
+)
+
+# Special target used as a default value of the hal_config label_flag. It's not
+# compatible with any platform: To use Pigweed's STM32Cube integration, you
+# must provide a hal_config.
+cc_library(
+ name = "unspecified",
+ target_compatible_with = ["@platforms//:incompatible"],
+)
+
+cc_library(
+ name = "default_timebase",
+ srcs = glob(["Src/*_hal_timebase_tim_template.c"]),
+ deps = [":hal_driver_without_timebase"],
+)
+
+_DISABLED_WARNINGS = [
+ "-Wno-unused-parameter",
+ "-Wno-redundant-decls",
+ "-Wno-sign-compare",
+ "-Wno-undef",
+ "-Wno-implicit-function-declaration",
+ "-Wno-switch-enum",
+]
+
+cc_library(
+ name = "hal_driver",
+ deps = [
+ ":hal_driver_without_timebase",
+ ":timebase",
+ ],
+ copts = _DISABLED_WARNINGS,
+)
+
+cc_library(
+ name = "hal_driver_without_timebase",
+ srcs = glob(
+ [
+ "Src/*.c",
+ "Src/Legacy/*.c",
+ ],
+ exclude = ["Src/*_template.c"],
+ ),
+ deps = [
+ ":cmsis_device",
+ ":cmsis_init",
+ ":hal_headers",
+ ],
+ copts = _DISABLED_WARNINGS,
+)
+
+cc_library(
+ name = "hal_headers",
+ hdrs = glob(
+ [
+ "Inc/*.h",
+ "Inc/Legacy/*.h",
+ ],
+ exclude = [
+ # Excluded because implementers may want to override this template.
+ "Inc/*_hal_conf_template.h",
+ ],
+ ),
+ includes = [
+ "Inc",
+ "Inc/Legacy",
+ ],
+ deps = [
+ ":cmsis_device",
+ ":hal_config",
+ ],
+ defines = [
+ "USE_HAL_DRIVER",
+ ],
+ copts = _DISABLED_WARNINGS,
+)