xref: /aosp_15_r20/external/pigweed/pw_stm32cube_build/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_stm32cube_build:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker==================
4*61c4878aSAndroid Build Coastguard Workerpw_stm32cube_build
5*61c4878aSAndroid Build Coastguard Worker==================
6*61c4878aSAndroid Build Coastguard WorkerThe ``pw_stm32cube_build`` module provides helper utilities for building a
7*61c4878aSAndroid Build Coastguard Workertarget with the stm32cube HAL and/or the stm32cube initialization code.
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard WorkerThe actual GN build files and headers live in ``third_party/stm32cube`` but
10*61c4878aSAndroid Build Coastguard Workerare documented here. The rationale for keeping the build files in `third_party`
11*61c4878aSAndroid Build Coastguard Workeris that code depending on stm32cube can clearly see that their dependency is on
12*61c4878aSAndroid Build Coastguard Workerthird party, not pigweed code.
13*61c4878aSAndroid Build Coastguard Worker
14*61c4878aSAndroid Build Coastguard Worker.. _module-pw_stm32cube_build-components:
15*61c4878aSAndroid Build Coastguard Worker
16*61c4878aSAndroid Build Coastguard Worker------------------------
17*61c4878aSAndroid Build Coastguard WorkerSTM32Cube MCU Components
18*61c4878aSAndroid Build Coastguard Worker------------------------
19*61c4878aSAndroid Build Coastguard WorkerEach stm32 product family (ex. F4, L5, etc.) has its own stm32cube libraries.
20*61c4878aSAndroid Build Coastguard WorkerThis integration depends on ST's 3 core  `MCU Components`_ instead of their
21*61c4878aSAndroid Build Coastguard Workermonolithic `MCU Package`. The components are the hal_driver, cmsis_core, and
22*61c4878aSAndroid Build Coastguard Workercmsis_device. All of these repos exist on `ST's GitHub page`_. Compatible
23*61c4878aSAndroid Build Coastguard Workerversion tags are specified on the ``README.md`` of each MCU component.
24*61c4878aSAndroid Build Coastguard Worker
25*61c4878aSAndroid Build Coastguard WorkerTo use Pigweed's STM32Cube integration, you will need to acquire the three
26*61c4878aSAndroid Build Coastguard Workercomponents. The details are build-system dependent.
27*61c4878aSAndroid Build Coastguard Worker
28*61c4878aSAndroid Build Coastguard Worker--------
29*61c4878aSAndroid Build Coastguard WorkerGN build
30*61c4878aSAndroid Build Coastguard Worker--------
31*61c4878aSAndroid Build Coastguard WorkerThe primary ``pw_source_set`` for this integration is
32*61c4878aSAndroid Build Coastguard Worker``$dir_pw_third_party/stm32cube:stm32cube``. This source set includes all of
33*61c4878aSAndroid Build Coastguard Workerthe HAL, init code, and templates, depending on the value of the `GN args`_.
34*61c4878aSAndroid Build Coastguard Worker
35*61c4878aSAndroid Build Coastguard WorkerDirectory setup
36*61c4878aSAndroid Build Coastguard Worker===============
37*61c4878aSAndroid Build Coastguard WorkerWithin a single directory, the following directory/file names are required.
38*61c4878aSAndroid Build Coastguard Worker
39*61c4878aSAndroid Build Coastguard Worker=============== =============================================
40*61c4878aSAndroid Build Coastguard WorkerDir/File Name     Description
41*61c4878aSAndroid Build Coastguard Worker=============== =============================================
42*61c4878aSAndroid Build Coastguard Workerhal_driver/       checkout of ``stm32{family}xx_hal_driver``
43*61c4878aSAndroid Build Coastguard Workercmsis_device/     checkout of ``cmsis_device_{family}``
44*61c4878aSAndroid Build Coastguard Workercmsis_core/       checkout of ``cmsis_core``
45*61c4878aSAndroid Build Coastguard Workerfiles.txt         list of files generated by `gen_file_list`_
46*61c4878aSAndroid Build Coastguard Worker=============== =============================================
47*61c4878aSAndroid Build Coastguard Worker
48*61c4878aSAndroid Build Coastguard Workerpw_package
49*61c4878aSAndroid Build Coastguard Worker----------
50*61c4878aSAndroid Build Coastguard WorkerThe stm32cube directory can alternatively be setup using ``pw_package``. This
51*61c4878aSAndroid Build Coastguard Workerwill automatically download compatible repos into the expected folders and
52*61c4878aSAndroid Build Coastguard Workergenerate the ``files.txt``.
53*61c4878aSAndroid Build Coastguard Worker
54*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
55*61c4878aSAndroid Build Coastguard Worker
56*61c4878aSAndroid Build Coastguard Worker   pw package install stm32cube_{family}
57*61c4878aSAndroid Build Coastguard Worker
58*61c4878aSAndroid Build Coastguard WorkerHeaders
59*61c4878aSAndroid Build Coastguard Worker=======
60*61c4878aSAndroid Build Coastguard Worker``$dir_pw_third_party/stm32cube:stm32cube`` contains the following primary
61*61c4878aSAndroid Build Coastguard Workerheaders that external targets / applications would care about.
62*61c4878aSAndroid Build Coastguard Worker
63*61c4878aSAndroid Build Coastguard Worker``{family}.h``
64*61c4878aSAndroid Build Coastguard Worker--------------
65*61c4878aSAndroid Build Coastguard Workerex. ``stm32f4xx.h``, ``stm32l5xx.h``
66*61c4878aSAndroid Build Coastguard Worker
67*61c4878aSAndroid Build Coastguard WorkerThis is the primary HAL header provided by stm32cube. It includes the entire
68*61c4878aSAndroid Build Coastguard WorkerHAL and all product specific defines.
69*61c4878aSAndroid Build Coastguard Worker
70*61c4878aSAndroid Build Coastguard Worker``stm32cube/stm32cube.h``
71*61c4878aSAndroid Build Coastguard Worker-------------------------
72*61c4878aSAndroid Build Coastguard WorkerThis is a convenience define provided by this integration. It simply includes
73*61c4878aSAndroid Build Coastguard Worker``{family}.h``.
74*61c4878aSAndroid Build Coastguard Worker
75*61c4878aSAndroid Build Coastguard WorkerThis is useful because there is a lot of commonality between the HAL's of the
76*61c4878aSAndroid Build Coastguard Workerdifferent stm32 families. Although the API's are not guaranteed to be
77*61c4878aSAndroid Build Coastguard Workercompatible, many basic API's often are (ex. GPIO, UART, etc.). This common
78*61c4878aSAndroid Build Coastguard Workerheader allows for stm32 family agnostic modules (ex. ``pw_sys_io_stm32``, which
79*61c4878aSAndroid Build Coastguard Workercould work with most, if not all families).
80*61c4878aSAndroid Build Coastguard Worker
81*61c4878aSAndroid Build Coastguard Worker``stm32cube/init.h``
82*61c4878aSAndroid Build Coastguard Worker--------------------
83*61c4878aSAndroid Build Coastguard WorkerAs described in the inject_init_ section, if you decide to use the built in
84*61c4878aSAndroid Build Coastguard Workerinit functionality, a pre main init function call, ``pw_stm32cube_Init()``, is
85*61c4878aSAndroid Build Coastguard Workerinjected into ST's startup scripts.
86*61c4878aSAndroid Build Coastguard Worker
87*61c4878aSAndroid Build Coastguard WorkerThis header contains the ``pw_stm32cube_Init()`` function declaration. It
88*61c4878aSAndroid Build Coastguard Workershould be included and implemented by target init code.
89*61c4878aSAndroid Build Coastguard Worker
90*61c4878aSAndroid Build Coastguard WorkerGN args
91*61c4878aSAndroid Build Coastguard Worker=======
92*61c4878aSAndroid Build Coastguard WorkerThe stm32cube GN build arguments are defined in
93*61c4878aSAndroid Build Coastguard Worker``$dir_pw_third_party/stm32cube/stm32cube.gni``.
94*61c4878aSAndroid Build Coastguard Worker
95*61c4878aSAndroid Build Coastguard Worker``dir_pw_third_party_stm32cube_xx``
96*61c4878aSAndroid Build Coastguard Worker-----------------------------------
97*61c4878aSAndroid Build Coastguard WorkerThese should be set to point to the stm32cube directory for each family that
98*61c4878aSAndroid Build Coastguard Workeryou need to build for. These are optional to set and are only provided for
99*61c4878aSAndroid Build Coastguard Workerconvenience if you need to build for multiple families in the same project.
100*61c4878aSAndroid Build Coastguard Worker
101*61c4878aSAndroid Build Coastguard Worker``dir_pw_third_party_stm32cube``
102*61c4878aSAndroid Build Coastguard Worker-----------------------------------
103*61c4878aSAndroid Build Coastguard WorkerThis needs to point to the stm32cube directory for the current build.
104*61c4878aSAndroid Build Coastguard Worker
105*61c4878aSAndroid Build Coastguard WorkerFor multi target projects, the standard practice to set this for each target:
106*61c4878aSAndroid Build Coastguard Worker
107*61c4878aSAndroid Build Coastguard Worker.. code-block:: text
108*61c4878aSAndroid Build Coastguard Worker
109*61c4878aSAndroid Build Coastguard Worker   dir_pw_third_party_stm32cube = dir_pw_third_party_stm32cube_f4
110*61c4878aSAndroid Build Coastguard Worker
111*61c4878aSAndroid Build Coastguard Worker
112*61c4878aSAndroid Build Coastguard Worker``pw_third_party_stm32cube_PRODUCT``
113*61c4878aSAndroid Build Coastguard Worker------------------------------------
114*61c4878aSAndroid Build Coastguard WorkerThe product specified in as much detail as possible.
115*61c4878aSAndroid Build Coastguard Workerex. ``stm32f429zit``, ``stm32l552ze``, ``stm32f207zg``, etc.
116*61c4878aSAndroid Build Coastguard Worker
117*61c4878aSAndroid Build Coastguard Worker``pw_third_party_stm32cube_CONFIG``
118*61c4878aSAndroid Build Coastguard Worker------------------------------------
119*61c4878aSAndroid Build Coastguard WorkerThe pw_source_set that provides ``stm32{family}xx_hal_conf.h``. The default
120*61c4878aSAndroid Build Coastguard Workeruses the in-tree ``stm32{family}xx_hal_conf_template.h``.
121*61c4878aSAndroid Build Coastguard Worker
122*61c4878aSAndroid Build Coastguard Worker``pw_third_party_stm32cube_TIMEBASE``
123*61c4878aSAndroid Build Coastguard Worker-------------------------------------
124*61c4878aSAndroid Build Coastguard WorkerThe pw_source_set containing the timebase. The default uses the in-tree
125*61c4878aSAndroid Build Coastguard Worker``stm32{family}xx_hal_timebase_tim_template.c``.
126*61c4878aSAndroid Build Coastguard Worker
127*61c4878aSAndroid Build Coastguard Worker``pw_third_party_stm32cube_CMSIS_INIT``
128*61c4878aSAndroid Build Coastguard Worker---------------------------------------
129*61c4878aSAndroid Build Coastguard WorkerThe pw_source_set containing the cmsis init logic. The default uses the in-tree
130*61c4878aSAndroid Build Coastguard Worker``system_stm32{family}xx.c``.
131*61c4878aSAndroid Build Coastguard Worker
132*61c4878aSAndroid Build Coastguard Worker``pw_third_party_stm32cube_CORE_INIT``
133*61c4878aSAndroid Build Coastguard Worker--------------------------------------
134*61c4878aSAndroid Build Coastguard Workerpw_source_set containing the core initialization logic. This normally includes
135*61c4878aSAndroid Build Coastguard Workera ``startup_stm32{...}.s`` + a dependent ``pw_linker_script``. The default
136*61c4878aSAndroid Build Coastguard Worker``core_init_template`` uses the upstream startup and linker script matching
137*61c4878aSAndroid Build Coastguard Worker``pw_third_party_stm32cube_PRODUCT``. If set to "", you must provide your own
138*61c4878aSAndroid Build Coastguard Workerlinker/startup logic somewhere else in the build.
139*61c4878aSAndroid Build Coastguard Worker
140*61c4878aSAndroid Build Coastguard Worker-----------------
141*61c4878aSAndroid Build Coastguard Workerstm32cube_builder
142*61c4878aSAndroid Build Coastguard Worker-----------------
143*61c4878aSAndroid Build Coastguard Worker``stm32cube_builder`` is utility that contains the backend scripts used by
144*61c4878aSAndroid Build Coastguard Worker``pw_package/stm32cube`` and the GN build scripts in ``third_party/stm32cube``
145*61c4878aSAndroid Build Coastguard Workerto interact with the stm32cube repos. You should only need to interact with
146*61c4878aSAndroid Build Coastguard Worker``stm32cube_builder`` directly if you are doing something custom, like
147*61c4878aSAndroid Build Coastguard Workerusing git submodules instead of pw_package, forking the stm32cube libraries,
148*61c4878aSAndroid Build Coastguard Workerinterfacing with a different build system, or using your own init.
149*61c4878aSAndroid Build Coastguard Worker
150*61c4878aSAndroid Build Coastguard Workergen_file_list
151*61c4878aSAndroid Build Coastguard Worker=============
152*61c4878aSAndroid Build Coastguard WorkerBuild systems like GN are unable to depend on arbitrary directories. Instead,
153*61c4878aSAndroid Build Coastguard Workerthey must have dependencies on specific files. The HAL for each stm32 product
154*61c4878aSAndroid Build Coastguard Workerfamily has different filenames, so ``files.txt`` was created as a workaround.
155*61c4878aSAndroid Build Coastguard Worker``files.txt`` is a basic list of all the files in the stm32cube directory with
156*61c4878aSAndroid Build Coastguard Workerrelavent file extensions. The build system only directly depends on this list,
157*61c4878aSAndroid Build Coastguard Workerwhich must be updated everytime the underlying repos are updated.
158*61c4878aSAndroid Build Coastguard Worker
159*61c4878aSAndroid Build Coastguard WorkerThis command will generate ``files.txt`` for correctly structured stm32cube
160*61c4878aSAndroid Build Coastguard Workerdirectories.
161*61c4878aSAndroid Build Coastguard Worker
162*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
163*61c4878aSAndroid Build Coastguard Worker
164*61c4878aSAndroid Build Coastguard Worker   stm32cube_builder gen_file_list /path/to/stm32cube_dir
165*61c4878aSAndroid Build Coastguard Worker
166*61c4878aSAndroid Build Coastguard Workerfind_files
167*61c4878aSAndroid Build Coastguard Worker==========
168*61c4878aSAndroid Build Coastguard WorkerWithin each stm32 family, there are specific products. Although most of the
169*61c4878aSAndroid Build Coastguard WorkerHAL is common between products, the init code is almost always different.
170*61c4878aSAndroid Build Coastguard Worker``find_files`` looks for all of the files relevant to a particular product
171*61c4878aSAndroid Build Coastguard Workerwithin a stm32cube directory.
172*61c4878aSAndroid Build Coastguard Worker
173*61c4878aSAndroid Build Coastguard WorkerThe product string should be specified in as much detail as possible because
174*61c4878aSAndroid Build Coastguard Workerthere are sometimes different defines or init code for submembers of products.
175*61c4878aSAndroid Build Coastguard Worker
176*61c4878aSAndroid Build Coastguard WorkerEx. ``stm32f412cx``, ``stm32f412rx``, ``stm32f412vx``, and ``stm32f412zx`` all
177*61c4878aSAndroid Build Coastguard Workerhave different init logic, while all ``stm32f439xx`` have the same init.
178*61c4878aSAndroid Build Coastguard Worker
179*61c4878aSAndroid Build Coastguard Worker``find_files`` only ever looks for init (linker + startup scripts) if the
180*61c4878aSAndroid Build Coastguard Worker``--init`` flag is provided.
181*61c4878aSAndroid Build Coastguard Worker
182*61c4878aSAndroid Build Coastguard WorkerThe output is currently only provided in the GN 'scope' format to stdout.
183*61c4878aSAndroid Build Coastguard WorkerThe following variables are output: ``family``, ``product_define``,
184*61c4878aSAndroid Build Coastguard Worker``sources``, ``headers``, ``include_dirs``, and the following three if
185*61c4878aSAndroid Build Coastguard Worker``--init`` is specified: ``startup``, ``gcc_linker``, ``iar_linker``.
186*61c4878aSAndroid Build Coastguard Worker
187*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
188*61c4878aSAndroid Build Coastguard Worker
189*61c4878aSAndroid Build Coastguard Worker   stm32cube_builder find_files /path/to/stm32cube_dir stm32{family}{product} [--init]
190*61c4878aSAndroid Build Coastguard Worker
191*61c4878aSAndroid Build Coastguard Workerinject_init
192*61c4878aSAndroid Build Coastguard Worker=============
193*61c4878aSAndroid Build Coastguard WorkerST provides init assembly files for every product in ``cmsis_device``. This is
194*61c4878aSAndroid Build Coastguard Workerhelpful for getting up and running quickly, but they directly call into
195*61c4878aSAndroid Build Coastguard Worker``main()`` before initializing the hardware / peripherals. This is because they
196*61c4878aSAndroid Build Coastguard Workerexpect to do that initialization in ``main()``, then call into the user
197*61c4878aSAndroid Build Coastguard Workerapplication. Upstream Pigweed unit tests expect at least ``sys_io`` to be
198*61c4878aSAndroid Build Coastguard Workerinitialized before ``main()`` is called.
199*61c4878aSAndroid Build Coastguard Worker
200*61c4878aSAndroid Build Coastguard WorkerThis command injects a call to ``pw_stm32cube_Init()`` immediately before the
201*61c4878aSAndroid Build Coastguard Workercall to ``main()``. This function should be implemented by the target to do
202*61c4878aSAndroid Build Coastguard Workerwhatever init is necessary (hal init, sys_io init, clock configuration, etc.)
203*61c4878aSAndroid Build Coastguard Worker
204*61c4878aSAndroid Build Coastguard Worker``inject_init`` takes in an ST assembly script and outputs the same script with
205*61c4878aSAndroid Build Coastguard Workerthe pre main init call. The output is printed to stdout, or to the specified
206*61c4878aSAndroid Build Coastguard Worker``--out-startup-path``.
207*61c4878aSAndroid Build Coastguard Worker
208*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
209*61c4878aSAndroid Build Coastguard Worker
210*61c4878aSAndroid Build Coastguard Worker   stm32cube_builder inject_init /path/to/startup.s [--out-startup-path /path/to/new_startup.s]
211*61c4878aSAndroid Build Coastguard Worker
212*61c4878aSAndroid Build Coastguard Workericf_to_ld
213*61c4878aSAndroid Build Coastguard Worker=========
214*61c4878aSAndroid Build Coastguard WorkerPigweed primarily uses GCC for its Cortex-M builds. However, ST only provides
215*61c4878aSAndroid Build Coastguard WorkerIAR linker scripts in ``cmsis_device`` for most product families. This script
216*61c4878aSAndroid Build Coastguard Workerconverts from ST's IAR linker script format (.icf) to a basic GCC linker
217*61c4878aSAndroid Build Coastguard Workerscript (.ld). This is a very basic converter that only works with exactly how
218*61c4878aSAndroid Build Coastguard WorkerST currently formats their .icf files.
219*61c4878aSAndroid Build Coastguard Worker
220*61c4878aSAndroid Build Coastguard WorkerThe output .ld files only contain ``RAM`` and ``FLASH`` sections. Anything more
221*61c4878aSAndroid Build Coastguard Workercomplicated will require hand customized .ld scripts. Output is printed to
222*61c4878aSAndroid Build Coastguard Workerstdout or the specified ``--ld-path``.
223*61c4878aSAndroid Build Coastguard Worker
224*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
225*61c4878aSAndroid Build Coastguard Worker
226*61c4878aSAndroid Build Coastguard Worker   stm32cube_builder inject_init /path/to/iar_linker.icf [--ld-path /path/to/gcc_linker.ld]
227*61c4878aSAndroid Build Coastguard Worker
228*61c4878aSAndroid Build Coastguard Worker.. _`MCU Components`: https://github.com/STMicroelectronics/STM32Cube_MCU_Overall_Offer#stm32cube-mcu-components
229*61c4878aSAndroid Build Coastguard Worker.. _`ST's GitHub page`: https://github.com/STMicroelectronics
230*61c4878aSAndroid Build Coastguard Worker
231*61c4878aSAndroid Build Coastguard Worker.. _module-pw_stm32cube_build-bazel:
232*61c4878aSAndroid Build Coastguard Worker
233*61c4878aSAndroid Build Coastguard Worker-----------
234*61c4878aSAndroid Build Coastguard WorkerBazel build
235*61c4878aSAndroid Build Coastguard Worker-----------
236*61c4878aSAndroid Build Coastguard Worker
237*61c4878aSAndroid Build Coastguard WorkerExternal dependencies
238*61c4878aSAndroid Build Coastguard Worker=====================
239*61c4878aSAndroid Build Coastguard WorkerAs discussed above in :ref:`module-pw_stm32cube_build-components`, you need the
240*61c4878aSAndroid Build Coastguard Workerthree STM32Cube Components for your MCU family to use Pigweed's STM32Cube
241*61c4878aSAndroid Build Coastguard Workerintegration. You need to add the following git repositories to your workspace:
242*61c4878aSAndroid Build Coastguard Worker
243*61c4878aSAndroid Build Coastguard Worker*  ``stm32{family}xx_hal_driver`` (e.g., `HAL driver repo for the F4 family
244*61c4878aSAndroid Build Coastguard Worker   <https://github.com/STMicroelectronics/stm32f4xx_hal_driver/>`_). We provide
245*61c4878aSAndroid Build Coastguard Worker   a Bazel build file which works for any family at
246*61c4878aSAndroid Build Coastguard Worker   ``@pigweed//third_party/stm32cube/stm32_hal_driver.BUILD.bazel``. Below,
247*61c4878aSAndroid Build Coastguard Worker   we'll refer to this repository as ``@hal_driver``.
248*61c4878aSAndroid Build Coastguard Worker*  ``cmsis_device_{family}`` (e.g., `CMSIS device repo for the F4 family
249*61c4878aSAndroid Build Coastguard Worker   <https://github.com/STMicroelectronics/cmsis_device_f4>`_). We provide a
250*61c4878aSAndroid Build Coastguard Worker   Bazel build file which works for any family at
251*61c4878aSAndroid Build Coastguard Worker   ``@pigweed//third_party/stm32cube/cmsis_device.BUILD.bazel``. Below, we'll
252*61c4878aSAndroid Build Coastguard Worker   refer to this repository as ``@cmsis_device``.
253*61c4878aSAndroid Build Coastguard Worker*  ``cmsis_core``, at https://github.com/STMicroelectronics/cmsis_core. We
254*61c4878aSAndroid Build Coastguard Worker   provide a Bazel build file for it at
255*61c4878aSAndroid Build Coastguard Worker   ``@pigweed//third_party/stm32cube/cmsis_core.BUILD.bazel``. Below, we'll
256*61c4878aSAndroid Build Coastguard Worker   refer to this repository as ``@cmsis_core``.
257*61c4878aSAndroid Build Coastguard Worker
258*61c4878aSAndroid Build Coastguard Worker.. _module-pw_stm32cube_build-bazel-multifamily:
259*61c4878aSAndroid Build Coastguard Worker
260*61c4878aSAndroid Build Coastguard WorkerBuilding for more than one MCU family
261*61c4878aSAndroid Build Coastguard Worker-------------------------------------
262*61c4878aSAndroid Build Coastguard WorkerDifferent MCU families require different HAL driver and CMSIS device packages
263*61c4878aSAndroid Build Coastguard Workerfrom STM. So, if your project builds firmware for more than one MCU family, you
264*61c4878aSAndroid Build Coastguard Workerwill need to configure separate sets of the three [#]_ STM repositories for each MCU
265*61c4878aSAndroid Build Coastguard Workerfamily. To do so,
266*61c4878aSAndroid Build Coastguard Worker
267*61c4878aSAndroid Build Coastguard Worker1.  Add the appropriate repositories to your WORKSPACE under different names,
268*61c4878aSAndroid Build Coastguard Worker    eg. ``@stm32f4xx_hal_driver`` and ``@stm32h7xx_hal_driver``.
269*61c4878aSAndroid Build Coastguard Worker2.  Set the corresponding :ref:`module-pw_stm32cube_build-bazel-label-flags` as
270*61c4878aSAndroid Build Coastguard Worker    part of the platform definition for your embedded target platforms.
271*61c4878aSAndroid Build Coastguard Worker
272*61c4878aSAndroid Build Coastguard Worker.. code-block:: text
273*61c4878aSAndroid Build Coastguard Worker
274*61c4878aSAndroid Build Coastguard Worker   platform(
275*61c4878aSAndroid Build Coastguard Worker     name = "...",
276*61c4878aSAndroid Build Coastguard Worker     ...
277*61c4878aSAndroid Build Coastguard Worker     flags = flags_from_dict({
278*61c4878aSAndroid Build Coastguard Worker       ...
279*61c4878aSAndroid Build Coastguard Worker       "@cmsis_core//:cc_defines": ":<your cc_defines target>",
280*61c4878aSAndroid Build Coastguard Worker       "@stm32f4xx_hal_driver//:hal_config": "//targets/stm32f429i_disc1_stm32cube:hal_config",
281*61c4878aSAndroid Build Coastguard Worker       "@pigweed//third_party/stm32cube:hal_driver": "@stm32f4xx_hal_driver//:hal_driver",
282*61c4878aSAndroid Build Coastguard Worker       "@stm32f4xx_hal_driver//:cmsis_device": "@cmsis_device_f4//:cmsis_device",
283*61c4878aSAndroid Build Coastguard Worker       "@stm32f4xx_hal_driver//:cmsis_init": "@cmsis_device_f4//:default_cmsis_init",
284*61c4878aSAndroid Build Coastguard Worker       "@cmsis_device_f4//:cmsis_core": "@cmsis_core",
285*61c4878aSAndroid Build Coastguard Worker     }),
286*61c4878aSAndroid Build Coastguard Worker   )
287*61c4878aSAndroid Build Coastguard Worker
288*61c4878aSAndroid Build Coastguard Worker.. [#] Although CMSIS core is shared by all MCU families, different CMSIS
289*61c4878aSAndroid Build Coastguard Worker   device repositories may not be compatible with the same version of CMSIS
290*61c4878aSAndroid Build Coastguard Worker   core. In this case, you may need to use separate versions of CMSIS core,
291*61c4878aSAndroid Build Coastguard Worker   too.
292*61c4878aSAndroid Build Coastguard Worker
293*61c4878aSAndroid Build Coastguard WorkerDefines
294*61c4878aSAndroid Build Coastguard Worker=======
295*61c4878aSAndroid Build Coastguard Worker
296*61c4878aSAndroid Build Coastguard Worker``STM32CUBE_HEADER``
297*61c4878aSAndroid Build Coastguard Worker--------------------
298*61c4878aSAndroid Build Coastguard WorkerUpstream Pigweed modules that depend on the STM32Cube HAL, like
299*61c4878aSAndroid Build Coastguard Worker:ref:`module-pw_sys_io_stm32cube`, include the HAL through the family-agnostic
300*61c4878aSAndroid Build Coastguard Workerheader ``stm32cube/stm32cube.h``. This header expects the family to be set
301*61c4878aSAndroid Build Coastguard Workerthrough a define of ``STM32CUBE_HEADER``. So, to use these Pigweed modules, you
302*61c4878aSAndroid Build Coastguard Workerneed to set that define to the correct value (e.g., ``\"stm32f4xx.h\"``; note
303*61c4878aSAndroid Build Coastguard Workerthe backslashes) as part of your build. This is most conveniently done via the
304*61c4878aSAndroid Build Coastguard Worker``defines`` attribute of a ``cc_library`` target which is then set as the
305*61c4878aSAndroid Build Coastguard Workervalue of the ``@cmsis_core//:cc_defines`` label flag.
306*61c4878aSAndroid Build Coastguard Worker
307*61c4878aSAndroid Build Coastguard Worker.. _module-pw_stm32cube_build-bazel-label-flags:
308*61c4878aSAndroid Build Coastguard Worker
309*61c4878aSAndroid Build Coastguard WorkerLabel flags
310*61c4878aSAndroid Build Coastguard Worker===========
311*61c4878aSAndroid Build Coastguard WorkerRequired
312*61c4878aSAndroid Build Coastguard Worker--------
313*61c4878aSAndroid Build Coastguard Worker``//third_party/stm32cube:hal_driver``
314*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
315*61c4878aSAndroid Build Coastguard WorkerThis label_flag should point to the repository containing the HAL driver.
316*61c4878aSAndroid Build Coastguard WorkerWe'll refer to this repository as ``@hal_driver`` below.
317*61c4878aSAndroid Build Coastguard Worker
318*61c4878aSAndroid Build Coastguard Worker``@hal_driver//:hal_config``
319*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^
320*61c4878aSAndroid Build Coastguard WorkerPoints to the ``cc_library`` target providing a header with the HAL
321*61c4878aSAndroid Build Coastguard Workerconfiguration. Note that this header needs an appropriate, family-specific name
322*61c4878aSAndroid Build Coastguard Worker(e.g., ``stm32f4xx_hal_conf.h`` for the F4 family).
323*61c4878aSAndroid Build Coastguard Worker
324*61c4878aSAndroid Build Coastguard Worker``@cmsis_core//:cc_defines``
325*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^
326*61c4878aSAndroid Build Coastguard WorkerThis label flag should point to a `cc_library` target which adds `define`
327*61c4878aSAndroid Build Coastguard Workerentries for `STM32CUBE_HEADER` and the `STM32....` family (e.g. `STM32F429xx`).
328*61c4878aSAndroid Build Coastguard Worker
329*61c4878aSAndroid Build Coastguard Worker``@cmsis_device//:cmsis_core``
330*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
331*61c4878aSAndroid Build Coastguard WorkerThis label flag should point to the repository containing the CMSIS core build
332*61c4878aSAndroid Build Coastguard Workertarget (``@cmsis_core``).
333*61c4878aSAndroid Build Coastguard Worker
334*61c4878aSAndroid Build Coastguard Worker``@hal_driver//:cmsis_device``
335*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
336*61c4878aSAndroid Build Coastguard WorkerThis label flag should point to the repository containing the CMSIS device
337*61c4878aSAndroid Build Coastguard Workerbuild target. (``@cmsis_device``).
338*61c4878aSAndroid Build Coastguard Worker
339*61c4878aSAndroid Build Coastguard Worker``@hal_driver//:cmsis_init``
340*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
341*61c4878aSAndroid Build Coastguard WorkerThis label flag should point to the CMSIS initialization code
342*61c4878aSAndroid Build Coastguard Worker``@cmsis_device://default_cmsis_init``, the ``system_{family}.c`` template
343*61c4878aSAndroid Build Coastguard Workerprovided in the CMSIS device repository, is a good starting choice.
344*61c4878aSAndroid Build Coastguard Worker
345*61c4878aSAndroid Build Coastguard WorkerOptional
346*61c4878aSAndroid Build Coastguard Worker--------
347*61c4878aSAndroid Build Coastguard WorkerThese label flags can be used to further customize the behavior of STM32Cube.
348*61c4878aSAndroid Build Coastguard Worker
349*61c4878aSAndroid Build Coastguard Worker
350*61c4878aSAndroid Build Coastguard Worker``@hal_driver//:timebase``
351*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^
352*61c4878aSAndroid Build Coastguard WorkerThis label flag should point to a ``cc_library`` providing a timebase
353*61c4878aSAndroid Build Coastguard Workerimplementation. By default it points to the template included with STM's HAL
354*61c4878aSAndroid Build Coastguard Workerrepository.
355