blob: 578acdd03027cad8d0bb7f169a33c4db1f8a26fd [file] [log] [blame] [view]
Damian Królikee937e62020-12-07 15:46:30 +01001# CHIP nRF Connect Lighting Example Application
Damian Królik7734e2a2020-09-11 21:53:22 +02002
Damian Królikee937e62020-12-07 15:46:30 +01003The nRF Connect Lighting Example demonstrates how to remotely control a white
Damian Królikbaa90e52021-01-05 17:08:37 +01004dimmable light bulb. It uses buttons to test changing the lighting and device
5states and LEDs to show the state of these changes. You can use this example as
6a reference for creating your own application.
Damian Królikee937e62020-12-07 15:46:30 +01007
Łukasz Duda4b61b4f2021-03-04 21:44:51 +01008<p align="center">
9 <img src="../../platform/nrfconnect/doc/images/Logo_RGB_H-small.png" alt="Nordic Semiconductor logo"/>
10 <img src="../../platform/nrfconnect/doc/images/nRF52840-DK-small.png" alt="nRF52840 DK">
11</p>
12
Damian Królikee937e62020-12-07 15:46:30 +010013The example is based on [CHIP](https://github.com/project-chip/connectedhomeip)
Łukasz Duda4b61b4f2021-03-04 21:44:51 +010014and Nordic Semiconductor's nRF Connect SDK, and supports remote access and
15control of a lighting over a low-power, 802.15.4 Thread network.
Damian Królikee937e62020-12-07 15:46:30 +010016
17The example behaves as a CHIP accessory, that is a device that can be paired
18into an existing CHIP network and can be controlled by this network.
Damian Królik7734e2a2020-09-11 21:53:22 +020019
20<hr>
21
Damian Królik1ff0b782021-01-07 15:25:43 +010022- [Overview](#overview)
23 - [Bluetooth LE advertising](#bluetooth-le-advertising)
24 - [Bluetooth LE rendezvous](#bluetooth-le-rendezvous)
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +020025 - [Device Firmware Upgrade](#device-firmware-upgrade)
Damian Królik1ff0b782021-01-07 15:25:43 +010026- [Requirements](#requirements)
Łukasz Duda4b61b4f2021-03-04 21:44:51 +010027 - [Supported devices](#supported_devices)
Damian Królik1ff0b782021-01-07 15:25:43 +010028- [Device UI](#device-ui)
29- [Setting up the environment](#setting-up-the-environment)
30 - [Using Docker container for setup](#using-docker-container-for-setup)
31 - [Using native shell for setup](#using-native-shell-for-setup)
32- [Building](#building)
33 - [Removing build artifacts](#removing-build-artifacts)
34 - [Building with release configuration](#building-with-release-configuration)
szatmz8a76b4a2020-12-09 13:55:05 -050035 - [Building with Pigweed RPCs](#building-with-pigweed-rpcs)
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +020036 - [Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support)
Damian Królik1ff0b782021-01-07 15:25:43 +010037- [Configuring the example](#configuring-the-example)
38- [Flashing and debugging](#flashing-and-debugging)
Damian Królikc3edd9a2021-07-03 03:59:59 +020039 - [Flashing on the development kits](#nrfdks_flashing)
40 - [Flashing on the nRF52840 Dongle](#nrf52840dongle_flashing)
Damian Królik1ff0b782021-01-07 15:25:43 +010041- [Testing the example](#testing-the-example)
Kamil Kasperczyk1073ccf2021-02-01 17:35:59 +010042 - [Testing using CHIPTool](#testing-using-chiptool)
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +020043 - [Testing Device Firmware Upgrade](#testing-device-firmware-upgrade)
Damian Królik7734e2a2020-09-11 21:53:22 +020044
45<hr>
46
Damian Królikee937e62020-12-07 15:46:30 +010047<a name="overview"></a>
Damian Królik7734e2a2020-09-11 21:53:22 +020048
Damian Królikee937e62020-12-07 15:46:30 +010049## Overview
Damian Królik7734e2a2020-09-11 21:53:22 +020050
Łukasz Duda4b61b4f2021-03-04 21:44:51 +010051This example is running on the nRF Connect platform, which is based on Nordic
52Semiconductor's
Damian Królikee937e62020-12-07 15:46:30 +010053[nRF Connect SDK](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/index.html)
54and [Zephyr RTOS](https://zephyrproject.org/). Visit CHIP's
55[nRF Connect platform overview](../../../docs/guides/nrfconnect_platform_overview.md)
56to read more about the platform structure and dependencies.
Damian Królik7734e2a2020-09-11 21:53:22 +020057
Damian Królikee937e62020-12-07 15:46:30 +010058The CHIP device that runs the lighting application is controlled by the CHIP
59controller device over the Thread protocol. By default, the CHIP device has
60Thread disabled, and it should be paired with CHIP controller and get
61configuration from it. Some actions required before establishing full
62communication are described below.
Damian Królik7734e2a2020-09-11 21:53:22 +020063
Damian Królikee937e62020-12-07 15:46:30 +010064The example also comes with a test mode, which allows to start Thread with the
65default settings by pressing button manually. However, this mode does not
66guarantee that the device will be able to communicate with the CHIP controller
67and other devices.
Damian Królik7734e2a2020-09-11 21:53:22 +020068
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +020069The example can be configured to use the secure bootloader and utilize it for
70performing over-the-air Device Firmware Upgrade using Bluetooth LE.
71
Damian Królikee937e62020-12-07 15:46:30 +010072### Bluetooth LE advertising
73
74To commission the device onto a CHIP network, the device must be discoverable
Kamil Kasperczykd369c412021-08-11 21:58:58 +020075over Bluetooth LE that starts automatically upon the device startup, but only
76for a predefined period of time (15 minutes by default). If the Bluetooth LE
77advertising times out, you can re-enable it manually using **Button 4**.
Damian Królikee937e62020-12-07 15:46:30 +010078
79### Bluetooth LE rendezvous
80
Damian Królikc3edd9a2021-07-03 03:59:59 +020081In CHIP, the commissioning procedure is done over Bluetooth LE between a CHIP
82device and the CHIP controller, where the controller has the commissioner role.
Damian Królikee937e62020-12-07 15:46:30 +010083
84To start the rendezvous, the controller must get the commissioning information
85from the CHIP device. The data payload is encoded within a QR code, printed to
Damian Królik6e96fca2021-07-27 17:21:21 +020086the UART console, and shared using an NFC tag. NFC tag emulation starts
87automatically when Bluetooth LE advertising is started and stays enabled until
88Bluetooth LE advertising timeout expires.
Damian Królikee937e62020-12-07 15:46:30 +010089
90#### Thread provisioning
91
92Last part of the rendezvous procedure, the provisioning operation involves
93sending the Thread network credentials from the CHIP controller to the CHIP
94device. As a result, device is able to join the Thread network and communicate
95with other Thread devices in the network.
96
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +020097### Device Firmware Upgrade
98
99The example allows enabling the over-the-air Device Firmware Upgrade feature. In
100this process, the device hosting new firmware image sends the image to the CHIP
101device using Bluetooth LE transport and
102[Simple Management Protocol](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/device_mgmt/index.html#device-mgmt).
103The
104[MCUboot](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/index.html)
105bootloader solution then replaces the old firmware image with the new one.
106
107#### Bootloader
108
109MCUboot is a secure bootloader used for swapping firmware images of different
110versions and generating proper build output files that can be used in the device
111firmware upgrade process.
112
113The bootloader solution requires an area of flash memory to swap application
114images during the firmware upgrade. The Nordic devices use an external memory
115chip for this purpose. The memory chip communicates with the microcontroller
116through the QSPI bus.
117
118See the
119[Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support)
120section to learn how to change MCUboot and flash configuration in this example.
121
122#### Simple Management Protocol
123
124Simple Management Protocol (SMP) is a basic transfer encoding that is used for
125device management purposes, including application image management. SMP supports
126using different transports, such as Bluetooth LE, UDP, or serial USB/UART.
127
128In this example, the CHIP device runs the SMP Server to download the application
129update image using the Bluetooth LE transport.
130
131See the
132[Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support)
133section to learn how to enable SMP and use it for the DFU purpose in this
134example.
135
Damian Królikee937e62020-12-07 15:46:30 +0100136<hr>
137
138<a name="requirements"></a>
139
140## Requirements
141
Kamil Kasperczyke4ab6f42021-03-11 15:17:03 +0100142The application requires a specific revision of the nRF Connect SDK to work
143correctly. See [Setting up the environment](#setting-up-the-environment) for
144more information.
Damian Królikee937e62020-12-07 15:46:30 +0100145
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100146<a name="supported_devices"></a>
147
148### Supported devices
149
Damian Królikee937e62020-12-07 15:46:30 +0100150The example supports building and running on the following devices:
151
Damian Królikc3edd9a2021-07-03 03:59:59 +0200152| Hardware platform | Build target | Platform image |
153| ------------------------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
154| [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_info-medium.jpg" alt="nRF52840 DK"/></details> |
155| [nRF5340 DK](https://www.nordicsemi.com/Software-and-Tools/Development-Kits/nRF5340-DK) | `nrf5340dk_nrf5340_cpuapp` | <details><summary>nRF5340 DK</summary><img src="../../platform/nrfconnect/doc/images/nRF5340_DK_info-medium.jpg" alt="nRF5340 DK"/></details> |
156| [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-medium.jpg" alt="nRF52840 Dongle"/></details> |
Damian Królikee937e62020-12-07 15:46:30 +0100157
158<hr>
Damian Królik7734e2a2020-09-11 21:53:22 +0200159
160<a name="device-ui"></a>
161
162## Device UI
163
Damian Królikee937e62020-12-07 15:46:30 +0100164This section lists the User Interface elements that you can use to control and
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100165monitor the state of the device. These correspond to PCB components on the
166platform image.
Damian Królik7734e2a2020-09-11 21:53:22 +0200167
Damian Królikc3edd9a2021-07-03 03:59:59 +0200168> **Note**:
169>
170> The following Device UI elements are missing on the nRF52840 Dongle: **Button
171> 2**, **Button 3**, **Button 4**, **SEGGER J-Link USB port**, and **NFC port
172> with antenna attached**. You can collect logs from the nRF52840 Dongle using
173> the **nRF USB port** instead of the **SEGGER J-Link USB port**.
174> Functionalities associated with the remaining missing elements are
175> inaccessible.
176
Damian Królikee937e62020-12-07 15:46:30 +0100177**LED 1** shows the overall state of the device and its connectivity. The
178following states are possible:
179
180- _Short Flash On (50 ms on/950 ms off)_ &mdash; The device is in the
Damian Królik7734e2a2020-09-11 21:53:22 +0200181 unprovisioned (unpaired) state and is waiting for a commissioning
182 application to connect.
183
Damian Królikee937e62020-12-07 15:46:30 +0100184- _Rapid Even Flashing (100 ms on/100 ms off)_ &mdash; The device is in the
185 unprovisioned state and a commissioning application is connected through
186 Bluetooth LE.
Damian Królik7734e2a2020-09-11 21:53:22 +0200187
Damian Królik994af3c2020-10-12 16:50:50 +0200188- _Short Flash Off (950ms on/50ms off)_ &mdash; The device is fully
Damian Królikee937e62020-12-07 15:46:30 +0100189 provisioned, but does not yet have full Thread network or service
Damian Królik7734e2a2020-09-11 21:53:22 +0200190 connectivity.
191
Damian Królikee937e62020-12-07 15:46:30 +0100192- _Solid On_ &mdash; The device is fully provisioned and has full Thread
193 network and service connectivity.
Damian Królik7734e2a2020-09-11 21:53:22 +0200194
Damian Królikee937e62020-12-07 15:46:30 +0100195**LED 2** simulates the light bulb and shows the state of the lighting. The
196following states are possible:
Damian Królik7734e2a2020-09-11 21:53:22 +0200197
Damian Królikee937e62020-12-07 15:46:30 +0100198- _Solid On_ &mdash; The light bulb is on.
Damian Królik7734e2a2020-09-11 21:53:22 +0200199
Damian Królikee937e62020-12-07 15:46:30 +0100200- _Off_ &mdash; The light bulb is off.
Damian Królik7734e2a2020-09-11 21:53:22 +0200201
Damian Królikee937e62020-12-07 15:46:30 +0100202**Button 1** can be used for the following purposes:
Damian Królik7734e2a2020-09-11 21:53:22 +0200203
Damian Królikee937e62020-12-07 15:46:30 +0100204- _Pressed for 6 s_ &mdash; Initiates the factory reset of the device.
205 Releasing the button within the 6-second window cancels the factory reset
206 procedure. **LEDs 1-4** blink in unison when the factory reset procedure is
207 initiated.
Damian Królik7734e2a2020-09-11 21:53:22 +0200208
Damian Królikee937e62020-12-07 15:46:30 +0100209- _Pressed for less than 3 s_ &mdash; Initiates the OTA software update
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +0200210 process. This feature is disabled by default, but can be enabled by
211 following the
212 [Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support)
213 instruction.
Kamil Kasperczyk8a84d972020-10-28 19:57:37 +0100214
Damian Królikee937e62020-12-07 15:46:30 +0100215**Button 2** &mdash; Pressing the button once changes the lighting state to the
216opposite one.
Kamil Kasperczyk005b7ae2020-11-05 17:42:51 +0100217
Damian Królikee937e62020-12-07 15:46:30 +0100218**Button 3** &mdash; Pressing the button once starts the Thread networking in
219the test mode using the default configuration.
Kamil Kasperczyk005b7ae2020-11-05 17:42:51 +0100220
Kamil Kasperczyke02e8d02021-01-11 21:28:51 +0100221**Button 4** &mdash; Pressing the button once starts the NFC tag emulation and
rgoliver8b1cac72021-09-15 16:03:57 -0400222enables Bluetooth LE advertising for the predefined period of time (15 minutes
223by default).
Damian Królikee937e62020-12-07 15:46:30 +0100224
225**SEGGER J-Link USB port** can be used to get logs from the device or
226communicate with it using the
227[command line interface](../../../docs/guides/nrfconnect_examples_cli.md).
228
229**NFC port with antenna attached** can be used to start the
230[rendezvous](#bluetooth-le-rendezvous) by providing the commissioning
231information from the CHIP device in a data payload that can be shared using NFC.
232
233<hr>
234
235## Setting up the environment
236
237Before building the example, check out the CHIP repository and sync submodules
238using the following command:
239
240 $ git submodule update --init
241
Kamil Kasperczyke4ab6f42021-03-11 15:17:03 +0100242The example requires a specific revision of the nRF Connect SDK. You can either
243install it along with the related tools directly on your system or use a Docker
244image that has the tools pre-installed.
Damian Królikee937e62020-12-07 15:46:30 +0100245
246If you are a macOS user, you won't be able to use the Docker container to flash
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100247the application onto a Nordic development kit due to
Damian Królikee937e62020-12-07 15:46:30 +0100248[certain limitations of Docker for macOS](https://docs.docker.com/docker-for-mac/faqs/#can-i-pass-through-a-usb-device-to-a-container).
249Use the [native shell](#using-native-shell) for building instead.
250
251### Using Docker container for setup
252
253To use the Docker container for setup, complete the following steps:
254
2551. If you do not have the nRF Connect SDK installed yet, create a directory for
256 it by running the following command:
257
258 $ mkdir ~/nrfconnect
259
2602. Download the latest version of the nRF Connect SDK Docker image by running
261 the following command:
262
263 $ docker pull nordicsemi/nrfconnect-chip
264
2653. Start Docker with the downloaded image by running the following command,
266 customized to your needs as described below:
267
268 $ docker run --rm -it -e RUNAS=$(id -u) -v ~/nrfconnect:/var/ncs -v ~/connectedhomeip:/var/chip \
269 -v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:* rmw" nordicsemi/nrfconnect-chip
270
271 In this command:
272
273 - _~/nrfconnect_ can be replaced with an absolute path to the nRF Connect
274 SDK source directory.
275 - _~/connectedhomeip_ must be replaced with an absolute path to the CHIP
276 source directory.
277 - _-v /dev/bus/usb:/dev/bus/usb --device-cgroup-rule "c 189:_ rmw"\*
278 parameters can be omitted if you are not planning to flash the example
279 onto hardware. These parameters give the container access to USB devices
280 connected to your computer such as the nRF52840 DK.
281 - _--rm_ can be omitted if you do not want the container to be
282 auto-removed when you exit the container shell session.
283 - _-e RUNAS=\$(id -u)_ is needed to start the container session as the
284 current user instead of root.
285
Kamil Kasperczyke4ab6f42021-03-11 15:17:03 +01002864. Update the nRF Connect SDK to the most recent supported revision, by running
287 the following command:
Damian Królikee937e62020-12-07 15:46:30 +0100288
Kamil Kasperczyke4ab6f42021-03-11 15:17:03 +0100289 $ cd /var/chip
290 $ python3 scripts/setup/nrfconnect/update_ncs.py --update
Damian Królikee937e62020-12-07 15:46:30 +0100291
292Now you can proceed with the [Building](#building) instruction.
293
294### Using native shell for setup
295
296To use the native shell for setup, complete the following steps:
297
2981. Download and install the following additional software:
299
300 - [nRF Command Line Tools](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Command-Line-Tools)
301 - [GN meta-build system](https://gn.googlesource.com/gn/)
302
Kamil Kasperczyke4ab6f42021-03-11 15:17:03 +01003032. If you do not have the nRF Connect SDK installed, follow the
304 [guide](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_assistant.html#)
305 in the nRF Connect SDK documentation to install the latest stable nRF
306 Connect SDK version. Since command-line tools will be used for building the
307 example, installing SEGGER Embedded Studio is not required.
Damian Królikee937e62020-12-07 15:46:30 +0100308
Kamil Kasperczyke4ab6f42021-03-11 15:17:03 +0100309 If you have the SDK already installed, continue to the next step and update
310 the nRF Connect SDK after initializing environment variables.
Damian Królikee937e62020-12-07 15:46:30 +0100311
3123. Initialize environment variables referred to by the CHIP and the nRF Connect
313 SDK build scripts. Replace _nrfconnect-dir_ with the path to your nRF
314 Connect SDK installation directory, and _toolchain-dir_ with the path to GNU
315 Arm Embedded Toolchain.
316
317 $ source nrfconnect-dir/zephyr/zephyr-env.sh
318 $ export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
319 $ export GNUARMEMB_TOOLCHAIN_PATH=toolchain-dir
320
Kamil Kasperczyke4ab6f42021-03-11 15:17:03 +01003214. Update the nRF Connect SDK to the most recent supported revision by running
322 the following command (replace _chip-dir_ with the path to CHIP repository
323 directory):
324
325 $ cd chip-dir
326 $ python3 scripts/setup/nrfconnect/update_ncs.py --update
327
Damian Królikee937e62020-12-07 15:46:30 +0100328Now you can proceed with the [Building](#building) instruction.
329
330<hr>
Damian Królik7734e2a2020-09-11 21:53:22 +0200331
332<a name="building"></a>
333
334## Building
335
Damian Królikee937e62020-12-07 15:46:30 +0100336Complete the following steps, regardless of the method used for setting up the
337environment:
Damian Królik7734e2a2020-09-11 21:53:22 +0200338
Damian Królikee937e62020-12-07 15:46:30 +01003391. Navigate to the example's directory:
Damian Królik994af3c2020-10-12 16:50:50 +0200340
Damian Królikee937e62020-12-07 15:46:30 +0100341 $ cd examples/lighting-app/nrfconnect
Damian Królik7734e2a2020-09-11 21:53:22 +0200342
Łukasz Duda4b61b4f2021-03-04 21:44:51 +01003432. Run the following command to build the example, with _build-target_ replaced
344 with the build target name of the Nordic Semiconductor's kit you own, for
345 example `nrf52840dk_nrf52840`:
Damian Królik7734e2a2020-09-11 21:53:22 +0200346
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100347 $ west build -b build-target
Damian Królik7734e2a2020-09-11 21:53:22 +0200348
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100349 You only need to specify the build target on the first build. See
350 [Requirements](#requirements) for the build target names of compatible kits.
Damian Królik7734e2a2020-09-11 21:53:22 +0200351
Damian Królikee937e62020-12-07 15:46:30 +0100352The output `zephyr.hex` file will be available in the `build/zephyr/` directory.
Damian Królik7734e2a2020-09-11 21:53:22 +0200353
Damian Królikee937e62020-12-07 15:46:30 +0100354### Removing build artifacts
Damian Królik7734e2a2020-09-11 21:53:22 +0200355
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100356If you're planning to build the example for a different kit or make changes to
Damian Królikee937e62020-12-07 15:46:30 +0100357the configuration, remove all build artifacts before building. To do so, use the
358following command:
Damian Królik7734e2a2020-09-11 21:53:22 +0200359
Damian Królikee937e62020-12-07 15:46:30 +0100360 $ rm -r build
Damian Królik7734e2a2020-09-11 21:53:22 +0200361
Damian Królikee937e62020-12-07 15:46:30 +0100362### Building with release configuration
Damian Królik7734e2a2020-09-11 21:53:22 +0200363
Damian Królikee937e62020-12-07 15:46:30 +0100364To build the example with release configuration that disables the diagnostic
365features like logs and command-line interface, run the following command:
Damian Królik7734e2a2020-09-11 21:53:22 +0200366
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100367 $ west build -b build-target -- -DOVERLAY_CONFIG=third_party/connectedhomeip/config/nrfconnect/app/release.conf
Damian Królik7734e2a2020-09-11 21:53:22 +0200368
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100369Remember to replace _build-target_ with the build target name of the Nordic
370Semiconductor's kit you own.
Damian Królik7734e2a2020-09-11 21:53:22 +0200371
Damian Królik1ff0b782021-01-07 15:25:43 +0100372### Building with Pigweed RPCs
373
rgoliver9783f902021-05-20 14:22:34 -0400374The RPCs in `lighting-common/lighting_service/lighting_service.proto` can be
375used to control various functionalities of the lighting app from a USB-connected
376host computer. To build the example with the RPC server, run the following
377command with _build-target_ replaced with the build target name of the Nordic
378Semiconductor's kit you own:
Damian Królik1ff0b782021-01-07 15:25:43 +0100379
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100380 $ west build -b build-target -- -DOVERLAY_CONFIG=rpc.overlay
Damian Królik1ff0b782021-01-07 15:25:43 +0100381
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +0200382### Building with Device Firmware Upgrade support
383
384To build the example with configuration that enables DFU, run the following
385command with _build-target_ replaced with the build target name of the Nordic
386Semiconductor's kit you own (for example `nrf52840dk_nrf52840`):
387
Kamil Kasperczykd369c412021-08-11 21:58:58 +0200388 $ west build -b build-target -- -DBUILD_WITH_DFU=1
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +0200389
Kamil Kasperczyk109214f2021-10-01 15:12:35 +0200390> **Note**:
391>
392> There are two types of Device Firmware Upgrade modes: single-image DFU and
393> multi-image DFU. Single-image mode supports upgrading only one firmware image,
394> the application image, and should be used for single-core nRF52840 DK devices.
395> Multi-image mode allows to upgrade more firmware images and is suitable for
396> upgrading the application core and network core firmware in two-core nRF5340
397> DK devices.
398
399#### Changing Device Firmware Upgrade configuration
400
401To change the default DFU configuration, edit the
402`overlay-single_image_dfu_support.conf` or
403`overlay-multi_image_dfu_support.conf` overlay files depending on whether the
404build target device supports multi-image DFU (nRF5340 DK) or single-image DFU
405(nRF52840 DK). The files are located in the `config/nrfconnect/app` directory.
406You can also define the desired options in your example's `prj.conf` file.
407
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +0200408#### Changing bootloader configuration
409
Kamil Kasperczyk109214f2021-10-01 15:12:35 +0200410To change the default MCUboot configuration, edit the
411`mcuboot_single_image_dfu.conf` or `mcuboot_multi_image_dfu.conf` overlay files
412depending on whether the build target device supports multi-image DFU (nRF5340
413DK) or single-image DFU (nRF52840 DK). The files are located in the
414`configuration` directory.
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +0200415
Kamil Kasperczyk109214f2021-10-01 15:12:35 +0200416Make sure to keep the configuration consistent with changes made to the
417application configuration. This is necessary for the configuration to work, as
418the bootloader image is a separate application from the user application and it
419has its own configuration file.
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +0200420
421#### Changing flash memory settings
422
423In the default configuration, the MCUboot uses the
424[Partition Manager](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/scripts/partition_manager/partition_manager.html#partition-manager)
425to configure flash partitions used for the bootloader application image slot
426purposes. You can change these settings by defining
427[static partitions](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/scripts/partition_manager/partition_manager.html#ug-pm-static).
428This example uses this option to define using an external flash.
429
430To modify the flash settings of your board (that is, your _build-target_, for
431example `nrf52840dk_nrf52840`), edit the `pm_static.yml` file located in the
432`configuration/build-target/` directory.
433
Damian Królikee937e62020-12-07 15:46:30 +0100434<hr>
Damian Królik19a520e2020-11-16 17:59:16 +0100435
Damian Królik7734e2a2020-09-11 21:53:22 +0200436<a name="configuring"></a>
437
438## Configuring the example
439
Damian Królikee937e62020-12-07 15:46:30 +0100440The Zephyr ecosystem is based on Kconfig files and the settings can be modified
441using the menuconfig utility.
Damian Królik7734e2a2020-09-11 21:53:22 +0200442
Damian Królikee937e62020-12-07 15:46:30 +0100443To open the menuconfig utility, run the following command from the example
444directory:
Damian Królik7734e2a2020-09-11 21:53:22 +0200445
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100446 $ west build -b build-target -t menuconfig
Damian Królik7734e2a2020-09-11 21:53:22 +0200447
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100448Remember to replace _build-target_ with the build target name of the Nordic
449Semiconductor's kit you own.
Damian Królik7734e2a2020-09-11 21:53:22 +0200450
Damian Królikee937e62020-12-07 15:46:30 +0100451Changes done with menuconfig will be lost if the `build` directory is deleted.
452To make them persistent, save the configuration options in the `prj.conf` file.
453For more information, see the
454[Configuring nRF Connect SDK examples](../../../docs/guides/nrfconnect_examples_configuration.md)
455page.
Damian Królik7734e2a2020-09-11 21:53:22 +0200456
Damian Królikee937e62020-12-07 15:46:30 +0100457<hr>
Damian Królik7734e2a2020-09-11 21:53:22 +0200458
459<a name="flashing"></a>
460
461## Flashing and debugging
462
Damian Królikc3edd9a2021-07-03 03:59:59 +0200463The flashing and debugging procedure is different for the development kits and
464the nRF52840 Dongle.
465
466<a name="nrfdks_flashing"></a>
467
468### Flashing on the development kits
469
Damian Królikee937e62020-12-07 15:46:30 +0100470To flash the application to the device, use the west tool and run the following
471command from the example directory:
Damian Królik7734e2a2020-09-11 21:53:22 +0200472
Damian Królik35dfbc42021-04-06 18:54:18 +0200473 $ west flash --erase
Damian Królik7734e2a2020-09-11 21:53:22 +0200474
Łukasz Duda4b61b4f2021-03-04 21:44:51 +0100475If you have multiple development kits connected, west will prompt you to pick
Damian Królikee937e62020-12-07 15:46:30 +0100476the correct one.
Damian Królik7734e2a2020-09-11 21:53:22 +0200477
Damian Królikee937e62020-12-07 15:46:30 +0100478To debug the application on target, run the following command from the example
479directory:
Damian Królik7734e2a2020-09-11 21:53:22 +0200480
Damian Królik7734e2a2020-09-11 21:53:22 +0200481 $ west debug
482
Damian Królikc3edd9a2021-07-03 03:59:59 +0200483<a name="nrf52840dongle_flashing"></a>
484
485### Flashing on the nRF52840 Dongle
486
487Visit
488[Programming and Debugging nRF52840 Dongle](https://docs.zephyrproject.org/latest/boards/arm/nrf52840dongle_nrf52840/doc/index.html#programming-and-debugging)
489to read more about flashing on the nRF52840 Dongle.
490
Damian Królikee937e62020-12-07 15:46:30 +0100491<hr>
Damian Królik7734e2a2020-09-11 21:53:22 +0200492
Damian Królikee937e62020-12-07 15:46:30 +0100493## Testing the example
Damian Królik7734e2a2020-09-11 21:53:22 +0200494
Damian Królikee937e62020-12-07 15:46:30 +0100495Check the [CLI tutorial](../../../docs/guides/nrfconnect_examples_cli.md) to
496learn how to use command-line interface of the application.
Kamil Kasperczyk1073ccf2021-02-01 17:35:59 +0100497
498### Testing using CHIPTool
499
500Read the
501[Android commissioning guide](../../../docs/guides/nrfconnect_android_commissioning.md)
502to see how to use [CHIPTool](../../../src/android/CHIPTool/README.md) for
503Android smartphones to commission and control the application within a
504CHIP-enabled Thread network.
Kamil Kasperczyk329ea7c2021-05-10 15:44:39 +0200505
506### Testing Device Firmware Upgrade
507
Kamil Kasperczyk17821b92021-06-02 00:10:40 +0200508Read the
509[DFU tutorial](../../../docs/guides/nrfconnect_examples_software_update.md) to
510see how to upgrade your device firmware.
rgoliver7f860ce2021-07-21 00:33:36 -0400511
512## Testing using the RPC console
513
514If the flashed device has been built with the pigweed RPCs, the RPC console can
515be used to interact with the device.
516
517Build or install the [rpc console](../../common/pigweed/rpc_console/README.md)
518
519Start the console
520
521 $ python -m chip_rpc.console --device /dev/ttyUSB0
522
523From within the console you can then invoke rpcs:
524
525 rpcs.chip.rpc.Lighting.Get()
526
rgoliver8b1cac72021-09-15 16:03:57 -0400527 rpcs.chip.rpc.Lighting.Set(on=True, level=128, color=protos.chip.rpc.LightingColor(hue=5, saturation=5))