[Matter] light bulb example (from nRF SDK) cannot bind Cluster 8 to light-switch-app (from original chip-Repo)

Following Setup:

1.) Building light-switch-app from original https://github.com/project-chip/connectedhomeip Repo for nRF5340 from command line with nRF SDK v2.1.0

cd <connecthomeip-repo>
source scripts/activate.sh
source <nrf-sdk-path>/zephyr/zephyr-env.sh

cd examples/light-switch-app/nrfconnect
west build -b nrf5340dk_nrf5340_cpuapp

2.) Building light-bulb example from nRF SDK with nRF VS Code Extension

Following steps to adapted this example to run on nRF52840 USB Dongle --> (Why is this example not available for nRF52840 USB Dongle out off the box???)

Create a pm_static_nrf52840dongle_nrf52840_no_dfu.yml file in root dir of example. Following content:

settings_storage:
    address: 0xd8000
    size: 0x8000
    region: flash_primary
open_bootloader:
    address: 0xe0000
    size: 0x20000
    region: flash_primary

Create a nrf52840dongle_nrf52840_no_dfu.conf file in boards dir of example. Following content:

#
#    Copyright (c) 2022 Project CHIP Authors
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

# Configure logging over USB
# - do enable shell to reduce flash usage
# - disable CDC ACM logs as it may lead to infinite loop when CDC ACM is used as the log backend
CONFIG_USB_DEVICE_STACK=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_LOG_BACKEND_UART=y
CONFIG_SHELL_LOG_BACKEND=n
CONFIG_UART_LINE_CTRL=y
CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y

# The minimal logging mode does not work properly with the USB CDC device, so use the deferred mode
CONFIG_LOG_MODE_MINIMAL=n
CONFIG_LOG2_MODE_DEFERRED=y
CONFIG_LOG_BUFFER_SIZE=8192

# Reduce the code size as the dongle reserves some space for MBR and Open Bootloader
CONFIG_ASSERT_VERBOSE=n
CONFIG_SHELL=n
CONFIG_OPENTHREAD_SHELL=n

# Use partition manager to configure the settings partition not to overlap with Open Bootloader
CONFIG_PM_SINGLE_IMAGE=y

# Disable factory data support. 
# --> disabled cause nRF create application don't know about these CONFIG_PARMS
#CONFIG_CHIP_FACTORY_DATA=n
#CONFIG_CHIP_FACTORY_DATA_BUILD=n

Create nrf52840dongle_nrf52840.overlay file in boards dir of example. Following content:

