Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull/nxp nxp smart lock demo app v2 #2340

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions config/k32w/k32w061-chip.mk
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ CHIP_CONFIGURE_OPTIONS = \
--with-lwip-target=k32w \
--with-inet-endpoint="tcp udp" \
--with-openssl=no \
--with-openthread=$(K32W061_SDK_ROOT)/middleware/wireless/openthread/openthread \
--with-openthread=internal \
--with-logging-style=external \
--with-chip-project-includes=$(CHIP_PROJECT_CONFIG) \
--with-chip-system-project-includes=$(CHIP_PROJECT_CONFIG) \
Expand Down Expand Up @@ -140,9 +140,7 @@ STD_INC_DIRS += \
$(K32W061_SDK_ROOT)/middleware/wireless/framework/Lists \
$(K32W061_SDK_ROOT)/middleware/wireless/framework/PDM/Include \
$(K32W061_SDK_ROOT)/middleware/wireless/framework/MemManager/Interface \
$(K32W061_SDK_ROOT)/middleware/wireless/openthread/openthread \
$(K32W061_SDK_ROOT)/middleware/wireless/openthread/openthread/include \
$(K32W061_SDK_ROOT)/middleware/wireless/openthread/openthread/examples/platforms
$(CHIP_ROOT)/third_party/openthread/repo/examples/platforms

# Add the location of CHIP libraries to application link action.
STD_LDFLAGS += -L$(CHIP_OUTPUT_DIR)/lib
Expand Down
84 changes: 84 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,8 @@ k32w)
CONFIG_DEVICE_LAYER=1
CHIP_DEVICE_LAYER_TARGET=K32W
CHIP_DEVICE_LAYER_TARGET_K32W=1
CFLAGS="${CFLAGS} -mcpu=cortex-m4 -mfloat-abi=soft -mthumb"
CXXFLAGS="${CXXFLAGS} -mcpu=cortex-m4 -mfloat-abi=soft -mthumb"
;;

nrfconnect)
Expand Down Expand Up @@ -1793,6 +1795,88 @@ NL_WITH_OPTIONAL_INTERNAL_PACKAGE(
maybe_openthread_dirstem="openthread"
;;

k32w)
OPENTHREAD_CPPFLAGS="-I\${abs_top_srcdir}/third_party/openthread/repo/include"
OPENTHREAD_LDFLAGS="-L${ac_pwd}/third_party/openthread"
OPENTHREAD_LIBS="-lopenthread-cli-ftd \
-lopenthread-ftd \
-lopenthread-platform-utils \
-lopenthread-mtd \
-lopenthread-k32w061_plat\
-lopenthread-k32w061_sdk \
-lmbedcrypto \
\${K32W061_SDK_ROOT}/middleware/wireless/ieee-802.15.4/lib/libMiniMac.a \
\${K32W061_SDK_ROOT}/middleware/wireless/framework/XCVR/lib/libRadio.a \
\${K32W061_SDK_ROOT}/middleware/wireless/framework/PDM/Library/libPDM.a "

# private definitions
ot_cppflags="-Wno-expansion-to-defined \
-I${chip_srcdir}/third_party/openthread/repo/examples/platforms/k32w/k32w061 \
-I${chip_srcdir}/third_party/openthread/repo/examples/platforms \
-I${chip_srcdir}/third_party/openthread/repo/include \
-I${chip_srcdir}/third_party/openthread/repo/src/core \
-I${chip_srcdir}/third_party/mbedtls/repo/include \
-I${chip_srcdir}/third_party/mbedtls/repo/ \
-I${K32W061_SDK_ROOT}/middleware/mbedtls/port/ksdk \
-I${K32W061_SDK_ROOT}/middleware/mbedtls/repo/include/mbedtls \
-I${K32W061_SDK_ROOT}/middleware/wireless/ieee-802.15.4/uMac/Include \
-I${K32W061_SDK_ROOT}/middleware/wireless/framework/Common \
-I${K32W061_SDK_ROOT}/middleware/wireless/framework/XCVR/DK6/Build/Include \
-I${K32W061_SDK_ROOT}/middleware/wireless/framework/XCVR/DK6 \
-I${K32W061_SDK_ROOT}/middleware/wireless/framework/SerialManager/Source \
-I${K32W061_SDK_ROOT}/middleware/wireless/framework/TimersManager/Source \
-I${K32W061_SDK_ROOT}/components/serial_manager \
-I${K32W061_SDK_ROOT}/components/uart \
-I${K32W061_SDK_ROOT}/devices/K32W061 \
-I${K32W061_SDK_ROOT}/devices/K32W061/drivers \
-I${K32W061_SDK_ROOT}/devices/K32W061/utilities \
-I${K32W061_SDK_ROOT}/devices/K32W061/utilities/debug_console \
-I${K32W061_SDK_ROOT}/devices/K32W061/utilities/str \
-I${K32W061_SDK_ROOT}/boards/k32w061dk6/wireless_examples/openthread/enablement \
-I${K32W061_SDK_ROOT}/CMSIS/Include \
-I${K32W061_SDK_ROOT}/rtos/amazon-freertos/lib/include \
-I${K32W061_SDK_ROOT}/rtos/amazon-freertos/lib/include/private \
-I${K32W061_SDK_ROOT}/rtos/amazon-freertos/template_application/ARM_CM3 \
-I${K32W061_SDK_ROOT}/rtos/amazon-freertos/lib/FreeRTOS/portable/GCC/ARM_CM3 \
-I${K32W061_SDK_ROOT}/rtos/amazon-freertos/lib/third_party/unity/src \
-DCPU_K32W061HN \
-DCPU_JN518X \
-DCPU_JN518X_REV=2 \
-DJENNIC_CHIP_FAMILY_JN518x \
-DJENNIC_CHIP_FAMILY_NAME=_JN518x \
-DSDK_DEBUGCONSOLE=0 \
-DUSE_RTOS=1 \
-DOPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE=1 \
-DOPENTHREAD_CONFIG_HEAP_INTERNAL_SIZE=16 \
-DOPENTHREAD_CONFIG_JOINER_ENABLE=1 \
-DOPENTHREAD_CONFIG_IP6_SLAAC_ENABLE=1 \
-DMBEDTLS_THREADING_C=1 \
-DMBEDTLS_THREADING_ALT=1 \
-DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\<openthread-core-k32w061-config.h\> \
-DMBEDTLS_USER_CONFIG_FILE=\<k32w061-mbedtls-config.h\> "

