From f986eefc40b3129694e682d5a0432fa7e614c17e Mon Sep 17 00:00:00 2001 From: jmartinez-silabs Date: Wed, 7 Oct 2020 15:44:25 -0400 Subject: [PATCH 1/6] Reduce Chip task and Thread task Stack size for EFR platforms (fix stack overflow for mg21) Fix CPU and Architecture flags for MG21 family Add ldflags to lock_app and lighting_app to show memory usage after build --- examples/lighting-app/efr32/BUILD.gn | 2 +- examples/lock-app/efr32/BUILD.gn | 2 +- src/platform/EFR32/CHIPDevicePlatformConfig.h | 4 ++-- third_party/efr32_sdk/efr32_arm.gni | 9 ++++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index 4f3e5d597b705b..3fa7974202d066 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -123,7 +123,7 @@ 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/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index d38c94a3d756c8..7c0171fea84fc9 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -123,7 +123,7 @@ 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/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..a907a8c404d29d 100644 --- a/third_party/efr32_sdk/efr32_arm.gni +++ b/third_party/efr32_sdk/efr32_arm.gni @@ -14,14 +14,17 @@ 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" } From 40ad50dae80e8c7b49de91ab2f2e2547b98235e7 Mon Sep 17 00:00:00 2001 From: jmartinez-silabs Date: Thu, 8 Oct 2020 17:26:07 -0400 Subject: [PATCH 2/6] Fix rebase conflict --- examples/lighting-app/efr32/include/AppTask.h | 4 +- examples/lighting-app/efr32/src/AppTask.cpp | 29 ++++++---- examples/lock-app/efr32/include/AppTask.h | 5 +- examples/lock-app/efr32/src/AppTask.cpp | 54 +++++++------------ examples/platform/efr32/Service.cpp | 29 ++++++++++ examples/platform/efr32/Service.h | 3 ++ 6 files changed, 71 insertions(+), 53 deletions(-) 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/include/AppTask.h b/examples/lock-app/efr32/include/AppTask.h index 020203287d28c7..64b20224b0d3f1 100644 --- a/examples/lock-app/efr32/include/AppTask.h +++ b/examples/lock-app/efr32/include/AppTask.h @@ -27,8 +27,6 @@ #include "FreeRTOS.h" #include "timers.h" // provides FreeRTOS timer support -#include -#include class AppTask { @@ -67,7 +65,7 @@ class AppTask { kFunction_NoneSelected = 0, kFunction_SoftwareUpdate = 0, - kFunction_Joiner = 1, + kFunction_StartThread = 1, kFunction_FactoryReset = 2, kFunction_Invalid @@ -76,7 +74,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..e9bfd62b92c1c9 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 (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartThread) { -#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) - { -#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. @@ -579,4 +561,4 @@ void AppTask::UpdateClusterState(void) { EFR32_LOG("ERR: updating on/off %x", status); } -} +} \ No newline at end of file diff --git a/examples/platform/efr32/Service.cpp b/examples/platform/efr32/Service.cpp index 27884b1cb86859..fb393fc08feab7 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); +} \ No newline at end of file diff --git a/examples/platform/efr32/Service.h b/examples/platform/efr32/Service.h index 1426ec65adec71..a107ca4ff2be56 100644 --- a/examples/platform/efr32/Service.h +++ b/examples/platform/efr32/Service.h @@ -19,3 +19,6 @@ void SetDeviceName(const char * newDeviceName); void PublishService(); +void StartDefaultThreadNetwork(void); + +#endif // EFR32_SERVICE_H From f5f364ee862a9281e20a7074ba2f90f011acf9c5 Mon Sep 17 00:00:00 2001 From: jmartinez-silabs Date: Tue, 13 Oct 2020 12:03:50 -0400 Subject: [PATCH 3/6] Fix build for lock app/Undo removed includes --- examples/lock-app/efr32/include/AppTask.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/lock-app/efr32/include/AppTask.h b/examples/lock-app/efr32/include/AppTask.h index 64b20224b0d3f1..ae7659b64c54d7 100644 --- a/examples/lock-app/efr32/include/AppTask.h +++ b/examples/lock-app/efr32/include/AppTask.h @@ -27,6 +27,8 @@ #include "FreeRTOS.h" #include "timers.h" // provides FreeRTOS timer support +#include +#include class AppTask { From 97dd4280124340abfb752b94c20d8831c641564b Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 13 Oct 2020 16:43:05 +0000 Subject: [PATCH 4/6] Restyled by whitespace --- examples/lock-app/efr32/src/AppTask.cpp | 2 +- examples/platform/efr32/Service.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/lock-app/efr32/src/AppTask.cpp b/examples/lock-app/efr32/src/AppTask.cpp index e9bfd62b92c1c9..adf109b5540645 100644 --- a/examples/lock-app/efr32/src/AppTask.cpp +++ b/examples/lock-app/efr32/src/AppTask.cpp @@ -561,4 +561,4 @@ void AppTask::UpdateClusterState(void) { EFR32_LOG("ERR: updating on/off %x", status); } -} \ No newline at end of file +} diff --git a/examples/platform/efr32/Service.cpp b/examples/platform/efr32/Service.cpp index fb393fc08feab7..8343dd40b9c0ef 100644 --- a/examples/platform/efr32/Service.cpp +++ b/examples/platform/efr32/Service.cpp @@ -134,4 +134,4 @@ void StartDefaultThreadNetwork(void) chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(false); chip::DeviceLayer::ThreadStackMgr().SetThreadProvision(deviceNetworkInfo); chip::DeviceLayer::ThreadStackMgr().SetThreadEnabled(true); -} \ No newline at end of file +} From 891cd76b797781b1c9646b2f607fec2c6f9e9cb7 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 13 Oct 2020 16:43:11 +0000 Subject: [PATCH 5/6] Restyled by gn --- examples/lighting-app/efr32/BUILD.gn | 6 +++++- examples/lock-app/efr32/BUILD.gn | 6 +++++- third_party/efr32_sdk/efr32_arm.gni | 1 - 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index 3fa7974202d066..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 = [ "-Wl,--print-memory-usage", "-fstack-usage", "-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/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index 7c0171fea84fc9..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 = [ "-Wl,--print-memory-usage", "-fstack-usage", "-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/third_party/efr32_sdk/efr32_arm.gni b/third_party/efr32_sdk/efr32_arm.gni index a907a8c404d29d..38e0a3849e3c40 100644 --- a/third_party/efr32_sdk/efr32_arm.gni +++ b/third_party/efr32_sdk/efr32_arm.gni @@ -14,7 +14,6 @@ import("efr32_board.gni") - if (efr32_family == "efr32mg12") { arm_arch = "armv7e-m" arm_abi = "aapcs" From 181c2da8dbcdc67448622a031308ae1d5795e88e Mon Sep 17 00:00:00 2001 From: jmartinez-silabs Date: Tue, 13 Oct 2020 13:04:14 -0400 Subject: [PATCH 6/6] Fix removed #ifdef with previous merge --- examples/platform/efr32/Service.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/platform/efr32/Service.h b/examples/platform/efr32/Service.h index a107ca4ff2be56..6a734a855149a6 100644 --- a/examples/platform/efr32/Service.h +++ b/examples/platform/efr32/Service.h @@ -19,6 +19,4 @@ void SetDeviceName(const char * newDeviceName); void PublishService(); -void StartDefaultThreadNetwork(void); - -#endif // EFR32_SERVICE_H +void StartDefaultThreadNetwork(void); \ No newline at end of file