tree: e8c13fbb5918b2ca243ed3ff873d6a4ca844e1ed [path history] [tgz]
  1. doc/
  2. main/
  3. third_party/
  4. Makefile
  5. README.md
examples/lock-app/k32w/README.md

CHIP K32W061 Lock Example Application

An example application showing the use of CHIP on the NXP K32W061 board.

Introduction

K32W061 DK6

The K32W lock example application provides a working demonstration of a connected door lock device, built using CHIP, and the NXP K32W061 SDK. The example supports remote access (e.g.: using CHIP Tool from a mobile phone) and control of a simulated door lock 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 NXP K32W061 DK6 development kit, but is readily adaptable to other K32W-based hardware.

The lock 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 NXP platform.

The example application builds upon the CHIP. A top-level Makefile orchestrates the entire build process, including building CHIP, and select files from the NXP SDK. The resultant image file can be flashed directly onto the NXP dev kit hardware using MCUXpresso.

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 OM15082 Expansion board attached to the DK6 board.

LED D2 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 SW2 can be used to reset the device to a default state.

Pressing and holding Button SW2 for 6 seconds initiates a factory reset. After an initial period of 3 seconds, LED2 D2 and D3 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 D3 shows the state of the simulated lock bolt. When the LED is lit the bolt is extended (i.e. door locked); when not lit, the bolt is retracted (door unlocked). The LED will flash whenever the simulated bolt is in motion from one position to another.

Button SW3 can be used to change the state of the simulated bolt. This can be used to mimick a user manually operating the lock. The button behaves as a toggle, swapping the state every time it is pressed.

Button SW4 can be used for joining a Thread network advertised by a Border Router. At this moment, Thread commissioning parameters are hard-coded but a future PR will add support for transmiting them over BLE.

The remaining two LEDs(D1/D2) and button (SW1) are unused.

Building

In order to build Project CHIP, we recommend using a Linux distribution (the demo-application was compiled on Ubuntu 20.04).

  • Download SDK 2.6.1 MR1 for Project CHIP. You need to create an account before being able to download an SDK. Once the account is created, login and follow the steps for downloading SDK_2.6.1_K32W061DK6. The UI is very intuitive and the correct selection should be similiar with the one from the image below. MCUXpresso SDK Download

  • Download the suitable ARM GCC toolchain for your Linux distribution

  • Set two Linux environmental variables based on the above downloaded packages:

user@ubuntu:~/Desktop/git/connectedhomeip$ export K32W061_SDK_ROOT=/home/user/Desktop/git/SDK_2.6.1_K32W061DK6
user@ubuntu:~/Desktop/git/connectedhomeip$ export GNU_INSTALL_ROOT=/home/user/Desktop/git/gcc-arm-none-eabi-7-2018-q2-update/bin/
  • You may start building the application
user@ubuntu:~/Desktop/git/connectedhomeip$ cd examples/lock-app/k32w/
user@ubuntu:~/Desktop/git/connectedhomeip/examples/lock-app/k32w$ make

In case OpenThread fails to compile due to some signing errors just follow the compilation logs and install the recommanded packages (python version > 3, pip3, pycrypto, pycryptodome):

user@ubuntu:~$ python3 --version
Python 3.8.2
user@ubuntu:~$ pip3 --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
user@ubuntu:~$ pip3 list | grep -i pycrypto
pycrypto               2.6.1
pycryptodome           3.9.8

The resulting elf file can be found in the build directory and it's named chip-k32w061-lock-example.elf.

Flashing and debugging

In order to flash the application we recommend using MCUXpresso IDE (version >= 11.0.0).

  • Import the previously downloaded NXP SDK into MCUXpresso IDE. This can be done by drag-and-dropping the SDK archive into MCUXpresso IDE's “Installed SDKs” tab; Select SDK
  • Import Project CHIP in MCUXpresso IDE as Makefile Project: File->Import->C/C++->Existing Code as Makefile Project-> Next . Select Project CHIP folder as the Existing Code Location. In the Toolchain for Indexer Settings list, be sure to keep the setting to none. Click Finish;
  • Configure MCU Settings: right click on project from the workspace and go to Properties->C/C++ Build->MCU Settings. Select K32W061 from the SDK MCUs list;
  • Configure the toolchain editor: C/C++ Build->Tool Chain Editor. Untick the Display compatible toolchains only checkbox. In the drop-down menu named Current toolchain, select NXP MCU Tools. Click Apply and Close;
  • Create a debug configuration: right click on the project and select Debug As->MCUXpresso IDE LinkServer (inc. CMSIS-DAP) probes. A window to select the binary will appear. Select examples/lock-app/k32w/build/chip-k32w061-lock-example.elf and click OK;
  • Use the debug configuration: under the menu bar, towards the center of the screen, there is a green bug icon with a drop-down arrow next to it. Click on the arrow and select Debug Configurations. In the right side of the Debug Configurations window, go to C/C++ (NXP Semiconductors) MCU Application->openthread LinkServer Default. Make sure that the C/C++ Application text box contains examples/lock-app/k32w/build/chip-k32w061-lock-example.elf path. Go to GUI Flash Tool tab. In Target Operations->Program->Options, select “bin” as the Format to use for programming. Make sure the Base address is 0x0. Click Debug. A pop-up window entitled Errors in Workspace will appear. Click Proceed. Debug_configuration