(mkdir -p ${ac_pwd}/third_party/openthread \
&& cd ${ac_pwd}/third_party/openthread \
&& CPPFLAGS="${ot_cppflags}" CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" ${chip_srcdir}/third_party/openthread/repo/configure \
--disable-docs \
--disable-executable \
--disable-tools \
--disable-tests \
--enable-cli \
--enable-ftd \
--enable-mtd \
--host=arm-none-eabi \
--prefix=${prefix} \
--exec-prefix=${exec_prefix} \
--with-examples=k32w061)

if test $? != 0; then
AC_MSG_ERROR([Failed to configure OpenThread!])
fi

maybe_openthread_dirstem="openthread"
;;

*)
AC_MSG_NOTICE([No internal OpenThread support yet!])
nl_with_openthread=no
Expand Down
13 changes: 7 additions & 6 deletions examples/lock-app/k32w/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ SRCS = \
$(K32W061_SDK_ROOT)/middleware/wireless/framework/GPIO/GPIO_Adapter.c \
$(K32W061_SDK_ROOT)/middleware/wireless/framework/TimersManager/Source/TimersManager.c \
$(K32W061_SDK_ROOT)/middleware/wireless/framework/TimersManager/Source/TMR_Adapter.c \
$(K32W061_SDK_ROOT)/boards/k32w061dk6/wireless_examples/openthread/reed/bm/board_utility.c \
$(K32W061_SDK_ROOT)/boards/k32w061dk6/wireless_examples/openthread/reed/bm/board.c \
$(K32W061_SDK_ROOT)/boards/k32w061dk6/wireless_examples/openthread/reed/bm/hardware_init.c \
$(K32W061_SDK_ROOT)/devices/K32W061/drivers/fsl_common.c \
Expand Down Expand Up @@ -91,11 +92,11 @@ INC_DIRS = \
$(CHIP_ROOT)/src/system

LIBS = \
$(K32W061_SDK_ROOT)/middleware/wireless/openthread/openthread/output/k32w061/lib/libopenthread-cli-ftd.a \
$(K32W061_SDK_ROOT)/middleware/wireless/openthread/openthread/output/k32w061/lib/libopenthread-ftd.a \
$(K32W061_SDK_ROOT)/middleware/wireless/openthread/openthread/output/k32w061/lib/libopenthread-k32w061_plat.a \
$(K32W061_SDK_ROOT)/middleware/wireless/openthread/openthread/output/k32w061/lib/libopenthread-k32w061_sdk.a \
$(K32W061_SDK_ROOT)/middleware/wireless/openthread/openthread/output/k32w061/lib/libmbedcrypto.a \
-lopenthread-cli-ftd \
-lopenthread-ftd \
-lopenthread-k32w061_plat \
-lopenthread-k32w061_sdk \
-lmbedcrypto \
$(K32W061_SDK_ROOT)/middleware/wireless/ieee-802.15.4/lib/libMiniMac.a \
$(K32W061_SDK_ROOT)/middleware/wireless/framework/XCVR/lib/libRadio.a \
$(K32W061_SDK_ROOT)/middleware/wireless/framework/PDM/Library/libPDM.a \
Expand All @@ -116,7 +117,7 @@ DEFINES = \
osCustomStartup=1 \
OM15082=1\
gKBD_KeysCount_c=3 \
gLEDsOnTargetBoardCnt_c=4 \
gLEDsOnTargetBoardCnt_c=2 \
gLED_InvertedMode_d=1 \
ENABLE_RAM_VECTOR_TABLE=1 \
gTMR_Enabled_d=1 \
Expand Down
170 changes: 169 additions & 1 deletion examples/lock-app/k32w/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,169 @@
TODO
# CHIP K32W061 Lock Example Application

