Skip to content

Commit

Permalink
bazel: Move stm32f429i defines into cc_library
Browse files Browse the repository at this point in the history
Change-Id: Ibe510a7d06e57679456bdd04171d469b09b4c2a9
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/234913
Commit-Queue: Taylor Cramer <cramertj@google.com>
Docs-Not-Needed: Taylor Cramer <cramertj@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Reviewed-by: Ted Pudlik <tpudlik@google.com>
  • Loading branch information
cramertj authored and CQ Bot Account committed Sep 10, 2024
1 parent df3b7ba commit 03466a7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
6 changes: 0 additions & 6 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@ build:stm32f429i_baremetal --platforms=//targets/stm32f429i_disc1:platform
# Config for the stm32f429i_disc1_stm32cube freertos platform.
#
build:stm32f429i_freertos --platforms=//targets/stm32f429i_disc1_stm32cube:platform
# This should be moved to platform-based flags once
# https://github.com/bazelbuild/bazel/issues/22453
# is fixed.
build:stm32f429i_freertos --copt="-DSTM32CUBE_HEADER=\"stm32f4xx.h\""
build:stm32f429i_freertos --copt="-DSTM32F429xx"


# Config for the lm3s6965evb platform, used to build pw_rust/examples.
build:lm3s6965evb --platforms=//pw_build/platforms:lm3s6965evb
Expand Down
40 changes: 23 additions & 17 deletions pw_stm32cube_build/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,23 +267,23 @@ family. To do so,
1. Add the appropriate repositories to your WORKSPACE under different names,
eg. ``@stm32f4xx_hal_driver`` and ``@stm32h7xx_hal_driver``.
2. Set the corresponding :ref:`module-pw_stm32cube_build-bazel-label-flags` as
part of the platform configuration for your embedded target platforms.
Currently, the best way to do this is via a `bazelrc config
<https://bazel.build/run/bazelrc#config>`_, which would look like this:
part of the platform definition for your embedded target platforms.

.. code-block::
build:stm32f429i --platforms=//targets/stm32f429i_disc1_stm32cube:platform
build:stm32f429i --@pigweed//third_party/stm32cube:hal_driver=@stm32f4xx_hal_driver//:hal_driver
build:stm32f429i --@stm32f4xx_hal_driver//:hal_config=//your/repo:hal_config
build:stm32f429i --@stm32f4xx_hal_driver//:cmsis_device=@cmsis_device_f4//:cmsis_device
build:stm32f429i --@stm32f4xx_hal_driver//:cmsis_core=@cmsis_core_f4
build:stm32f429i --@stm32f4xx_hal_driver//:cmsis_init=@cmsis_device_f4//:default_cmsis_init
.. code-block:: text
However, once `platform-based flags
<https://github.com/bazelbuild/proposals/blob/main/designs/2023-06-08-platform-based-flags.md>`_
are implemented in Bazel, it will be possible to set these flags directly
in the platform definition.
platform(
name = "...",
...
flags = flags_from_dict({
...
"@cmsis_core//:cc_defines": ":<your cc_defines target>",
"@stm32f4xx_hal_driver//:hal_config": "//targets/stm32f429i_disc1_stm32cube:hal_config",
"@pigweed//third_party/stm32cube:hal_driver": "@stm32f4xx_hal_driver//:hal_driver",
"@stm32f4xx_hal_driver//:cmsis_device": "@cmsis_device_f4//:cmsis_device",
"@stm32f4xx_hal_driver//:cmsis_init": "@cmsis_device_f4//:default_cmsis_init",
"@cmsis_device_f4//:cmsis_core": "@cmsis_core",
}),
)
.. [#] Although CMSIS core is shared by all MCU families, different CMSIS
device repositories may not be compatible with the same version of CMSIS
Expand All @@ -300,8 +300,9 @@ Upstream Pigweed modules that depend on the STM32Cube HAL, like
header ``stm32cube/stm32cube.h``. This header expects the family to be set
through a define of ``STM32CUBE_HEADER``. So, to use these Pigweed modules, you
need to set that define to the correct value (e.g., ``\"stm32f4xx.h\"``; note
the backslashes) as part of your build. This is most conveniently done through
``copts`` associated with the target platform.
the backslashes) as part of your build. This is most conveniently done via the
``defines`` attribute of a ``cc_library`` target which is then set as the
value of the ``@cmsis_core//:cc_defines`` label flag.

.. _module-pw_stm32cube_build-bazel-label-flags:

Expand All @@ -320,6 +321,11 @@ Points to the ``cc_library`` target providing a header with the HAL
configuration. Note that this header needs an appropriate, family-specific name
(e.g., ``stm32f4xx_hal_conf.h`` for the F4 family).

``@cmsis_core//:cc_defines``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This label flag should point to a `cc_library` target which adds `define`
entries for `STM32CUBE_HEADER` and the `STM32....` family (e.g. `STM32F429xx`).

``@cmsis_device//:cmsis_core``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This label flag should point to the repository containing the CMSIS core build
Expand Down
17 changes: 9 additions & 8 deletions targets/stm32f429i_disc1_stm32cube/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ platform(
"@rust_crates//:no_std",
],
flags = flags_from_dict(FREERTOS_FLAGS | {
"@cmsis_core//:cc_defines": ":cc_defines",
"@pigweed//pw_assert:check_backend": "//pw_assert_basic",
"@pigweed//pw_assert:check_backend_impl": "//pw_assert_basic:impl",
"@pigweed//pw_boot:backend": "//pw_boot_cortex_m",
Expand All @@ -72,14 +73,14 @@ platform(
"@pigweed//pw_unit_test:main": "//targets/stm32f429i_disc1_stm32cube:unit_test_app",
"@stm32f4xx_hal_driver//:hal_config": "//targets/stm32f429i_disc1_stm32cube:hal_config",
}),
# These flags should be added once
# https://github.com/bazelbuild/bazel/issues/22453
# is fixed.
#
# + [
# "--copt=\"-DSTM32CUBE_HEADER=\\\"stm32f4xx.h\\\"\"",
# "--copt=\"-DSTM32F429xx\"",
# ],
)

cc_library(
name = "cc_defines",
defines = [
"STM32CUBE_HEADER=\\\"stm32f4xx.h\\\"",
"STM32F429xx",
],
)

cc_library(
Expand Down
8 changes: 8 additions & 0 deletions third_party/stm32cube/cmsis_core.BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ cc_library(
"Include",
"Include/DSP/Include",
],
deps = [
":cc_defines",
],
)

label_flag(
name = "cc_defines",
build_setting_default = "@pigweed//pw_build:empty_cc_library",
)

0 comments on commit 03466a7

Please sign in to comment.