xref: /aosp_15_r20/external/pigweed/targets/apollo4_pw_system/target_docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1.. _target-apollo4-pw-system:
2
3============================
4Ambiq Apollo4 with pw_system
5============================
6
7.. warning::
8
9  This target is in a very preliminary state and is under active development.
10  This demo gives a preview of the direction we are heading with
11  :ref:`pw_system<module-pw_system>`, but it is not yet ready for production
12  use.
13
14This target configuration uses :ref:`pw_system<module-pw_system>` on top of
15FreeRTOS and the `AmbiqSuite SDK
16<https://ambiq.com/apollo4-blue-plus>`_ HAL.
17
18-----
19Setup
20-----
21To use this target, Pigweed must be set up to use FreeRTOS and the AmbiqSuite
22SDK HAL for the Apollo4 series. The FreeRTOS repository can be downloaded via
23``pw package``, and the `AmbiqSuite SDK`_ can be downloaded from the Ambiq
24website.
25
26.. _AmbiqSuite SDK: https://ambiq.com/apollo4-blue-plus
27
28Once the AmbiqSuite SDK package has been downloaded and extracted, the user
29needs to set ``dir_pw_third_party_ambiq_SDK`` build arg to the location of
30extracted directory:
31
32.. code-block:: sh
33
34   $ gn args out
35
36Then add the following lines to that text file:
37
38.. code-block::
39
40   # Path to the extracted AmbiqSuite SDK package.
41   dir_pw_third_party_ambiq_SDK = "/path/to/AmbiqSuite_R4.3.0"
42
43   # Path to the FreeRTOS source directory.
44   dir_pw_third_party_freertos = "/path/to/pigweed/third_party/freertos"
45
46-----------------------------
47Building and Running the Demo
48-----------------------------
49This target has an associated demo application that can be built and then
50flashed to a device with the following commands:
51
52.. code-block:: sh
53
54   ninja -C out pw_system_demo
55
56.. seealso::
57
58   The :ref:`target-apollo4` for more info on flashing the Apollo4 board.
59
60Once the board has been flashed, you can connect to it and send RPC commands
61via the Pigweed console:
62
63.. code-block:: sh
64
65   pw-system-console -d /dev/{ttyX} -b 115200 \
66     --proto-globs pw_rpc/echo.proto \
67     --token-databases \
68       out/apollo4_pw_system.size_optimized/obj/pw_system/bin/system_example.elf
69
70Replace ``{ttyX}`` with the appropriate device on your machine. On Linux this
71may look like ``ttyACM0``, and on a Mac it may look like ``cu.usbmodem***``.
72
73When the console opens, try sending an Echo RPC request. You should get back
74the same message you sent to the device.
75
76.. code-block:: pycon
77
78   >>> device.rpcs.pw.rpc.EchoService.Echo(msg="Hello, Pigweed!")
79   (Status.OK, pw.rpc.EchoMessage(msg='Hello, Pigweed!'))
80
81You can also try out our thread snapshot RPC service, which should return a
82stack usage overview of all running threads on the device in Host Logs.
83
84.. code-block:: pycon
85
86   >>> device.rpcs.pw.thread.proto.ThreadSnapshotService.GetPeakStackUsage()
87
88Example output:
89
90.. code-block::
91
92   20220826 09:47:22  INF  PendingRpc(channel=1, method=pw.thread.ThreadSnapshotService.GetPeakStackUsage) completed: Status.OK
93   20220826 09:47:22  INF  Thread State
94   20220826 09:47:22  INF    5 threads running.
95   20220826 09:47:22  INF
96   20220826 09:47:22  INF  Thread (UNKNOWN): IDLE
97   20220826 09:47:22  INF  Est CPU usage: unknown
98   20220826 09:47:22  INF  Stack info
99   20220826 09:47:22  INF    Current usage:   0x20002da0 - 0x???????? (size unknown)
100   20220826 09:47:22  INF    Est peak usage:  390 bytes, 76.77%
101   20220826 09:47:22  INF    Stack limits:    0x20002da0 - 0x20002ba4 (508 bytes)
102   20220826 09:47:22  INF
103   20220826 09:47:22  INF  ...
104
105You are now up and running!
106
107.. seealso::
108
109   The :ref:`module-pw_console`
110   :bdg-ref-primary-line:`module-pw_console-user_guide` for more info on using
111   the the pw_console UI.
112