diff --git a/.bazelrc b/.bazelrc index 332256603c..f3b0b7ac23 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/pw_stm32cube_build/docs.rst b/pw_stm32cube_build/docs.rst index 5fcb4bd1ac..2190156297 100644 --- a/pw_stm32cube_build/docs.rst +++ b/pw_stm32cube_build/docs.rst @@ -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 - `_, 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 - `_ - 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": ":", + "@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 @@ -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: @@ -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 diff --git a/targets/stm32f429i_disc1_stm32cube/BUILD.bazel b/targets/stm32f429i_disc1_stm32cube/BUILD.bazel index d03ef1f7ef..b8799dd8eb 100644 --- a/targets/stm32f429i_disc1_stm32cube/BUILD.bazel +++ b/targets/stm32f429i_disc1_stm32cube/BUILD.bazel @@ -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", @@ -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( diff --git a/third_party/stm32cube/cmsis_core.BUILD.bazel b/third_party/stm32cube/cmsis_core.BUILD.bazel index 083434f802..f6e9713705 100644 --- a/third_party/stm32cube/cmsis_core.BUILD.bazel +++ b/third_party/stm32cube/cmsis_core.BUILD.bazel @@ -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", )