d41732a855c99b9cf0107510163760cdb27f9b0a
[platform/upstream/connectedhomeip.git] / examples / pigweed-app / nrfconnect / README.md
1 # CHIP nRF Connect Pigweed Example Application
2
3 The nRF Connect Pigweed Example demonstrates the usage of Pigweed module
4 functionalities in an application.
5
6 <p align="center">
7   <img src="../../platform/nrfconnect/doc/images/Logo_RGB_H-small.png" alt="Nordic Semiconductor logo"/>
8   <img src="../../platform/nrfconnect/doc/images/nRF52840-DK-small.png" alt="nRF52840 DK">
9 </p>
10
11 The example is based on [CHIP](https://github.com/project-chip/connectedhomeip),
12 the [Pigweed](https://pigweed.googlesource.com/pigweed/pigweed) module, which is
13 a collection of libraries that provide different functionalities for embedded
14 systems, and Nordic Semiconductor's nRF Connect SDK.
15
16 You can use this example as a training ground for making experiments, testing
17 Pigweed module features and checking what actions are necessary to fully
18 integrate Pigweed in a CHIP project.
19
20 Pigweed functionalities are being gradually integrated into CHIP. Currently, the
21 following features are available:
22
23 -   **Echo RPC** - Creates a Remote Procedure Call server and allows sending
24     commands through the serial port to the device, which makes echo and sends
25     the received commands back.
26
27 <hr>
28
29 -   [Overview](#overview)
30 -   [Requirements](#requirements)
31     -   [Supported devices](#supported_devices)
32 -   [Device UI](#device-ui)
33 -   [Setting up the environment](#setting-up-the-environment)
34     -   [Using Docker container for setup](#using-docker-container-for-setup)
35     -   [Using native shell for setup](#using-native-shell-for-setup)
36 -   [Building](#building)
37 -   [Configuring the example](#configuring-the-example)
38 -   [Flashing and debugging](#flashing-and-debugging)
39     -   [Flashing on the nRF52840 DK](#nrf52840dk_flashing)
40     -   [Flashing on the nRF52840 Dongle](#nrf52840dongle_flashing)
41 -   [Testing the example](#testing-the-example)
42
43 <hr>
44
45 <a name="overview"></a>
46
47 ## Overview
48
49 This example is running on the nRF Connect platform, which is based on the
50 [nRF Connect SDK](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/index.html)
51 and [Zephyr RTOS](https://zephyrproject.org/). Visit CHIP's
52 [nRF Connect platform overview](../../../docs/guides/nrfconnect_platform_overview.md)
53 to read more about the platform structure and dependencies.
54
55 Pigweed libraries are built and organized in a way that enables faster and more
56 reliable development. In the CHIP project, the Pigweed module is planned to be
57 used to create system infrastructures, for example for performing on-device
58 tests, but considering its general functionalities, it can be useful also in
59 other cases.
60
61 <hr>
62
63 <a name="requirements"></a>
64
65 ## Requirements
66
67 The application requires the nRF Connect SDK v1.5.0 to work correctly.
68
69 <a name="supported_devices"></a>
70
71 ### Supported devices
72
73 The example supports building and running on the following devices:
74
75 | Hardware platform                                                                                 | Build target              | Platform image                                                                                                                                         |
76 | ------------------------------------------------------------------------------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
77 | [nRF52840 Dongle](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-Dongle) | `nrf52840dongle_nrf52840` | <details><summary>nRF52840 Dongle</summary><img src="../../platform/nrfconnect/doc/images/nRF52840-Dongle-small.jpg" alt="nRF52840 Dongle"/></details> |
78 | [nRF52840 DK](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF52840-DK)         | `nrf52840dk_nrf52840`     | <details><summary>nRF52840 DK</summary><img src="../../platform/nrfconnect/doc/images/nRF52840-DK_top-view-small.jpg" alt="nRF52840 DK"/></details>    |
79
80 <hr>
81
82 <a name="device-ui"></a>
83
84 ## Device UI
85
86 This section lists the User Interface elements that you can use to control and
87 monitor the state of the device. These correspond to PCB components on the
88 hardware platform.
89
90 **LED 1** shows the overall state of the device. The following states are
91 possible:
92
93 -   _Solid On_ &mdash; The application was flashed and ran successfully.
94
95 **Serial port** can be used to communicate with the device by sending commands
96 and receiving responses.
97
98 > **Important**:
99 >
100 > Please note that supported hardware platforms are using different transport
101 > interfaces to perform serial communication, which leads to differences in
102 > configuration. By default, these interfaces are used:
103 >
104 > -   `nrf52840dk_nrf52840` - UART interface routed to the SEGGER J-Link USB
105 >     port.
106 > -   `nrf52840dongle_nrf52840` - USB interface routed to the USB port.
107
108 <hr>
109
110 ## Setting up the environment
111
112 Before building the example, check out the CHIP repository and sync submodules
113 using the following command:
114
115         $ git submodule update --init
116
117 The example requires the nRF Connect SDK v1.5.0. You can either install it along
118 with the related tools directly on your system or use a Docker image that has
119 the tools pre-installed.
120
121 If you are a macOS user, you won't be able to use the Docker container to flash
122 the application onto a Nordic development kit due to
123 [certain limitations of Docker for macOS](https://docs.docker.com/docker-for-mac/faqs/#can-i-pass-through-a-usb-device-to-a-container).
124 Use the [native shell](#using-native-shell) for building instead.
125
126 ### Using Docker container for setup
127
128 To use the Docker container for setup, complete the following steps:
129
130 1.  If you do not have the nRF Connect SDK installed yet, create a directory for
131     it by running the following command:
132
133         $ mkdir ~/nrfconnect
134
135 2.  Download the latest version of the nRF Connect SDK Docker image by running
136     the following command:
137
138         $ docker pull nordicsemi/nrfconnect-chip
139
140 3.  Start Docker with the downloaded image by running the following command,
141     customized to your needs as described below:
142
143          $ docker run --rm -it -e RUNAS=$(id -u) -v ~/nrfconnect:/var/ncs -v ~/connectedhomeip:/var/chip \
144              -v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:* rmw" nordicsemi/nrfconnect-chip
145
146     In this command:
147
148     -   _~/nrfconnect_ can be replaced with an absolute path to the nRF Connect
149         SDK source directory.
150     -   _~/connectedhomeip_ must be replaced with an absolute path to the CHIP
151         source directory.
152     -   _-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:_ rmw"\*
153         parameters can be omitted if you are not planning to flash the example
154         onto hardware. These parameters give the container access to USB devices
155         connected to your computer such as the nRF52840 DK.
156     -   _--rm_ can be omitted if you do not want the container to be
157         auto-removed when you exit the container shell session.
158     -   _-e RUNAS=\$(id -u)_ is needed to start the container session as the
159         current user instead of root.
160
161 4.  Check out or update the nRF Connect SDK to the recommended `v1.5.0` version
162     by running the following command in the Docker container:
163
164          $ setup --ncs v1.5.0
165          /var/ncs repository is empty. Do you wish to check out nRF Connect SDK sources [v1.5.0]? [Y/N] y
166          ...
167          /var/chip repository is initialized, skipping...
168
169 Now you can proceed with the [Building](#building) instruction.
170
171 ### Using native shell for setup
172
173 To use the native shell for setup, complete the following steps:
174
175 1.  Download and install the following additional software:
176
177     -   [nRF Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
178     -   [GN meta-build system](https://gn.googlesource.com/gn/)
179
180 2.  Depending on whether you have the nRF Connect SDK installed:
181
182     -   Follow the
183         [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
184         in the nRF Connect SDK documentation to install the nRF Connect SDK
185         v1.5.0. Since command-line tools will be used for building the example,
186         installing SEGGER Embedded Studio is not required.
187
188     -   If you have an older version of the SDK installed, use the following
189         commands to update it to the recommended version. Replace
190         _nrfconnect-dir_ with the path to your nRF Connect SDK installation
191         directory.
192
193                $ cd nrfconnect-dir/nrf
194                $ git fetch origin
195                $ git checkout v1.5.0
196                $ west update
197
198 3.  Initialize environment variables referred to by the CHIP and the nRF Connect
199     SDK build scripts. Replace _nrfconnect-dir_ with the path to your nRF
200     Connect SDK installation directory, and _toolchain-dir_ with the path to GNU
201     Arm Embedded Toolchain.
202
203          $ source nrfconnect-dir/zephyr/zephyr-env.sh
204          $ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
205          $ export GNUARMEMB_TOOLCHAIN_PATH=toolchain-dir
206
207 Now you can proceed with the [Building](#building) instruction.
208
209 <hr>
210
211 <a name="building"></a>
212
213 ## Building
214
215 Complete the following steps, regardless of the method used for setting up the
216 environment:
217
218 1.  Run the `activate.sh` script, regardless of the building strategy. The
219     script is required for building the Pigweed library. Use the following
220     command:
221
222             $ source scripts/activate.sh
223
224 2.  Navigate to the example's directory:
225
226         $ cd examples/pigweed-app/nrfconnect
227
228 3.  Run the following command to build the example, with _build-target_ replaced
229     with the build target name of the Nordic Semiconductor's kit you own, for
230     example `nrf52840dk_nrf52840`:
231
232          $ west build -b build-target
233
234     You only need to specify the build target on the first build. See
235     [Requirements](#requirements) for the build target names of compatible kits.
236
237 The output `zephyr.hex` file will be available in the `build/zephyr/` directory.
238
239 ### Removing build artifacts
240
241 If you're planning to build the example for a different kit or make changes to
242 the configuration, remove all build artifacts before building. To do so, use the
243 following command:
244
245     $ rm -r build
246
247 <hr>
248
249 <a name="configuring"></a>
250
251 ## Configuring the example
252
253 The Zephyr ecosystem is highly configurable and allows you to modify many
254 aspects of the application. The configuration system is based on Kconfig files
255 and the settings can be modified using the menuconfig utility.
256
257 To open the menuconfig utility, complete the following steps:
258
259 1.  Go to the example directory by running the following command, with the
260     _example-dir_ directory name updated for your configuration:
261
262          $ cd example-dir
263
264 2.  Choose one of the following options:
265
266     -   If you are running the build for the first time, run the following
267         command:
268
269                $ west build -b nrf52840dk_nrf52840 -t menuconfig
270
271     -   If you are running a subsequent build, run the following command:
272
273                $ west build -t menuconfig
274
275     -   If you are running menuconfig with ninja, run the following commands:
276
277                $ cd example-dir/build
278                $ ninja menuconfig
279
280 Changes done with menuconfig will be lost if the `build` directory is deleted.
281 To make them persistent, save the configuration options in the `prj.conf` file.
282
283 For more information, see the
284 [Configuring nRF Connect SDK examples](../../../docs/guides/nrfconnect_examples_configuration.md)
285 page.
286
287 <hr>
288
289 <a name="flashing"></a>
290
291 ## Flashing and debugging
292
293 The flashing and debugging procedure is different for the nRF52840 DK and the
294 nRF52840 Dongle.
295
296 <a name="nrf52840dk_flashing"></a>
297
298 ### Flashing on the nRF52840 DK
299
300 To flash the application to the device, use the west tool and run the following
301 commands, with the _example-dir_ directory name updated for your configuration:
302
303         $ cd example-dir
304         $ west flash
305
306 If you have multiple nRF52840 development kits connected, west will prompt you
307 to pick the correct one.
308
309 To debug the application on target, run the following commands:
310
311         $ cd example-dir
312         $ west debug
313
314 <a name="nrf52840dongle_flashing"></a>
315
316 ### Flashing on the nRF52840 Dongle
317
318 Visit
319 [Programming and Flashing nRF52840 Dongle](https://docs.zephyrproject.org/latest/boards/arm/nrf52840dongle_nrf52840/doc/index.html#programming-and-debugging)
320 to read more about flashing on the nRF52840 Dongle.
321
322 <hr>
323
324 <a name="currently-implemented-features"></a>
325
326 ## Testing the example
327
328 Run the following command to start an interactive Python shell, where the Echo
329 RPC commands can be invoked:
330
331         python -m pw_hdlc.rpc_console --device /dev/ttyACM0 -b 115200 $CHIP_ROOT/third_party/pigweed/repo/pw_rpc/pw_rpc_protos/echo.proto -o /tmp/pw_rpc.out
332
333 To send an Echo RPC message, type the following command, where the actual
334 message is the text in quotation marks after the `msg=` phrase:
335
336         rpcs.pw.rpc.EchoService.Echo(msg="hi")