K32W
本範例的運作方式為燈泡裝置類型,具有開啟/關閉功能。這些步驟已在 NXP K32W 開發板 (IOTZTB-DK006 開發套件) 中完成驗證。
初始設定
- 確認您已安裝 Python 3 及這些套件。本文使用 Python 3.8 驗證的操作步驟。
- 下載並安裝 K32W061 MCUXpresso SDK 2.6.9。
- 建立 SDK 後,請下載 SDK 套件並將其解壓縮到主目錄中。將環境變數
NXP_K32W0_SDK_ROOT
設為您擷取 SDK 的位置。我們也建議您針對您使用的殼層,將這個指令加入.*rc
檔案,例如.zshrc
:export NXP_K32W0_SDK_ROOT=$HOME/SDK_2_6_9_K32W061DK6/
複製並初始化 NXP/Micro 存放區:
git clone https://github.com/NXPmicro/matter.git
cd matter
git fetch origin v1.0-branch-nxp
git checkout FETCH_HEAD
git submodule update --init --recursive
source ./scripts/activate.sh
本範例使用「一般切換節點」設定。確保 JP4/JP7 的跳躍式裝置位於最左方的位置 (LPC-JN UART0):
重新設定 JLink 專用的 Jamboard
- 在電腦上下載並安裝 JLink。
- 在電路板上,確認在 USB 連接埠旁邊的 BOOT 跳接器上選取了 [DFU],然後使用迷你 USB 傳輸線將 Jamboard 連接到電腦。
- 在電腦上下載並安裝 LPCScrypt。
- 如果是 MacOS,請按兩下下載的套件以進行安裝。
- 如果是 Linux,請前往下載套件的資料夾:
chmod +x lpcscrypt-2.1.2_57.x86_64.deb.bin
./lpcscrypt-2.1.2_57.x86_64.deb.bin
- 安裝 LPCScrypt 後,請執行這個指令碼重新編寫板 (將
<LPCScrypt_InstallDir>
替換為 LPCScrypt 的實際安裝路徑):<LPCScrypt_InstallDir>/scripts/program_JLINK
- 您應該會看到類似以下的訊息。按下空格鍵即可開始程式設計。完成後,請按下 Enter 鍵結束操作。
LPCScrypt - J-Link firmware programming script v2.1.2 Nov 2020.
Connect an LPC-Link2 or LPCXpresso V2/V3 Board via USB then press Space. Booting LPCScrypt . LPCXpresso V2/V3 programmed with Firmware_JLink_LPCXpressoV2_20190404.bin -To use: remove DFU link and reboot the board
Connect next board then press Space (or <return> to Quit)
- 拔除 Jamboard 並將 BOOT 跳接器切換回 NORMAL。你的 Jamboard 現已重新設定為使用 JLink 來刷新圖片。
建構映像檔
- 準備存放區:
source ./scripts/activate.sh
- 安裝依附元件:
pip3 install pycrypto pycryptodome
- 更新範例專案設定中的
VENDOR_ID
(CHIPProjectConfig.h
)。這應該是依據 CSA Matter specification, or a VID allocated for testing purposes. The value you provide forVENDOR_ID
must match the one you use when creating the Matter integration in the Google Home Developer Console.grep VENDOR_ID ./examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h
* CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID #define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID your-hex-VID
提供的 VID。 - 請查看範例專案設定中的
PRODUCT_ID
(CHIPProjectConfig.h
)。PRODUCT_ID
值可以保持與範例預設值相同,也可以視需要變更,但必須遵守目前的先決條件中所述的產品 ID 限制。另請注意,您為PRODUCT_ID
提供的值必須與您在 Developer Console 中建立 Matter 整合時使用的值相符。grep PRODUCT_ID ./examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h
* CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x4B4C
- 建構照明應用程式:
- 如果 OM15082 擴充板已連接至 K32W 板,請務必將
chip_with_OM15082
建構引數設為1
:cd examples/lighting-app/nxp/k32w/k32w0/
gn gen out/debug --args="k32w0_sdk_root="${NXP_K32W0_SDK_ROOT}" chip_with_OM15082=1 chip_with_ot_cli=0 is_debug=false chip_crypto="platform" chip_with_se05x=0 chip_pw_tokenizer_logging=true chip_enable_ota_requestor=false"
ninja -C out/debug
- 如果未附加 OM15082 擴充板,請省略
chip_with_OM15082
建構引數:
請注意,Pigweed 權杖化工具是一種可對字串進行雜湊處理,可大幅減少記錄所需的閃光模組,以便在上方啟用cd examples/lighting-app/nxp/k32w/k32w0/
gn gen out/debug --args="k32w0_sdk_root="${NXP_K32W0_SDK_ROOT}" chip_with_ot_cli=0 is_debug=false chip_crypto="platform" chip_with_se05x=0 chip_pw_tokenizer_logging=true chip_enable_ota_requestor=false"
ninja -C out/debug
chip_pw_tokenizer_logging
至true
啟用。需要將權杖化器指令碼才能剖析經過雜湊處理的指令碼。相關詳情請參閱本文。
- 如果 OM15082 擴充板已連接至 K32W 板,請務必將
MacOS 使用者 (如果您並未在 MacOS 上進行建構,請略過這個步驟):
在文字編輯器中開啟
sign_images.sh
指令碼 (位於$NXP_K32W0_SDK_ROOT/tools/imagetool/sign_images.sh
),然後進行下列變更:- 請註解或移除這些行,以解決 MacOS 上的「未安裝套件」錯誤:
is_linux_package_installed "python3" is_linux_package_installed "python3-pip"
- 修正
file
公用程式的引數 (「-ib
」應為「-Ib
」),否則簽署指令碼會無聲產生.bin
檔案:MIME_SET="$(file -ib $FILENAME)"
變更為:MIME_SET="$(file -Ib $FILENAME)"
- 請註解或移除這些行,以解決 MacOS 上的「未安裝套件」錯誤:
簽署映像檔:
chmod +x $NXP_K32W0_SDK_ROOT/tools/imagetool/sign_images.sh
$NXP_K32W0_SDK_ROOT/tools/imagetool/sign_images.sh out/debug/
刷上黑板
- 使用 mini USB 傳輸線連接 Jamboard 的 JLink 指令列:
JLinkExe -device K32W061 -if SWD -speed 4000 -autoconnect 1
- 在 JLink 指令列中輸入
erase
指令,以清除 Jamboard 上的現有映像檔。若是曾經刷按了固定板,則需要這項權限。erase
Without any give address range, Erase Chip will be executed Erasing device... J-Link: Flash download: Total time needed: 2.878s (Prepare: 0.051s, Compare: 0.000s, Erase: 2.789s, Program: 0.000s, Verify: 0.000s, Restore: 0.037s) Erasing done. - 然後使用
loadbin
指令重新整理映像檔:loadbin out/debug/chip-k32w061-light-example.bin, 0
Downloading file [out/debug/chip-k32w061-light-example.bin]... J-Link: Flash download: Bank 0 @ 0x00000000: 1 range affected (586752 bytes) J-Link: Flash download: Total: 7.492s (Prepare: 0.054s, Erase: 2.738s, Program & Verify: 4.661s, Restore: 0.037s) J-Link: Flash download: Program & Verify speed: 122 KB/s O.K. - 輸入
exit
即可結束 JLink CLI。 - 重新啟動 JLink:
JLinkExe -device K32W061 -if SWD -speed 4000 -autoconnect 1
- 再次刷新映像檔,這次略過
erase
指令:loadbin out/debug/chip-k32w061-light-example.bin, 0
Downloading file [out/debug/chip-k32w061-light-example.bin]... J-Link: Flash download: Bank 0 @ 0x00000000: 1 range affected (586752 bytes) J-Link: Flash download: Total: 7.492s (Prepare: 0.054s, Erase: 2.738s, Program & Verify: 4.661s, Restore: 0.037s) J-Link: Flash download: Program & Verify speed: 122 KB/s O.K. - 完成
loadbin
指令後,按下擴充板上的 SW2 按鈕以恢復原廠設定,然後按下主機板上的 SW4 RESET 按鈕,開始執行映像檔。
驗證範例
- 裝置應以電腦上的 USB 序列裝置的形式呈現。您可以在
/dev/
中查看:
您可以使用 python3 指令碼 detokenizer.py 開啟序列主控台,這個指令碼會從序列通訊埠將 Pigweed 權杖化記錄解碼。舉例來說,如果裝置位於ls -la /dev/tty*
/dev/ttyACM0
:python3 ./scripts/detokenizer.py serial -i /dev/ttyACM0 -d out/debug/chip-k32w061-light-example-database.bin
- 如要將 Jamboard 恢復原廠設定,請按下 SW2 按鈕。LED2 和 LED3 將會閃爍一段時間。您應該會在序列主控台中看到類似以下的訊息:
[Info]Factory Reset Triggered. Push the RESET button within 6000 ms to cancel! [Info]Device will factory reset... [Info]Performing factory reset
- 如要切換燈泡的狀態 (開啟/關閉),請按一下 [SW3] 按鈕。應該可以切換 LED 燈 D3。
佣金先決條件
委託 NXP K32W 開發委員會前,請注意下列事項:
- 您必須先啟用 BLE 廣告,才能在 Google Home 生態系統中探索及委託該裝置。如要暫時啟用廣告 (根據 Matter 規格為 15 分鐘),按下使用者按鈕。
如果沒有密碼編譯硬體加速器模組,K32 開發板可能無法在 Android mobile device side. You can identify that a timeout occurred by using
adb logcat
from a computer attached to your phone. When a timeout occurs, you will see a log message like:Device connection failed. Error third_party/connectedhomeip/src/protocols/secure_channel/CASESession.cpp:275: CHIP Error 0x00000032: Timeout
的傳輸時間結束之前完成修訂版本如要進一步瞭解如何設定及使用
adb
,請參閱疑難排解。
後續步驟
成功建立 Matter 範例後,請建立開發人員專案。