From e3cab4d65cc4923b3097b5c64758da458e8306cf Mon Sep 17 00:00:00 2001 From: Lazar Kovacic Date: Thu, 11 Jul 2024 10:38:50 +0200 Subject: [PATCH 1/2] Update ACL after content app is installed (#34229) * Add code to update ACL after app is installed * Restyled by whitespace * Restyled by clang-format * Update code per comments * Restyled by whitespace * Restyled by clang-format * Minor code updates * Restyled by clang-format * Update description * Update logic to support extern DeviceCommissioner & CommissionerDiscoveryController * Restyled by clang-format * Test the change to see if it will fix the tests * Update AppTv.cpp * Update code as it failed tests * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io --- examples/common/m5stack-tft/repo | 2 +- .../content-app/src/main/AndroidManifest.xml | 2 +- examples/tv-app/android/java/AppImpl.cpp | 87 +++++++++++++ examples/tv-app/android/java/TVApp-JNI.cpp | 2 + examples/tv-app/linux/main.cpp | 25 ++++ .../tv-common/shell/AppTvShellCommands.cpp | 11 ++ examples/tv-app/tv-common/src/AppTv.cpp | 116 +++++++++++++++--- src/app/app-platform/ContentAppPlatform.cpp | 51 ++++++++ src/app/app-platform/ContentAppPlatform.h | 14 +++ 9 files changed, 293 insertions(+), 17 deletions(-) diff --git a/examples/common/m5stack-tft/repo b/examples/common/m5stack-tft/repo index d99f5ef8df180a..a6299b6c7c0b2e 160000 --- a/examples/common/m5stack-tft/repo +++ b/examples/common/m5stack-tft/repo @@ -1 +1 @@ -Subproject commit d99f5ef8df180ab34b3d9fff6888d5bede7665c5 +Subproject commit a6299b6c7c0b2e3eb62fa08ee4bf7155c39bad1f diff --git a/examples/tv-app/android/App/content-app/src/main/AndroidManifest.xml b/examples/tv-app/android/App/content-app/src/main/AndroidManifest.xml index 61d036e0a90ef4..fff52c4b59db7e 100644 --- a/examples/tv-app/android/App/content-app/src/main/AndroidManifest.xml +++ b/examples/tv-app/android/App/content-app/src/main/AndroidManifest.xml @@ -19,7 +19,7 @@ - + diff --git a/examples/tv-app/android/java/AppImpl.cpp b/examples/tv-app/android/java/AppImpl.cpp index 4dfabd03f12ec6..c24e7e537dbb23 100644 --- a/examples/tv-app/android/java/AppImpl.cpp +++ b/examples/tv-app/android/java/AppImpl.cpp @@ -355,6 +355,87 @@ ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vend return nullptr; } +class DevicePairedCommand : public Controller::DevicePairingDelegate +{ +public: + struct CallbackContext + { + uint16_t vendorId; + uint16_t productId; + chip::NodeId nodeId; + + CallbackContext(uint16_t vId, uint16_t pId, chip::NodeId nId) : vendorId(vId), productId(pId), nodeId(nId) {} + }; + DevicePairedCommand(uint16_t vendorId, uint16_t productId, chip::NodeId nodeId) : + mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this) + { + mContext = std::make_shared(vendorId, productId, nodeId); + } + + static void OnDeviceConnectedFn(void * context, chip::Messaging::ExchangeManager & exchangeMgr, + const chip::SessionHandle & sessionHandle) + { + auto * pairingCommand = static_cast(context); + auto cbContext = pairingCommand->mContext; + + if (pairingCommand) + { + ChipLogProgress(DeviceLayer, + "OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 + " and vendor id: %d and product id: %d", + ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); + + GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, + cbContext->nodeId, exchangeMgr, sessionHandle); + } + } + + static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) + { + auto * pairingCommand = static_cast(context); + auto cbContext = pairingCommand->mContext; + + if (pairingCommand) + { + ChipLogProgress(DeviceLayer, + "OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 + " and vendor id: %d and product id: %d", + ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); + // TODO: Remove Node Id + } + } + + chip::Callback::Callback mOnDeviceConnectedCallback; + chip::Callback::Callback mOnDeviceConnectionFailureCallback; + std::shared_ptr mContext; +}; + +void refreshConnectedClientsAcl(uint16_t vendorId, uint16_t productId, ContentAppImpl * app) +{ + + std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); + + for (const auto & allowedVendor : app->GetApplicationBasicDelegate()->GetAllowedVendorList()) + { + std::set tempNodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForAllowVendorId(allowedVendor); + + nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); + } + + for (const auto & nodeId : nodeIds) + { + + ChipLogProgress(DeviceLayer, + "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + ChipLogValueX64(nodeId), vendorId, productId); + + std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); + + GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, + &pairingCommand->mOnDeviceConnectionFailureCallback); + } +} + EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId, const char * szApplicationVersion, std::vector supportedClusters, jobject manager) @@ -369,6 +450,9 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1 app->GetEndpointId()); mContentApps.push_back(app); mDataVersions.push_back(dataVersionBuf); + + refreshConnectedClientsAcl(vendorId, productId, app); + return epId; } @@ -387,6 +471,9 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1 app->GetEndpointId()); mContentApps.push_back(app); mDataVersions.push_back(dataVersionBuf); + + refreshConnectedClientsAcl(vendorId, productId, app); + return epId; } diff --git a/examples/tv-app/android/java/TVApp-JNI.cpp b/examples/tv-app/android/java/TVApp-JNI.cpp index 04b5f4199edcaa..65a0a4409e9b8f 100644 --- a/examples/tv-app/android/java/TVApp-JNI.cpp +++ b/examples/tv-app/android/java/TVApp-JNI.cpp @@ -258,6 +258,8 @@ class MyPostCommissioningListener : public PostCommissioningListener // read current binding list chip::Controller::ClusterBase cluster(exchangeMgr, sessionHandle, kTargetBindingClusterEndpointId); + ContentAppPlatform::GetInstance().StoreNodeIdForContentApp(vendorId, productId, nodeId); + cacheContext(vendorId, productId, nodeId, exchangeMgr, sessionHandle); CHIP_ERROR err = diff --git a/examples/tv-app/linux/main.cpp b/examples/tv-app/linux/main.cpp index 29fdd69cb36792..c2055e0abd03f3 100644 --- a/examples/tv-app/linux/main.cpp +++ b/examples/tv-app/linux/main.cpp @@ -45,6 +45,31 @@ void ApplicationInit() ChipLogDetail(DeviceLayer, "TV Linux App: Warning - Fixed Content App Endpoint Not Disabled"); // Can't disable this without breaking CI unit tests that act upon account login cluster (only available on ep3) // emberAfEndpointEnableDisable(3, false); + +#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED + // Install Content Apps + ContentAppFactoryImpl * factory = GetContentAppFactoryImpl(); + + // Content App 1 + constexpr uint16_t kApp1VendorId = 65521; + constexpr uint16_t kApp1ProductId = 32769; + factory->InstallContentApp(kApp1VendorId, kApp1ProductId); + + // Content App 2 + constexpr uint16_t kApp2VendorId = 1; + constexpr uint16_t kApp2ProductId = 11; + factory->InstallContentApp(kApp2VendorId, kApp2ProductId); + + // Content App 3 + constexpr uint16_t kApp3VendorId = 9050; + constexpr uint16_t kApp3ProductId = 22; + factory->InstallContentApp(kApp3VendorId, kApp3ProductId); + + // Content App 4 + constexpr uint16_t kApp4VendorId = 1111; + constexpr uint16_t kApp4ProductId = 22; + factory->InstallContentApp(kApp4VendorId, kApp4ProductId); +#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED } void ApplicationShutdown() {} diff --git a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp index b39e84ad40f89a..5125ebbbbd7ecd 100644 --- a/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp +++ b/examples/tv-app/tv-common/shell/AppTvShellCommands.cpp @@ -209,6 +209,10 @@ static CHIP_ERROR PrintAllCommands() #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE streamer_printf(sout, " print-app-access Print all ACLs for app platform fabric. Usage: app print-app-access\r\n"); streamer_printf(sout, " remove-app-access Remove all ACLs for app platform fabric. Usage: app remove-app-access\r\n"); + streamer_printf( + sout, + " print-installed-apps Print all installed content apps with their endpoints. Usage: app print-installed-apps\r\n"); + streamer_printf(sout, " commission Commission given udc-entry using given pincode from corresponding app. Usage: " "app commission 0\r\n"); @@ -436,6 +440,13 @@ static CHIP_ERROR AppPlatformHandler(int argc, char ** argv) Access::GetAccessControl().DeleteAllEntriesForFabric(GetDeviceCommissioner()->GetFabricIndex()); return CHIP_NO_ERROR; } + else if (strcmp(argv[0], "print-installed-apps") == 0) + { + ContentAppFactoryImpl * factory = GetContentAppFactoryImpl(); + factory->LogInstalledApps(); + + return CHIP_NO_ERROR; + } else if (strcmp(argv[0], "commission") == 0) { if (argc < 2) diff --git a/examples/tv-app/tv-common/src/AppTv.cpp b/examples/tv-app/tv-common/src/AppTv.cpp index 03422c3fa462e7..8d81d9cf6c2c5c 100644 --- a/examples/tv-app/tv-common/src/AppTv.cpp +++ b/examples/tv-app/tv-common/src/AppTv.cpp @@ -164,6 +164,8 @@ class MyPostCommissioningListener : public PostCommissioningListener // read current binding list chip::Controller::ClusterBase cluster(exchangeMgr, sessionHandle, kTargetBindingClusterEndpointId); + ContentAppPlatform::GetInstance().StoreNodeIdForContentApp(vendorId, productId, nodeId); + cacheContext(vendorId, productId, nodeId, exchangeMgr, sessionHandle); CHIP_ERROR err = @@ -565,6 +567,63 @@ void ContentAppFactoryImpl::AddAdminVendorId(uint16_t vendorId) mAdminVendorIds.push_back(vendorId); } +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE +class DevicePairedCommand : public Controller::DevicePairingDelegate +{ +public: + struct CallbackContext + { + uint16_t vendorId; + uint16_t productId; + chip::NodeId nodeId; + + CallbackContext(uint16_t vId, uint16_t pId, chip::NodeId nId) : vendorId(vId), productId(pId), nodeId(nId) {} + }; + DevicePairedCommand(uint16_t vendorId, uint16_t productId, chip::NodeId nodeId) : + mOnDeviceConnectedCallback(OnDeviceConnectedFn, this), mOnDeviceConnectionFailureCallback(OnDeviceConnectionFailureFn, this) + { + mContext = std::make_shared(vendorId, productId, nodeId); + } + + static void OnDeviceConnectedFn(void * context, chip::Messaging::ExchangeManager & exchangeMgr, + const chip::SessionHandle & sessionHandle) + { + auto * pairingCommand = static_cast(context); + auto cbContext = pairingCommand->mContext; + + if (pairingCommand) + { + ChipLogProgress(DeviceLayer, + "OnDeviceConnectedFn - Updating ACL for node id: " ChipLogFormatX64 + " and vendor id: %d and product id: %d", + ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); + + GetCommissionerDiscoveryController()->CommissioningSucceeded(cbContext->vendorId, cbContext->productId, + cbContext->nodeId, exchangeMgr, sessionHandle); + } + } + + static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error) + { + auto * pairingCommand = static_cast(context); + auto cbContext = pairingCommand->mContext; + + if (pairingCommand) + { + ChipLogProgress(DeviceLayer, + "OnDeviceConnectionFailureFn - Not updating ACL for node id: " ChipLogFormatX64 + " and vendor id: %d and product id: %d", + ChipLogValueX64(cbContext->nodeId), cbContext->vendorId, cbContext->productId); + // TODO: Remove Node Id + } + } + + chip::Callback::Callback mOnDeviceConnectedCallback; + chip::Callback::Callback mOnDeviceConnectionFailureCallback; + std::shared_ptr mContext; +}; +#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE + void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t productId) { auto make_default_supported_clusters = []() { @@ -605,6 +664,46 @@ void ContentAppFactoryImpl::InstallContentApp(uint16_t vendorId, uint16_t produc make_default_supported_clusters()); mContentApps.emplace_back(std::move(ptr)); } + +#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE + // Get the list of node ids + std::set nodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForContentApp(vendorId, productId); + + // update ACLs + for (auto & contentApp : mContentApps) + { + auto app = contentApp.get(); + + if (app->MatchesPidVid(productId, vendorId)) + { + CatalogVendorApp vendorApp = app->GetApplicationBasicDelegate()->GetCatalogVendorApp(); + + GetContentAppFactoryImpl()->LoadContentApp(vendorApp); + } + + // update the list of node ids with content apps allowed vendor list + for (const auto & allowedVendor : app->GetApplicationBasicDelegate()->GetAllowedVendorList()) + { + std::set tempNodeIds = ContentAppPlatform::GetInstance().GetNodeIdsForAllowVendorId(allowedVendor); + + nodeIds.insert(tempNodeIds.begin(), tempNodeIds.end()); + } + } + + // refresh ACLs + for (const auto & nodeId : nodeIds) + { + + ChipLogProgress(DeviceLayer, + "Creating Pairing Command with node id: " ChipLogFormatX64 " and vendor id: %d and product id: %d", + ChipLogValueX64(nodeId), vendorId, productId); + + std::shared_ptr pairingCommand = std::make_shared(vendorId, productId, nodeId); + + GetDeviceCommissioner()->GetConnectedDevice(nodeId, &pairingCommand->mOnDeviceConnectedCallback, + &pairingCommand->mOnDeviceConnectionFailureCallback); + } +#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE } bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t productId) @@ -625,8 +724,9 @@ bool ContentAppFactoryImpl::UninstallContentApp(uint16_t vendorId, uint16_t prod ChipLogProgress(DeviceLayer, "Found an app vid=%d pid=%d. Uninstalling it.", app->GetApplicationBasicDelegate()->HandleGetVendorId(), app->GetApplicationBasicDelegate()->HandleGetProductId()); + EndpointId removedEndpointID = ContentAppPlatform::GetInstance().RemoveContentApp(app); + ChipLogProgress(DeviceLayer, "Removed content app at endpoint id: %d", removedEndpointID); mContentApps.erase(mContentApps.begin() + index); - // TODO: call ContentAppPlatform->RemoveContentApp(ids...) return true; } @@ -701,22 +801,8 @@ std::list ContentAppFactoryImpl::GetAllowedClusterListForStaticEndpoi CHIP_ERROR AppTvInit() { #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED - // test data for apps - constexpr uint16_t kApp1VendorId = 1; - constexpr uint16_t kApp1ProductId = 11; - constexpr uint16_t kApp2VendorId = 65521; - constexpr uint16_t kApp2ProductId = 32769; - constexpr uint16_t kApp3VendorId = 9050; - constexpr uint16_t kApp3ProductId = 22; - constexpr uint16_t kApp4VendorId = 1111; - constexpr uint16_t kApp4ProductId = 22; - ContentAppPlatform::GetInstance().SetupAppPlatform(); ContentAppPlatform::GetInstance().SetContentAppFactory(&gFactory); - gFactory.InstallContentApp(kApp1VendorId, kApp1ProductId); - gFactory.InstallContentApp(kApp2VendorId, kApp2ProductId); - gFactory.InstallContentApp(kApp3VendorId, kApp3ProductId); - gFactory.InstallContentApp(kApp4VendorId, kApp4ProductId); uint16_t value; if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(value) != CHIP_NO_ERROR) { diff --git a/src/app/app-platform/ContentAppPlatform.cpp b/src/app/app-platform/ContentAppPlatform.cpp index fb2d6ab39a1b5f..214af261e26e54 100644 --- a/src/app/app-platform/ContentAppPlatform.cpp +++ b/src/app/app-platform/ContentAppPlatform.cpp @@ -387,6 +387,57 @@ ContentApp * ContentAppPlatform::GetContentApp(EndpointId id) return nullptr; } +// create a string key from vendorId and productId +std::string createKey(uint16_t vendorId, uint16_t productId) +{ + return std::to_string(vendorId) + ":" + std::to_string(productId); +} + +void ContentAppPlatform::StoreNodeIdForContentApp(uint16_t vendorId, uint16_t productId, NodeId nodeId) +{ + std::string key = createKey(vendorId, productId); + + ChipLogProgress(DeviceLayer, "Stored node id: " ChipLogFormatX64 " for key: %s", ChipLogValueX64(nodeId), key.c_str()); + + mConnectedContentAppNodeIds[key].insert(nodeId); +} + +std::set ContentAppPlatform::GetNodeIdsForContentApp(uint16_t vendorId, uint16_t productId) +{ + std::string key = createKey(vendorId, productId); + + ChipLogProgress(DeviceLayer, "Retrieving node id for key: %s", key.c_str()); + + auto it = mConnectedContentAppNodeIds.find(key); + if (it != mConnectedContentAppNodeIds.end()) + { + ChipLogProgress(DeviceLayer, "Found node id"); + return it->second; + } + + ChipLogProgress(DeviceLayer, "Didn't find node id"); + // If key not found, return an empty set + return {}; +} + +std::set ContentAppPlatform::GetNodeIdsForAllowVendorId(uint16_t vendorId) +{ + std::set result; + std::string vendorPrefix = std::to_string(vendorId) + ":"; + + for (const auto & pair : mConnectedContentAppNodeIds) + { + const std::string & key = pair.first; + if (key.find(vendorPrefix) == 0) + { // Check if the key starts with the vendor prefix + const std::set & nodeIds = pair.second; + result.insert(nodeIds.begin(), nodeIds.end()); + } + } + + return result; +} + void ContentAppPlatform::SetCurrentApp(ContentApp * app) { if (!HasCurrentApp()) diff --git a/src/app/app-platform/ContentAppPlatform.h b/src/app/app-platform/ContentAppPlatform.h index 16a47c26a3b991..45615d09ed8ddf 100644 --- a/src/app/app-platform/ContentAppPlatform.h +++ b/src/app/app-platform/ContentAppPlatform.h @@ -161,6 +161,18 @@ class DLL_EXPORT ContentAppPlatform bool HasTargetContentApp(uint16_t vendorId, uint16_t productId, CharSpan rotatingId, Protocols::UserDirectedCommissioning::TargetAppInfo & info, uint32_t & passcode); + // returns set of connected nodes for a given content app + std::set GetNodeIdsForContentApp(uint16_t vendorId, uint16_t productId); + + // returns set of connected nodes for a given allowed vendor id + std::set GetNodeIdsForAllowVendorId(uint16_t vendorId); + + // store node id for content app after commissioning + // node id can be used later on to update ACL + // in case app is not installed + // Note: This is in memory storing, the values are deleted after reboot + void StoreNodeIdForContentApp(uint16_t vendorId, uint16_t productId, NodeId nodeId); + /** * @brief * Add ACLs on this device for the given client, @@ -201,6 +213,8 @@ class DLL_EXPORT ContentAppPlatform EndpointId mCurrentEndpointId; EndpointId mFirstDynamicEndpointId; ContentApp * mContentApps[CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT]; + // key is string -> vendorId:producTid + std::map> mConnectedContentAppNodeIds; private: void IncrementCurrentEndpointID(); From 2405b122be5b98222c4e1b18ac7e133f101e3e74 Mon Sep 17 00:00:00 2001 From: yeaissa <133245269+yeaissa@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:51:06 +0200 Subject: [PATCH 2/2] [NXP] Adding Zephyr examples (#34103) * [NXP] Adding Zephyr examples Adding 3 examples: *All-cluster-app *Thermostat *Laundry-washer-app Signed-off-by: Axel Le Bourhis Signed-off-by: Yassine El Aissaoui * Restyled by prettier-markdown * [NXP] Fix spelling issues on all-clusters-app Readme * [NXP] add support for rw61x Zephyr on build_examples With the current change, NXP Matter apps using Zephyr can be built using the build_examples.py. Build examples that are supported are: * all-clusters-app * laundry-washer * thermostat Build variants that are supported for now: * build with factory data More variants can be added later. * Restyled by autopep8 --------- Signed-off-by: Axel Le Bourhis Signed-off-by: Yassine El Aissaoui Co-authored-by: Restyled.io --- .github/workflows/examples-nxp.yaml | 24 +- .../all-clusters-app/nxp/zephyr/.gitignore | 1 + .../nxp/zephyr/CMakeLists.txt | 115 ++++ examples/all-clusters-app/nxp/zephyr/Kconfig | 20 + .../all-clusters-app/nxp/zephyr/README.md | 609 ++++++++++++++++++ .../nxp/zephyr/boards/rd_rw612_bga.overlay | 39 ++ .../nxp/zephyr/boards/rd_rw612_bga_fdata.conf | 23 + .../zephyr/main/include/CHIPProjectConfig.h | 31 + .../all-clusters-app/nxp/zephyr/main/main.cpp | 37 ++ examples/all-clusters-app/nxp/zephyr/prj.conf | 59 ++ .../nxp/zephyr/prj_fdata.conf | 80 +++ .../all-clusters-app/nxp/zephyr/prj_ota.conf | 31 + .../nxp/zephyr/third_party/connectedhomeip | 1 + .../laundry-washer-app/nxp/zephyr/.gitignore | 1 + .../nxp/zephyr/CMakeLists.txt | 116 ++++ .../laundry-washer-app/nxp/zephyr/Kconfig | 20 + .../laundry-washer-app/nxp/zephyr/README.md | 4 + .../nxp/zephyr/boards/rd_rw612_bga.overlay | 39 ++ .../nxp/zephyr/boards/rd_rw612_bga_fdata.conf | 23 + .../zephyr/main/include/CHIPProjectConfig.h | 35 + .../nxp/zephyr/main/main.cpp | 37 ++ .../laundry-washer-app/nxp/zephyr/prj.conf | 59 ++ .../nxp/zephyr/prj_fdata.conf | 80 +++ .../nxp/zephyr/prj_ota.conf | 31 + .../nxp/zephyr/third_party/connectedhomeip | 1 + examples/thermostat/nxp/zephyr/.gitignore | 1 + examples/thermostat/nxp/zephyr/CMakeLists.txt | 104 +++ examples/thermostat/nxp/zephyr/Kconfig | 20 + examples/thermostat/nxp/zephyr/README.md | 4 + .../nxp/zephyr/boards/rd_rw612_bga.overlay | 39 ++ .../nxp/zephyr/boards/rd_rw612_bga_fdata.conf | 23 + .../zephyr/main/include/CHIPProjectConfig.h | 35 + examples/thermostat/nxp/zephyr/main/main.cpp | 37 ++ examples/thermostat/nxp/zephyr/prj.conf | 59 ++ examples/thermostat/nxp/zephyr/prj_fdata.conf | 80 +++ examples/thermostat/nxp/zephyr/prj_ota.conf | 31 + .../nxp/zephyr/third_party/connectedhomeip | 1 + scripts/build/build/targets.py | 20 +- scripts/build/builders/nxp.py | 91 ++- .../build/testdata/all_targets_linux_x64.txt | 2 +- 40 files changed, 2037 insertions(+), 26 deletions(-) create mode 100644 examples/all-clusters-app/nxp/zephyr/.gitignore create mode 100644 examples/all-clusters-app/nxp/zephyr/CMakeLists.txt create mode 100644 examples/all-clusters-app/nxp/zephyr/Kconfig create mode 100644 examples/all-clusters-app/nxp/zephyr/README.md create mode 100644 examples/all-clusters-app/nxp/zephyr/boards/rd_rw612_bga.overlay create mode 100644 examples/all-clusters-app/nxp/zephyr/boards/rd_rw612_bga_fdata.conf create mode 100644 examples/all-clusters-app/nxp/zephyr/main/include/CHIPProjectConfig.h create mode 100644 examples/all-clusters-app/nxp/zephyr/main/main.cpp create mode 100644 examples/all-clusters-app/nxp/zephyr/prj.conf create mode 100644 examples/all-clusters-app/nxp/zephyr/prj_fdata.conf create mode 100644 examples/all-clusters-app/nxp/zephyr/prj_ota.conf create mode 120000 examples/all-clusters-app/nxp/zephyr/third_party/connectedhomeip create mode 100644 examples/laundry-washer-app/nxp/zephyr/.gitignore create mode 100644 examples/laundry-washer-app/nxp/zephyr/CMakeLists.txt create mode 100644 examples/laundry-washer-app/nxp/zephyr/Kconfig create mode 100644 examples/laundry-washer-app/nxp/zephyr/README.md create mode 100644 examples/laundry-washer-app/nxp/zephyr/boards/rd_rw612_bga.overlay create mode 100644 examples/laundry-washer-app/nxp/zephyr/boards/rd_rw612_bga_fdata.conf create mode 100644 examples/laundry-washer-app/nxp/zephyr/main/include/CHIPProjectConfig.h create mode 100644 examples/laundry-washer-app/nxp/zephyr/main/main.cpp create mode 100644 examples/laundry-washer-app/nxp/zephyr/prj.conf create mode 100644 examples/laundry-washer-app/nxp/zephyr/prj_fdata.conf create mode 100644 examples/laundry-washer-app/nxp/zephyr/prj_ota.conf create mode 120000 examples/laundry-washer-app/nxp/zephyr/third_party/connectedhomeip create mode 100644 examples/thermostat/nxp/zephyr/.gitignore create mode 100644 examples/thermostat/nxp/zephyr/CMakeLists.txt create mode 100644 examples/thermostat/nxp/zephyr/Kconfig create mode 100644 examples/thermostat/nxp/zephyr/README.md create mode 100644 examples/thermostat/nxp/zephyr/boards/rd_rw612_bga.overlay create mode 100644 examples/thermostat/nxp/zephyr/boards/rd_rw612_bga_fdata.conf create mode 100644 examples/thermostat/nxp/zephyr/main/include/CHIPProjectConfig.h create mode 100644 examples/thermostat/nxp/zephyr/main/main.cpp create mode 100644 examples/thermostat/nxp/zephyr/prj.conf create mode 100644 examples/thermostat/nxp/zephyr/prj_fdata.conf create mode 100644 examples/thermostat/nxp/zephyr/prj_ota.conf create mode 120000 examples/thermostat/nxp/zephyr/third_party/connectedhomeip diff --git a/.github/workflows/examples-nxp.yaml b/.github/workflows/examples-nxp.yaml index 05d434b0a67792..07ab55d1315bb5 100644 --- a/.github/workflows/examples-nxp.yaml +++ b/.github/workflows/examples-nxp.yaml @@ -60,14 +60,14 @@ jobs: run: | scripts/run_in_build_env.sh "\ ./scripts/build/build_examples.py \ - --target nxp-k32w0-lighting \ - --target nxp-k32w0-lighting-factory \ - --target nxp-k32w0-lighting-rotating-id \ - --target nxp-k32w0-contact-sensor \ - --target nxp-k32w0-contact-sensor-low-power \ - --target nxp-k32w0-contact-sensor-low-power-factory \ - --target nxp-k32w1-lighting \ - --target nxp-k32w1-contact-sensor-low-power \ + --target nxp-k32w0-freertos-lighting \ + --target nxp-k32w0-freertos-lighting-factory \ + --target nxp-k32w0-freertos-lighting-rotating-id \ + --target nxp-k32w0-freertos-contact-sensor \ + --target nxp-k32w0-freertos-contact-sensor-low-power \ + --target nxp-k32w0-freertos-contact-sensor-low-power-factory \ + --target nxp-k32w1-freertos-lighting \ + --target nxp-k32w1-freertos-contact-sensor-low-power \ build \ --copy-artifacts-to out/artifacts \ " @@ -75,21 +75,21 @@ jobs: run: | .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ nxp k32w0+release light \ - out/artifacts/nxp-k32w0-lighting/chip-k32w0x-light-example.elf \ + out/artifacts/nxp-k32w0-freertos-lighting/chip-k32w0x-light-example.elf \ /tmp/bloat_reports/ .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ nxp k32w1+release light \ - out/artifacts/nxp-k32w1-lighting/chip-k32w1-light-example.elf \ + out/artifacts/nxp-k32w1-freertos-lighting/chip-k32w1-light-example.elf \ /tmp/bloat_reports/ - name: Get contact sensor size stats run: | .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ nxp k32w0+release contact \ - out/artifacts/nxp-k32w0-contact-sensor-low-power/chip-k32w0x-contact-example.elf \ + out/artifacts/nxp-k32w0-freertos-contact-sensor-low-power/chip-k32w0x-contact-example.elf \ /tmp/bloat_reports/ .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ nxp k32w1+release contact \ - out/artifacts/nxp-k32w1-contact-sensor-low-power/chip-k32w1-contact-example.elf \ + out/artifacts/nxp-k32w1-freertos-contact-sensor-low-power/chip-k32w1-contact-example.elf \ /tmp/bloat_reports/ - name: Uploading Size Reports uses: ./.github/actions/upload-size-reports diff --git a/examples/all-clusters-app/nxp/zephyr/.gitignore b/examples/all-clusters-app/nxp/zephyr/.gitignore new file mode 100644 index 00000000000000..84c048a73cc2e5 --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/examples/all-clusters-app/nxp/zephyr/CMakeLists.txt b/examples/all-clusters-app/nxp/zephyr/CMakeLists.txt new file mode 100644 index 00000000000000..2fa2d558a2724a --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/CMakeLists.txt @@ -0,0 +1,115 @@ +# +# Copyright (c) 2023-2024 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. +# +cmake_minimum_required(VERSION 3.13.1) + +get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH) +get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH) +get_filename_component(ALL_CLUSTERS_COMMON_DIR ${CHIP_ROOT}/examples/all-clusters-app/all-clusters-common REALPATH) +get_filename_component(ALL_CLUSTERS_NXP_COMMON_DIR ${CHIP_ROOT}/examples/all-clusters-app/nxp/common REALPATH) +get_filename_component(EXAMPLE_PLATFORM_NXP_COMMON_DIR ${CHIP_ROOT}/examples/platform/nxp/common REALPATH) +get_filename_component(EXAMPLE_PLATFORM_NXP_ZEPHYR_DIR ${CHIP_ROOT}/examples/platform/nxp/zephyr REALPATH) + +# Perform common operations like detecting extra overlays in the platform folder for the target board +# This must be called before find_package(Zephyr) +include(${CHIP_ROOT}/config/nxp/app/pre-zephyr.cmake) + +list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nxp/chip-module) +find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) + +# -Wmaybe-uninitialized has too many false positives, including on std::optional +# and chip::Optional. Make it nonfatal. +# +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635 +target_compile_options(app PRIVATE -Werror -Wno-error=maybe-uninitialized) + +project(chip-nxp-all-clusters-app-example) + +include(${CHIP_ROOT}/config/nxp/app/enable-gnu-std.cmake) +include(${CHIP_ROOT}/src/app/chip_data_model.cmake) + +target_include_directories(app + PRIVATE + ${ALL_CLUSTERS_NXP_COMMON_DIR}/main/include + ${ALL_CLUSTERS_COMMON_DIR}/include + ${GEN_DIR}/app-common + ${GEN_DIR}/all-clusters-app + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_manager/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/icd/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_callbacks/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/factory_data/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/include +) + +target_sources(app + PRIVATE + main/main.cpp + ${ALL_CLUSTERS_NXP_COMMON_DIR}/main/AppTask.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_manager/source/CHIPDeviceManager.cpp + ${ALL_CLUSTERS_NXP_COMMON_DIR}/main/DeviceCallbacks.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_callbacks/source/CommonDeviceCallbacks.cpp + ${ALL_CLUSTERS_NXP_COMMON_DIR}/main/ZclCallbacks.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/binding-handler.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/source/AppTaskBase.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/source/AppTaskZephyr.cpp + ${EXAMPLE_PLATFORM_NXP_ZEPHYR_DIR}/factory_data/source/AppFactoryDataExample.cpp +) + +target_compile_definitions(app PUBLIC + "EXTERNAL_FACTORY_DATA_PROVIDER_IMPL_HEADER=\"platform/nxp/zephyr/FactoryDataProviderImpl.h\"" +) + +if(CONFIG_CHIP_OTA_REQUESTOR) + target_sources(app PRIVATE + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/source/OTARequestorInitiatorCommon.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/source/OTARequestorInitiatorZephyr.cpp + ) + target_include_directories(app PRIVATE + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/include/ + ) +endif() + +chip_configure_data_model(app + INCLUDE_SERVER + ZAP_FILE ${ALL_CLUSTERS_COMMON_DIR}/all-clusters-app.zap +) + +if(CONFIG_CHIP_LIB_SHELL) + target_compile_definitions(app PRIVATE ENABLE_CHIP_SHELL) + target_include_directories(app PRIVATE + ${CHIP_ROOT}/examples/shell/shell_common/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/matter_cli/include + ) + target_sources(app PRIVATE + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/matter_cli/source/AppCLIBase.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/matter_cli/source/AppCLIZephyr.cpp + ${CHIP_ROOT}/examples/shell/shell_common/cmd_misc.cpp + ${CHIP_ROOT}/examples/shell/shell_common/cmd_otcli.cpp + ${CHIP_ROOT}/examples/shell/shell_common/cmd_server.cpp + ) +endif() + +target_sources(app + PRIVATE + ${ALL_CLUSTERS_COMMON_DIR}/src/smco-stub.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/static-supported-modes-manager.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/static-supported-temperature-levels.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/bridged-actions-stub.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/fan-stub.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/air-quality-instance.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/concentration-measurement-instances.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/resource-monitoring-delegates.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/icd/source/ICDUtil.cpp +) diff --git a/examples/all-clusters-app/nxp/zephyr/Kconfig b/examples/all-clusters-app/nxp/zephyr/Kconfig new file mode 100644 index 00000000000000..748835a9d0fe6b --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/Kconfig @@ -0,0 +1,20 @@ +# +# Copyright (c) 2024 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. +# +mainmenu "Matter NXP All Clusters Example Application" + +rsource "../../../../config/nxp/chip-module/Kconfig.features" +rsource "../../../../config/nxp/chip-module/Kconfig.defaults" +source "Kconfig.zephyr" diff --git a/examples/all-clusters-app/nxp/zephyr/README.md b/examples/all-clusters-app/nxp/zephyr/README.md new file mode 100644 index 00000000000000..45f71ee76c077b --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/README.md @@ -0,0 +1,609 @@ +# CHIP NXP Zephyr All-clusters Application + +The all-clusters example implements a server which can be accessed by a CHIP +controller and can accept basic cluster commands. + +The example is based on +[Project CHIP](https://github.com/project-chip/connectedhomeip) and the NXP +Zephyr SDK, and provides a prototype application that demonstrates device +commissioning and different cluster control. + +
+ +- [Introduction](#introduction) +- [Building](#building) +- [Flashing and debugging](#flashing-and-debugging) +- [Factory data](#factory-data) +- [Manufacturing data](#generate-factory-data) +- [OTA Software Update](#ota-software-update) +- [Testing the example](#testing-the-example) +- [Using Matter CLI in NXP Zephyr examples](#using-matter-cli-in-nxp-zephyr-examples) + +
+ + + +## Introduction + +The Zephyr application provides a working demonstration of supported board +integration from Zephyr, built using the Project CHIP codebase and the +NXP/Zephyr SDK. + +The example supports: + +- Matter over Wi-Fi + +The supported boards are: + +- `rd_rw612_bga` + + + +## Building + +In order to build the Project CHIP example, we recommend using a Linux +distribution (the demo-application was compiled on Ubuntu 20.04). + +Prerequisites: + +- Follow instruction from [BUILDING.md](../../../../docs/guides/BUILDING.md) + to setup the Matter environment +- Follow instruction from + [Getting Started Guide](https://docs.zephyrproject.org/latest/develop/getting_started/index.html) + to setup a Zephyr workspace, however, the west init command to use is as + follows: + +```shell +$ west init zephyrproject -m https://github.com/nxp-zephyr-ear/zephyr.git --mr zephyr_rw61x_v3.6_RFP +``` + +> **Note**: Currently, supported NXP platforms in Zephyr targeting Matter are +> not available in the official Zephyr repo, you'll have to use the NXP fork +> `https://github.com/nxp-zephyr-ear/zephyr` github repo. Reach to your NXP +> contact for more details. + +Steps to build the example, targeting `rd_rw612_bga` board: + +1. Activate your Matter env: + +```shell +source /scripts/activate.sh +``` + +2. Source zephyr-env.sh: + +```shell +source /zephyr-env.sh +``` + +3. Run west build command: + +```shell +west build -b rd_rw612_bga -p +``` + +By default, a folder `build` will be created in the same folder you run the +command from. The binaries will be created in `build/zephyr` with the name +`zephyr.elf` and `zephyr.bin`. + +You can get more details on `west build` with +[Zephyr's building guide](https://docs.zephyrproject.org/latest/develop/west/build-flash-debug.html#building-west-build) + + + +## Flashing and debugging + +### Flashing without debugging + +`west` can be used to flash a target, as an example for `rd_rw612_bga` board: + +```shell +west flash -i +``` + +You can get more details on `west flash` with +[Zephyr's flashing guide](https://docs.zephyrproject.org/latest/develop/west/build-flash-debug.html#flashing-west-flash) + +> **Note**: `west flash` will not start a debug session, it will only flash and +> reset the device + +### Flash and debug + +To debug a Matter with Zephyr application, you could use several methods: + +- [MCUXpresso IDE (version >= 11.6.0)](https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-integrated-development-environment-ide:MCUXpresso-IDE) +- `west debug` + [Zephyr's debugging guide](https://docs.zephyrproject.org/latest/develop/west/build-flash-debug.html#id29) + +> **Note**: As the build provides an elf file, any compatible debugging tool can +> be used. + + + +## Factory data + +NXP Zephyr examples are not using factory data support by default. Please refer +the the section below to build with factory data. + +You may refer to `src/platform/nxp/zephyr/boards//.overlay` file +to obtain the memory region used by this partition. + +For example, the factory data partition on `rd_rw612_bga` is reserved in the +last sector of the `flexspi` flash of `RD BGA` board, at `0x1BFFF000`. + +``` +&flexspi { + status = "okay"; + + mx25u51245g: mx25u51245g@0 { + ... + factory_partition: partition@3FFF000 { + label = "factory-data"; + reg = <0x03FFF000 DT_SIZE_K(4)>; + }; + }; +}; +``` + +> **Note**: You may also refer to +> `src/platform/nxp/zephyr/boards//.overlay` file to check other +> memory partitions used by the platform, such as the file system partition +> mentioned with the `storage` label. + +### Build with factory data support + +To build the example with factory data support, you can add +`-DFILE_SUFFIX=fdata` in the west build command line. + +Example: + +```bash +west build -b rd_rw612_bga -p -- -DFILE_SUFFIX=fdata +``` + +`prj_fdata.conf` configuration file will enable `CONFIG_CHIP_FACTORY_DATA` +Kconfig so the application will load the factory data at boot. + + + +### Generate factory data + +#### Automatically (recommended) + +The factory data can be generated automatically during the build of the +application. To do so, you can use the configuration +`CONFIG_CHIP_FACTORY_DATA_BUILD=y` in `prj_fdata.conf`. + +You will have to specify the source of the certificates to be used for the +factory data. Please refer to `CHIP_FACTORY_DATA_CERT_SOURCE` Kconfig for more +info. + +> **Note**: The application demonstrates the usage of encrypted Matter factory +> data storage. Matter factory data should be encrypted using an AES 128 +> software key before flashing them to the device flash. You can encrypt the +> factory data automatically during the build by enabling +> `CHIP_ENCRYPTED_FACTORY_DATA` Kconfig. See also +> `CHIP_ENCRYPTED_FACTORY_DATA_AES128_KEY` Kconfig if you want to use a specific +> key. + +The resulting factory data will be provided along `zephyr.bin` as a binary file +named `factory_data.bin`. In order to flash it to your device, you need to know +the partition address: please refer to `factory_partition` defined in +`src/platform/nxp/zephyr/boards//.overlay`. + +#### Manually + +See +[Guide for writing manufacturing data on NXP devices](../../../../docs/guides/nxp/nxp_manufacturing_flow.md) + + + +## OTA Software Update + +See +[Guide for OTA Software Update on NXP devices using Zephyr SDK](../../../../docs/guides/nxp/nxp_zephyr_ota_software_update.md) + + + +## Testing the example + +To know how to commission a device over BLE, follow the instructions from +[chip-tool's README.md 'Commission a device over BLE'](../../../chip-tool/README.md#commission-a-device-over-ble). + + + +## Using Matter CLI in NXP Zephyr examples + +Some Matter examples for the development kits from NXP include a command-line +interface that allows access to application logs and +[Zephyr shell](https://docs.zephyrproject.org/1.13.0/subsystems/shell.html). + +Depending on the platform, the CLI console and the logs can be split on two +different interfaces. + +You may refer to `boards/.overlay` file to check how the board is +configured for the example. The binding `zephyr,console` is used to print the +logs, while the binding `zephyr,shell-uart` is used for the CLI. If the logs and +the CLI are split among two serial interfaces, you will have to open both ports. + +As an example, the Matter CLI on `rd_rw612_bga` is configured to be output on +`flexcomm3` with a baudrate of `115200`. The logs are configured to be output on +`flexcomm0` with a baudrate of `115200`. + +> **Note**: `flexcomm3` is wired to the USB `FTDI` port of the `RD BGA` board by +> default. `flexcomm0` is wired to `GPIO2` (RX) and `GPIO3` (TX). Those pins are +> accessible on `HD2` pin header. + +To access the CLI console, use a serial terminal emulator of your choice, like +Minicom or GNU Screen. Use the baud rate set to `115200`. + +### Example: Starting the CLI console with Minicom + +For example, to start using the CLI console with Minicom, run the following +command with `/dev/ttyACM0` replaced with the device node name of your +development kit: + +``` +minicom -D /dev/ttyACM0 -b 115200 +``` + +When you reboot the kit, you will see the boot logs in the console, similar to +the following messages: + +```shell +uart:~$ MAC Address: C0:95:DA:00:00:6E +... +wlan-version +wlan-mac +wlan-thread-info +wlan-net-stats +... +*** Booting Zephyr OS build zephyr-v3.4.0-187-g2ddf1330209b *** +I: Init CHIP stack +... +``` + +This means that the console is working correctly and you can start using shell +commands. For example, issuing the `kernel threads` command will print +information about all running threads: + +```shell +uart:~$ kernel threads +Scheduler: 277 since last call +Threads: + 0x20006518 CHIP + options: 0x0, priority: -1 timeout: 536896912 + state: pending + stack size 8192, unused 7256, usage 936 / 8192 (11 %) + + 0x20004ab0 SDC RX + options: 0x0, priority: -10 timeout: 536890152 + state: pending + stack size 1024, unused 848, usage 176 / 1024 (17 %) +... +``` + +## Listing all commands + +To list all available commands, use the Tab key, which is normally used for the +command completion feature. + +Pressing the Tab key in an empty command line prints the list of available +commands: + +```shell +uart:~$ + clear device help history + hwinfo kernel matter resize + retval shell +``` + +Pressing the Tab key with a command entered in the command line cycles through +available options for the given command. + +You can also run the `help` command: + +```shell +uart:~$ help +Please press the button to see all available commands. +You can also use the button to prompt or auto-complete all commands or its subcommands. +You can try to call commands with <-h> or <--help> parameter for more information. + +Shell supports following meta-keys: + Ctrl + (a key from: abcdefklnpuw) + Alt + (a key from: bf) +Please refer to shell documentation for more details. + +Available commands: + clear :Clear screen. + device :Device commands + help :Prints the help message. + history :Command history. + hwinfo :HWINFO commands + kernel :Kernel commands + matter :Matter commands + resize :Console gets terminal screen size or assumes default in case + the readout fails. It must be executed after each terminal + width change to ensure correct text display. + retval :Print return value of most recent command + shell :Useful, not Unix-like shell commands. +``` + +## Using General purpose commands + +### `kernel` command group + +#### `reboot` subcommand + +Performs either a warm or cold reset. Difference between warm and cold resets +may vary from a platform to another, but on default Cortex-M architectures, both +methods are the same, so use either one if nothing is specific to your platform. + +```shell +uart:~$ kernel reboot cold|warm +``` + +## Using Matter-specific commands + +The NXP Zephyr examples let you use several Matter-specific CLI commands. + +These commands are not available by default and to enable using them, set the +`CONFIG_CHIP_LIB_SHELL=y` Kconfig option in the `prj.conf` file of the given +example. + +Every invoked command must be preceded by the `matter` prefix. + +See the following subsections for the description of each Matter-specific +command. + +### `device` command group + +Handles a group of commands that are used to manage the device. You must use +this command together with one of the additional subcommands listed below. + +#### `factoryreset` subcommand + +Performs device factory reset that is hardware reset preceded by erasing of the +whole Matter settings stored in a non-volatile memory. + +```shell +uart:~$ matter device factoryreset +Performing factory reset ... +``` + +### `onboardingcodes` command group + +Handles a group of commands that are used to view information about device +onboarding codes. The `onboardingcodes` command takes one required parameter for +the rendezvous type, then an optional parameter for printing a specific type of +onboarding code. + +The full format of the command is as follows: + +``` +onboardingcodes none|softap|ble|onnetwork [qrcode|qrcodeurl|manualpairingcode] +``` + +#### `none` subcommand + +Prints all onboarding codes. For example: + +```shell +uart:~$ matter onboardingcodes none +QRCode: MT:W0GU2OTB00KA0648G00 +QRCodeUrl: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3AW0GU2OTB00KA0648G00 +ManualPairingCode: 34970112332 +``` + +#### `none qrcode` subcommand + +Prints the device onboarding QR code payload. Takes no arguments. + +```shell +uart:~$ matter onboardingcodes none qrcode +MT:W0GU2OTB00KA0648G00 +``` + +#### `none qrcodeurl` subcommand + +Prints the URL to view the device onboarding QR code in a web browser. Takes no +arguments. + +```shell +uart:~$ matter onboardingcodes none qrcodeurl +https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3AW0GU2OTB00KA0648G00 +``` + +#### `none manualpairingcode` subcommand + +Prints the pairing code for the manual onboarding of a device. Takes no +arguments. + +```shell +uart:~$ matter onboardingcodes none manualpairingcode +34970112332 +``` + +### `config` command group + +Handles a group of commands that are used to view device configuration +information. You can use this command without any subcommand to print all +available configuration data or to add a specific subcommand. + +```shell +uart:~$ matter config +VendorId: 65521 (0xFFF1) +ProductId: 32768 (0x8000) +HardwareVersion: 1 (0x1) +FabricId: +PinCode: 020202021 +Discriminator: f00 +DeviceId: +``` + +The `config` command can also take the subcommands listed below. + +#### `pincode` subcommand + +Prints the PIN code for device setup. Takes no arguments. + +```shell +uart:~$ matter config pincode +020202021 +``` + +#### `discriminator` subcommand + +Prints the device setup discriminator. Takes no arguments. + +```shell +uart:~$ matter config discriminator +f00 +``` + +#### `vendorid` subcommand + +Prints the vendor ID of the device. Takes no arguments. + +```shell +uart:~$ matter config vendorid +65521 (0xFFFF1) +``` + +#### `productid` subcommand + +Prints the product ID of the device. Takes no arguments. + +```shell +uart:~$ matter config productid +32768 (0x8000) +``` + +#### `hardwarever` subcommand + +Prints the hardware version of the device. Takes no arguments. + +```shell +uart:~$ matter config hardwarever +1 (0x1) +``` + +#### `deviceid` subcommand + +Prints the device identifier. Takes no arguments. + +#### `fabricid` subcommand + +Prints the fabric identifier. Takes no arguments. + +### `ble` command group + +Handles a group of commands that are used to control the device Bluetooth LE +transport state. You must use this command together with one of the additional +subcommands listed below. + +#### `help` subcommand + +Prints help information about the `ble` command group. + +```shell +uart:~$ matter ble help + help Usage: ble + adv Enable or disable advertisement. Usage: ble adv +``` + +#### `adv start` subcommand + +Enables Bluetooth LE advertising. + +```shell +uart:~$ matter ble adv start +Starting BLE advertising +``` + +#### `adv stop` subcommand + +Disables Bluetooth LE advertising. + +```shell +uart:~$ matter ble adv stop +Stopping BLE advertising +``` + +#### `adv status` subcommand + +Prints the information about the current Bluetooth LE advertising status. + +```shell +uart:~$ matter ble adv state +BLE advertising is disabled + +``` + +### `dns` command group + +Handles a group of commands that are used to trigger performing DNS queries. You +must use this command together with one of the additional subcommands listed +below. + +#### `browse` subcommand + +Browses for DNS services of `_matterc_udp` type and prints the received +response. Takes no argument. + +```shell +uart:~$ matter dns browse +Browsing ... +DNS browse succeeded: + Hostname: 0E824F0CA6DE309C + Vendor ID: 9050 + Product ID: 20043 + Long discriminator: 3840 + Device type: 0 + Device name: + Commissioning mode: 0 + IP addresses: + fd08:b65e:db8e:f9c7:2cc2:2043:1366:3b31 +``` + +#### `resolve` subcommand + +Resolves the specified Matter node service given by the _fabric-id_ and +_node-id_. + +```shell +uart:~$ matter dns resolve fabric-id node-id +Resolving ... +DNS resolve for 000000014A77CBB3-0000000000BC5C01 succeeded: + IP address: fd08:b65e:db8e:f9c7:8052:1a8e:4dd4:e1f3 + Port: 5540 +``` + +### `stat` command group + +Handles a group of commands that are used to get and reset the peak usage of +critical system resources used by Matter. These commands are only available when +the `CONFIG_CHIP_STATISTICS=y` Kconfig option is set. + +#### `peak` subcommand + +Prints the peak usage of system resources. + +```shell +uart:~$ matter stat peak +Packet Buffers: 1 +Timers: 2 +TCP endpoints: 0 +UDP endpoints: 1 +Exchange contexts: 0 +Unsolicited message handlers: 5 +Platform events: 2 +``` + +#### `reset` subcommand + +Resets the peak usage of system resources. + +```shell +uart:~$ matter stat reset +``` diff --git a/examples/all-clusters-app/nxp/zephyr/boards/rd_rw612_bga.overlay b/examples/all-clusters-app/nxp/zephyr/boards/rd_rw612_bga.overlay new file mode 100644 index 00000000000000..86bb20739527cd --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/boards/rd_rw612_bga.overlay @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023-2024 Project CHIP Authors + * All rights reserved. + * + * 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 = &flexcomm0; + zephyr,shell-uart = &flexcomm3; + }; +}; + +&flexcomm0 { + compatible = "nxp,lpc-usart"; + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&pinmux_flexcomm0_usart>; + pinctrl-names = "default"; +}; + +&flexcomm3 { + compatible = "nxp,lpc-usart"; + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&pinmux_flexcomm3_usart>; + pinctrl-names = "default"; +}; diff --git a/examples/all-clusters-app/nxp/zephyr/boards/rd_rw612_bga_fdata.conf b/examples/all-clusters-app/nxp/zephyr/boards/rd_rw612_bga_fdata.conf new file mode 100644 index 00000000000000..73d139c3948d95 --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/boards/rd_rw612_bga_fdata.conf @@ -0,0 +1,23 @@ +# +# Copyright (c) 2023-2024 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. +# + +CONFIG_SETTINGS_NVS_SECTOR_COUNT=16 + +# 0xA226 +CONFIG_CHIP_DEVICE_PRODUCT_ID=41510 +CONFIG_CHIP_DEVICE_PRODUCT_URL="https://www.nxp.com/products/wireless-connectivity/wi-fi-plus-bluetooth-plus-802-15-4/wireless-mcu-with-integrated-tri-radio-1x1-wi-fi-6-plus-bluetooth-low-energy-5-3-802-15-4:RW612" +CONFIG_CHIP_DEVICE_PRODUCT_LABEL="RW612" +CONFIG_CHIP_DEVICE_PART_NUMBER="RW612" diff --git a/examples/all-clusters-app/nxp/zephyr/main/include/CHIPProjectConfig.h b/examples/all-clusters-app/nxp/zephyr/main/include/CHIPProjectConfig.h new file mode 100644 index 00000000000000..f6c88ccef18162 --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/main/include/CHIPProjectConfig.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023-2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +/** + * @file + * Example project configuration file for CHIP. + * + * This is a place to put application or project-specific overrides + * to the default configuration values for general CHIP features. + * + */ + +#pragma once + +// All clusters app has 3 group endpoints. This needs to defined here so that +// CHIP_CONFIG_MAX_GROUPS_PER_FABRIC is properly configured. +#define CHIP_CONFIG_MAX_GROUP_ENDPOINTS_PER_FABRIC 3 diff --git a/examples/all-clusters-app/nxp/zephyr/main/main.cpp b/examples/all-clusters-app/nxp/zephyr/main/main.cpp new file mode 100644 index 00000000000000..9be47dfe0a95d8 --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/main/main.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023-2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#include "AppTask.h" + +#include + +LOG_MODULE_REGISTER(app, CONFIG_CHIP_APP_LOG_LEVEL); + +using namespace ::chip; + +int main() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + if (err == CHIP_NO_ERROR) + { + err = chip::NXP::App::GetAppTask().Start(); + } + + LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, err.Format()); + return err == CHIP_NO_ERROR ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/examples/all-clusters-app/nxp/zephyr/prj.conf b/examples/all-clusters-app/nxp/zephyr/prj.conf new file mode 100644 index 00000000000000..936bc5984f4f35 --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/prj.conf @@ -0,0 +1,59 @@ +# +# Copyright (c) 2023-2024 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. +# + +# This sample uses Kconfig.defaults to set options common for all +# samples. This file should contain only options specific for this sample +# or overrides of default values. + +# Enable CHIP +CONFIG_CHIP=y +CONFIG_STD_CPP17=y +CONFIG_CHIP_PROJECT_CONFIG="main/include/CHIPProjectConfig.h" +CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y +# CHIP PID: 32769 == 0x8001 (all-clusters-app) +CONFIG_CHIP_DEVICE_PRODUCT_ID=32769 +CONFIG_CHIP_DEVICE_PRODUCT_NAME="All Clusters" +CONFIG_CHIP_DEVICE_DISCRIMINATOR=0x800 + +# Enable MbedTLS PSA - heavily experimental, not thread safe yet +# CONFIG_CHIP_CRYPTO_PSA=y + +# Bluetooth overrides +CONFIG_BT_DEVICE_NAME="NXPAllClusters" + +# Additional configs for debbugging experience. +CONFIG_THREAD_NAME=y +CONFIG_MPU_STACK_GUARD=y + +CONFIG_DEBUG=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_THREAD_INFO=y +# use this config if stepping during debug session is not consistent +# CONFIG_NO_OPTIMIZATIONS=y +CONFIG_EXCEPTION_STACK_TRACE=y +CONFIG_ASSERT=y +# by default west will generate the full assembly output, which can take several minutes when binaries are large +CONFIG_OUTPUT_DISASSEMBLY=n +# embedded thread analyzer with thread statistics (stack usage, cpu usage...) +# CONFIG_THREAD_ANALYZER=y +# CONFIG_THREAD_ANALYZER_USE_PRINTK=y +# CONFIG_THREAD_ANALYZER_AUTO=y + +# enable Matter CLI +CONFIG_CHIP_LIB_SHELL=y +# enable NET commands if desired +#CONFIG_NET_SHELL=y +CONFIG_CHIP_STATISTICS=y diff --git a/examples/all-clusters-app/nxp/zephyr/prj_fdata.conf b/examples/all-clusters-app/nxp/zephyr/prj_fdata.conf new file mode 100644 index 00000000000000..a82618a5f46078 --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/prj_fdata.conf @@ -0,0 +1,80 @@ +# +# Copyright (c) 2023-2024 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. +# + +# This sample uses Kconfig.defaults to set options common for all +# samples. This file should contain only options specific for this sample +# or overrides of default values. + +# Enable CHIP +CONFIG_CHIP=y +CONFIG_STD_CPP17=y +CONFIG_CHIP_PROJECT_CONFIG="main/include/CHIPProjectConfig.h" +CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y + +# Enable MbedTLS PSA - heavily experimental, not thread safe yet +# CONFIG_CHIP_CRYPTO_PSA=y + +# Bluetooth overrides +CONFIG_BT_DEVICE_NAME="NXPAllClusters" + +# enable Matter CLI +CONFIG_CHIP_LIB_SHELL=y +CONFIG_CHIP_STATISTICS=y + +# Factory data configuration +CONFIG_CHIP_DEVICE_VENDOR_ID=4151 +CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xA00 +CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE=14014 +CONFIG_CHIP_DEVICE_PRODUCT_NAME="All Clusters" +CONFIG_CHIP_DEVICE_TYPE=115 +CONFIG_CHIP_DEVICE_MANUFACTURING_DATE="2023-01-01" +CONFIG_CHIP_DEVICE_SERIAL_NUMBER="12345678" +CONFIG_CHIP_DEVICE_PRODUCT_COLOR="Green" +CONFIG_CHIP_DEVICE_PRODUCT_FINISH="Matte" + +# Use factory data provider for device info +CONFIG_CHIP_FACTORY_DATA=y +# Generate factor data raw binary during the build process +# CONFIG_CHIP_FACTORY_DATA_BUILD=y +# Generate test certificates for factory data during the build process +# CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_GENERATED=y +# Spake2p verifier will be generated during factory data generation +# CONFIG_CHIP_FACTORY_DATA_GENERATE_SPAKE2_VERIFIER=y + +# Example of using pre-generated certificates +# CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_USER=y +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_CD_CERT="/Chip-Test-CD-1037-A226.der" +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_CERT="/Chip-DAC-NXP-1037-A226-Cert.der" +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_KEY="/Chip-DAC-NXP-1037-A226-Key.der" +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_PAI_CERT="/Chip-PAI-NXP-1037-A226-Cert.der" + +# Additional configs for debbugging experience. +CONFIG_THREAD_NAME=y +CONFIG_MPU_STACK_GUARD=y + +CONFIG_DEBUG=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_THREAD_INFO=y +# use this config if stepping during debug session is not consistent +# CONFIG_NO_OPTIMIZATIONS=y +CONFIG_EXCEPTION_STACK_TRACE=y +CONFIG_ASSERT=y +# by default west will generate the full assembly output, which can take several minutes when binaries are large +CONFIG_OUTPUT_DISASSEMBLY=n +# embedded thread analyzer with thread statistics (stack usage, cpu usage...) +# CONFIG_THREAD_ANALYZER=y +# CONFIG_THREAD_ANALYZER_USE_PRINTK=y +# CONFIG_THREAD_ANALYZER_AUTO=y diff --git a/examples/all-clusters-app/nxp/zephyr/prj_ota.conf b/examples/all-clusters-app/nxp/zephyr/prj_ota.conf new file mode 100644 index 00000000000000..bdc65e94fabf70 --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/prj_ota.conf @@ -0,0 +1,31 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# 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. +# + +# Options needed for OTA are located on this file +# This file should contain only options specific for this sample +# or overrides the default ones. + +CONFIG_CHIP_OTA_REQUESTOR=y + +# To generate an OTA image based on the application +CONFIG_CHIP_OTA_IMAGE_BUILD=y + +# By default, MCUBOOT bootloader uses a signature key provided in their repository. +# Change the key to the appropriate one. +# Note: You need to use the same signature key used by MCUBOOT, i.e BOOT_SIGNATURE_KEY_FILE. +# Default CONFIG_BOOT_SIGNATURE_KEY_FILE is defined in config/nxp/app/bootloader.conf +CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="./bootloader/mcuboot/root-rsa-2048.pem" diff --git a/examples/all-clusters-app/nxp/zephyr/third_party/connectedhomeip b/examples/all-clusters-app/nxp/zephyr/third_party/connectedhomeip new file mode 120000 index 00000000000000..3efed95be5dbe9 --- /dev/null +++ b/examples/all-clusters-app/nxp/zephyr/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../../ \ No newline at end of file diff --git a/examples/laundry-washer-app/nxp/zephyr/.gitignore b/examples/laundry-washer-app/nxp/zephyr/.gitignore new file mode 100644 index 00000000000000..84c048a73cc2e5 --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/examples/laundry-washer-app/nxp/zephyr/CMakeLists.txt b/examples/laundry-washer-app/nxp/zephyr/CMakeLists.txt new file mode 100644 index 00000000000000..f7b32881ada959 --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/CMakeLists.txt @@ -0,0 +1,116 @@ +# +# Copyright (c) 2023-2024 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. +# +cmake_minimum_required(VERSION 3.13.1) + +get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH) +get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH) +get_filename_component(ALL_CLUSTERS_COMMON_DIR ${CHIP_ROOT}/examples/all-clusters-app/all-clusters-common REALPATH) +get_filename_component(LAUNDRY_WASHER_NXP_COMMON_DIR ${CHIP_ROOT}/examples/laundry-washer-app/nxp/common REALPATH) +get_filename_component(EXAMPLE_PLATFORM_NXP_COMMON_DIR ${CHIP_ROOT}/examples/platform/nxp/common REALPATH) +get_filename_component(EXAMPLE_PLATFORM_NXP_ZEPHYR_DIR ${CHIP_ROOT}/examples/platform/nxp/zephyr REALPATH) + +# Perform common operations like detecting extra overlays in the platform folder for the target board +# This must be called before find_package(Zephyr) +include(${CHIP_ROOT}/config/nxp/app/pre-zephyr.cmake) + +list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nxp/chip-module) +find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) + +# -Wmaybe-uninitialized has too many false positives, including on std::optional +# and chip::Optional. Make it nonfatal. +# +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635 +target_compile_options(app PRIVATE -Werror -Wno-error=maybe-uninitialized) +target_compile_options(app PRIVATE -Werror PRIVATE -Wno-error=format) + +project(chip-nxp-all-clusters-app-example) + +include(${CHIP_ROOT}/config/nxp/app/enable-gnu-std.cmake) +include(${CHIP_ROOT}/src/app/chip_data_model.cmake) + +target_include_directories(app + PRIVATE + ${LAUNDRY_WASHER_NXP_COMMON_DIR}/main/include + ${LAUNDRY_WASHER_NXP_COMMON_DIR}/Zephyr/include + ${ALL_CLUSTERS_COMMON_DIR}/include + ${GEN_DIR}/app-common + ${GEN_DIR}/all-clusters-app + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_manager/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/icd/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_callbacks/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/factory_data/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/include +) + +target_sources(app + PRIVATE + main/main.cpp + ${LAUNDRY_WASHER_NXP_COMMON_DIR}/main/AppTask.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_manager/source/CHIPDeviceManager.cpp + ${LAUNDRY_WASHER_NXP_COMMON_DIR}/main/DeviceCallbacks.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_callbacks/source/CommonDeviceCallbacks.cpp + ${LAUNDRY_WASHER_NXP_COMMON_DIR}/main/ZclCallbacks.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/binding-handler.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/source/AppTaskBase.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/source/AppTaskZephyr.cpp + ${EXAMPLE_PLATFORM_NXP_ZEPHYR_DIR}/factory_data/source/AppFactoryDataExample.cpp +) + +target_compile_definitions(app PUBLIC + "EXTERNAL_FACTORY_DATA_PROVIDER_IMPL_HEADER=\"platform/nxp/zephyr/FactoryDataProviderImpl.h\"" +) + +if(CONFIG_CHIP_OTA_REQUESTOR) + target_sources(app PRIVATE + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/source/OTARequestorInitiatorCommon.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/source/OTARequestorInitiatorZephyr.cpp + ) + target_include_directories(app PRIVATE + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/include/ + ) +endif() + +chip_configure_data_model(app + INCLUDE_SERVER + ZAP_FILE ${ALL_CLUSTERS_COMMON_DIR}/../../laundry-washer-app/nxp/zap/laundry-washer-app.zap +) + +if(CONFIG_CHIP_LIB_SHELL) + target_compile_definitions(app PRIVATE ENABLE_CHIP_SHELL) + target_include_directories(app PRIVATE + ${CHIP_ROOT}/examples/shell/shell_common/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/matter_cli/include + ) + target_sources(app PRIVATE + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/matter_cli/source/AppCLIBase.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/matter_cli/source/AppCLIZephyr.cpp + ${CHIP_ROOT}/examples/shell/shell_common/cmd_misc.cpp + ${CHIP_ROOT}/examples/shell/shell_common/cmd_otcli.cpp + ${CHIP_ROOT}/examples/shell/shell_common/cmd_server.cpp + ) +endif() + +target_sources(app + PRIVATE + ${ALL_CLUSTERS_COMMON_DIR}/src/smco-stub.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/bridged-actions-stub.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/static-supported-modes-manager.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/static-supported-temperature-levels.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/laundry-washer-mode.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/laundry-washer-controls-delegate-impl.cpp + ${LAUNDRY_WASHER_NXP_COMMON_DIR}/main/operational-state-delegate-impl.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/icd/source/ICDUtil.cpp +) diff --git a/examples/laundry-washer-app/nxp/zephyr/Kconfig b/examples/laundry-washer-app/nxp/zephyr/Kconfig new file mode 100644 index 00000000000000..1d8b3f96581e51 --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/Kconfig @@ -0,0 +1,20 @@ +# +# Copyright (c) 2024 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. +# +mainmenu "Matter NXP Laundry Washer Example Application" + +rsource "../../../../config/nxp/chip-module/Kconfig.features" +rsource "../../../../config/nxp/chip-module/Kconfig.defaults" +source "Kconfig.zephyr" diff --git a/examples/laundry-washer-app/nxp/zephyr/README.md b/examples/laundry-washer-app/nxp/zephyr/README.md new file mode 100644 index 00000000000000..406ee3b7796ede --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/README.md @@ -0,0 +1,4 @@ +# CHIP NXP Zephyr Laundry Washer Application + +All instructions describing how to use a Matter application on NXP Zephyr can be +found in [README.md](../../../all-clusters-app/nxp/zephyr/README.md) root readme diff --git a/examples/laundry-washer-app/nxp/zephyr/boards/rd_rw612_bga.overlay b/examples/laundry-washer-app/nxp/zephyr/boards/rd_rw612_bga.overlay new file mode 100644 index 00000000000000..86bb20739527cd --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/boards/rd_rw612_bga.overlay @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023-2024 Project CHIP Authors + * All rights reserved. + * + * 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 = &flexcomm0; + zephyr,shell-uart = &flexcomm3; + }; +}; + +&flexcomm0 { + compatible = "nxp,lpc-usart"; + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&pinmux_flexcomm0_usart>; + pinctrl-names = "default"; +}; + +&flexcomm3 { + compatible = "nxp,lpc-usart"; + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&pinmux_flexcomm3_usart>; + pinctrl-names = "default"; +}; diff --git a/examples/laundry-washer-app/nxp/zephyr/boards/rd_rw612_bga_fdata.conf b/examples/laundry-washer-app/nxp/zephyr/boards/rd_rw612_bga_fdata.conf new file mode 100644 index 00000000000000..73d139c3948d95 --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/boards/rd_rw612_bga_fdata.conf @@ -0,0 +1,23 @@ +# +# Copyright (c) 2023-2024 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. +# + +CONFIG_SETTINGS_NVS_SECTOR_COUNT=16 + +# 0xA226 +CONFIG_CHIP_DEVICE_PRODUCT_ID=41510 +CONFIG_CHIP_DEVICE_PRODUCT_URL="https://www.nxp.com/products/wireless-connectivity/wi-fi-plus-bluetooth-plus-802-15-4/wireless-mcu-with-integrated-tri-radio-1x1-wi-fi-6-plus-bluetooth-low-energy-5-3-802-15-4:RW612" +CONFIG_CHIP_DEVICE_PRODUCT_LABEL="RW612" +CONFIG_CHIP_DEVICE_PART_NUMBER="RW612" diff --git a/examples/laundry-washer-app/nxp/zephyr/main/include/CHIPProjectConfig.h b/examples/laundry-washer-app/nxp/zephyr/main/include/CHIPProjectConfig.h new file mode 100644 index 00000000000000..84c57df1ea140d --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/main/include/CHIPProjectConfig.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023-2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +/** + * @file + * Example project configuration file for CHIP. + * + * This is a place to put application or project-specific overrides + * to the default configuration values for general CHIP features. + * + */ + +#pragma once + +// Use a default pairing code if one hasn't been provisioned in flash. +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR CONFIG_CHIP_DEVICE_DISCRIMINATOR + +// All clusters app has 3 group endpoints. This needs to defined here so that +// CHIP_CONFIG_MAX_GROUPS_PER_FABRIC is properly configured. +#define CHIP_CONFIG_MAX_GROUP_ENDPOINTS_PER_FABRIC 3 diff --git a/examples/laundry-washer-app/nxp/zephyr/main/main.cpp b/examples/laundry-washer-app/nxp/zephyr/main/main.cpp new file mode 100644 index 00000000000000..9be47dfe0a95d8 --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/main/main.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023-2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#include "AppTask.h" + +#include + +LOG_MODULE_REGISTER(app, CONFIG_CHIP_APP_LOG_LEVEL); + +using namespace ::chip; + +int main() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + if (err == CHIP_NO_ERROR) + { + err = chip::NXP::App::GetAppTask().Start(); + } + + LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, err.Format()); + return err == CHIP_NO_ERROR ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/examples/laundry-washer-app/nxp/zephyr/prj.conf b/examples/laundry-washer-app/nxp/zephyr/prj.conf new file mode 100644 index 00000000000000..ed59218a7da0e9 --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/prj.conf @@ -0,0 +1,59 @@ +# +# Copyright (c) 2023-2024 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. +# + +# This sample uses Kconfig.defaults to set options common for all +# samples. This file should contain only options specific for this sample +# or overrides of default values. + +# Enable CHIP +CONFIG_CHIP=y +CONFIG_STD_CPP17=y +CONFIG_CHIP_PROJECT_CONFIG="main/include/CHIPProjectConfig.h" +CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y +# CHIP PID: 32769 == 0x8001 (all-clusters-app) +CONFIG_CHIP_DEVICE_PRODUCT_ID=32769 +CONFIG_CHIP_DEVICE_PRODUCT_NAME="Laundry Washer" +CONFIG_CHIP_DEVICE_DISCRIMINATOR=0x800 + +# Enable MbedTLS PSA - heavily experimental, not thread safe yet +# CONFIG_CHIP_CRYPTO_PSA=y + +# Bluetooth overrides +CONFIG_BT_DEVICE_NAME="LaundryWasher" + +# Additional configs for debbugging experience. +CONFIG_THREAD_NAME=y +CONFIG_MPU_STACK_GUARD=y + +CONFIG_DEBUG=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_THREAD_INFO=y +# use this config if stepping during debug session is not consistent +# CONFIG_NO_OPTIMIZATIONS=y +CONFIG_EXCEPTION_STACK_TRACE=y +CONFIG_ASSERT=y +# by default west will generate the full assembly output, which can take several minutes when binaries are large +CONFIG_OUTPUT_DISASSEMBLY=n +# embedded thread analyzer with thread statistics (stack usage, cpu usage...) +# CONFIG_THREAD_ANALYZER=y +# CONFIG_THREAD_ANALYZER_USE_PRINTK=y +# CONFIG_THREAD_ANALYZER_AUTO=y + +# enable Matter CLI +CONFIG_CHIP_LIB_SHELL=y +# enable NET commands if desired +#CONFIG_NET_SHELL=y +CONFIG_CHIP_STATISTICS=y diff --git a/examples/laundry-washer-app/nxp/zephyr/prj_fdata.conf b/examples/laundry-washer-app/nxp/zephyr/prj_fdata.conf new file mode 100644 index 00000000000000..986fc877aec5df --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/prj_fdata.conf @@ -0,0 +1,80 @@ +# +# Copyright (c) 2023-2024 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. +# + +# This sample uses Kconfig.defaults to set options common for all +# samples. This file should contain only options specific for this sample +# or overrides of default values. + +# Enable CHIP +CONFIG_CHIP=y +CONFIG_STD_CPP17=y +CONFIG_CHIP_PROJECT_CONFIG="main/include/CHIPProjectConfig.h" +CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y + +# Enable MbedTLS PSA - heavily experimental, not thread safe yet +# CONFIG_CHIP_CRYPTO_PSA=y + +# Bluetooth overrides +CONFIG_BT_DEVICE_NAME="LaundryWasher" + +# enable Matter CLI +CONFIG_CHIP_LIB_SHELL=y +CONFIG_CHIP_STATISTICS=y + +# Factory data configuration +CONFIG_CHIP_DEVICE_VENDOR_ID=4151 +CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xA00 +CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE=14014 +CONFIG_CHIP_DEVICE_PRODUCT_NAME="Laundry Washer" +CONFIG_CHIP_DEVICE_TYPE=115 +CONFIG_CHIP_DEVICE_MANUFACTURING_DATE="2023-01-01" +CONFIG_CHIP_DEVICE_SERIAL_NUMBER="12345678" +CONFIG_CHIP_DEVICE_PRODUCT_COLOR="Green" +CONFIG_CHIP_DEVICE_PRODUCT_FINISH="Matte" + +# Use factory data provider for device info +CONFIG_CHIP_FACTORY_DATA=y +# Generate factor data raw binary during the build process +# CONFIG_CHIP_FACTORY_DATA_BUILD=y +# Generate test certificates for factory data during the build process +# CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_GENERATED=y +# Spake2p verifier will be generated during factory data generation +# CONFIG_CHIP_FACTORY_DATA_GENERATE_SPAKE2_VERIFIER=y + +# Example of using pre-generated certificates +# CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_USER=y +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_CD_CERT="/Chip-Test-CD-1037-A226.der" +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_CERT="/Chip-DAC-NXP-1037-A226-Cert.der" +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_KEY="/Chip-DAC-NXP-1037-A226-Key.der" +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_PAI_CERT="/Chip-PAI-NXP-1037-A226-Cert.der" + +# Additional configs for debbugging experience. +CONFIG_THREAD_NAME=y +CONFIG_MPU_STACK_GUARD=y + +CONFIG_DEBUG=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_THREAD_INFO=y +# use this config if stepping during debug session is not consistent +# CONFIG_NO_OPTIMIZATIONS=y +CONFIG_EXCEPTION_STACK_TRACE=y +CONFIG_ASSERT=y +# by default west will generate the full assembly output, which can take several minutes when binaries are large +CONFIG_OUTPUT_DISASSEMBLY=n +# embedded thread analyzer with thread statistics (stack usage, cpu usage...) +# CONFIG_THREAD_ANALYZER=y +# CONFIG_THREAD_ANALYZER_USE_PRINTK=y +# CONFIG_THREAD_ANALYZER_AUTO=y diff --git a/examples/laundry-washer-app/nxp/zephyr/prj_ota.conf b/examples/laundry-washer-app/nxp/zephyr/prj_ota.conf new file mode 100644 index 00000000000000..bdc65e94fabf70 --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/prj_ota.conf @@ -0,0 +1,31 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# 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. +# + +# Options needed for OTA are located on this file +# This file should contain only options specific for this sample +# or overrides the default ones. + +CONFIG_CHIP_OTA_REQUESTOR=y + +# To generate an OTA image based on the application +CONFIG_CHIP_OTA_IMAGE_BUILD=y + +# By default, MCUBOOT bootloader uses a signature key provided in their repository. +# Change the key to the appropriate one. +# Note: You need to use the same signature key used by MCUBOOT, i.e BOOT_SIGNATURE_KEY_FILE. +# Default CONFIG_BOOT_SIGNATURE_KEY_FILE is defined in config/nxp/app/bootloader.conf +CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="./bootloader/mcuboot/root-rsa-2048.pem" diff --git a/examples/laundry-washer-app/nxp/zephyr/third_party/connectedhomeip b/examples/laundry-washer-app/nxp/zephyr/third_party/connectedhomeip new file mode 120000 index 00000000000000..3efed95be5dbe9 --- /dev/null +++ b/examples/laundry-washer-app/nxp/zephyr/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../../ \ No newline at end of file diff --git a/examples/thermostat/nxp/zephyr/.gitignore b/examples/thermostat/nxp/zephyr/.gitignore new file mode 100644 index 00000000000000..84c048a73cc2e5 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/examples/thermostat/nxp/zephyr/CMakeLists.txt b/examples/thermostat/nxp/zephyr/CMakeLists.txt new file mode 100644 index 00000000000000..2b0fb87a55e7f9 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/CMakeLists.txt @@ -0,0 +1,104 @@ +# +# Copyright (c) 2023-2024 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. +# +cmake_minimum_required(VERSION 3.13.1) + +get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip REALPATH) +get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH) +get_filename_component(ALL_CLUSTERS_COMMON_DIR ${CHIP_ROOT}/examples/all-clusters-app/all-clusters-common REALPATH) +get_filename_component(THERMOSTAT_NXP_COMMON_DIR ${CHIP_ROOT}/examples/thermostat/nxp/common REALPATH) +get_filename_component(EXAMPLE_PLATFORM_NXP_COMMON_DIR ${CHIP_ROOT}/examples/platform/nxp/common REALPATH) +get_filename_component(EXAMPLE_PLATFORM_NXP_ZEPHYR_DIR ${CHIP_ROOT}/examples/platform/nxp/zephyr REALPATH) + +# Perform common operations like detecting extra overlays in the platform folder for the target board +# This must be called before find_package(Zephyr) +include(${CHIP_ROOT}/config/nxp/app/pre-zephyr.cmake) + +list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nxp/chip-module) +find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) + +# -Wmaybe-uninitialized has too many false positives, including on std::optional +# and chip::Optional. Make it nonfatal. +# +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635 +target_compile_options(app PRIVATE -Werror -Wno-error=maybe-uninitialized) +target_compile_options(app PRIVATE -Werror PRIVATE -Wno-error=format) + +project(chip-nxp-all-clusters-app-example) + +include(${CHIP_ROOT}/config/nxp/app/enable-gnu-std.cmake) +include(${CHIP_ROOT}/src/app/chip_data_model.cmake) + +target_include_directories(app + PRIVATE + ${THERMOSTAT_NXP_COMMON_DIR}/main/include + ${ALL_CLUSTERS_COMMON_DIR}/include + ${GEN_DIR}/app-common + ${GEN_DIR}/all-clusters-app + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_manager/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/icd/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_callbacks/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/factory_data/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/include +) + +target_sources(app + PRIVATE + main/main.cpp + ${THERMOSTAT_NXP_COMMON_DIR}/main/AppTask.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_manager/source/CHIPDeviceManager.cpp + ${THERMOSTAT_NXP_COMMON_DIR}/main/DeviceCallbacks.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/device_callbacks/source/CommonDeviceCallbacks.cpp + ${THERMOSTAT_NXP_COMMON_DIR}/main/ZclCallbacks.cpp + ${ALL_CLUSTERS_COMMON_DIR}/src/binding-handler.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/source/AppTaskBase.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/app_task/source/AppTaskZephyr.cpp + ${EXAMPLE_PLATFORM_NXP_ZEPHYR_DIR}/factory_data/source/AppFactoryDataExample.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/icd/source/ICDUtil.cpp +) + +target_compile_definitions(app PUBLIC + "EXTERNAL_FACTORY_DATA_PROVIDER_IMPL_HEADER=\"platform/nxp/zephyr/FactoryDataProviderImpl.h\"" +) + +if(CONFIG_CHIP_OTA_REQUESTOR) + target_sources(app PRIVATE + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/source/OTARequestorInitiatorCommon.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/source/OTARequestorInitiatorZephyr.cpp + ) + target_include_directories(app PRIVATE + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/ota_requestor/include/ + ) +endif() + +chip_configure_data_model(app + INCLUDE_SERVER + ZAP_FILE ${ALL_CLUSTERS_COMMON_DIR}/../../thermostat/nxp/zap/thermostat_matter_wifi.zap +) + +if(CONFIG_CHIP_LIB_SHELL) + target_compile_definitions(app PRIVATE ENABLE_CHIP_SHELL) + target_include_directories(app PRIVATE + ${CHIP_ROOT}/examples/shell/shell_common/include + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/matter_cli/include + ) + target_sources(app PRIVATE + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/matter_cli/source/AppCLIBase.cpp + ${EXAMPLE_PLATFORM_NXP_COMMON_DIR}/matter_cli/source/AppCLIZephyr.cpp + ${CHIP_ROOT}/examples/shell/shell_common/cmd_misc.cpp + ${CHIP_ROOT}/examples/shell/shell_common/cmd_otcli.cpp + ${CHIP_ROOT}/examples/shell/shell_common/cmd_server.cpp + ) +endif() diff --git a/examples/thermostat/nxp/zephyr/Kconfig b/examples/thermostat/nxp/zephyr/Kconfig new file mode 100644 index 00000000000000..72e90f047d1e38 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/Kconfig @@ -0,0 +1,20 @@ +# +# Copyright (c) 2024 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. +# +mainmenu "Matter NXP Thermostat Example Application" + +rsource "../../../../config/nxp/chip-module/Kconfig.features" +rsource "../../../../config/nxp/chip-module/Kconfig.defaults" +source "Kconfig.zephyr" diff --git a/examples/thermostat/nxp/zephyr/README.md b/examples/thermostat/nxp/zephyr/README.md new file mode 100644 index 00000000000000..84d3fb9e59cf01 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/README.md @@ -0,0 +1,4 @@ +# CHIP NXP Zephyr Thermostat Application + +All instructions describing how to use a Matter application on NXP Zephyr can be +found in [README.md](../../../all-clusters-app/nxp/zephyr/README.md) root readme diff --git a/examples/thermostat/nxp/zephyr/boards/rd_rw612_bga.overlay b/examples/thermostat/nxp/zephyr/boards/rd_rw612_bga.overlay new file mode 100644 index 00000000000000..86bb20739527cd --- /dev/null +++ b/examples/thermostat/nxp/zephyr/boards/rd_rw612_bga.overlay @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023-2024 Project CHIP Authors + * All rights reserved. + * + * 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 = &flexcomm0; + zephyr,shell-uart = &flexcomm3; + }; +}; + +&flexcomm0 { + compatible = "nxp,lpc-usart"; + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&pinmux_flexcomm0_usart>; + pinctrl-names = "default"; +}; + +&flexcomm3 { + compatible = "nxp,lpc-usart"; + status = "okay"; + current-speed = <115200>; + pinctrl-0 = <&pinmux_flexcomm3_usart>; + pinctrl-names = "default"; +}; diff --git a/examples/thermostat/nxp/zephyr/boards/rd_rw612_bga_fdata.conf b/examples/thermostat/nxp/zephyr/boards/rd_rw612_bga_fdata.conf new file mode 100644 index 00000000000000..73d139c3948d95 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/boards/rd_rw612_bga_fdata.conf @@ -0,0 +1,23 @@ +# +# Copyright (c) 2023-2024 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. +# + +CONFIG_SETTINGS_NVS_SECTOR_COUNT=16 + +# 0xA226 +CONFIG_CHIP_DEVICE_PRODUCT_ID=41510 +CONFIG_CHIP_DEVICE_PRODUCT_URL="https://www.nxp.com/products/wireless-connectivity/wi-fi-plus-bluetooth-plus-802-15-4/wireless-mcu-with-integrated-tri-radio-1x1-wi-fi-6-plus-bluetooth-low-energy-5-3-802-15-4:RW612" +CONFIG_CHIP_DEVICE_PRODUCT_LABEL="RW612" +CONFIG_CHIP_DEVICE_PART_NUMBER="RW612" diff --git a/examples/thermostat/nxp/zephyr/main/include/CHIPProjectConfig.h b/examples/thermostat/nxp/zephyr/main/include/CHIPProjectConfig.h new file mode 100644 index 00000000000000..84c57df1ea140d --- /dev/null +++ b/examples/thermostat/nxp/zephyr/main/include/CHIPProjectConfig.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023-2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +/** + * @file + * Example project configuration file for CHIP. + * + * This is a place to put application or project-specific overrides + * to the default configuration values for general CHIP features. + * + */ + +#pragma once + +// Use a default pairing code if one hasn't been provisioned in flash. +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR CONFIG_CHIP_DEVICE_DISCRIMINATOR + +// All clusters app has 3 group endpoints. This needs to defined here so that +// CHIP_CONFIG_MAX_GROUPS_PER_FABRIC is properly configured. +#define CHIP_CONFIG_MAX_GROUP_ENDPOINTS_PER_FABRIC 3 diff --git a/examples/thermostat/nxp/zephyr/main/main.cpp b/examples/thermostat/nxp/zephyr/main/main.cpp new file mode 100644 index 00000000000000..9be47dfe0a95d8 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/main/main.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023-2024 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +#include "AppTask.h" + +#include + +LOG_MODULE_REGISTER(app, CONFIG_CHIP_APP_LOG_LEVEL); + +using namespace ::chip; + +int main() +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + if (err == CHIP_NO_ERROR) + { + err = chip::NXP::App::GetAppTask().Start(); + } + + LOG_ERR("Exited with code %" CHIP_ERROR_FORMAT, err.Format()); + return err == CHIP_NO_ERROR ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/examples/thermostat/nxp/zephyr/prj.conf b/examples/thermostat/nxp/zephyr/prj.conf new file mode 100644 index 00000000000000..8bb5bd9f275756 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/prj.conf @@ -0,0 +1,59 @@ +# +# Copyright (c) 2023-2024 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. +# + +# This sample uses Kconfig.defaults to set options common for all +# samples. This file should contain only options specific for this sample +# or overrides of default values. + +# Enable CHIP +CONFIG_CHIP=y +CONFIG_STD_CPP17=y +CONFIG_CHIP_PROJECT_CONFIG="main/include/CHIPProjectConfig.h" +CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y +# CHIP PID: 32769 == 0x8001 (all-clusters-app) +CONFIG_CHIP_DEVICE_PRODUCT_ID=32769 +CONFIG_CHIP_DEVICE_PRODUCT_NAME="Thermostat" +CONFIG_CHIP_DEVICE_DISCRIMINATOR=0x800 + +# Enable MbedTLS PSA - heavily experimental, not thread safe yet +# CONFIG_CHIP_CRYPTO_PSA=y + +# Bluetooth overrides +CONFIG_BT_DEVICE_NAME="Thermostat" + +# Additional configs for debbugging experience. +CONFIG_THREAD_NAME=y +CONFIG_MPU_STACK_GUARD=y + +CONFIG_DEBUG=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_THREAD_INFO=y +# use this config if stepping during debug session is not consistent +# CONFIG_NO_OPTIMIZATIONS=y +CONFIG_EXCEPTION_STACK_TRACE=y +CONFIG_ASSERT=y +# by default west will generate the full assembly output, which can take several minutes when binaries are large +CONFIG_OUTPUT_DISASSEMBLY=n +# embedded thread analyzer with thread statistics (stack usage, cpu usage...) +# CONFIG_THREAD_ANALYZER=y +# CONFIG_THREAD_ANALYZER_USE_PRINTK=y +# CONFIG_THREAD_ANALYZER_AUTO=y + +# enable Matter CLI +CONFIG_CHIP_LIB_SHELL=y +# enable NET commands if desired +#CONFIG_NET_SHELL=y +CONFIG_CHIP_STATISTICS=y diff --git a/examples/thermostat/nxp/zephyr/prj_fdata.conf b/examples/thermostat/nxp/zephyr/prj_fdata.conf new file mode 100644 index 00000000000000..ee559b42ed9a71 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/prj_fdata.conf @@ -0,0 +1,80 @@ +# +# Copyright (c) 2023-2024 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. +# + +# This sample uses Kconfig.defaults to set options common for all +# samples. This file should contain only options specific for this sample +# or overrides of default values. + +# Enable CHIP +CONFIG_CHIP=y +CONFIG_STD_CPP17=y +CONFIG_CHIP_PROJECT_CONFIG="main/include/CHIPProjectConfig.h" +CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y + +# Enable MbedTLS PSA - heavily experimental, not thread safe yet +# CONFIG_CHIP_CRYPTO_PSA=y + +# Bluetooth overrides +CONFIG_BT_DEVICE_NAME="Thermostat" + +# enable Matter CLI +CONFIG_CHIP_LIB_SHELL=y +CONFIG_CHIP_STATISTICS=y + +# Factory data configuration +CONFIG_CHIP_DEVICE_VENDOR_ID=4151 +CONFIG_CHIP_DEVICE_DISCRIMINATOR=0xA00 +CONFIG_CHIP_DEVICE_SPAKE2_PASSCODE=14014 +CONFIG_CHIP_DEVICE_PRODUCT_NAME="Thermostat" +CONFIG_CHIP_DEVICE_TYPE=769 +CONFIG_CHIP_DEVICE_MANUFACTURING_DATE="2023-01-01" +CONFIG_CHIP_DEVICE_SERIAL_NUMBER="12345678" +CONFIG_CHIP_DEVICE_PRODUCT_COLOR="Green" +CONFIG_CHIP_DEVICE_PRODUCT_FINISH="Matte" + +# Use factory data provider for device info +CONFIG_CHIP_FACTORY_DATA=y +# Generate factor data raw binary during the build process +# CONFIG_CHIP_FACTORY_DATA_BUILD=y +# Generate test certificates for factory data during the build process +# CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_GENERATED=y +# Spake2p verifier will be generated during factory data generation +# CONFIG_CHIP_FACTORY_DATA_GENERATE_SPAKE2_VERIFIER=y + +# Example of using pre-generated certificates +# CONFIG_CHIP_FACTORY_DATA_CERT_SOURCE_USER=y +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_CD_CERT="/Chip-Test-CD-1037-A226.der" +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_CERT="/Chip-DAC-NXP-1037-A226-Cert.der" +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_DAC_KEY="/Chip-DAC-NXP-1037-A226-Key.der" +# CONFIG_CHIP_FACTORY_DATA_USER_CERTS_PAI_CERT="/Chip-PAI-NXP-1037-A226-Cert.der" + +# Additional configs for debbugging experience. +CONFIG_THREAD_NAME=y +CONFIG_MPU_STACK_GUARD=y + +CONFIG_DEBUG=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_THREAD_INFO=y +# use this config if stepping during debug session is not consistent +# CONFIG_NO_OPTIMIZATIONS=y +CONFIG_EXCEPTION_STACK_TRACE=y +CONFIG_ASSERT=y +# by default west will generate the full assembly output, which can take several minutes when binaries are large +CONFIG_OUTPUT_DISASSEMBLY=n +# embedded thread analyzer with thread statistics (stack usage, cpu usage...) +# CONFIG_THREAD_ANALYZER=y +# CONFIG_THREAD_ANALYZER_USE_PRINTK=y +# CONFIG_THREAD_ANALYZER_AUTO=y diff --git a/examples/thermostat/nxp/zephyr/prj_ota.conf b/examples/thermostat/nxp/zephyr/prj_ota.conf new file mode 100644 index 00000000000000..bdc65e94fabf70 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/prj_ota.conf @@ -0,0 +1,31 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# 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. +# + +# Options needed for OTA are located on this file +# This file should contain only options specific for this sample +# or overrides the default ones. + +CONFIG_CHIP_OTA_REQUESTOR=y + +# To generate an OTA image based on the application +CONFIG_CHIP_OTA_IMAGE_BUILD=y + +# By default, MCUBOOT bootloader uses a signature key provided in their repository. +# Change the key to the appropriate one. +# Note: You need to use the same signature key used by MCUBOOT, i.e BOOT_SIGNATURE_KEY_FILE. +# Default CONFIG_BOOT_SIGNATURE_KEY_FILE is defined in config/nxp/app/bootloader.conf +CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="./bootloader/mcuboot/root-rsa-2048.pem" diff --git a/examples/thermostat/nxp/zephyr/third_party/connectedhomeip b/examples/thermostat/nxp/zephyr/third_party/connectedhomeip new file mode 120000 index 00000000000000..3efed95be5dbe9 --- /dev/null +++ b/examples/thermostat/nxp/zephyr/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../../ \ No newline at end of file diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 0a72b3733a96d1..97f8e90af507d5 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -28,7 +28,7 @@ from builders.mw320 import MW320App, MW320Builder from builders.nrf import NrfApp, NrfBoard, NrfConnectBuilder from builders.nuttx import NuttXApp, NuttXBoard, NuttXBuilder -from builders.nxp import NxpApp, NxpBoard, NxpBuilder +from builders.nxp import NxpApp, NxpBoard, NxpBuilder, NxpOsUsed from builders.openiotsdk import OpenIotSdkApp, OpenIotSdkBuilder, OpenIotSdkCryptoBackend from builders.qpg import QpgApp, QpgBoard, QpgBuilder from builders.rw61x import RW61XApp, RW61XBuilder @@ -499,13 +499,23 @@ def BuildNxpTarget(): # boards target.AppendFixedTargets([ TargetPart('k32w0', board=NxpBoard.K32W0), - TargetPart('k32w1', board=NxpBoard.K32W1) + TargetPart('k32w1', board=NxpBoard.K32W1), + TargetPart('rw61x', board=NxpBoard.RW61X) + ]) + + # OS + target.AppendFixedTargets([ + TargetPart('zephyr', os_env=NxpOsUsed.ZEPHYR).OnlyIfRe('rw61x'), + TargetPart('freertos', os_env=NxpOsUsed.FREERTOS).ExceptIfRe('rw61x'), ]) # apps target.AppendFixedTargets([ TargetPart('lighting', app=NxpApp.LIGHTING).OnlyIfRe('(k32w0|k32w1)'), - TargetPart('contact-sensor', app=NxpApp.CONTACT).OnlyIfRe('(k32w0|k32w1)') + TargetPart('contact-sensor', app=NxpApp.CONTACT).OnlyIfRe('(k32w0|k32w1)'), + TargetPart('all-clusters', app=NxpApp.ALLCLUSTERS).OnlyIfRe('rw61x'), + TargetPart('laundry-washer', app=NxpApp.LAUNDRYWASHER).OnlyIfRe('rw61x'), + TargetPart('thermostat', app=NxpApp.THERMOSTAT).OnlyIfRe('rw61x') ]) target.AppendModifier(name="factory", enable_factory_data=True) @@ -513,8 +523,8 @@ def BuildNxpTarget(): target.AppendModifier(name="lit", enable_lit=True).OnlyIfRe('contact-sensor') target.AppendModifier(name="fro32k", use_fro32k=True).OnlyIfRe('k32w0') target.AppendModifier(name="smu2", smu2=True).OnlyIfRe('k32w1-lighting') - target.AppendModifier(name="dac-conversion", convert_dac_pk=True).OnlyIfRe('factory').ExceptIfRe('k32w0') - target.AppendModifier(name="rotating-id", enable_rotating_id=True) + target.AppendModifier(name="dac-conversion", convert_dac_pk=True).OnlyIfRe('factory').ExceptIfRe('(k32w0|rw61x)') + target.AppendModifier(name="rotating-id", enable_rotating_id=True).ExceptIfRe('rw61x') target.AppendModifier(name="sw-v2", has_sw_version_2=True) return target diff --git a/scripts/build/builders/nxp.py b/scripts/build/builders/nxp.py index 4bd4f0ae451875..74f40eaa0a36aa 100644 --- a/scripts/build/builders/nxp.py +++ b/scripts/build/builders/nxp.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Project CHIP Authors +# Copyright (c) 2021-2024 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. @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging import os from enum import Enum, auto @@ -19,15 +20,31 @@ from .gn import GnBuilder +class NxpOsUsed(Enum): + FREERTOS = auto() + ZEPHYR = auto() + + def OsEnv(self): + if self == NxpOsUsed.ZEPHYR: + return 'zephyr' + elif self == NxpOsUsed.FREERTOS: + return 'freertos' + else: + raise Exception('Unknown OS type: %r' % self) + + class NxpBoard(Enum): K32W0 = auto() K32W1 = auto() + RW61X = auto() def Name(self): if self == NxpBoard.K32W0: return 'k32w0x' elif self == NxpBoard.K32W1: return 'k32w1' + elif self == NxpBoard.RW61X: + return 'rd_rw612_bga' else: raise Exception('Unknown board type: %r' % self) @@ -36,6 +53,8 @@ def FolderName(self): return 'k32w/k32w0' elif self == NxpBoard.K32W1: return 'k32w/k32w1' + elif self == NxpBoard.RW61X: + return 'zephyr' else: raise Exception('Unknown board type: %r' % self) @@ -43,12 +62,21 @@ def FolderName(self): class NxpApp(Enum): LIGHTING = auto() CONTACT = auto() + ALLCLUSTERS = auto() + LAUNDRYWASHER = auto() + THERMOSTAT = auto() def ExampleName(self): if self == NxpApp.LIGHTING: return 'lighting-app' elif self == NxpApp.CONTACT: return "contact-sensor-app" + elif self == NxpApp.ALLCLUSTERS: + return "all-clusters-app" + elif self == NxpApp.LAUNDRYWASHER: + return "laundry-washer-app" + elif self == NxpApp.THERMOSTAT: + return "thermostat" else: raise Exception('Unknown app type: %r' % self) @@ -57,6 +85,12 @@ def NameSuffix(self): return 'light-example' elif self == NxpApp.CONTACT: return 'contact-example' + elif self == NxpApp.ALLCLUSTERS: + return "all-cluster-example" + elif self == NxpApp.LAUNDRYWASHER: + return "laundry-washer-example" + elif self == NxpApp.THERMOSTAT: + return "thermostat-example" else: raise Exception('Unknown app type: %r' % self) @@ -71,6 +105,7 @@ def __init__(self, runner, app: NxpApp = NxpApp.LIGHTING, board: NxpBoard = NxpBoard.K32W0, + os_env: NxpOsUsed = NxpOsUsed.FREERTOS, low_power: bool = False, smu2: bool = False, enable_factory_data: bool = False, @@ -85,6 +120,7 @@ def __init__(self, self.code_root = root self.app = app self.board = board + self.os_env = os_env self.low_power = low_power self.smu2 = smu2 self.enable_factory_data = enable_factory_data @@ -125,15 +161,54 @@ def GnBuildArgs(self): return args + def WestBuildArgs(self): + args = [] + if self.enable_factory_data: + args.append('-DFILE_SUFFIX=fdata') + + if self.has_sw_version_2: + args.append('-DCONFIG_CHIP_DEVICE_SOFTWARE_VERSION=2') + + build_args = " -- " + " ".join(args) if len(args) > 0 else "" + return build_args + def generate(self): - super(NxpBuilder, self).generate() + if self.os_env == NxpOsUsed.ZEPHYR: + if 'ZEPHYR_NXP_SDK_INSTALL_DIR' in os.environ: + cmd = 'export ZEPHYR_SDK_INSTALL_DIR="$ZEPHYR_NXP_SDK_INSTALL_DIR"\n' + else: + raise Exception("ZEPHYR_SDK_INSTALL_DIR need to be set") + if 'ZEPHYR_NXP_BASE' in os.environ: + cmd += 'export ZEPHYR_BASE="$ZEPHYR_NXP_BASE"\n' + else: + raise Exception("ZEPHYR_NXP_BASE need to be set") + build_args = self.WestBuildArgs() + cmd += ''' + west build -p --cmake-only -b {board_name} -d {out_folder} {example_folder} {build_args} + '''.format( + board_name=self.board.Name(), + out_folder=self.output_dir, + example_folder=self.app.BuildRoot(self.code_root, self.board), + build_args=build_args).strip() + self._Execute(['bash', '-c', cmd], title='Generating ' + self.identifier) + else: + super(NxpBuilder, self).generate() def build_outputs(self): name = 'chip-%s-%s' % (self.board.Name(), self.app.NameSuffix()) - yield BuilderOutput( - os.path.join(self.output_dir, name), - f'{name}.elf') - if self.options.enable_link_map_file: + if self.os_env == NxpOsUsed.ZEPHYR: + yield BuilderOutput( + os.path.join(self.output_dir, 'zephyr', 'zephyr.elf'), + f'{name}.elf') + if self.options.enable_link_map_file: + yield BuilderOutput( + os.path.join(self.output_dir, 'zephyr', 'zephyr.map'), + f'{name}.map') + else: yield BuilderOutput( - os.path.join(self.output_dir, f'{name}.map'), - f'{name}.map') + os.path.join(self.output_dir, name), + f'{name}.elf') + if self.options.enable_link_map_file: + yield BuilderOutput( + os.path.join(self.output_dir, f'{name}.map'), + f'{name}.map') diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 7714bddaae42e3..2d9fee76e68ac0 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -14,7 +14,7 @@ linux-x64-efr32-test-runner[-clang] imx-{chip-tool,lighting-app,thermostat,all-clusters-app,all-clusters-minimal-app,ota-provider-app}[-release] infineon-psoc6-{lock,light,all-clusters,all-clusters-minimal}[-ota][-updateimage][-trustm] rw61x-{all-clusters-app,thermostat,laundry-washer}[-ota][-wifi][-thread][-factory-data][-matter-shell] -nxp-{k32w0,k32w1}-{lighting,contact-sensor}[-factory][-low-power][-lit][-fro32k][-smu2][-dac-conversion][-rotating-id][-sw-v2] +nxp-{k32w0,k32w1,rw61x}-{zephyr,freertos}-{lighting,contact-sensor,all-clusters,laundry-washer,thermostat}[-factory][-low-power][-lit][-fro32k][-smu2][-dac-conversion][-rotating-id][-sw-v2] mbed-cy8cproto_062_4343w-{lock,light,all-clusters,all-clusters-minimal,pigweed,ota-requestor,shell}[-release][-develop][-debug] mw320-all-clusters-app nrf-{nrf5340dk,nrf52840dk,nrf52840dongle}-{all-clusters,all-clusters-minimal,lock,light,light-switch,shell,pump,pump-controller,window-covering}[-rpc]