/*
 *    Copyright (c) 2021 Project CHIP Authors
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http: //www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

 / {
 	chosen {
 		zephyr,console = &cdc_acm_uart0;
	};
};

&zephyr_udc0 {
	cdc_acm_uart0: cdc_acm_uart0 {
		compatible = "zephyr,cdc-acm-uart";
		label = "CDC_ACM_0";
	};
};

Change CMakeLists.txt in root dir of example. File content should look like:

#
# Copyright (c) 2021 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)

get_filename_component(MATTER_MODULE_ROOT $ENV{ZEPHYR_BASE}/../modules/lib/matter REALPATH)

# Set Kconfig root files that will be processed as a first Kconfig for used child images.
set(mcuboot_KCONFIG_ROOT ${MATTER_MODULE_ROOT}/config/nrfconnect/chip-module/Kconfig.mcuboot.root)
set(multiprotocol_rpmsg_KCONFIG_ROOT ${MATTER_MODULE_ROOT}/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.root)

if(NOT CONF_FILE STREQUAL "prj_no_dfu.conf" AND NOT BOARD STREQUAL "nrf52840dongle_nrf52840")
    set(PM_STATIC_YML_FILE ${CMAKE_CURRENT_SOURCE_DIR}/configuration/${BOARD}/pm_static_dfu.yml)
endif()

find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})

project(matter-light-bulb)

set(COMMON_ROOT ${ZEPHYR_NRF_MODULE_DIR}/samples/matter/common)
set(NLIO_ROOT ${MATTER_MODULE_ROOT}/third_party/nlio/repo)
include(${MATTER_MODULE_ROOT}/config/nrfconnect/app/enable-gnu-std.cmake)
include(${MATTER_MODULE_ROOT}/src/app/chip_data_model.cmake)

# NORDIC SDK APP START
target_include_directories(app PRIVATE
    src
    ${COMMON_ROOT}/src
    ${NLIO_ROOT}/include
    ${MATTER_MODULE_ROOT}/zzz_generated/app-common
)

target_sources(app PRIVATE
    src/app_task.cpp
    src/lighting_manager.cpp
    src/main.cpp
    src/zcl_callbacks.cpp
    src/zap-generated/IMClusterCommandHandler.cpp
    src/zap-generated/callback-stub.cpp
    ${COMMON_ROOT}/src/led_widget.cpp
    ${COMMON_ROOT}/src/thread_util.cpp
)

if(CONFIG_CHIP_OTA_REQUESTOR)
    target_sources(app PRIVATE ${COMMON_ROOT}/src/ota_util.cpp)
endif()

if(CONFIG_MCUMGR_SMP_BT)
    target_sources(app PRIVATE ${COMMON_ROOT}/src/dfu_over_smp.cpp)
endif()

chip_configure_data_model(app
    INCLUDE_SERVER
    ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/light_bulb.zap
)

if (CONFIG_SHELL AND BOARD STREQUAL "nrf52840dongle_nrf52840")
  target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUTrigger.cpp)
endif()
# NORDIC SDK APP END

Change the main.c in src dir of the example. Like this

/*
 * Copyright (c) 2021 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#include "app_task.h"

#include <zephyr/logging/log.h>

#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart)
#include <zephyr/drivers/uart.h>
#include <zephyr/usb/usb_device.h>
#endif

LOG_MODULE_REGISTER(app, CONFIG_MATTER_LOG_LEVEL);

using namespace ::chip;

#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart)
static int InitUSB()
{
    int err = usb_enable(nullptr);

    if (err)
    {
        LOG_ERR("Failed to initialize USB device");
        return err;
    }

    const struct device * dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
    uint32_t dtr              = 0;

    while (!dtr)
    {
        uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
        k_sleep(K_MSEC(100));
    }

    return 0;
}
#endif

int main()
{
	CHIP_ERROR err = CHIP_NO_ERROR;

#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart)
    err = System::MapErrorZephyr(InitUSB());
#endif
	
	err = GetAppTask().StartApp();

	LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, err.Format());
	return err == CHIP_NO_ERROR ? EXIT_SUCCESS : EXIT_FAILURE;
}

Now you can build the light-build example for nRF52840 USB Dongle.

Copy the light-bulb application to the nRF52840 by nRF Programmer Tool.

3.) Pair both matter devices to an existing or new created thread-network with chip-tool

4.) Set the ACL access for the light-bulb

sudo ./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": [light-switch-id], "targets": [{"cluster": 6, "endpoint": 1, "deviceType": null}, {"cluster": 8, "endpoint": 1, "deviceType": null}]}]' light-bulb-id 0

There is an error in the chip tool log

1665610428271] [16033:1856894] CHIP: [EM] >>> [E:4373i M:3817318090 (Ack:115418483)] (U) Msg RX from 0:0000000000000000 [0000] --- Type 0000:10 (SecureChannel:StandaloneAck)
[1665610428272] [16033:1856894] CHIP: [EM] OnMessageReceived failed, err = ../connectedhomeip/examples/chip-tool/third_party/connectedhomeip/src/messaging/ExchangeMgr.cpp:305: CHIP Error 0x00000070: Unsolicited msg with originator bit clear
[1665610428457] [16033:1856854] CHIP: [EM] >>> [E:4374i M:11470867 (Ack:81659602)] (S) Msg RX from 1:0000000000000100 [0BB5] --- Type 0001:07 (IM:WriteResponse)

5.) Create the binding to cluster 6 and cluster 8 for the light-switch

sudo ./chip-tool binding write binding '[{"fabricIndex": 1, "node": light-bulb-id, "endpoint": 1, "cluster": 6}, {"fabricIndex": 1, "node": light-bulb-id, "endpoint": 1, "cluster": 8}]' light-switch-id 1

There is an error in the Log of the light-switch application (nRF5340DK) during the binding:

I: 327706 [EM]<<< [E:47538i M:132360026 (Ack:3817318092)] (U) Msg TX to 0:0000000000000000 [0000] --- Type
 0000:10 (SecureChannel:StandaloneAck)
I: 327719 [IN](U) Sending msg 132360026 to IP address 'UDP:[fdf9:547d:593b:1:cd8:1a0f:d500:29a2]:5540'
D: 327729 [EM]Flushed pending ack for MessageCounter:3817318092 on exchange 47538i
I: 327737 [EM]>>> [E:47538i M:3817318093 (Ack:132360023)] (U) Msg RX from 0:0000000000000000 [0000] --- Ty
pe 0000:10 (SecureChannel:StandaloneAck)
E: 327750 [EM]OnMessageReceived failed, err = 70

6.) Press the button 2 of the nRF5340DK Board to toggle the light-bulb on the nRF52840 Dongle. (works).

7.) Press button 2 for longer time to dim the LED of the light-bulb --> That doesn't work (seems to be a binding error)

I: 397578 [DMG]Received Command Response Status for Endpoint=1 Cluster=0x0000_0008 Command=0x0000_0000 Sta
tus=0x85
E: Binding command was not applied! Reason: 585

Parents
  • Hi,

    Is there a specific reason you are using the samples directly from the connectedhomeip repository and not use the Matter samples from nRF Connect SDK? The samples in the SDK are tested before a tagged release together with the described tool versions. If you are using the code from main branch on the upstream repository, there may exist issue that have not yet been discovered through release testing.

    Can you try out the same steps with the samples from nRF Connect SDK v2.1.0? If this does not work, please include a sniffer trace of the on-air traffic during the process of binding the clusters.

    Best regards,
    Jørgen

Reply
  • Hi,

    Is there a specific reason you are using the samples directly from the connectedhomeip repository and not use the Matter samples from nRF Connect SDK? The samples in the SDK are tested before a tagged release together with the described tool versions. If you are using the code from main branch on the upstream repository, there may exist issue that have not yet been discovered through release testing.

    Can you try out the same steps with the samples from nRF Connect SDK v2.1.0? If this does not work, please include a sniffer trace of the on-air traffic during the process of binding the clusters.

    Best regards,
    Jørgen

Children
Related