Portrait of me in my natural habitat

Using the nRF52840 DK

Posted 2023-07-12

I've recently bought a nRF52850 DK from Nordic Semiconductor to try my hand at making Matter-based devices. I like it, and I've had little trouble building and running the provided samples. However, now that I've moved onto trying to do my own implementations, I've been running into issue after issue. Fortunately, the support teams at Nordic Semiconductor have been really helpful and committed to debugging these problems. That said, the solutions are disperate, and often hard to find or use. They're spread across the forums, private email threads, and are compounded by the fact that engineers are using the tools across Windows, Linux, and macOS.

The first major place I've been having issues is with the ZAP tool. It's the tool used for adding Matter cluters to your application, at outlined in this tutorial. After following the instructions to install here, you'll get an instruction to add the ZAP locations to your path. It probably looks something like this:

#############################################################################################
# Please add the following location(s) to the system PATH:                                  #
# /opt/nordic/ncs/v2.4.0/modules/lib/matter/zap_location/zap-mac/zap.app/Contents/MacOS/zap #
# /opt/nordic/ncs/v2.4.0/modules/lib/matter/zap_location/zap-mac                            #
#############################################################################################

For me, this doesn't work. Upon repoenenig the terminal and running zap src/template.zap, it'll tell me the zap command is not found.

command not found: zap

I needed to cut the /zap of the end of the first path for it to be able to find the zap command. After that, the command will execute.

Note: it doesn't say it explicity (or I didn't see it), but the steps assume you're starting from the root folder of the sdk. On my machine that's /opt/nordic/ncs/v2.4.0.

After getting past the above issue, when trying to run ZAP I encountered an error message that says something like this:

dyld[1660]: Library not loaded: @rpath/Electron Framework.framework/Electron Framework
  Referenced from: <4C4C44DA-5555-3144-A10D-1E87A10EA9F8> /opt/nordic/ncs/v2.4.0/modules/lib/matter/zap_location/zap-mac/zap.app/Contents/MacOS/zap
  Reason: tried: '/opt/nordic/ncs/v2.4.0/modules/lib/matter/zap_location/zap-mac/zap.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (not a mach-o file), '/opt/nordic/ncs/v2.4.0/modules/lib/matter/zap_location/zap-mac/zap.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (not a mach-o file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/Electron Framework.framework/Electron Framework' (no such file), '/opt/nordic/ncs/v2.4.0/modules/lib/matter/zap_location/zap-mac/zap.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (not a mach-o file), '/opt/nordic/ncs/v2.4.0/modules/lib/matter/zap_location/zap-mac/zap.app/Contents/Frameworks/Electron Framework.framework/Electron Framework' (not a mach-o file), '/Library/Frameworks/Electron Framework.framework/Electron Framework' (no such file), '/System/Library/Frameworks/Electron Framework.framework/Electron Framework' (no such file, not in dyld cache)
[1]    1660 abort      zap nrf/samples/matter/template/src/template.zap

This is after following the instructions to install here to install the tool. A thread posted on the forums suggest to install the tool without using the provided script, using this instead:

wget github.com/.../zap-mac.zip && unzip -d zap-mac zap-mac.zip

I ran that from my root sdk folder, and ended up recreating the folder structure that the download script creates, and moving the unziped contents there:

/opt/nordic/ncs/v2.4.0/modules/lib/matter/zap_location/zap-mac/zap.app/

Again I tried running zap src/template.zap, now encountering a new error:

Error while running sql statement:
INSERT INTO
  ENUM (ENUM_ID, SIZE)
VALUES (
  (SELECT DATA_TYPE_ID FROM DATA_TYPE WHERE PACKAGE_REF IN (2) AND NAME = ? AND DISCRIMINATOR_REF = ?),
  (SELECT
    CASE
      WHEN (
        (SELECT
          SIZE
         FROM
          ENUM
         INNER JOIN
          DATA_TYPE
         ON
          ENUM.ENUM_ID = DATA_TYPE.DATA_TYPE_ID
         WHERE
          DATA_TYPE.PACKAGE_REF IN (2)
          AND DATA_TYPE.NAME = ?
          AND DATA_TYPE.DISCRIMINATOR_REF = ?)
        IS NULL )
        THEN
          (SELECT
            SIZE
          FROM
            ENUM
          INNER JOIN
            DATA_TYPE
          ON
            ENUM.ENUM_ID = DATA_TYPE.DATA_TYPE_ID
          WHERE
            DATA_TYPE.PACKAGE_REF IN (2) AND DATA_TYPE.NAME = ?)
      ELSE
        (SELECT
          SIZE
         FROM
          ENUM
         INNER JOIN
          DATA_TYPE
         ON
          ENUM.ENUM_ID = DATA_TYPE.DATA_TYPE_ID
         WHERE
          DATA_TYPE.PACKAGE_REF IN (2)
          AND DATA_TYPE.NAME = ?
          AND DATA_TYPE.DISCRIMINATOR_REF = ?)
    END AS SIZE)), values: ProductFinishEnum,3,enum8,3,enum8,enum8,3, Error: SQLITE_CONSTRAINT: UNIQUE constraint failed: ENUM.ENUM_ID

As best I could understand from email threads with support, this is from trying to pull in the proper Matter cluster templates and definitions since they're not shipped with ZAP by default.

I started looking for other solutions to the Electron Framework problem, which brought me to this thread on the Matter GitHub repository. Essentially the unzip functionality doesn't prefer symlinks. This time I installed the current released version from the repository releases (specifically v2023.05.04), placing it in the same spot like I did with the previous fix.

This time, the magic happened! The ZAP tool opened with the expected Matter definitions.

ZAP with template project zap file loaded