xref: /aosp_15_r20/external/pigweed/targets/stm32f429i_disc1/target_docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _target-stm32f429i-disc1:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker----------------
4*61c4878aSAndroid Build Coastguard Workerstm32f429i-disc1
5*61c4878aSAndroid Build Coastguard Worker----------------
6*61c4878aSAndroid Build Coastguard WorkerThe STMicroelectronics STM32F429I-DISC1 development board is currently Pigweed's
7*61c4878aSAndroid Build Coastguard Workerprimary target for on-device testing and development.
8*61c4878aSAndroid Build Coastguard Worker
9*61c4878aSAndroid Build Coastguard WorkerBuilding
10*61c4878aSAndroid Build Coastguard Worker========
11*61c4878aSAndroid Build Coastguard WorkerTo build for this Pigweed target, simply build the top-level "stm32f429i" Ninja
12*61c4878aSAndroid Build Coastguard Workertarget.
13*61c4878aSAndroid Build Coastguard Worker
14*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh
15*61c4878aSAndroid Build Coastguard Worker
16*61c4878aSAndroid Build Coastguard Worker   $ ninja -C out stm32f429i
17*61c4878aSAndroid Build Coastguard Worker
18*61c4878aSAndroid Build Coastguard WorkerTesting
19*61c4878aSAndroid Build Coastguard Worker=======
20*61c4878aSAndroid Build Coastguard WorkerWhen working in upstream Pigweed, building this target will build all Pigweed modules' unit tests.
21*61c4878aSAndroid Build Coastguard WorkerThese tests can be run on-device in a few different ways.
22*61c4878aSAndroid Build Coastguard Worker
23*61c4878aSAndroid Build Coastguard WorkerRun a unit test
24*61c4878aSAndroid Build Coastguard Worker---------------
25*61c4878aSAndroid Build Coastguard WorkerIf using ``out`` as a build directory, tests will be located in
26*61c4878aSAndroid Build Coastguard Worker``out/stm32f429i_disc1_debug/obj/[module name]/[test_name].elf``. To run these
27*61c4878aSAndroid Build Coastguard Workeron device, the stm32f429i-disc1 target provides a helper script that flashes the
28*61c4878aSAndroid Build Coastguard Workertest to a device and then runs it.
29*61c4878aSAndroid Build Coastguard Worker
30*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh
31*61c4878aSAndroid Build Coastguard Worker
32*61c4878aSAndroid Build Coastguard Worker   # Setup pigweed environment.
33*61c4878aSAndroid Build Coastguard Worker   $ source activate.sh
34*61c4878aSAndroid Build Coastguard Worker   # Run test.
35*61c4878aSAndroid Build Coastguard Worker   $ stm32f429i_disc1_unit_test_runner /path/to/binary
36*61c4878aSAndroid Build Coastguard Worker
37*61c4878aSAndroid Build Coastguard WorkerRun multiple tests
38*61c4878aSAndroid Build Coastguard Worker------------------
39*61c4878aSAndroid Build Coastguard WorkerRunning all tests one-by-one is rather tedious. To make running multiple
40*61c4878aSAndroid Build Coastguard Workertests easier, use Pigweed's ``pw test`` command and pass it a path to the build
41*61c4878aSAndroid Build Coastguard Workerdirectory and the name of the test runner. By default, ``pw test`` will run all
42*61c4878aSAndroid Build Coastguard Workertests, but it can be restricted it to specific ``pw_test_group`` targets using
43*61c4878aSAndroid Build Coastguard Workerthe ``--group`` argument. Alternatively, individual test binaries can be
44*61c4878aSAndroid Build Coastguard Workerspecified with the ``--test`` option.
45*61c4878aSAndroid Build Coastguard Worker
46*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh
47*61c4878aSAndroid Build Coastguard Worker
48*61c4878aSAndroid Build Coastguard Worker   # Setup Pigweed environment.
49*61c4878aSAndroid Build Coastguard Worker   $ source activate.sh
50*61c4878aSAndroid Build Coastguard Worker   # Run test.
51*61c4878aSAndroid Build Coastguard Worker   $ pw test --root out/stm32f429i_disc_debug/  \
52*61c4878aSAndroid Build Coastguard Worker         --runner stm32f429i_disc1_unit_test_runner
53*61c4878aSAndroid Build Coastguard Worker
54*61c4878aSAndroid Build Coastguard WorkerRun tests affected by code changes
55*61c4878aSAndroid Build Coastguard Worker----------------------------------
56*61c4878aSAndroid Build Coastguard WorkerWhen writing code that will impact multiple modules, it's helpful to only run
57*61c4878aSAndroid Build Coastguard Workerall tests that are affected by a given code change. Thanks to the GN/Ninja
58*61c4878aSAndroid Build Coastguard Workerbuild, this is possible! This is done by using a ``pw_target_runner_server``
59*61c4878aSAndroid Build Coastguard Workerthat Ninja can send the tests to as it rebuilds affected targets.
60*61c4878aSAndroid Build Coastguard Worker
61*61c4878aSAndroid Build Coastguard WorkerAdditionally, this method enables distributed testing. If multiple devices are
62*61c4878aSAndroid Build Coastguard Workerconnected, the tests will be run across all attached devices to further speed up
63*61c4878aSAndroid Build Coastguard Workertesting.
64*61c4878aSAndroid Build Coastguard Worker
65*61c4878aSAndroid Build Coastguard WorkerStep 1: Start test server
66*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^
67*61c4878aSAndroid Build Coastguard WorkerTo allow Ninja to properly serialize tests to run on an arbitrary number of
68*61c4878aSAndroid Build Coastguard Workerdevices, Ninja will send test requests to a server running in the background.
69*61c4878aSAndroid Build Coastguard WorkerThe first step is to launch this server. By default, the script will attempt
70*61c4878aSAndroid Build Coastguard Workerto automatically detect all attached STM32f429I-DISC1 boards and use them for
71*61c4878aSAndroid Build Coastguard Workertesting. To override this behavior, provide a custom server configuration file
72*61c4878aSAndroid Build Coastguard Workerwith ``--server-config``.
73*61c4878aSAndroid Build Coastguard Worker
74*61c4878aSAndroid Build Coastguard Worker.. tip::
75*61c4878aSAndroid Build Coastguard Worker
76*61c4878aSAndroid Build Coastguard Worker  If you unplug or plug in any boards, you'll need to restart the test server
77*61c4878aSAndroid Build Coastguard Worker  for hardware changes to properly be detected.
78*61c4878aSAndroid Build Coastguard Worker
79*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh
80*61c4878aSAndroid Build Coastguard Worker
81*61c4878aSAndroid Build Coastguard Worker   $ stm32f429i_disc1_test_server
82*61c4878aSAndroid Build Coastguard Worker
83*61c4878aSAndroid Build Coastguard WorkerStep 2: Configure GN
84*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^
85*61c4878aSAndroid Build Coastguard WorkerBy default, this hardware target has incremental testing via
86*61c4878aSAndroid Build Coastguard Worker``pw_target_runner`` disabled. Enabling the ``pw_use_test_server`` build arg
87*61c4878aSAndroid Build Coastguard Workertells GN to send requests to a running ``stm32f429i_disc1_test_server``.
88*61c4878aSAndroid Build Coastguard Worker
89*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh
90*61c4878aSAndroid Build Coastguard Worker
91*61c4878aSAndroid Build Coastguard Worker   $ gn args out
92*61c4878aSAndroid Build Coastguard Worker   # Modify and save the args file to use pw_target_runner.
93*61c4878aSAndroid Build Coastguard Worker   pw_use_test_server = true
94*61c4878aSAndroid Build Coastguard Worker
95*61c4878aSAndroid Build Coastguard WorkerStep 3: Build changes
96*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^
97*61c4878aSAndroid Build Coastguard WorkerWhenever you run ``ninja -C out stm32f429i``, affected tests will be built and
98*61c4878aSAndroid Build Coastguard Workerrun on the attached device(s). Alternatively, you may use ``pw watch`` to set up
99*61c4878aSAndroid Build Coastguard WorkerPigweed to build/test whenever it sees changes to source files.
100*61c4878aSAndroid Build Coastguard Worker
101*61c4878aSAndroid Build Coastguard WorkerRPC server
102*61c4878aSAndroid Build Coastguard Worker==========
103*61c4878aSAndroid Build Coastguard WorkerThe stm32f429i target implements a system RPC server that over a simple UART
104*61c4878aSAndroid Build Coastguard Workerdriver. To communicate with a device running the RPC server, run
105*61c4878aSAndroid Build Coastguard Worker``pw rpc -d <device> -b 115200 <protos>``.
106*61c4878aSAndroid Build Coastguard Worker
107*61c4878aSAndroid Build Coastguard WorkerDebugging
108*61c4878aSAndroid Build Coastguard Worker=========
109*61c4878aSAndroid Build Coastguard WorkerThere are multiple ways to debug the device, including using commercial tools
110*61c4878aSAndroid Build Coastguard Workerlike SEGGER's J-Link. However, the Discovery board has an on-board STLink
111*61c4878aSAndroid Build Coastguard Workerdebugger, which is supported by the open source OpenOCD debugger. To debug with
112*61c4878aSAndroid Build Coastguard WorkerOpenOCD requires a few steps. Summary version of the steps:
113*61c4878aSAndroid Build Coastguard Worker
114*61c4878aSAndroid Build Coastguard Worker#. Connect OpenOCD to the device in terminal A. Leave this running
115*61c4878aSAndroid Build Coastguard Worker
116*61c4878aSAndroid Build Coastguard Worker   .. code-block:: sh
117*61c4878aSAndroid Build Coastguard Worker
118*61c4878aSAndroid Build Coastguard Worker      $ openocd -f targets/stm32f429i_disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg
119*61c4878aSAndroid Build Coastguard Worker
120*61c4878aSAndroid Build Coastguard Worker#. Connect GDB to the running OpenOCD instance in terminal B
121*61c4878aSAndroid Build Coastguard Worker
122*61c4878aSAndroid Build Coastguard Worker   .. code-block:: sh
123*61c4878aSAndroid Build Coastguard Worker
124*61c4878aSAndroid Build Coastguard Worker      $ arm-none-eabi-gdb -ex "target remote :3333" \
125*61c4878aSAndroid Build Coastguard Worker        out/stm32f429i_disc1_debug/obj/pw_assert/test/assert_facade_test.elf
126*61c4878aSAndroid Build Coastguard Worker
127*61c4878aSAndroid Build Coastguard Worker#. Flash (``load``), run (``mon reset run; continue``), and debug
128*61c4878aSAndroid Build Coastguard Worker
129*61c4878aSAndroid Build Coastguard Worker   .. code-block:: none
130*61c4878aSAndroid Build Coastguard Worker
131*61c4878aSAndroid Build Coastguard Worker      (gdb) set print pretty on
132*61c4878aSAndroid Build Coastguard Worker      (gdb) load
133*61c4878aSAndroid Build Coastguard Worker      (gdb) mon reset run
134*61c4878aSAndroid Build Coastguard Worker      (gdb) continue
135*61c4878aSAndroid Build Coastguard Worker
136*61c4878aSAndroid Build Coastguard Worker#. You can re-flash the device after compiling by running ``load``.
137*61c4878aSAndroid Build Coastguard Worker
138*61c4878aSAndroid Build Coastguard Worker
139*61c4878aSAndroid Build Coastguard WorkerStep 1: Start an OpenOCD server and connect to the device
140*61c4878aSAndroid Build Coastguard Worker---------------------------------------------------------
141*61c4878aSAndroid Build Coastguard WorkerOpenOCD is a persistent server that you run and leave running to bridge between
142*61c4878aSAndroid Build Coastguard WorkerGDB and the device. To run it for the Discovery board:
143*61c4878aSAndroid Build Coastguard Worker
144*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh
145*61c4878aSAndroid Build Coastguard Worker
146*61c4878aSAndroid Build Coastguard Worker   $ openocd -f targets/stm32f429i_disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg
147*61c4878aSAndroid Build Coastguard Worker
148*61c4878aSAndroid Build Coastguard WorkerTypical output:
149*61c4878aSAndroid Build Coastguard Worker
150*61c4878aSAndroid Build Coastguard Worker.. code-block:: none
151*61c4878aSAndroid Build Coastguard Worker
152*61c4878aSAndroid Build Coastguard Worker   Open On-Chip Debugger 0.10.0+dev-01243-ge41c0f49-dirty (2020-05-21-10:27)
153*61c4878aSAndroid Build Coastguard Worker   Licensed under GNU GPL v2
154*61c4878aSAndroid Build Coastguard Worker   For bug reports, read
155*61c4878aSAndroid Build Coastguard Worker           http://openocd.org/doc/doxygen/bugs.html
156*61c4878aSAndroid Build Coastguard Worker   DEPRECATED! use 'adapter driver' not 'interface'
157*61c4878aSAndroid Build Coastguard Worker   Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
158*61c4878aSAndroid Build Coastguard Worker   srst_only separate srst_nogate srst_open_drain connect_deassert_srst
159*61c4878aSAndroid Build Coastguard Worker
160*61c4878aSAndroid Build Coastguard Worker   Info : Listening on port 6666 for tcl connections
161*61c4878aSAndroid Build Coastguard Worker   Info : Listening on port 4444 for telnet connections
162*61c4878aSAndroid Build Coastguard Worker   Info : clock speed 2000 kHz
163*61c4878aSAndroid Build Coastguard Worker   Info : STLINK V2J25M14 (API v2) VID:PID 0483:374B
164*61c4878aSAndroid Build Coastguard Worker   Info : Target voltage: 2.871879
165*61c4878aSAndroid Build Coastguard Worker   Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
166*61c4878aSAndroid Build Coastguard Worker   Info : starting gdb server for stm32f4x.cpu on 3333
167*61c4878aSAndroid Build Coastguard Worker   Info : Listening on port 3333 for gdb connections
168*61c4878aSAndroid Build Coastguard Worker
169*61c4878aSAndroid Build Coastguard WorkerStep 2: Start GDB and connect to the OpenOCD server
170*61c4878aSAndroid Build Coastguard Worker---------------------------------------------------
171*61c4878aSAndroid Build Coastguard WorkerStart GDB pointing to the correct .elf file, and tell it to connect to the
172*61c4878aSAndroid Build Coastguard WorkerOpenOCD server (running on port 333 by default).
173*61c4878aSAndroid Build Coastguard Worker
174*61c4878aSAndroid Build Coastguard Worker.. code-block:: sh
175*61c4878aSAndroid Build Coastguard Worker
176*61c4878aSAndroid Build Coastguard Worker   $ arm-none-eabi-gdb -ex "target remote :3333" \
177*61c4878aSAndroid Build Coastguard Worker     out/stm32f429i_disc1_debug/obj/pw_assert/test/assert_facade_test.elf
178*61c4878aSAndroid Build Coastguard Worker
179*61c4878aSAndroid Build Coastguard WorkerIn this case the assert facade test is debugged, but substitute your own ELF
180*61c4878aSAndroid Build Coastguard Workerfile. This should produce output similar to the following:
181*61c4878aSAndroid Build Coastguard Worker
182*61c4878aSAndroid Build Coastguard Worker.. code-block:: none
183*61c4878aSAndroid Build Coastguard Worker
184*61c4878aSAndroid Build Coastguard Worker   GNU gdb (GNU Arm Embedded Toolchain 9-2020-q2-update) 8.3.1.20191211-git
185*61c4878aSAndroid Build Coastguard Worker   Copyright (C) 2019 Free Software Foundation, Inc.
186*61c4878aSAndroid Build Coastguard Worker   License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
187*61c4878aSAndroid Build Coastguard Worker   This is free software: you are free to change and redistribute it.
188*61c4878aSAndroid Build Coastguard Worker   There is NO WARRANTY, to the extent permitted by law.
189*61c4878aSAndroid Build Coastguard Worker   Type "show copying" and "show warranty" for details.
190*61c4878aSAndroid Build Coastguard Worker   This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
191*61c4878aSAndroid Build Coastguard Worker   Type "show configuration" for configuration details.
192*61c4878aSAndroid Build Coastguard Worker   For bug reporting instructions, please see:
193*61c4878aSAndroid Build Coastguard Worker   <http://www.gnu.org/software/gdb/bugs/>.
194*61c4878aSAndroid Build Coastguard Worker   Find the GDB manual and other documentation resources online at:
195*61c4878aSAndroid Build Coastguard Worker       <http://www.gnu.org/software/gdb/documentation/>.
196*61c4878aSAndroid Build Coastguard Worker
197*61c4878aSAndroid Build Coastguard Worker   For help, type "help".
198*61c4878aSAndroid Build Coastguard Worker   Type "apropos word" to search for commands related to "word"...
199*61c4878aSAndroid Build Coastguard Worker   Reading symbols from out/stm32f429i_disc1_debug/obj/pw_assert//test/assert_facade_test.elf...
200*61c4878aSAndroid Build Coastguard Worker   Remote debugging using :3333
201*61c4878aSAndroid Build Coastguard Worker   pw_BootEntry () at ../pw_boot_cortex_m/core_init.c:117
202*61c4878aSAndroid Build Coastguard Worker   117	  }
203*61c4878aSAndroid Build Coastguard Worker
204*61c4878aSAndroid Build Coastguard WorkerStep 3: Flash, run, and debug
205*61c4878aSAndroid Build Coastguard Worker-----------------------------
206*61c4878aSAndroid Build Coastguard WorkerNow that the GDB instance is connected to the device, you can flash, run, and debug.
207*61c4878aSAndroid Build Coastguard Worker
208*61c4878aSAndroid Build Coastguard WorkerTo flash
209*61c4878aSAndroid Build Coastguard Worker
210*61c4878aSAndroid Build Coastguard Worker.. code-block:: none
211*61c4878aSAndroid Build Coastguard Worker
212*61c4878aSAndroid Build Coastguard Worker   (gdb) load
213*61c4878aSAndroid Build Coastguard Worker
214*61c4878aSAndroid Build Coastguard WorkerThis will produce output similar to:
215*61c4878aSAndroid Build Coastguard Worker
216*61c4878aSAndroid Build Coastguard Worker.. code-block:: none
217*61c4878aSAndroid Build Coastguard Worker
218*61c4878aSAndroid Build Coastguard Worker   (gdb) load
219*61c4878aSAndroid Build Coastguard Worker   Loading section .vector_table, size 0x10 lma 0x8000000
220*61c4878aSAndroid Build Coastguard Worker   Loading section .code, size 0xdb8c lma 0x8000200
221*61c4878aSAndroid Build Coastguard Worker   Loading section .ARM, size 0x8 lma 0x800dd90
222*61c4878aSAndroid Build Coastguard Worker   Loading section .static_init_ram, size 0x1d0 lma 0x800dd98
223*61c4878aSAndroid Build Coastguard Worker   Start address 0x8007c48, load size 56692
224*61c4878aSAndroid Build Coastguard Worker   Transfer rate: 25 KB/sec, 8098 bytes/write.
225*61c4878aSAndroid Build Coastguard Worker
226*61c4878aSAndroid Build Coastguard WorkerTo reset the device and halt on the first instruction (before main):
227*61c4878aSAndroid Build Coastguard Worker
228*61c4878aSAndroid Build Coastguard Worker.. code-block:: none
229*61c4878aSAndroid Build Coastguard Worker
230*61c4878aSAndroid Build Coastguard Worker   (gdb) mon reset run
231*61c4878aSAndroid Build Coastguard Worker
232*61c4878aSAndroid Build Coastguard Worker
233*61c4878aSAndroid Build Coastguard WorkerThis will produce output similar to:
234*61c4878aSAndroid Build Coastguard Worker
235*61c4878aSAndroid Build Coastguard Worker.. code-block:: none
236*61c4878aSAndroid Build Coastguard Worker
237*61c4878aSAndroid Build Coastguard Worker   (gdb) mon reset run
238*61c4878aSAndroid Build Coastguard Worker   Unable to match requested speed 2000 kHz, using 1800 kHz
239*61c4878aSAndroid Build Coastguard Worker   Unable to match requested speed 2000 kHz, using 1800 kHz
240*61c4878aSAndroid Build Coastguard Worker   target halted due to debug-request, current mode: Thread
241*61c4878aSAndroid Build Coastguard Worker   xPSR: 0x01000000 pc: 0x08007930 msp: 0x20030000
242*61c4878aSAndroid Build Coastguard Worker   Unable to match requested speed 8000 kHz, using 4000 kHz
243*61c4878aSAndroid Build Coastguard Worker   Unable to match requested speed 8000 kHz, using 4000 kHz
244*61c4878aSAndroid Build Coastguard Worker
245*61c4878aSAndroid Build Coastguard WorkerThe device is now ready for debugging. You can place breakpoints and start the
246*61c4878aSAndroid Build Coastguard Workerdevice with ``continue``.
247