此存储库中的应用程序示例是基于 FreeRTOS 的应用程序,在支持 NXP OpenThread 的平台(例如NXP FRDM-MCXW71)上运行开源 KNX IoT 堆栈。
演示应用程序是 lightsensor(模拟 KNX 光开关传感器基本应用程序 - 来自 KNX IoT 堆栈 repo 的 LSSB)和 lightactuator(模拟 KNX 开关执行器基本应用程序 - 来自 KNX IoT 堆栈 repo 的 LSAB)。
主板:FRDM-MCXW71
类别:无线连接
外设:UART
工具链:GCC
目录
1.软件
构建系统基于 ot-nxp 存储库构建系统。支持的开发和构建环境包括:
- Linux操作系统
- 使用 WSL 的 Windows 操作系统(推荐使用 Ubuntu 22.04 WSL)
构建系统使用cmake
、ninja
以及gcc
ARM 版本。您可以使用存储库中的专用环境设置脚本来安装它们。更多详情,请参阅ot-nxp 存储库。
另一个必需的工具是git
,用于拉取存储库代码。
安全配置 SDK 工具 (SPSDK)是处理 NBU 更新所必需的。可以使用 Python 安装此工具:
$ pip install spsdk
注意:某些依赖项可能会与已安装的 Python 模块发生冲突。但是,blhost
该工具仍然已安装并可以使用。
关于 Windows 和 WSL 的注意事项: Windows Subsystem for Linux 不会自动映射已连接的 USB 设备。为了解决这个问题,用户需要使用 WSL 控制台构建应用程序,并使用 Windows 命令提示符/Power Shell 与 blhost 和 Jlink 配合使用,将所需的二进制文件写入开发板。
为了进行调试,需要安装MCUXpresso IDE 。
需要用于 FRDM-MCXW71 的 MCUXpresso SDK 2.16.100,可以从MCUXpresso SDK 页面下载为 zip 文件。
2.硬件
- 个人电脑
- USB Type C 线缆
至少需要两块板来运行演示应用程序。
设备用户界面
light_actuator 板上的状态反馈通过 LED 效果提供:
| 小部件 | 影响 | 状态 | 描述 |
| --------- | ----------- | --------------------------------------- | ----------------------------------------------------------------------------------- |
| RGB LED | 绿色开/关 | 委托给 Thread 网络和 KNX 应用程序配置 | /p/o_1_1
每当收到带有 uri 路径的 KNX CoAP 消息时,RGB LED 将打开/关闭绿灯 |
| 单色LED | 蓝色开/关 | 委托给 Thread 网络和 KNX 应用程序配置 | /p/o_1_2
每当收到带有 uri 路径的 KNX CoAP 消息时,单色 LED 都会打开/关闭蓝灯 |
用户在 light_sensor 板上的操作总结如下:
| 按钮 | 行动 | 状态 | 输出 |
| ------ | ------ | --------------------------------------- | ----------------------------------------------------------------------- |
| SW2 | 短按 | 委托给 Thread 网络和 KNX 应用程序配置 | /p/o_1_1
设备将使用 CoAP 和uri 路径通过 Thread 发送多播 KNX 消息 |
| SW4 | 短按 | 委托给 Thread 网络和 KNX 应用程序配置 | /p/o_1_2
设备将使用 CoAP 和uri 路径通过 Thread 发送多播 KNX 消息 |
3. 设置
3.1 步骤 1 - 克隆并设置构建环境
克隆工作区内的存储库:
git clone https://github.com/nxp-appcodehub/dm-knx-iot-examples-on-nxp-mcxw71.git
环境设置脚本位于存储库的根目录中。可以通过在 CLI 中发出以下./environment_setup.sh
命令列出该脚本的可能参数:
shell
$ ./environment_setup.sh
This is a setup script to set the NXP port of KNX IoT OpenThread examples environment.
Usage: ./environment_setup.sh clean|setup_repos|setup_tools|apply_ot_patch
用户可以使用该脚本来设置子存储库、设置构建环境工具和 SDK 或清理存储库。
- 设置存储库的命令输出示例:
shell
$ ./environment_setup.sh setup_repos
This is a setup script to set the NXP port of KNX IoT OpenThread examples environment.
Setting up the repositories.
The script will update all repositories (ot-nxp and NXP SDK).
The setup will take several minutes to complete.
Setting up submodules.
Submodule 'KNX-IOT-STACK' (https://github.com/KNX-IOT/KNX-IOT-STACK.git) registered for path 'KNX-IOT-STACK'
Submodule 'ot-nxp' (https://github.com/NXP/ot-nxp.git) registered for path 'ot-nxp'
Cloning into '/home/user/knx_iot_nxp_repo/KNX-IOT-STACK'...
Cloning into '/home/user/knx_iot_nxp_repo/ot-nxp'...
Submodule path 'KNX-IOT-STACK': checked out '270890a6cfab8ab0ff92cd155cc2be11ff36b4bb'
Submodule path 'ot-nxp': checked out 'dfbe12280af4a87cb9ae0c0c1d90d71de3372d82'
Submodule 'deps/gtest' (https://github.com/google/googletest.git) registered for path 'KNX-IOT-STACK/deps/gtest'
Submodule 'deps/mbedtls' (https://github.com/ARMmbed/mbedtls.git) registered for path 'KNX-IOT-STACK/deps/mbedtls'
Submodule 'deps/tinycbor' (https://github.com/intel/tinycbor.git) registered for path 'KNX-IOT-STACK/deps/tinycbor'
Cloning into '/home/user/knx_iot_nxp_repo/KNX-IOT-STACK/deps/gtest'...
Cloning into '/home/user/knx_iot_nxp_repo/KNX-IOT-STACK/deps/mbedtls'...
Cloning into '/home/user/knx_iot_nxp_repo/KNX-IOT-STACK/deps/tinycbor'...
Submodule path 'KNX-IOT-STACK/deps/gtest': checked out 'c99458533a9b4c743ed51537e25989ea55944908'
Submodule path 'KNX-IOT-STACK/deps/mbedtls': checked out 'd81c11b8ab61fd5b2da8133aa73c5fe33a0633eb'
Submodule path 'KNX-IOT-STACK/deps/tinycbor': checked out '70aba6ba51881e5b8d108c105a17ed9cdee6bc30'
Submodule path 'ot-nxp': checked out 'ce3f5e4752efb3a4e3ca03887f7c8c0f2d841980'
Submodule 'openthread' (https://github.com/NXP/openthread.git) registered for path 'ot-nxp/openthread'
Cloning into '/home/user/knx_iot_nxp_repo/ot-nxp/openthread'...
Submodule path 'ot-nxp/openthread': checked out '4cc1ffd17439db6e0b97b010ad00043d7509f246'
Setting up submodules done.
Patching ot-nxp repo.
ot-nxp repo has been patched!
Pulling NXP SDK.
=== Initializing from existing manifest repository manifest
--- Creating /home/user/knx_iot_nxp_repo/ot-nxp/third_party/github_sdk/.west and local configuration file
=== Initialized. Now run "west update" inside /home/user/knx_iot_nxp_repo/ot-nxp/third_party/github_sdk.
=== updating sdk-release (core):
--- sdk-release: initializing
Initialized empty Git repository in /home/user/knx_iot_nxp_repo/ot-nxp/third_party/github_sdk/core/.git/
--- sdk-release: fetching, need revision MCUX_2.16.100
...
- 清理存储库的命令输出示例(需要先设置存储库):
shell
$ ./environment_setup.sh clean
This is a setup script to set the NXP port of KNX IoT OpenThread examples environment.
Cleaning the environment.
Resetting ot-nxp repository.
HEAD is now at ce3f5e4 [common] Enable Dns over TCP feature for Thread 1.4
Cleaning NXP SDK.
=== running "git reset --hard && git clean -xdf" in sdk-release (core):
...
- 设置构建工具链的命令输出示例:
shell
$ ./environment_setup.sh setup_tools
This is a setup script to set the NXP port of KNX IoT OpenThread examples environment.
Setting up the toolchain.
The script will update the toolchain.
The setup will take several minutes to complete.
Setting up ot-nxp toolchain environment.
+ main
++ dirname ./script/bootstrap
...
注意:在 Windows WSL 上,
pip install <package>
命令可能会返回error: externally-managed-environment
。此问题可以通过在命令末尾添加参数来修复。例如pip install
, 。--break-system-packages``pip install west --break-system-packages
- 需要对 ot-nxp 存储库进行某些更改。这些更改将在后续版本中集成。因此,在本演示中,需要在 ot-nxp 存储库上应用一个补丁。以下是修补 ot-nxp 存储库的命令输出示例:
shell
$ ./environment_setup.sh apply_ot_patch
This is a setup script to set the NXP port of KNX IoT OpenThread examples environment.
Applying ot-nxp repo patch.
ot-nxp repo has been patched!
3.2 第 2 步 - 构建示例
构建脚本位于script
文件夹中。要为 NXP 平台(例如 MCXW71)构建所有可用的 KNX 物联网应用程序,用户需要从存储库根目录运行以下命令:
shell
$ ./script/build_mcxw71_knx
要构建一个特定的应用程序,例如light_sensor
或,用户需要通过关键字 和light_actuator
向前一个命令添加所需的应用程序。knx_light_sensor``knx_light_actuator
shell
$ ./script/build_mcxw71_knx knx_light_sensor
构建的输出位于build_mcxw71
文件夹中,该文件夹包含两个单独的子文件夹build_mcxw71/knx_light_sensor
和build_mcxw71/knx_light_actuator
。构建的 elf 和二进制文件位于bin
每个应用程序的子文件夹中。
3.3 步骤 3 - 刷新 FRDM-MCXW71 板
必须将两个图像写入电路板:一个用于主机(CM33),一个用于NBU
(CM3)。
闪烁NBU
图像
NBU
仅当新的 NXP SDK 发布时才需要写入镜像。执行此步骤之前需要安装SPSDK 。
``
NBU
It is necessary to work with the matchingimage for the SDK version of
NBU
the application you are working with. This means that when you download your
SDK, prior to loading any wireless SDK example, update yourimage with
FRDM` users, please write the following
the SDK provided binaries. For
binary:
middleware/wireless/ieee-802.15.4/bin/mcxw71/mcxw71_nbu_ble_15_4_dyn_matter_<nbu_version>.sb3
Please note that <nbu_version>
may vary depending on the SDK version. The tested NBU binary from SDK 2.16.100 is version 1_0_17_2
.
- Before writing the image, please make sure that MCXW71 is in
ISP
mode by keeping theSW3
button (also namedISP
) pressed while connecting the MCXW71 board to an USB port (unplug the board if already connected to an USB port). - Once the device is connected, you may find the assigned port by running:
nxpdevscan
- Run the
blhost
command to write thesb3
file:
blhost -p <assigned_port> receive-sb-file <path_to_SDK>/middleware/wireless/ieee-802.15.4/bin/mcxw71/mcxw71_nbu_ble_15_4_dyn_matter_<nbu_version>.sb3
An example<path_to_SDK>
is/home/user/knx_iot_nxp_repo/ot-nxp/third_party/github_sdk
.
```
刷写主机镜像
build_mcxw71/knx_light_actuator/bin
主机镜像是在或下找到的镜像build_mcxw71/knx_light_actuator/bin
。它应该在每次构建过程后写入。
如果需要调试,请直接跳至“调试” 部分。否则,如果只需要烧写,则 可以使用JLink :
- 插入
MCXW71
USB 端口(执行此操作时无需按住SW3
按钮,例如主机闪烁不需要 ISP 模式) - 将 JLink 连接到设备:
shell
JLinkExe -device MCXW71 -if SWD -speed 4000 -autoconnect 1
- 运行以下命令:
shell
reset
halt
loadfile light-actuator-mcxw71.srec
reset
go
quit
3.4 步骤 4 - 调试
调试的一个选项是使用 MCUXpresso IDE。
- 将包含 FRDM-MCXW71 的 NXP SDK 的 zip 文件拖放到“已安装的 SDK”选项卡中:
- 从已安装的 SDK 导入任何演示应用程序:
Import SDK example(s).. -> choose a demo app (demo_apps -> hello_world) -> Finish
- 将之前导入的演示应用程序刷入到开发板上:
Right click on the application (from Project Explorer) -> Debug as -> JLink/CMSIS-DAP
完成此步骤后,即创建了针对该开发板的调试配置MCXW71
。此调试配置稍后将用于调试 ot-nxp 编译后生成的应用程序。
- 将 KNX IoT NXP 端口 repo 导入 MCUXpresso IDE 作为 Makefile 项目。索引器设置的工具链设置为 ?none?:
File -> Import -> C/C++ -> Existing Code as Makefile Project
- 将现有演示应用程序的路径替换为
MCXW71
应用程序的路径:
Run -> Debug Configurations... -> C/C++ Application
3.5 步骤 5 - 运行 KNX 演示
请参阅:
有关 KNX shell 的详细信息,请参阅KNX shell 文档。
4. 支持
- 访问 NXP 无线社区页面获取更多支持 - NXP 无线社区
- KNX IoT 堆栈介绍 - KNX IoT 堆栈
- KNX 协会对 KNX IoT 的介绍 - KNX IoT
- 最新的 KNX IoT Point API 堆栈开发 - KNX IoT Point API
项目元数据
有关此示例的内容/正确性的问题可以作为此 GitHub 存储库中的问题输入。
来源:恩智浦appcodehub