tree: 03d0ba844d077cf108216ca4e07ec44c277d5661 [path history] [tgz]
  1. main/
  2. third_party/
  3. .gn
  4. args.gni
  5. BUILD.gn
  6. README.md
examples/lighting-app/nrf5/README.md

CHIP nRF52840 Lighting Example Application

:warning: nRF5 platform deprecated

This platform based on the nRF5 SDK for Thread and Zigbee is in maintenance mode and support for it will be removed from the CHIP project repository.

To develop CHIP applications on Nordic Semiconductor devices such as nRF52840, use the platform based on the nRF Connect SDK, located in the lighting-app/nrfconnect directory.

An example application showing the use CHIP on the Nordic nRF52840.

Introduction

nrf52840 DK

The nRF52840 lighting example application provides a working demonstration of a connected lighting device, built using CHIP, and the Nordic nRF5 SDK. The example supports remote access and control of a lighting over a low-power, 802.15.4 Thread network. It is capable of being paired into an existing CHIP network along with other CHIP-enabled devices. The example targets the Nordic nRF52840 DK development kit, but is readily adaptable to other nRF52840-based hardware.

The lighting example is intended to serve both as a means to explore the workings of CHIP, as well as a template for creating real products based on the Nordic platform.

The example application builds upon the CHIP. The build system orchestrates the entire build process, including building CHIP, and select files from the nRF5 SDK. The resultant image file can be flashed directly onto the Nordic dev kit hardware.

Device UI

The example application provides a simple UI that depicts the state of the device and offers basic user control. This UI is implemented via the general-purpose LEDs and buttons built in to the nRF52840 DK dev board.

LED #1 shows the overall state of the device and its connectivity. Four states are depicted:

  • Short Flash On (50ms on/950ms off) — The device is in an unprovisioned (unpaired) state and is waiting for a commissioning application to connect.
  • Rapid Even Flashing (100ms on/100ms off) — The device is in an unprovisioned state and a commissioning application is connected via BLE.
  • Short Flash Off (950ms on/50ms off) — The device is full provisioned, but does not yet have full network (Thread) or service connectivity.
  • Solid On — The device is fully provisioned and has full network and service connectivity.

Button #1 can be used to initiate a OTA software update as well as to reset the device to a default state.

Pressing and holding Button #1 for 6 seconds initiates a factory reset. After an initial period of 3 seconds, all four LED will flash in unison to signal the pending reset. Holding the button past 6 seconds will cause the device to reset its persistent configuration and initiate a reboot. The reset action can be cancelled by releasing the button at any point before the 6 second limit.

LED #2 shows the state of the lighting.

Button #2 can be used to change the state of the lighting. This can be used to mimick a user manually switching the lighting. The button behaves as a toggle, swapping the state every time it is pressed.

The remaining two LEDs and buttons (#3 and #4) are unused.

Building

Using CHIP's VSCode devcontainer

Tools and SDK are preinstalled in CHIP's VSCode devcontainer.

Other alternatives:

  • Run Build nRF5 Lock Example VSCode task.

  • Run the Build & Test (all) VSCode task.

  • Run the following commands in the Docker container shell.

    $ cd /workspaces/connectedhomeip/examples/lighting-app/nrf5
    
    $ git submodule update --init
    $ source third_party/connectedhomeip/scripts/activate.sh
    $ gn gen out/debug --args="nrf5_sdk_root=\"${NRF5_SDK_ROOT}\""
    $ ninja -C out/debug
    

Using Native Shell

  • Install some additional tools:

       # Linux
       $ sudo apt-get install git
    
  • Set the following environment variables based on the locations/versions of the packages installed above:

      export NRF5_SDK_ROOT=${HOME}/tools/nRF5_SDK_for_Thread_and_Zigbee_v4.0.0
      export NRF5_TOOLS_ROOT=${HOME}/tools/nRF-Command-Line-Tools
      export ARM_GCC_INSTALL_ROOT=${HOME}/tools/gcc-arm-none-eabi-9-2019-q4-major/bin
      export PATH=${PATH}:${NRF5_TOOLS_ROOT}/nrfjprog
    
  • Clone the CHIP repo into a local directory

      $ cd ~
      $ git clone https://github.com/project-chip/connectedhomeip.git
    
  • Run GN to build the application

      $ cd ~/connectedhomeip/examples/lighting-app/nrf5
      $ git submodule update --init
      $ source third_party/connectedhomeip/scripts/activate.sh
      $ gn gen out/debug --args="nrf5_sdk_root=\"${NRF5_SDK_ROOT}\""
      $ ninja -C out/debug
    

Initializing the nRF52840 DK

The example application is designed to run on the Nordic nRF52840 DK development kit. Prior to installing the application, the device's flash memory should be erased and the Nordic SoftDevice image installed.

  • Connect the host machine to the J-Link Interface MCU USB connector on the nRF52840 DK. The Interface MCU connector is the one on the short side of the board.
  • If you are using the GN build, the flashing script will install the SoftDevice image if it is not already present. If you prefer to do so manually first, to verify your board function, run:

      $ python3 \
          ~/connectedhomeip/third_party/nrf5_sdk/nrf5_firmware_utils.py \
          --eraseall \
          --application $NRF5_SDK_ROOT/components/softdevice/s140/hex/s140_nrf52_*_softdevice.hex
    

Once the above is complete, it shouldn't need be done again unless the SoftDevice image or the Nordic configuration storage (fds) area becomes corrupt. To correct either of these problems erase the device and reflash the SoftDevice and application again.

Flashing the Application

To flash the example app, run the following commands:

    $ cd ~/connectedhomeip/examples/lighting-app/nrf5
    $ python3 out/debug/chip-nrf52840-lighting-example.flash.py

The VSCode devcontainer cannot communicate with the nRF device. So, the above command must be run from a native shell. This also means that the nRF command line tools must be installed on your development machine.

Viewing Logging Output

The example application is built to use the SEGGER Real Time Transfer (RTT) facility for log output. RTT is a feature built-in to the J-Link Interface MCU on the development kit board. It allows bi-directional communication with an embedded application without the need for a dedicated UART.

Using the RTT facility requires downloading and installing the SEGGER J-Link Software and Documentation Pack (web site).

  • Download the J-Link installer by navigating to the appropriate URL and agreeing to the license agreement.
  • Install the J-Link software

      $ cd ~/Downloads
      $ sudo dpkg -i JLink_Linux_V*_x86_64.deb
    
  • In Linux, grant the logged in user the ability to talk to the development hardware via the linux tty device (/dev/ttyACMx) by adding them to the dialout group.

      $ sudo usermod -a -G dialout ${USER}
    

Once the above is complete, log output can be viewed using the JLinkExe tool in combination with JLinkRTTClient as follows:

  • Run the JLinkExe tool with arguments to autoconnect to the nRF82480 DK board:

      $ JLinkExe -device NRF52840_XXAA -if SWD -speed 4000 -autoconnect 1
    
  • In a second terminal, run the JLinkRTTClient:

      $ JLinkRTTClient
    

Logging output will appear in the second terminal.

An alternate method for viewing log output is to use the J-Link GDB server described in the following section.