xref: /aosp_15_r20/external/pigweed/pw_build_mcuxpresso/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_build_mcuxpresso:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker===================
4*61c4878aSAndroid Build Coastguard Workerpw_build_mcuxpresso
5*61c4878aSAndroid Build Coastguard Worker===================
6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module::
7*61c4878aSAndroid Build Coastguard Worker   :name: pw_build_mcuxpresso
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard WorkerThe ``pw_build_mcuxpresso`` module provides helper utilities for building a
10*61c4878aSAndroid Build Coastguard Workertarget based on an NXP MCUXpresso SDK.
11*61c4878aSAndroid Build Coastguard Worker
12*61c4878aSAndroid Build Coastguard WorkerThe GN build files live in ``third_party/mcuxpresso`` but are documented here.
13*61c4878aSAndroid Build Coastguard WorkerThe rationale for keeping the build files in ``third_party`` is that code
14*61c4878aSAndroid Build Coastguard Workerdepending on an MCUXpresso SDK can clearly see that their dependency is on
15*61c4878aSAndroid Build Coastguard Workerthird party, not pigweed code.
16*61c4878aSAndroid Build Coastguard Worker
17*61c4878aSAndroid Build Coastguard Worker-----------------------
18*61c4878aSAndroid Build Coastguard WorkerUsing an MCUXpresso SDK
19*61c4878aSAndroid Build Coastguard Worker-----------------------
20*61c4878aSAndroid Build Coastguard WorkerAn MCUXpresso SDK consists of a number of components, each of which has a set
21*61c4878aSAndroid Build Coastguard Workerof sources, headers, preprocessor defines, and dependencies on other
22*61c4878aSAndroid Build Coastguard Workercomponents. These are all described in an XML "manifest" file included in the
23*61c4878aSAndroid Build Coastguard WorkerSDK package.
24*61c4878aSAndroid Build Coastguard Worker
25*61c4878aSAndroid Build Coastguard WorkerTo use the SDK within a Pigweed project, the set of components you need must be
26*61c4878aSAndroid Build Coastguard Workercombined into a library that you can depend on. This library will include all of
27*61c4878aSAndroid Build Coastguard Workerthe sources and headers, along with necessary preprocessor defines, for those
28*61c4878aSAndroid Build Coastguard Workercomponents and their dependencies.
29*61c4878aSAndroid Build Coastguard Worker
30*61c4878aSAndroid Build Coastguard WorkerOptional components
31*61c4878aSAndroid Build Coastguard Worker===================
32*61c4878aSAndroid Build Coastguard WorkerIncluding components will include all of their required dependencies. Where the
33*61c4878aSAndroid Build Coastguard Workercomponents you include have optional dependencies, they must be satisfied by the
34*61c4878aSAndroid Build Coastguard Workerset of components you include otherwise the library generation will fail with an
35*61c4878aSAndroid Build Coastguard Workererror.
36*61c4878aSAndroid Build Coastguard Worker
37*61c4878aSAndroid Build Coastguard WorkerExcluding components
38*61c4878aSAndroid Build Coastguard Worker====================
39*61c4878aSAndroid Build Coastguard WorkerComponents can be excluded from the generated source set, for example to
40*61c4878aSAndroid Build Coastguard Workersuppress errors about optional dependencies your project does not need, or to
41*61c4878aSAndroid Build Coastguard Workerprevent an unwanted component dependency from being introduced into your
42*61c4878aSAndroid Build Coastguard Workerproject.
43*61c4878aSAndroid Build Coastguard Worker
44*61c4878aSAndroid Build Coastguard Workermcuxpresso_builder
45*61c4878aSAndroid Build Coastguard Worker==================
46*61c4878aSAndroid Build Coastguard Worker``mcuxpresso_builder`` is a utility installed into the environment that is used
47*61c4878aSAndroid Build Coastguard Workerby the GN build scripts in ``third_party/mcuxpresso``, or directly by you to
48*61c4878aSAndroid Build Coastguard Workergenerate rules for the Bazel build.
49*61c4878aSAndroid Build Coastguard Worker
50*61c4878aSAndroid Build Coastguard WorkerUsage is documented for each build system in the relevant section.
51*61c4878aSAndroid Build Coastguard Worker
52*61c4878aSAndroid Build Coastguard Worker------------
53*61c4878aSAndroid Build Coastguard WorkerThe GN build
54*61c4878aSAndroid Build Coastguard Worker------------
55*61c4878aSAndroid Build Coastguard WorkerUsing an MCUxpresso SDK within a Pigweed project that uses the GN Build system
56*61c4878aSAndroid Build Coastguard Workerinvolves the creation of one or more ``pw_source_set`` targets you can depend on
57*61c4878aSAndroid Build Coastguard Workerin your executable targets.
58*61c4878aSAndroid Build Coastguard Worker
59*61c4878aSAndroid Build Coastguard WorkerThese source sets sets are defined using the ``pw_mcuxpresso_sdk`` template.
60*61c4878aSAndroid Build Coastguard WorkerProvide the path to the ``manifest`` XML, along with the names of the components
61*61c4878aSAndroid Build Coastguard Workeryou wish to ``include``.
62*61c4878aSAndroid Build Coastguard Worker
63*61c4878aSAndroid Build Coastguard WorkerFor boards with multiple cores, pass the specific core to filter components for
64*61c4878aSAndroid Build Coastguard Workerin ``device_core``.
65*61c4878aSAndroid Build Coastguard Worker
66*61c4878aSAndroid Build Coastguard Worker.. code-block:: text
67*61c4878aSAndroid Build Coastguard Worker
68*61c4878aSAndroid Build Coastguard Worker   import("$dir_pw_third_party/mcuxpresso/mcuxpresso.gni")
69*61c4878aSAndroid Build Coastguard Worker
70*61c4878aSAndroid Build Coastguard Worker   pw_mcuxpresso_sdk("sample_project_sdk") {
71*61c4878aSAndroid Build Coastguard Worker     manifest = "$dir_pw_third_party/mcuxpresso/evkmimxrt595/EVK-MIMXRT595_manifest_v3_13.xml"
72*61c4878aSAndroid Build Coastguard Worker     include = [
73*61c4878aSAndroid Build Coastguard Worker       "component.serial_manager_uart.MIMXRT595S",
74*61c4878aSAndroid Build Coastguard Worker       "project_template.evkmimxrt595.MIMXRT595S",
75*61c4878aSAndroid Build Coastguard Worker       "utility.debug_console.MIMXRT595S",
76*61c4878aSAndroid Build Coastguard Worker     ]
77*61c4878aSAndroid Build Coastguard Worker     device_core = "cm33_MIMXRT595S"
78*61c4878aSAndroid Build Coastguard Worker   }
79*61c4878aSAndroid Build Coastguard Worker
80*61c4878aSAndroid Build Coastguard Worker   pw_executable("hello_world") {
81*61c4878aSAndroid Build Coastguard Worker     sources = [ "hello_world.cc" ]
82*61c4878aSAndroid Build Coastguard Worker     deps = [ ":sample_project_sdk" ]
83*61c4878aSAndroid Build Coastguard Worker   }
84*61c4878aSAndroid Build Coastguard Worker
85*61c4878aSAndroid Build Coastguard WorkerTo exclude components, provide the list to ``exclude`` as an argument to the
86*61c4878aSAndroid Build Coastguard Workertemplate. For example to replace the FreeRTOS kernel bundled with the MCUXpresso
87*61c4878aSAndroid Build Coastguard WorkerSDK with the Pigweed third-party target:
88*61c4878aSAndroid Build Coastguard Worker
89*61c4878aSAndroid Build Coastguard Worker.. code-block:: text
90*61c4878aSAndroid Build Coastguard Worker
91*61c4878aSAndroid Build Coastguard Worker   pw_mcuxpresso_sdk("freertos_project_sdk") {
92*61c4878aSAndroid Build Coastguard Worker     // manifest and includes ommitted for clarity
93*61c4878aSAndroid Build Coastguard Worker     exclude = [ "middleware.freertos-kernel.MIMXRT595S" ]
94*61c4878aSAndroid Build Coastguard Worker     public_deps = [ "$dir_pw_third_party/freertos" ]
95*61c4878aSAndroid Build Coastguard Worker   }
96*61c4878aSAndroid Build Coastguard Worker
97*61c4878aSAndroid Build Coastguard WorkerIntroducing dependencies
98*61c4878aSAndroid Build Coastguard Worker========================
99*61c4878aSAndroid Build Coastguard WorkerAs seen above, the generated source set can have dependencies added by passing
100*61c4878aSAndroid Build Coastguard Workerthe ``public_deps`` (or ``deps``) arguments to the template.
101*61c4878aSAndroid Build Coastguard Worker
102*61c4878aSAndroid Build Coastguard WorkerYou can also pass the ``allow_circular_includes_from``, ``configs``, and
103*61c4878aSAndroid Build Coastguard Worker``public_configs`` arguments to augment the generated source set.
104*61c4878aSAndroid Build Coastguard Worker
105*61c4878aSAndroid Build Coastguard WorkerFor example it is very common to replace the ``project_template`` component with
106*61c4878aSAndroid Build Coastguard Workera source set of your own that provides modified copies of the files from the
107*61c4878aSAndroid Build Coastguard WorkerSDK.
108*61c4878aSAndroid Build Coastguard Worker
109*61c4878aSAndroid Build Coastguard WorkerTo resolve circular dependencies, in addition to the generated source set, two
110*61c4878aSAndroid Build Coastguard Workerconfigs named with the ``__defines`` and ``__includes`` suffixes on the template
111*61c4878aSAndroid Build Coastguard Workername are generated, to provide the preprocessor defines and include paths that
112*61c4878aSAndroid Build Coastguard Workerthe source set uses.
113*61c4878aSAndroid Build Coastguard Worker
114*61c4878aSAndroid Build Coastguard Worker.. code-block:: text
115*61c4878aSAndroid Build Coastguard Worker
116*61c4878aSAndroid Build Coastguard Worker   pw_mcuxpresso_sdk("my_project_sdk") {
117*61c4878aSAndroid Build Coastguard Worker     manifest = "$dir_pw_third_party/mcuxpresso/evkmimxrt595/EVK-MIMXRT595_manifest_v3_13.xml"
118*61c4878aSAndroid Build Coastguard Worker     include = [
119*61c4878aSAndroid Build Coastguard Worker       "component.serial_manager_uart.MIMXRT595S",
120*61c4878aSAndroid Build Coastguard Worker       "utility.debug_console.MIMXRT595S",
121*61c4878aSAndroid Build Coastguard Worker     ]
122*61c4878aSAndroid Build Coastguard Worker     public_deps = [ ":my_project_config" ]
123*61c4878aSAndroid Build Coastguard Worker     allow_circular_includes_from = [ ":my_project_config" ]
124*61c4878aSAndroid Build Coastguard Worker   }
125*61c4878aSAndroid Build Coastguard Worker
126*61c4878aSAndroid Build Coastguard Worker   pw_source_set("my_project_config") {
127*61c4878aSAndroid Build Coastguard Worker     sources = [ "board.c", "clock_config.c", "pin_mux.c" ]
128*61c4878aSAndroid Build Coastguard Worker     public = [ "board.h", "clock_config.h", "pin_mux.h "]
129*61c4878aSAndroid Build Coastguard Worker     public_configs = [
130*61c4878aSAndroid Build Coastguard Worker       ":my_project_sdk__defines",
131*61c4878aSAndroid Build Coastguard Worker       ":my_project_sdk__includes"
132*61c4878aSAndroid Build Coastguard Worker     ]
133*61c4878aSAndroid Build Coastguard Worker   }
134*61c4878aSAndroid Build Coastguard Worker
135*61c4878aSAndroid Build Coastguard Workermcuxpresso_builder
136*61c4878aSAndroid Build Coastguard Worker==================
137*61c4878aSAndroid Build Coastguard WorkerFor the GN build, this utility is invoked by the ``pw_mcuxpresso_sdk`` template.
138*61c4878aSAndroid Build Coastguard WorkerYou should only need to interact with ``mcuxpresso_builder`` directly if you are
139*61c4878aSAndroid Build Coastguard Workerdoing something custom.
140*61c4878aSAndroid Build Coastguard Worker
141*61c4878aSAndroid Build Coastguard WorkerThe ``gn`` subcommand outputs a GN scope describing the result of expanding the
142*61c4878aSAndroid Build Coastguard Workerset of included and excluded components.
143*61c4878aSAndroid Build Coastguard Worker
144*61c4878aSAndroid Build Coastguard WorkerThe ``--prefix`` option specifies the GN location of the SDK files.
145*61c4878aSAndroid Build Coastguard Worker
146*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
147*61c4878aSAndroid Build Coastguard Worker
148*61c4878aSAndroid Build Coastguard Worker   mcuxpresso_builder gn /path/to/manifest.xml \
149*61c4878aSAndroid Build Coastguard Worker       --include project_template.evkmimxrt595.MIMXRT595S \
150*61c4878aSAndroid Build Coastguard Worker       --include utility.debug_console.MIMXRT595S \
151*61c4878aSAndroid Build Coastguard Worker       --include component.serial_manager_uart.MIMXRT595S \
152*61c4878aSAndroid Build Coastguard Worker       --exclude middleware.freertos-kernel.MIMXRT595S \
153*61c4878aSAndroid Build Coastguard Worker       --device-core cm33_MIMXRT595S \
154*61c4878aSAndroid Build Coastguard Worker       --prefix //path/to/sdk
155*61c4878aSAndroid Build Coastguard Worker
156*61c4878aSAndroid Build Coastguard Worker---------------
157*61c4878aSAndroid Build Coastguard WorkerThe Bazel build
158*61c4878aSAndroid Build Coastguard Worker---------------
159*61c4878aSAndroid Build Coastguard WorkerTo use an MCUxpresso SDK within a Pigweed project that uses tha Bazel build
160*61c4878aSAndroid Build Coastguard Workersystem, you must use the ``mcuxpresso_builder`` tool directly and place its
161*61c4878aSAndroid Build Coastguard Workeroutput in ``BUILD`` or ``BUILD.bazel`` files yourself.
162*61c4878aSAndroid Build Coastguard Worker
163*61c4878aSAndroid Build Coastguard WorkerProvide the path to the manifest XML, the ``--name`` of the ``cc_library`` to
164*61c4878aSAndroid Build Coastguard Workercreate, along with the names of the components you wish to ``--include`` or
165*61c4878aSAndroid Build Coastguard Worker``--exclude``.
166*61c4878aSAndroid Build Coastguard Worker
167*61c4878aSAndroid Build Coastguard Worker.. code-block:: bash
168*61c4878aSAndroid Build Coastguard Worker
169*61c4878aSAndroid Build Coastguard Worker   mcuxpresso_builder bazel /path/to/manifest.xml \
170*61c4878aSAndroid Build Coastguard Worker       --name example_sdk \
171*61c4878aSAndroid Build Coastguard Worker       --include project_template.evkmimxrt595.MIMXRT595S \
172*61c4878aSAndroid Build Coastguard Worker       --include utility.debug_console.MIMXRT595S \
173*61c4878aSAndroid Build Coastguard Worker       --include component.serial_manager_uart.MIMXRT595S \
174*61c4878aSAndroid Build Coastguard Worker       --exclude middleware.freertos-kernel.MIMXRT595S \
175*61c4878aSAndroid Build Coastguard Worker       --device-core cm33_MIMXRT595S
176*61c4878aSAndroid Build Coastguard Worker
177*61c4878aSAndroid Build Coastguard Worker
178*61c4878aSAndroid Build Coastguard WorkerPlace the resulting output in a ``BUILD`` file, and then modify your
179*61c4878aSAndroid Build Coastguard Worker``WORKSPACE`` to associate this build file with the path to the MCUxpresso SDK
180*61c4878aSAndroid Build Coastguard Workercheckout.
181*61c4878aSAndroid Build Coastguard Worker
182*61c4878aSAndroid Build Coastguard Worker.. code-block:: python
183*61c4878aSAndroid Build Coastguard Worker
184*61c4878aSAndroid Build Coastguard Worker   new_local_repository(
185*61c4878aSAndroid Build Coastguard Worker       name = "mcuxpresso_sdk",
186*61c4878aSAndroid Build Coastguard Worker       build_file = "//third_party/mcuxpresso_sdk/BUILD",
187*61c4878aSAndroid Build Coastguard Worker       path = "third_party/evkmimxrt595/sdk",
188*61c4878aSAndroid Build Coastguard Worker   )
189*61c4878aSAndroid Build Coastguard Worker
190*61c4878aSAndroid Build Coastguard WorkerTo add other dependencies, compiler definitions, etc. it is recommended that
191*61c4878aSAndroid Build Coastguard Workeryou do so by creating a new target, and add a dependency to it, rather than
192*61c4878aSAndroid Build Coastguard Workermodifying the generated targets.
193