| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 1 | # CHIP nRF Connect Lighting Example Application |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 2 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 3 | The nRF Connect Lighting Example demonstrates how to remotely control a white |
| Damian Królik | baa90e5 | 2021-01-05 17:08:37 +0100 | [diff] [blame] | 4 | dimmable light bulb. It uses buttons to test changing the lighting and device |
| 5 | states and LEDs to show the state of these changes. You can use this example as |
| 6 | a reference for creating your own application. |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 7 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 8 | <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ólik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 13 | The example is based on [CHIP](https://github.com/project-chip/connectedhomeip) |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 14 | and Nordic Semiconductor's nRF Connect SDK, and supports remote access and |
| 15 | control of a lighting over a low-power, 802.15.4 Thread network. |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 16 | |
| 17 | The example behaves as a CHIP accessory, that is a device that can be paired |
| 18 | into an existing CHIP network and can be controlled by this network. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 19 | |
| 20 | <hr> |
| 21 | |
| Damian Królik | 1ff0b78 | 2021-01-07 15:25:43 +0100 | [diff] [blame] | 22 | - [Overview](#overview) |
| 23 | - [Bluetooth LE advertising](#bluetooth-le-advertising) |
| 24 | - [Bluetooth LE rendezvous](#bluetooth-le-rendezvous) |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 25 | - [Device Firmware Upgrade](#device-firmware-upgrade) |
| Damian Królik | 1ff0b78 | 2021-01-07 15:25:43 +0100 | [diff] [blame] | 26 | - [Requirements](#requirements) |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 27 | - [Supported devices](#supported_devices) |
| Damian Królik | 1ff0b78 | 2021-01-07 15:25:43 +0100 | [diff] [blame] | 28 | - [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) |
| szatmz | 8a76b4a | 2020-12-09 13:55:05 -0500 | [diff] [blame] | 35 | - [Building with Pigweed RPCs](#building-with-pigweed-rpcs) |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 36 | - [Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support) |
| Damian Królik | 1ff0b78 | 2021-01-07 15:25:43 +0100 | [diff] [blame] | 37 | - [Configuring the example](#configuring-the-example) |
| 38 | - [Flashing and debugging](#flashing-and-debugging) |
| Damian Królik | c3edd9a | 2021-07-03 03:59:59 +0200 | [diff] [blame] | 39 | - [Flashing on the development kits](#nrfdks_flashing) |
| 40 | - [Flashing on the nRF52840 Dongle](#nrf52840dongle_flashing) |
| Damian Królik | 1ff0b78 | 2021-01-07 15:25:43 +0100 | [diff] [blame] | 41 | - [Testing the example](#testing-the-example) |
| Kamil Kasperczyk | 1073ccf | 2021-02-01 17:35:59 +0100 | [diff] [blame] | 42 | - [Testing using CHIPTool](#testing-using-chiptool) |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 43 | - [Testing Device Firmware Upgrade](#testing-device-firmware-upgrade) |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 44 | |
| 45 | <hr> |
| 46 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 47 | <a name="overview"></a> |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 48 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 49 | ## Overview |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 50 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 51 | This example is running on the nRF Connect platform, which is based on Nordic |
| 52 | Semiconductor's |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 53 | [nRF Connect SDK](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/index.html) |
| 54 | and [Zephyr RTOS](https://zephyrproject.org/). Visit CHIP's |
| 55 | [nRF Connect platform overview](../../../docs/guides/nrfconnect_platform_overview.md) |
| 56 | to read more about the platform structure and dependencies. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 57 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 58 | The CHIP device that runs the lighting application is controlled by the CHIP |
| 59 | controller device over the Thread protocol. By default, the CHIP device has |
| 60 | Thread disabled, and it should be paired with CHIP controller and get |
| 61 | configuration from it. Some actions required before establishing full |
| 62 | communication are described below. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 63 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 64 | The example also comes with a test mode, which allows to start Thread with the |
| 65 | default settings by pressing button manually. However, this mode does not |
| 66 | guarantee that the device will be able to communicate with the CHIP controller |
| 67 | and other devices. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 68 | |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 69 | The example can be configured to use the secure bootloader and utilize it for |
| 70 | performing over-the-air Device Firmware Upgrade using Bluetooth LE. |
| 71 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 72 | ### Bluetooth LE advertising |
| 73 | |
| 74 | To commission the device onto a CHIP network, the device must be discoverable |
| Kamil Kasperczyk | d369c41 | 2021-08-11 21:58:58 +0200 | [diff] [blame] | 75 | over Bluetooth LE that starts automatically upon the device startup, but only |
| 76 | for a predefined period of time (15 minutes by default). If the Bluetooth LE |
| 77 | advertising times out, you can re-enable it manually using **Button 4**. |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 78 | |
| 79 | ### Bluetooth LE rendezvous |
| 80 | |
| Damian Królik | c3edd9a | 2021-07-03 03:59:59 +0200 | [diff] [blame] | 81 | In CHIP, the commissioning procedure is done over Bluetooth LE between a CHIP |
| 82 | device and the CHIP controller, where the controller has the commissioner role. |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 83 | |
| 84 | To start the rendezvous, the controller must get the commissioning information |
| 85 | from the CHIP device. The data payload is encoded within a QR code, printed to |
| Damian Królik | 6e96fca | 2021-07-27 17:21:21 +0200 | [diff] [blame] | 86 | the UART console, and shared using an NFC tag. NFC tag emulation starts |
| 87 | automatically when Bluetooth LE advertising is started and stays enabled until |
| 88 | Bluetooth LE advertising timeout expires. |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 89 | |
| 90 | #### Thread provisioning |
| 91 | |
| 92 | Last part of the rendezvous procedure, the provisioning operation involves |
| 93 | sending the Thread network credentials from the CHIP controller to the CHIP |
| 94 | device. As a result, device is able to join the Thread network and communicate |
| 95 | with other Thread devices in the network. |
| 96 | |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 97 | ### Device Firmware Upgrade |
| 98 | |
| 99 | The example allows enabling the over-the-air Device Firmware Upgrade feature. In |
| 100 | this process, the device hosting new firmware image sends the image to the CHIP |
| 101 | device 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). |
| 103 | The |
| 104 | [MCUboot](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/mcuboot/index.html) |
| 105 | bootloader solution then replaces the old firmware image with the new one. |
| 106 | |
| 107 | #### Bootloader |
| 108 | |
| 109 | MCUboot is a secure bootloader used for swapping firmware images of different |
| 110 | versions and generating proper build output files that can be used in the device |
| 111 | firmware upgrade process. |
| 112 | |
| 113 | The bootloader solution requires an area of flash memory to swap application |
| 114 | images during the firmware upgrade. The Nordic devices use an external memory |
| 115 | chip for this purpose. The memory chip communicates with the microcontroller |
| 116 | through the QSPI bus. |
| 117 | |
| 118 | See the |
| 119 | [Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support) |
| 120 | section to learn how to change MCUboot and flash configuration in this example. |
| 121 | |
| 122 | #### Simple Management Protocol |
| 123 | |
| 124 | Simple Management Protocol (SMP) is a basic transfer encoding that is used for |
| 125 | device management purposes, including application image management. SMP supports |
| 126 | using different transports, such as Bluetooth LE, UDP, or serial USB/UART. |
| 127 | |
| 128 | In this example, the CHIP device runs the SMP Server to download the application |
| 129 | update image using the Bluetooth LE transport. |
| 130 | |
| 131 | See the |
| 132 | [Building with Device Firmware Upgrade support](#building-with-device-firmware-upgrade-support) |
| 133 | section to learn how to enable SMP and use it for the DFU purpose in this |
| 134 | example. |
| 135 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 136 | <hr> |
| 137 | |
| 138 | <a name="requirements"></a> |
| 139 | |
| 140 | ## Requirements |
| 141 | |
| Kamil Kasperczyk | e4ab6f4 | 2021-03-11 15:17:03 +0100 | [diff] [blame] | 142 | The application requires a specific revision of the nRF Connect SDK to work |
| 143 | correctly. See [Setting up the environment](#setting-up-the-environment) for |
| 144 | more information. |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 145 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 146 | <a name="supported_devices"></a> |
| 147 | |
| 148 | ### Supported devices |
| 149 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 150 | The example supports building and running on the following devices: |
| 151 | |
| Damian Królik | c3edd9a | 2021-07-03 03:59:59 +0200 | [diff] [blame] | 152 | | 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ólik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 157 | |
| 158 | <hr> |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 159 | |
| 160 | <a name="device-ui"></a> |
| 161 | |
| 162 | ## Device UI |
| 163 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 164 | This section lists the User Interface elements that you can use to control and |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 165 | monitor the state of the device. These correspond to PCB components on the |
| 166 | platform image. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 167 | |
| Damian Królik | c3edd9a | 2021-07-03 03:59:59 +0200 | [diff] [blame] | 168 | > **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ólik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 177 | **LED 1** shows the overall state of the device and its connectivity. The |
| 178 | following states are possible: |
| 179 | |
| 180 | - _Short Flash On (50 ms on/950 ms off)_ — The device is in the |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 181 | unprovisioned (unpaired) state and is waiting for a commissioning |
| 182 | application to connect. |
| 183 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 184 | - _Rapid Even Flashing (100 ms on/100 ms off)_ — The device is in the |
| 185 | unprovisioned state and a commissioning application is connected through |
| 186 | Bluetooth LE. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 187 | |
| Damian Królik | 994af3c | 2020-10-12 16:50:50 +0200 | [diff] [blame] | 188 | - _Short Flash Off (950ms on/50ms off)_ — The device is fully |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 189 | provisioned, but does not yet have full Thread network or service |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 190 | connectivity. |
| 191 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 192 | - _Solid On_ — The device is fully provisioned and has full Thread |
| 193 | network and service connectivity. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 194 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 195 | **LED 2** simulates the light bulb and shows the state of the lighting. The |
| 196 | following states are possible: |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 197 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 198 | - _Solid On_ — The light bulb is on. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 199 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 200 | - _Off_ — The light bulb is off. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 201 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 202 | **Button 1** can be used for the following purposes: |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 203 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 204 | - _Pressed for 6 s_ — 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ólik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 208 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 209 | - _Pressed for less than 3 s_ — Initiates the OTA software update |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 210 | 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 Kasperczyk | 8a84d97 | 2020-10-28 19:57:37 +0100 | [diff] [blame] | 214 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 215 | **Button 2** — Pressing the button once changes the lighting state to the |
| 216 | opposite one. |
| Kamil Kasperczyk | 005b7ae | 2020-11-05 17:42:51 +0100 | [diff] [blame] | 217 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 218 | **Button 3** — Pressing the button once starts the Thread networking in |
| 219 | the test mode using the default configuration. |
| Kamil Kasperczyk | 005b7ae | 2020-11-05 17:42:51 +0100 | [diff] [blame] | 220 | |
| Kamil Kasperczyk | e02e8d0 | 2021-01-11 21:28:51 +0100 | [diff] [blame] | 221 | **Button 4** — Pressing the button once starts the NFC tag emulation and |
| rgoliver | 8b1cac7 | 2021-09-15 16:03:57 -0400 | [diff] [blame] | 222 | enables Bluetooth LE advertising for the predefined period of time (15 minutes |
| 223 | by default). |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 224 | |
| 225 | **SEGGER J-Link USB port** can be used to get logs from the device or |
| 226 | communicate 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 |
| 231 | information from the CHIP device in a data payload that can be shared using NFC. |
| 232 | |
| 233 | <hr> |
| 234 | |
| 235 | ## Setting up the environment |
| 236 | |
| 237 | Before building the example, check out the CHIP repository and sync submodules |
| 238 | using the following command: |
| 239 | |
| 240 | $ git submodule update --init |
| 241 | |
| Kamil Kasperczyk | e4ab6f4 | 2021-03-11 15:17:03 +0100 | [diff] [blame] | 242 | The example requires a specific revision of the nRF Connect SDK. You can either |
| 243 | install it along with the related tools directly on your system or use a Docker |
| 244 | image that has the tools pre-installed. |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 245 | |
| 246 | If you are a macOS user, you won't be able to use the Docker container to flash |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 247 | the application onto a Nordic development kit due to |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 248 | [certain limitations of Docker for macOS](https://docs.docker.com/docker-for-mac/faqs/#can-i-pass-through-a-usb-device-to-a-container). |
| 249 | Use the [native shell](#using-native-shell) for building instead. |
| 250 | |
| 251 | ### Using Docker container for setup |
| 252 | |
| 253 | To use the Docker container for setup, complete the following steps: |
| 254 | |
| 255 | 1. 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 | |
| 260 | 2. 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 | |
| 265 | 3. 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 Kasperczyk | e4ab6f4 | 2021-03-11 15:17:03 +0100 | [diff] [blame] | 286 | 4. Update the nRF Connect SDK to the most recent supported revision, by running |
| 287 | the following command: |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 288 | |
| Kamil Kasperczyk | e4ab6f4 | 2021-03-11 15:17:03 +0100 | [diff] [blame] | 289 | $ cd /var/chip |
| 290 | $ python3 scripts/setup/nrfconnect/update_ncs.py --update |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 291 | |
| 292 | Now you can proceed with the [Building](#building) instruction. |
| 293 | |
| 294 | ### Using native shell for setup |
| 295 | |
| 296 | To use the native shell for setup, complete the following steps: |
| 297 | |
| 298 | 1. 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 Kasperczyk | e4ab6f4 | 2021-03-11 15:17:03 +0100 | [diff] [blame] | 303 | 2. 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ólik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 308 | |
| Kamil Kasperczyk | e4ab6f4 | 2021-03-11 15:17:03 +0100 | [diff] [blame] | 309 | 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ólik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 311 | |
| 312 | 3. 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 Kasperczyk | e4ab6f4 | 2021-03-11 15:17:03 +0100 | [diff] [blame] | 321 | 4. 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ólik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 328 | Now you can proceed with the [Building](#building) instruction. |
| 329 | |
| 330 | <hr> |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 331 | |
| 332 | <a name="building"></a> |
| 333 | |
| 334 | ## Building |
| 335 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 336 | Complete the following steps, regardless of the method used for setting up the |
| 337 | environment: |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 338 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 339 | 1. Navigate to the example's directory: |
| Damian Królik | 994af3c | 2020-10-12 16:50:50 +0200 | [diff] [blame] | 340 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 341 | $ cd examples/lighting-app/nrfconnect |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 342 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 343 | 2. 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ólik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 346 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 347 | $ west build -b build-target |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 348 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 349 | 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ólik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 351 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 352 | The output `zephyr.hex` file will be available in the `build/zephyr/` directory. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 353 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 354 | ### Removing build artifacts |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 355 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 356 | If you're planning to build the example for a different kit or make changes to |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 357 | the configuration, remove all build artifacts before building. To do so, use the |
| 358 | following command: |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 359 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 360 | $ rm -r build |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 361 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 362 | ### Building with release configuration |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 363 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 364 | To build the example with release configuration that disables the diagnostic |
| 365 | features like logs and command-line interface, run the following command: |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 366 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 367 | $ west build -b build-target -- -DOVERLAY_CONFIG=third_party/connectedhomeip/config/nrfconnect/app/release.conf |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 368 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 369 | Remember to replace _build-target_ with the build target name of the Nordic |
| 370 | Semiconductor's kit you own. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 371 | |
| Damian Królik | 1ff0b78 | 2021-01-07 15:25:43 +0100 | [diff] [blame] | 372 | ### Building with Pigweed RPCs |
| 373 | |
| rgoliver | 9783f90 | 2021-05-20 14:22:34 -0400 | [diff] [blame] | 374 | The RPCs in `lighting-common/lighting_service/lighting_service.proto` can be |
| 375 | used to control various functionalities of the lighting app from a USB-connected |
| 376 | host computer. To build the example with the RPC server, run the following |
| 377 | command with _build-target_ replaced with the build target name of the Nordic |
| 378 | Semiconductor's kit you own: |
| Damian Królik | 1ff0b78 | 2021-01-07 15:25:43 +0100 | [diff] [blame] | 379 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 380 | $ west build -b build-target -- -DOVERLAY_CONFIG=rpc.overlay |
| Damian Królik | 1ff0b78 | 2021-01-07 15:25:43 +0100 | [diff] [blame] | 381 | |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 382 | ### Building with Device Firmware Upgrade support |
| 383 | |
| 384 | To build the example with configuration that enables DFU, run the following |
| 385 | command with _build-target_ replaced with the build target name of the Nordic |
| 386 | Semiconductor's kit you own (for example `nrf52840dk_nrf52840`): |
| 387 | |
| Kamil Kasperczyk | d369c41 | 2021-08-11 21:58:58 +0200 | [diff] [blame] | 388 | $ west build -b build-target -- -DBUILD_WITH_DFU=1 |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 389 | |
| Kamil Kasperczyk | 109214f | 2021-10-01 15:12:35 +0200 | [diff] [blame] | 390 | > **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 | |
| 401 | To 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 |
| 404 | build 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. |
| 406 | You can also define the desired options in your example's `prj.conf` file. |
| 407 | |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 408 | #### Changing bootloader configuration |
| 409 | |
| Kamil Kasperczyk | 109214f | 2021-10-01 15:12:35 +0200 | [diff] [blame] | 410 | To change the default MCUboot configuration, edit the |
| 411 | `mcuboot_single_image_dfu.conf` or `mcuboot_multi_image_dfu.conf` overlay files |
| 412 | depending on whether the build target device supports multi-image DFU (nRF5340 |
| 413 | DK) or single-image DFU (nRF52840 DK). The files are located in the |
| 414 | `configuration` directory. |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 415 | |
| Kamil Kasperczyk | 109214f | 2021-10-01 15:12:35 +0200 | [diff] [blame] | 416 | Make sure to keep the configuration consistent with changes made to the |
| 417 | application configuration. This is necessary for the configuration to work, as |
| 418 | the bootloader image is a separate application from the user application and it |
| 419 | has its own configuration file. |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 420 | |
| 421 | #### Changing flash memory settings |
| 422 | |
| 423 | In 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) |
| 425 | to configure flash partitions used for the bootloader application image slot |
| 426 | purposes. 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). |
| 428 | This example uses this option to define using an external flash. |
| 429 | |
| 430 | To modify the flash settings of your board (that is, your _build-target_, for |
| 431 | example `nrf52840dk_nrf52840`), edit the `pm_static.yml` file located in the |
| 432 | `configuration/build-target/` directory. |
| 433 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 434 | <hr> |
| Damian Królik | 19a520e | 2020-11-16 17:59:16 +0100 | [diff] [blame] | 435 | |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 436 | <a name="configuring"></a> |
| 437 | |
| 438 | ## Configuring the example |
| 439 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 440 | The Zephyr ecosystem is based on Kconfig files and the settings can be modified |
| 441 | using the menuconfig utility. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 442 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 443 | To open the menuconfig utility, run the following command from the example |
| 444 | directory: |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 445 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 446 | $ west build -b build-target -t menuconfig |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 447 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 448 | Remember to replace _build-target_ with the build target name of the Nordic |
| 449 | Semiconductor's kit you own. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 450 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 451 | Changes done with menuconfig will be lost if the `build` directory is deleted. |
| 452 | To make them persistent, save the configuration options in the `prj.conf` file. |
| 453 | For more information, see the |
| 454 | [Configuring nRF Connect SDK examples](../../../docs/guides/nrfconnect_examples_configuration.md) |
| 455 | page. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 456 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 457 | <hr> |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 458 | |
| 459 | <a name="flashing"></a> |
| 460 | |
| 461 | ## Flashing and debugging |
| 462 | |
| Damian Królik | c3edd9a | 2021-07-03 03:59:59 +0200 | [diff] [blame] | 463 | The flashing and debugging procedure is different for the development kits and |
| 464 | the nRF52840 Dongle. |
| 465 | |
| 466 | <a name="nrfdks_flashing"></a> |
| 467 | |
| 468 | ### Flashing on the development kits |
| 469 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 470 | To flash the application to the device, use the west tool and run the following |
| 471 | command from the example directory: |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 472 | |
| Damian Królik | 35dfbc4 | 2021-04-06 18:54:18 +0200 | [diff] [blame] | 473 | $ west flash --erase |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 474 | |
| Łukasz Duda | 4b61b4f | 2021-03-04 21:44:51 +0100 | [diff] [blame] | 475 | If you have multiple development kits connected, west will prompt you to pick |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 476 | the correct one. |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 477 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 478 | To debug the application on target, run the following command from the example |
| 479 | directory: |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 480 | |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 481 | $ west debug |
| 482 | |
| Damian Królik | c3edd9a | 2021-07-03 03:59:59 +0200 | [diff] [blame] | 483 | <a name="nrf52840dongle_flashing"></a> |
| 484 | |
| 485 | ### Flashing on the nRF52840 Dongle |
| 486 | |
| 487 | Visit |
| 488 | [Programming and Debugging nRF52840 Dongle](https://docs.zephyrproject.org/latest/boards/arm/nrf52840dongle_nrf52840/doc/index.html#programming-and-debugging) |
| 489 | to read more about flashing on the nRF52840 Dongle. |
| 490 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 491 | <hr> |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 492 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 493 | ## Testing the example |
| Damian Królik | 7734e2a | 2020-09-11 21:53:22 +0200 | [diff] [blame] | 494 | |
| Damian Królik | ee937e6 | 2020-12-07 15:46:30 +0100 | [diff] [blame] | 495 | Check the [CLI tutorial](../../../docs/guides/nrfconnect_examples_cli.md) to |
| 496 | learn how to use command-line interface of the application. |
| Kamil Kasperczyk | 1073ccf | 2021-02-01 17:35:59 +0100 | [diff] [blame] | 497 | |
| 498 | ### Testing using CHIPTool |
| 499 | |
| 500 | Read the |
| 501 | [Android commissioning guide](../../../docs/guides/nrfconnect_android_commissioning.md) |
| 502 | to see how to use [CHIPTool](../../../src/android/CHIPTool/README.md) for |
| 503 | Android smartphones to commission and control the application within a |
| 504 | CHIP-enabled Thread network. |
| Kamil Kasperczyk | 329ea7c | 2021-05-10 15:44:39 +0200 | [diff] [blame] | 505 | |
| 506 | ### Testing Device Firmware Upgrade |
| 507 | |
| Kamil Kasperczyk | 17821b9 | 2021-06-02 00:10:40 +0200 | [diff] [blame] | 508 | Read the |
| 509 | [DFU tutorial](../../../docs/guides/nrfconnect_examples_software_update.md) to |
| 510 | see how to upgrade your device firmware. |
| rgoliver | 7f860ce | 2021-07-21 00:33:36 -0400 | [diff] [blame] | 511 | |
| 512 | ## Testing using the RPC console |
| 513 | |
| 514 | If the flashed device has been built with the pigweed RPCs, the RPC console can |
| 515 | be used to interact with the device. |
| 516 | |
| 517 | Build or install the [rpc console](../../common/pigweed/rpc_console/README.md) |
| 518 | |
| 519 | Start the console |
| 520 | |
| 521 | $ python -m chip_rpc.console --device /dev/ttyUSB0 |
| 522 | |
| 523 | From within the console you can then invoke rpcs: |
| 524 | |
| 525 | rpcs.chip.rpc.Lighting.Get() |
| 526 | |
| rgoliver | 8b1cac7 | 2021-09-15 16:03:57 -0400 | [diff] [blame] | 527 | rpcs.chip.rpc.Lighting.Set(on=True, level=128, color=protos.chip.rpc.LightingColor(hue=5, saturation=5)) |