An example application showing the use of
[CHIP](https://github.com/project-chip/connectedhomeip) on the NXP K32W061
board.

<hr>

- [CHIP K32W Lock Example Application](#chip-k32w-lock-example-application) -
[Introduction](#introduction) - [Device UI](#device-ui) -
[Building](#building) - [Flashing and debugging](#flashdebug)
<hr>

<a name="intro"></a>

## Introduction

![K32W061 DK6](doc/images/k32w-dk6.jpg)

The K32W lock example application provides a working demonstration of a
connected door lock device, built using CHIP, and the NXP K32W061 SDK. The
functionality at this moment is limited and the demo app can be used for
changing the state of a door lock and also for factoryreset the board. Soon,
functionality for BLE pairing and ZCL control will be added. This will allow a
user to control the door lock using a mobile application (CHIP Tool).

The example targets the
[NXP K32W061 DK6](https://www.nxp.com/products/wireless/thread/k32w061-41-high-performance-secure-and-ultra-low-power-mcu-for-zigbeethread-and-bluetooth-le-5-0-with-built-in-nfc-option:K32W061_41)
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)_ &mdash; The device is in an
unprovisioned (unpaired) state and is waiting for a commissioning
application to connect.

* _Rapid Even Flashing (100ms on/100ms off)_ &mdash; The device is in an
unprovisioned state and a commissioning application is connected via BLE.

- _Short Flash Off (950ms on/50ms off)_ &mdash; The device is full
provisioned, but does not yet have full network (Thread) or service
connectivity.

* _Solid On_ &mdash; 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.

The remaining two LEDs and buttons (D1/D4 and SW1/SW4) are unused.

<a name="building"></a>

## 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](https://mcuxpresso.nxp.com/). 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](doc/images/mcux-sdk-download.JPG)

- Download the suitable
[ARM GCC toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads/7-2018-q2-update)
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)](https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-integrated-development-environment-ide:MCUXpresso-IDE?tab=Design_Tools_Tab).

- 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](doc/images/select-sdk.JPG)
- Import Project CHIP in MCUXpresso IDE as Makefile Project:
<i>File->Import->C/C++->Existing Code as Makefile Project-> Next </i>.
Select Project CHIP folder as the <i>Existing Code Location</i>. In the
<i>Toolchain for Indexer Settings </i> list, be sure to keep the setting to
<i>none</i>. Click <i>Finish</i>;
- Configure MCU Settings: right click on project from the workspace and go to
<i>Properties->C/C++ Build->MCU Settings</i>. Select K32W061 from the SDK
MCUs list;
- Configure the toolchain editor: <i>C/C++ Build->Tool Chain Editor</i>.
Untick the <i>Display compatible toolchains only</i> checkbox. In the
drop-down menu named <i>Current toolchain</i>, select <i>NXP MCU Tools</i>.
Click <i>Apply and Close</i>;
- Create a debug configuration: right click on the project and select <i>Debug
As->MCUXpresso IDE LinkServer (inc. CMSIS-DAP) probes</i>. A window to
select the binary will appear. Select
<i>examples/lock-app/k32w/build/chip-k32w061-lock-example.elf</i> 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 <i>Debug Configurations</i>. In the right side of
the Debug Configurations window, go to <i>C/C++ (NXP Semiconductors) MCU
Application->openthread LinkServer Default</i>. Make sure that the <i>C/C++
Application</i> text box contains
<i>examples/lock-app/k32w/build/chip-k32w061-lock-example.elf</i> path. Go
to <i>GUI Flash Tool</i> tab. In <i>Target Operations->Program->Options</i>,
select "bin" as the <i>Format to use for programming</i>. Make sure the
<i>Base address</i> is 0x0. Click <i>Debug</i>. A pop-up window entitled
<i>Errors in Workspace</i> will appear. Click <i>Proceed</i>.
![Debug_configuration](doc/images/debg-conf.JPG)
Binary file added examples/lock-app/k32w/doc/images/debg-conf.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/lock-app/k32w/doc/images/k32w-dk6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/lock-app/k32w/doc/images/select-sdk.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 0 additions & 15 deletions examples/lock-app/k32w/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ static QueueHandle_t sAppEventQueue;

static LEDWidget sStatusLED;
static LEDWidget sLockLED;
static LEDWidget sUnusedLED;
static LEDWidget sUnusedLED_1;

static bool sIsThreadProvisioned = false;
static bool sIsThreadEnabled = false;
Expand Down Expand Up @@ -87,9 +85,6 @@ int AppTask::Init()
sLockLED.Init(LOCK_STATE_LED);
sLockLED.Set(!BoltLockMgr().IsUnlocked());

sUnusedLED.Init(LED3);
sUnusedLED_1.Init(LED4);

/* intialize the Keyboard and button press calback */
KBD_Init(KBD_Callback);

Expand Down Expand Up @@ -212,8 +207,6 @@ void AppTask::AppTaskMain(void * pvParameter)

sStatusLED.Animate();
sLockLED.Animate();
sUnusedLED.Animate();
sUnusedLED_1.Animate();

HandleKeyboard();
}
Expand Down Expand Up @@ -326,10 +319,6 @@ void AppTask::ResetActionEventHandler(AppEvent * aEvent)
sLockLED.Set(true);
}

