此存儲庫中的應(yīng)用程序示例是基于 FreeRTOS 的應(yīng)用程序,在支持 NXP OpenThread 的平臺(例如NXP FRDM-MCXW71)上運(yùn)行開源 KNX IoT 堆棧。
演示應(yīng)用程序是 lightsensor(模擬 KNX 光開關(guān)傳感器基本應(yīng)用程序 - 來自 KNX IoT 堆棧 repo 的 LSSB)和 lightactuator(模擬 KNX 開關(guān)執(zhí)行器基本應(yīng)用程序 - 來自 KNX IoT 堆棧 repo 的 LSAB)。
主板:FRDM-MCXW71
類別:無線連接
外設(shè):UART
工具鏈:GCC
目錄
1.軟件
構(gòu)建系統(tǒng)基于 ot-nxp 存儲庫構(gòu)建系統(tǒng)。支持的開發(fā)和構(gòu)建環(huán)境包括:
- Linux操作系統(tǒng)
- 使用 WSL 的 Windows 操作系統(tǒng)(推薦使用 Ubuntu 22.04 WSL)
構(gòu)建系統(tǒng)使用cmake
、ninja
以及gcc
ARM 版本。您可以使用存儲庫中的專用環(huán)境設(shè)置腳本來安裝它們。更多詳情,請參閱ot-nxp 存儲庫。
另一個(gè)必需的工具是git
,用于拉取存儲庫代碼。
安全配置 SDK 工具 (SPSDK)是處理 NBU 更新所必需的??梢允褂?Python 安裝此工具:
$ pip install spsdk
注意:某些依賴項(xiàng)可能會與已安裝的 Python 模塊發(fā)生沖突。但是,blhost
該工具仍然已安裝并可以使用。
關(guān)于 Windows 和 WSL 的注意事項(xiàng): Windows Subsystem for Linux 不會自動(dòng)映射已連接的 USB 設(shè)備。為了解決這個(gè)問題,用戶需要使用 WSL 控制臺構(gòu)建應(yīng)用程序,并使用 Windows 命令提示符/Power Shell 與 blhost 和 Jlink 配合使用,將所需的二進(jìn)制文件寫入開發(fā)板。
為了進(jìn)行調(diào)試,需要安裝MCUXpresso IDE 。
需要用于 FRDM-MCXW71 的 MCUXpresso SDK 2.16.100,可以從MCUXpresso SDK 頁面下載為 zip 文件。
2.硬件
- 個(gè)人電腦
- USB Type C 線纜
至少需要兩塊板來運(yùn)行演示應(yīng)用程序。
設(shè)備用戶界面
light_actuator 板上的狀態(tài)反饋通過 LED 效果提供:
| 小部件 | 影響 | 狀態(tài) | 描述 |
| --------- | ----------- | --------------------------------------- | ----------------------------------------------------------------------------------- |
| RGB LED | 綠色開/關(guān) | 委托給 Thread 網(wǎng)絡(luò)和 KNX 應(yīng)用程序配置 | /p/o_1_1
每當(dāng)收到帶有 uri 路徑的 KNX CoAP 消息時(shí),RGB LED 將打開/關(guān)閉綠燈 |
| 單色LED | 藍(lán)色開/關(guān) | 委托給 Thread 網(wǎng)絡(luò)和 KNX 應(yīng)用程序配置 | /p/o_1_2
每當(dāng)收到帶有 uri 路徑的 KNX CoAP 消息時(shí),單色 LED 都會打開/關(guān)閉藍(lán)燈 |
用戶在 light_sensor 板上的操作總結(jié)如下:
| 按鈕 | 行動(dòng) | 狀態(tài) | 輸出 |
| ------ | ------ | --------------------------------------- | ----------------------------------------------------------------------- |
| SW2 | 短按 | 委托給 Thread 網(wǎng)絡(luò)和 KNX 應(yīng)用程序配置 | /p/o_1_1
設(shè)備將使用 CoAP 和uri 路徑通過 Thread 發(fā)送多播 KNX 消息 |
| SW4 | 短按 | 委托給 Thread 網(wǎng)絡(luò)和 KNX 應(yīng)用程序配置 | /p/o_1_2
設(shè)備將使用 CoAP 和uri 路徑通過 Thread 發(fā)送多播 KNX 消息 |
3. 設(shè)置
3.1 步驟 1 - 克隆并設(shè)置構(gòu)建環(huán)境
克隆工作區(qū)內(nèi)的存儲庫:
git clone https://github.com/nxp-appcodehub/dm-knx-iot-examples-on-nxp-mcxw71.git
環(huán)境設(shè)置腳本位于存儲庫的根目錄中??梢酝ㄟ^在 CLI 中發(fā)出以下./environment_setup.sh
命令列出該腳本的可能參數(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
用戶可以使用該腳本來設(shè)置子存儲庫、設(shè)置構(gòu)建環(huán)境工具和 SDK 或清理存儲庫。
- 設(shè)置存儲庫的命令輸出示例:
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
...
- 清理存儲庫的命令輸出示例(需要先設(shè)置存儲庫):
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):
...
- 設(shè)置構(gòu)建工具鏈的命令輸出示例:
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
。此問題可以通過在命令末尾添加參數(shù)來修復(fù)。例如pip install
, 。--break-system-packages``pip install west --break-system-packages
- 需要對 ot-nxp 存儲庫進(jìn)行某些更改。這些更改將在后續(xù)版本中集成。因此,在本演示中,需要在 ot-nxp 存儲庫上應(yīng)用一個(gè)補(bǔ)丁。以下是修補(bǔ) 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 步 - 構(gòu)建示例
構(gòu)建腳本位于script
文件夾中。要為 NXP 平臺(例如 MCXW71)構(gòu)建所有可用的 KNX 物聯(lián)網(wǎng)應(yīng)用程序,用戶需要從存儲庫根目錄運(yùn)行以下命令:
shell
$ ./script/build_mcxw71_knx
要構(gòu)建一個(gè)特定的應(yīng)用程序,例如light_sensor
或,用戶需要通過關(guān)鍵字 和light_actuator
向前一個(gè)命令添加所需的應(yīng)用程序。knx_light_sensor``knx_light_actuator
shell
$ ./script/build_mcxw71_knx knx_light_sensor
構(gòu)建的輸出位于build_mcxw71
文件夾中,該文件夾包含兩個(gè)單獨(dú)的子文件夾build_mcxw71/knx_light_sensor
和build_mcxw71/knx_light_actuator
。構(gòu)建的 elf 和二進(jìn)制文件位于bin
每個(gè)應(yīng)用程序的子文件夾中。
3.3 步驟 3 - 刷新 FRDM-MCXW71 板
必須將兩個(gè)圖像寫入電路板:一個(gè)用于主機(jī)(CM33),一個(gè)用于NBU
(CM3)。
閃爍NBU
圖像
NBU
僅當(dāng)新的 NXP SDK 發(fā)布時(shí)才需要寫入鏡像。執(zhí)行此步驟之前需要安裝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
.
```
刷寫主機(jī)鏡像
build_mcxw71/knx_light_actuator/bin
主機(jī)鏡像是在或下找到的鏡像build_mcxw71/knx_light_actuator/bin
。它應(yīng)該在每次構(gòu)建過程后寫入。
如果需要調(diào)試,請直接跳至“調(diào)試” 部分。否則,如果只需要燒寫,則 可以使用JLink :
- 插入
MCXW71
USB 端口(執(zhí)行此操作時(shí)無需按住SW3
按鈕,例如主機(jī)閃爍不需要 ISP 模式) - 將 JLink 連接到設(shè)備:
shell
JLinkExe -device MCXW71 -if SWD -speed 4000 -autoconnect 1
- 運(yùn)行以下命令:
shell
reset
halt
loadfile light-actuator-mcxw71.srec
reset
go
quit
3.4 步驟 4 - 調(diào)試
調(diào)試的一個(gè)選項(xiàng)是使用 MCUXpresso IDE。
- 將包含 FRDM-MCXW71 的 NXP SDK 的 zip 文件拖放到“已安裝的 SDK”選項(xiàng)卡中:
- 從已安裝的 SDK 導(dǎo)入任何演示應(yīng)用程序:
Import SDK example(s).. -> choose a demo app (demo_apps -> hello_world) -> Finish
- 將之前導(dǎo)入的演示應(yīng)用程序刷入到開發(fā)板上:
Right click on the application (from Project Explorer) -> Debug as -> JLink/CMSIS-DAP
完成此步驟后,即創(chuàng)建了針對該開發(fā)板的調(diào)試配置MCXW71
。此調(diào)試配置稍后將用于調(diào)試 ot-nxp 編譯后生成的應(yīng)用程序。
- 將 KNX IoT NXP 端口 repo 導(dǎo)入 MCUXpresso IDE 作為 Makefile 項(xiàng)目。索引器設(shè)置的工具鏈設(shè)置為 ?none?:
File -> Import -> C/C++ -> Existing Code as Makefile Project
- 將現(xiàn)有演示應(yīng)用程序的路徑替換為
MCXW71
應(yīng)用程序的路徑:
Run -> Debug Configurations... -> C/C++ Application
3.5 步驟 5 - 運(yùn)行 KNX 演示
請參閱:
有關(guān) KNX shell 的詳細(xì)信息,請參閱KNX shell 文檔。
4. 支持
- 訪問 NXP 無線社區(qū)頁面獲取更多支持 - NXP 無線社區(qū)
- KNX IoT 堆棧介紹 - KNX IoT 堆棧
- KNX 協(xié)會對 KNX IoT 的介紹 - KNX IoT
- 最新的 KNX IoT Point API 堆棧開發(fā) - KNX IoT Point API
項(xiàng)目元數(shù)據(jù)
有關(guān)此示例的內(nèi)容/正確性的問題可以作為此 GitHub 存儲庫中的問題輸入。
來源:恩智浦appcodehub