Fix for x86_64 build fail
[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 a specific revision of the nRF Connect SDK to work
68 correctly. See [Setting up the environment](#setting-up-the-environment) for
69 more information.
70
71 <a name="supported_devices"></a>
72
73 ### Supported devices
74
75 The example supports building and running on the following devices:
76
77 | Hardware platform                                                                                 | Build target              | Platform image                                                                                                                                         |
78 | ------------------------------------------------------------------------------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
79 | [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> |
80 | [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>    |
81
82 <hr>
83
84 <a name="device-ui"></a>
85
86 ## Device UI
87
88 This section lists the User Interface elements that you can use to control and
89 monitor the state of the device. These correspond to PCB components on the
90 hardware platform.
91
92 **LED 1** shows the overall state of the device. The following states are
93 possible:
94
95 -   _Solid On_ &mdash; The application was flashed and ran successfully.
96
97 **Serial port** can be used to communicate with the device by sending commands
98 and receiving responses.
99
100 > **Important**:
101 >
102 > Please note that supported hardware platforms are using different transport
103 > interfaces to perform serial communication, which leads to differences in
104 > configuration. By default, these interfaces are used:
105 >
106 > -   `nrf52840dk_nrf52840` - UART interface routed to the SEGGER J-Link USB
107 >     port.
108 > -   `nrf52840dongle_nrf52840` - USB interface routed to the USB port.
109
110 <hr>
111
112 ## Setting up the environment
113
114 Before building the example, check out the CHIP repository and sync submodules
115 using the following command:
116
117         $ git submodule update --init
118
119 The example requires a specific revision of the nRF Connect SDK. You can either
120 install it along with the related tools directly on your system or use a Docker
121 image that has the tools pre-installed.
122
123 If you are a macOS user, you won't be able to use the Docker container to flash
124 the application onto a Nordic development kit due to
125 [certain limitations of Docker for macOS](https://docs.docker.com/docker-for-mac/faqs/#can-i-pass-through-a-usb-device-to-a-container).
126 Use the [native shell](#using-native-shell) for building instead.
127
128 ### Using Docker container for setup
129
130 To use the Docker container for setup, complete the following steps:
131
132 1.  If you do not have the nRF Connect SDK installed yet, create a directory for
133     it by running the following command:
134
135         $ mkdir ~/nrfconnect
136
137 2.  Download the latest version of the nRF Connect SDK Docker image by running
138     the following command:
139
140         $ docker pull nordicsemi/nrfconnect-chip
141
142 3.  Start Docker with the downloaded image by running the following command,
143     customized to your needs as described below:
144
145          $ docker run --rm -it -e RUNAS=$(id -u) -v ~/nrfconnect:/var/ncs -v ~/connectedhomeip:/var/chip \
146              -v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:* rmw" nordicsemi/nrfconnect-chip
147
148     In this command:
149
150     -   _~/nrfconnect_ can be replaced with an absolute path to the nRF Connect
151         SDK source directory.
152     -   _~/connectedhomeip_ must be replaced with an absolute path to the CHIP
153         source directory.
154     -   _-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:_ rmw"\*
155         parameters can be omitted if you are not planning to flash the example
156         onto hardware. These parameters give the container access to USB devices
157         connected to your computer such as the nRF52840 DK.
158     -   _--rm_ can be omitted if you do not want the container to be
159         auto-removed when you exit the container shell session.
160     -   _-e RUNAS=\$(id -u)_ is needed to start the container session as the
161         current user instead of root.
162
163 4.  Update the nRF Connect SDK to the most recent supported revision, by running
164     the following command:
165
166          $ cd /var/chip
167          $ python3 scripts/setup/nrfconnect/update_ncs.py --update
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.  If you do not have the nRF Connect SDK installed, follow the
181     [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
182     in the nRF Connect SDK documentation to install the latest stable nRF
183     Connect SDK version. Since command-line tools will be used for building the
184     example, installing SEGGER Embedded Studio is not required.
185
186     If you have the SDK already installed, continue to the next step and update
187     the nRF Connect SDK after initializing environment variables.
188
189 3.  Initialize environment variables referred to by the CHIP and the nRF Connect
190     SDK build scripts. Replace _nrfconnect-dir_ with the path to your nRF
191     Connect SDK installation directory, and _toolchain-dir_ with the path to GNU
192     Arm Embedded Toolchain.
193
194          $ source nrfconnect-dir/zephyr/zephyr-env.sh
195          $ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
196          $ export GNUARMEMB_TOOLCHAIN_PATH=toolchain-dir
197
198 4.  Update the nRF Connect SDK to the most recent supported revision by running
199     the following command (replace _chip-dir_ with the path to CHIP repository
200     directory):
201
202          $ cd chip-dir
203          $ python3 scripts/setup/nrfconnect/update_ncs.py --update
204
205 Now you can proceed with the [Building](#building) instruction.
206
207 <hr>
208
209 <a name="building"></a>
210
211 ## Building
212
213 Complete the following steps, regardless of the method used for setting up the
214 environment:
215
216 1.  Run the `activate.sh` script, regardless of the building strategy. The
217     script is required for building the Pigweed library. Use the following
218     command:
219
220             $ source scripts/activate.sh
221
222 2.  Navigate to the example's directory:
223
224         $ cd examples/pigweed-app/nrfconnect
225
226 3.  Run the following command to build the example, with _build-target_ replaced
227     with the build target name of the Nordic Semiconductor's kit you own, for
228     example `nrf52840dk_nrf52840`:
229
230          $ west build -b build-target
231
232     You only need to specify the build target on the first build. See
233     [Requirements](#requirements) for the build target names of compatible kits.
234
235 The output `zephyr.hex` file will be available in the `build/zephyr/` directory.
236
237 ### Removing build artifacts
238
239 If you're planning to build the example for a different kit or make changes to
240 the configuration, remove all build artifacts before building. To do so, use the
241 following command:
242
243     $ rm -r build
244
245 <hr>
246
247 <a name="configuring"></a>
248
249 ## Configuring the example
250
251 The Zephyr ecosystem is highly configurable and allows you to modify many
252 aspects of the application. The configuration system is based on Kconfig files
253 and the settings can be modified using the menuconfig utility.
254
255 To open the menuconfig utility, complete the following steps:
256
257 1.  Go to the example directory by running the following command, with the
258     _example-dir_ directory name updated for your configuration:
259
260          $ cd example-dir
261
262 2.  Choose one of the following options:
263
264     -   If you are running the build for the first time, run the following
265         command:
266
267                $ west build -b nrf52840dk_nrf52840 -t menuconfig
268
269     -   If you are running a subsequent build, run the following command:
270
271                $ west build -t menuconfig
272
273     -   If you are running menuconfig with ninja, run the following commands:
274
275                $ cd example-dir/build
276                $ ninja menuconfig
277
278 Changes done with menuconfig will be lost if the `build` directory is deleted.
279 To make them persistent, save the configuration options in the `prj.conf` file.
280
281 For more information, see the
282 [Configuring nRF Connect SDK examples](../../../docs/guides/nrfconnect_examples_configuration.md)
283 page.
284
285 <hr>
286
287 <a name="flashing"></a>
288
289 ## Flashing and debugging
290
291 The flashing and debugging procedure is different for the nRF52840 DK and the
292 nRF52840 Dongle.
293
294 <a name="nrf52840dk_flashing"></a>
295
296 ### Flashing on the nRF52840 DK
297
298 To flash the application to the device, use the west tool and run the following
299 commands, with the _example-dir_ directory name updated for your configuration:
300
301         $ cd example-dir
302         $ west flash
303
304 If you have multiple nRF52840 development kits connected, west will prompt you
305 to pick the correct one.
306
307 To debug the application on target, run the following commands:
308
309         $ cd example-dir
310         $ west debug
311
312 <a name="nrf52840dongle_flashing"></a>
313
314 ### Flashing on the nRF52840 Dongle
315
316 Visit
317 [Programming and Flashing nRF52840 Dongle](https://docs.zephyrproject.org/latest/boards/arm/nrf52840dongle_nrf52840/doc/index.html#programming-and-debugging)
318 to read more about flashing on the nRF52840 Dongle.
319
320 <hr>
321
322 <a name="currently-implemented-features"></a>
323
324 ## Testing the example
325
326 Run the following command to start an interactive Python shell, where the Echo
327 RPC commands can be invoked:
328
329         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
330
331 To send an Echo RPC message, type the following command, where the actual
332 message is the text in quotation marks after the `msg=` phrase:
333
334         rpcs.pw.rpc.EchoService.Echo(msg="hi")