/* turn off LEDS used for RESET indication */
sUnusedLED_1.Set(false);
sUnusedLED.Set(false);

K32W_LOG("Factory Reset was cancelled!");
}
else
Expand All @@ -356,13 +345,9 @@ void AppTask::ResetActionEventHandler(AppEvent * aEvent)
/* LEDs will start blinking to signal that a Factory Reset was scheduled */
sStatusLED.Set(false);
sLockLED.Set(false);
sUnusedLED_1.Set(false);
sUnusedLED.Set(false);

sStatusLED.Blink(500);
sLockLED.Blink(500);
sUnusedLED.Blink(500);
sUnusedLED_1.Blink(500);

sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ INT_STORAGE_SIZE = INT_STORAGE_END - INT_STORAGE_S

FREESCALE_PROD_DATA_BASE_ADDR = m_fsl_prodInfo_start;
INT_STORAGE_SECTOR_SIZE = m_sector_size;
m_app_size = 0x84000;
m_app_size = 0x90000;

__ram_vector_table__ = 1;
vector_table_size = 0x120;
Expand Down
2 changes: 1 addition & 1 deletion third_party/openthread/repo
Submodule repo updated 33 files
+10 −0 .github/workflows/posix.yml
+8 −5 .github/workflows/simulation-1.2.yml
+29 −2 .github/workflows/simulation.yml
+4 −0 .github/workflows/toranj.yml
+2 −1 examples/platforms/k32w/jn5189/Makefile.am
+2 −1 examples/platforms/k32w/k32w061/Makefile.am
+17 −0 examples/platforms/k32w/src/alarm.c
+8 −0 examples/platforms/k32w/src/radio.c
+2 −2 examples/platforms/k32w/src/system.c
+36 −20 examples/platforms/k32w/src/uart.c
+1 −0 script/check-simulation-build-autotools
+14 −3 script/check-simulation-build-cmake
+3 −1 src/core/api/message_api.cpp
+2 −2 src/core/coap/coap.cpp
+1 −1 src/core/coap/coap.hpp
+13 −24 src/core/common/message.cpp
+5 −4 src/core/common/message.hpp
+2 −2 src/core/common/time_ticker.hpp
+3 −9 src/core/net/ip6.cpp
+2 −2 src/core/net/ip6_mpl.cpp
+1 −1 src/core/net/ip6_mpl.hpp
+2 −4 src/core/net/sntp_client.hpp
+3 −1 src/core/thread/dua_manager.cpp
+15 −15 src/core/thread/neighbor_table.cpp
+21 −7 src/core/thread/neighbor_table.hpp
+60 −4 tests/unit/test_message.cpp
+277 −0 third_party/nxp/JN5189DK6/middleware/wireless/framework/Common/EmbeddedTypes.h
+98 −0 third_party/nxp/JN5189DK6/middleware/wireless/framework/SerialManager/Source/UART_Serial_Adapter.h
+151 −0 third_party/nxp/JN5189DK6/middleware/wireless/framework/TimersManager/Source/TMR_Adapter.h
+26 −7 third_party/nxp/K32W061DK6/devices/K32W061/mcuxpresso/startup_k32w061.c
+277 −0 third_party/nxp/K32W061DK6/middleware/wireless/framework/Common/EmbeddedTypes.h
+98 −0 third_party/nxp/K32W061DK6/middleware/wireless/framework/SerialManager/Source/UART_Serial_Adapter.h
+151 −0 third_party/nxp/K32W061DK6/middleware/wireless/framework/TimersManager/Source/TMR_Adapter.h