• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _target-raspberry-pi-pico-pw-system:
2
3================================
4Raspberry Pi Pico with pw_system
5================================
6.. warning::
7
8  This target is in a very preliminary state and is under active development.
9  This demo gives a preview of the direction we are heading with
10  :ref:`pw_system<module-pw_system>`, but it is not yet ready for production
11  use.
12
13This target configuration uses :ref:`pw_system<module-pw_system>` on top of
14FreeRTOS and the `Raspberry Pi Pico SDK
15<https://github.com/raspberrypi/pico-sdk>`_ HAL rather than a from-the-ground-up
16baremetal approach.
17
18-----
19Setup
20-----
21To use this target, Pigweed must be set up to use FreeRTOS and the STM32Cube HAL
22for the STM32F4 series. The supported repositories can be downloaded via
23``pw package``, and then the build must be manually configured to point to the
24locations the repositories were downloaded to.
25
26.. code:: sh
27
28   pw package install nanopb
29   pw package install freertos
30   pw package install pico_sdk
31
32   gn gen out --export-compile-commands --args="
33     dir_pw_third_party_nanopb=\"//environment/packages/nanopb\"
34     dir_pw_third_party_freertos=\"//environment/packages/freertos\"
35     PICO_SRC_DIR=\"//environment/packages/pico_sdk\"
36   "
37
38.. tip::
39
40   Instead of the ``gn gen out`` with args set on the command line above you can
41   run:
42
43   .. code:: sh
44
45      gn args out
46
47   Then add the following lines to that text file:
48
49   .. code::
50
51      dir_pw_third_party_nanopb = pw_env_setup_PACKAGE_ROOT + "/nanopb"
52      dir_pw_third_party_freertos = pw_env_setup_PACKAGE_ROOT + "/freertos"
53      PICO_SRC_DIR = pw_env_setup_PACKAGE_ROOT + "/pico_sdk"
54
55-----------------------------
56Building and Running the Demo
57-----------------------------
58This target has an associated demo application that can be built and then
59flashed to a device with the following commands:
60
61**Build**
62
63.. code:: sh
64
65   ninja -C out pw_system_demo
66
67**Flash**
68
69- Using a uf2 file:
70
71  Copy to ``out/rp2040_pw_system.size_optimized/obj/pw_system/system_example.uf2``
72  your Pico when it is in USB bootloader mode. Hold down the BOOTSEL button when
73  plugging in the pico and it will appear as a mass storage device.
74
75- Using a Pico Probe and openocd:
76
77  This requires installing the Raspberry Pi foundation's OpenOCD fork for the
78  Pico probe. More details including how to connect the two Pico boards is
79  available in ``Appendix A: Using Picoprobe`` of the `Getting started with
80  Raspberry Pi Pico
81  <https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf>`_ guide.
82
83  **Install RaspberryPi's OpenOCD Fork:**
84
85  .. code:: sh
86
87     git clone https://github.com/raspberrypi/openocd.git \
88       --branch picoprobe \
89       --depth=1 \
90       --no-single-branch \
91       openocd-picoprobe
92
93     cd openocd-picoprobe
94
95     ./bootstrap
96     ./configure --enable-picoprobe --prefix=$HOME/apps/openocd --disable-werror
97     make -j2
98     make install
99
100  **Setup udev rules (Linux only):**
101
102  .. code:: sh
103
104     cat <<EOF > 49-picoprobe.rules
105     SUBSYSTEMS=="usb", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000[43a]", MODE:="0666"
106     KERNEL=="ttyACM*", ATTRS{idVendor}=="2e8a", ATTRS{idProduct}=="000[43a]", MODE:="0666"
107     EOF
108     sudo cp 49-picoprobe.rules /usr/lib/udev/rules.d/49-picoprobe.rules
109     sudo udevadm control --reload-rules
110
111  **Flash the Pico:**
112
113  .. code:: sh
114
115     ~/apps/openocd/bin/openocd -f ~/apps/openocd/share/openocd/scripts/interface/picoprobe.cfg -f ~/apps/openocd/share/openocd/scripts/target/rp2040.cfg -c 'program out/rp2040_pw_system.size_optimized/obj/pw_system/bin/system_example.elf verify reset exit'
116
117**Connect with pw_console**
118
119Once the board has been flashed, you can connect to it and send RPC commands
120via the Pigweed console:
121
122.. code:: sh
123
124   pw-system-console -d /dev/{ttyX} -b 115200 \
125     --proto-globs pw_rpc/echo.proto \
126     --token-databases \
127       out/rp2040_pw_system.size_optimized/obj/pw_system/bin/system_example.elf
128
129Replace ``{ttyX}`` with the appropriate device on your machine. On Linux this
130may look like ``ttyACM0``, and on a Mac it may look like ``cu.usbmodem***``.
131
132When the console opens, try sending an Echo RPC request. You should get back
133the same message you sent to the device.
134
135.. code:: pycon
136
137   >>> device.rpcs.pw.rpc.EchoService.Echo(msg="Hello, Pigweed!")
138   (Status.OK, pw.rpc.EchoMessage(msg='Hello, Pigweed!'))
139
140You can also try out our thread snapshot RPC service, which should return a
141stack usage overview of all running threads on the device in Host Logs.
142
143.. code:: pycon
144
145   >>> device.snapshot_peak_stack_usage()
146
147Example output:
148
149.. code::
150
151   20220826 09:47:22  INF  PendingRpc(channel=1, method=pw.thread.ThreadSnapshotService.GetPeakStackUsage) completed: Status.OK
152   20220826 09:47:22  INF  Thread State
153   20220826 09:47:22  INF    5 threads running.
154   20220826 09:47:22  INF
155   20220826 09:47:22  INF  Thread (UNKNOWN): IDLE
156   20220826 09:47:22  INF  Est CPU usage: unknown
157   20220826 09:47:22  INF  Stack info
158   20220826 09:47:22  INF    Current usage:   0x20002da0 - 0x???????? (size unknown)
159   20220826 09:47:22  INF    Est peak usage:  390 bytes, 76.77%
160   20220826 09:47:22  INF    Stack limits:    0x20002da0 - 0x20002ba4 (508 bytes)
161   20220826 09:47:22  INF
162   20220826 09:47:22  INF  ...
163
164You are now up and running!
165
166.. seealso::
167
168   The :ref:`module-pw_console`
169   :bdg-ref-primary-line:`module-pw_console-user_guide` for more info on using
170   the the pw_console UI.
171