diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index 4f3e5d597b705b..15f025807b7693 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -123,7 +123,11 @@ efr32_executable("lighting_app") { ldscript = "${efr32_project_dir}/ldscripts/efr32-light-example-MG21.ld" } - ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ] + ldflags = [ + "-Wl,--print-memory-usage", + "-fstack-usage", + "-T" + rebase_path(ldscript, root_build_dir), + ] } group("efr32") { diff --git a/examples/lighting-app/efr32/include/AppTask.h b/examples/lighting-app/efr32/include/AppTask.h index 64405818e6ec2c..e286abf5fc686a 100644 --- a/examples/lighting-app/efr32/include/AppTask.h +++ b/examples/lighting-app/efr32/include/AppTask.h @@ -67,7 +67,8 @@ class AppTask { kFunction_NoneSelected = 0, kFunction_SoftwareUpdate = 0, - kFunction_FactoryReset, + kFunction_StartThread = 1, + kFunction_FactoryReset = 2, kFunction_Invalid } Function; @@ -75,7 +76,6 @@ class AppTask Function_t mFunction; bool mFunctionTimerActive; bool mSyncClusterToButtonAction; - chip::Ble::BLEEndPoint * mBLEEndPoint; static AppTask sAppTask; }; diff --git a/examples/lighting-app/efr32/src/AppTask.cpp b/examples/lighting-app/efr32/src/AppTask.cpp index aeacbef2eba838..a3ed269afcfffc 100644 --- a/examples/lighting-app/efr32/src/AppTask.cpp +++ b/examples/lighting-app/efr32/src/AppTask.cpp @@ -35,9 +35,6 @@ #include #include -using namespace chip::TLV; -using namespace chip::DeviceLayer; - #include #if CHIP_ENABLE_OPENTHREAD #include @@ -67,6 +64,7 @@ static bool sIsThreadAttached = false; static bool sHaveBLEConnections = false; static bool sHaveServiceConnectivity = false; +using namespace chip::TLV; using namespace ::chip::DeviceLayer; AppTask AppTask::sAppTask; @@ -355,7 +353,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, // initiate factory reset - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartThread) { EFR32_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); @@ -400,20 +398,29 @@ void AppTask::FunctionHandler(AppEvent * aEvent) if (!sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_NoneSelected) { sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT); - sAppTask.mFunction = kFunction_SoftwareUpdate; + sAppTask.mFunction = kFunction_StartThread; } } else { - // If the button was released before factory reset got initiated, trigger a - // software update. - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) + // If the button was released before factory reset got initiated, start Thread Network + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartThread) { sAppTask.CancelTimer(); - sAppTask.mFunction = kFunction_NoneSelected; - - EFR32_LOG("Software Update currently not supported."); +#if CHIP_ENABLE_OPENTHREAD + if (!chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned()) + { + StartDefaultThreadNetwork(); + EFR32_LOG("Device is not commissioned to a Thread network. Starting with the default configuration."); + } + else + { + EFR32_LOG("Device is commissioned to a Thread network."); + } +#elif + EFR32_LOG("Thread is not defined."); +#endif } else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset) { diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index d38c94a3d756c8..8df12d93aad91b 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -123,7 +123,11 @@ efr32_executable("lock_app") { ldscript = "${efr32_project_dir}/ldscripts/efr32-lock-example-MG21.ld" } - ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ] + ldflags = [ + "-Wl,--print-memory-usage", + "-fstack-usage", + "-T" + rebase_path(ldscript, root_build_dir), + ] } group("efr32") { diff --git a/examples/lock-app/efr32/include/AppTask.h b/examples/lock-app/efr32/include/AppTask.h index 020203287d28c7..ae7659b64c54d7 100644 --- a/examples/lock-app/efr32/include/AppTask.h +++ b/examples/lock-app/efr32/include/AppTask.h @@ -67,7 +67,7 @@ class AppTask { kFunction_NoneSelected = 0, kFunction_SoftwareUpdate = 0, - kFunction_Joiner = 1, + kFunction_StartThread = 1, kFunction_FactoryReset = 2, kFunction_Invalid @@ -76,7 +76,6 @@ class AppTask Function_t mFunction; bool mFunctionTimerActive; bool mSyncClusterToButtonAction; - chip::Ble::BLEEndPoint * mBLEEndPoint; static AppTask sAppTask; }; diff --git a/examples/lock-app/efr32/src/AppTask.cpp b/examples/lock-app/efr32/src/AppTask.cpp index 048407d18e75f5..adf109b5540645 100644 --- a/examples/lock-app/efr32/src/AppTask.cpp +++ b/examples/lock-app/efr32/src/AppTask.cpp @@ -35,16 +35,12 @@ #include #include -using namespace chip::TLV; -using namespace chip::DeviceLayer; - #include #if CHIP_ENABLE_OPENTHREAD #include #include #include #include -#define JOINER_START_TRIGGER_TIMEOUT 1500 #endif #define FACTORY_RESET_TRIGGER_TIMEOUT 3000 @@ -68,6 +64,7 @@ static bool sIsPairedToAccount = false; static bool sHaveBLEConnections = false; static bool sHaveServiceConnectivity = false; +using namespace chip::TLV; using namespace ::chip::DeviceLayer; AppTask AppTask::sAppTask; @@ -358,17 +355,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, // initiate factory reset - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) - { -#if CHIP_ENABLE_OPENTHREAD - EFR32_LOG("Release button now to Start Thread Joiner"); - EFR32_LOG("Hold to trigger Factory Reset"); - sAppTask.mFunction = kFunction_Joiner; - sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT); - } - else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_Joiner) + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartThread) { -#endif EFR32_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT); // Start timer for FACTORY_RESET_CANCEL_WINDOW_TIMEOUT to allow user to @@ -411,37 +399,31 @@ void AppTask::FunctionHandler(AppEvent * aEvent) { if (!sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_NoneSelected) { -#if CHIP_ENABLE_OPENTHREAD - sAppTask.StartTimer(JOINER_START_TRIGGER_TIMEOUT); -#else sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT); -#endif - - sAppTask.mFunction = kFunction_SoftwareUpdate; + sAppTask.mFunction = kFunction_StartThread; } } else { - // If the button was released before factory reset got initiated, trigger a - // software update. - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) + // If the button was released before factory reset got initiated, start Thread Network + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartThread) { sAppTask.CancelTimer(); - sAppTask.mFunction = kFunction_NoneSelected; - - EFR32_LOG("Software Update currently not supported."); - } #if CHIP_ENABLE_OPENTHREAD - else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_Joiner) - { - sAppTask.CancelTimer(); - sAppTask.mFunction = kFunction_NoneSelected; - - CHIP_ERROR error = ThreadStackMgr().JoinerStart(); - EFR32_LOG("Thread joiner triggered: %s", chip::ErrorStr(error)); - } + if (!chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned()) + { + StartDefaultThreadNetwork(); + EFR32_LOG("Device is not commissioned to a Thread network. Starting with the default configuration."); + } + else + { + EFR32_LOG("Device is commissioned to a Thread network."); + } +#elif + EFR32_LOG("Thread is not defined."); #endif + } else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset) { // Set lock status LED back to show state of lock. diff --git a/examples/platform/efr32/Service.cpp b/examples/platform/efr32/Service.cpp index 27884b1cb86859..8343dd40b9c0ef 100644 --- a/examples/platform/efr32/Service.cpp +++ b/examples/platform/efr32/Service.cpp @@ -106,3 +106,32 @@ void PublishService() } ThreadStackMgrImpl().UnlockThreadStack(); } + +void StartDefaultThreadNetwork(void) +{ + // Set default thread network Info and enable the etWORK + + chip::DeviceLayer::Internal::DeviceNetworkInfo deviceNetworkInfo; + memset(&deviceNetworkInfo, 0, sizeof(deviceNetworkInfo)); + const char * networkName = "OpenThread"; + const uint8_t masterKey[chip::DeviceLayer::Internal::kThreadNetworkKeyLength] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, + 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, + 0xcc, 0xdd, 0xee, 0xff }; + const uint8_t threadMeshPrefix[chip::DeviceLayer::Internal::kThreadMeshPrefixLength] = { 0xfd, 0xde, 0xad, 0x00, + 0xbe, 0xef, 0x00, 0x00 }; + + const uint8_t extendedPanId[chip::DeviceLayer::Internal::kThreadExtendedPANIdLength] = { 0xDE, 0xAD, 0x00, 0xBE, + 0xEF, 0x00, 0xCA, 0xFE }; + memcpy(deviceNetworkInfo.ThreadNetworkName, networkName, strlen(networkName)); + memcpy(deviceNetworkInfo.ThreadExtendedPANId, extendedPanId, sizeof(extendedPanId)); + deviceNetworkInfo.FieldPresent.ThreadExtendedPANId = true; + memcpy(deviceNetworkInfo.ThreadNetworkKey, masterKey, sizeof(masterKey)); + deviceNetworkInfo.FieldPresent.ThreadMeshPrefix = true; + memcpy(deviceNetworkInfo.ThreadMeshPrefix, threadMeshPrefix, sizeof(threadMeshPrefix)); + deviceNetworkInfo.ThreadPANId = 0x1234; + deviceNetworkInfo.ThreadChannel = 11; + + chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(false); + chip::DeviceLayer::ThreadStackMgr().SetThreadProvision(deviceNetworkInfo); + chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(true); +} diff --git a/examples/platform/efr32/Service.h b/examples/platform/efr32/Service.h index 1426ec65adec71..6a734a855149a6 100644 --- a/examples/platform/efr32/Service.h +++ b/examples/platform/efr32/Service.h @@ -19,3 +19,4 @@ void SetDeviceName(const char * newDeviceName); void PublishService(); +void StartDefaultThreadNetwork(void); \ No newline at end of file diff --git a/src/platform/EFR32/CHIPDevicePlatformConfig.h b/src/platform/EFR32/CHIPDevicePlatformConfig.h index 809e6d2e456678..e387f044a60503 100644 --- a/src/platform/EFR32/CHIPDevicePlatformConfig.h +++ b/src/platform/EFR32/CHIPDevicePlatformConfig.h @@ -116,11 +116,11 @@ #endif // CHIP_DEVICE_CONFIG_BLE_APP_TASK_STACK_SIZE #ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE -#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 8192 +#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 4096 #endif // CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE #ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE -#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 8192 +#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 4096 #endif // CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY 0 diff --git a/third_party/efr32_sdk/efr32_arm.gni b/third_party/efr32_sdk/efr32_arm.gni index 2e871b39139b37..38e0a3849e3c40 100644 --- a/third_party/efr32_sdk/efr32_arm.gni +++ b/third_party/efr32_sdk/efr32_arm.gni @@ -14,14 +14,16 @@ import("efr32_board.gni") -arm_arch = "armv7e-m" -arm_abi = "aapcs" -arm_cpu = "cortex-m4" - if (efr32_family == "efr32mg12") { + arm_arch = "armv7e-m" + arm_abi = "aapcs" + arm_cpu = "cortex-m4" arm_float_abi = "softfp" arm_fpu = "fpv4-sp-d16" } else if (efr32_family == "efr32mg21") { + arm_arch = "armv8-m.main+dsp" + arm_abi = "aapcs" + arm_cpu = "cortex-m33" arm_float_abi = "hard" arm_fpu = "fpv5-sp-d16" }