From ffc2fbfc467343a838613375525256cee5ba049c Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Wed, 26 Apr 2023 15:02:14 -0400 Subject: [PATCH 1/2] Move NVM initialization to sl_platform_init() in matter_support submodule Also move nvm3_Sem creation to nvm3_lockBegin() --- src/platform/silabs/SilabsConfig.cpp | 19 +++++++++---------- third_party/silabs/matter_support | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/platform/silabs/SilabsConfig.cpp b/src/platform/silabs/SilabsConfig.cpp index d07b9ced36cfc0..d4096726eb1bdc 100644 --- a/src/platform/silabs/SilabsConfig.cpp +++ b/src/platform/silabs/SilabsConfig.cpp @@ -43,6 +43,12 @@ static StaticSemaphore_t nvm3_SemStruct; void nvm3_lockBegin(void) { + if (nvm3_Sem == NULL) + { + nvm3_Sem = xSemaphoreCreateBinaryStatic(&nvm3_SemStruct); + xSemaphoreGive(nvm3_Sem); + } + VerifyOrDie(nvm3_Sem != NULL); xSemaphoreTake(nvm3_Sem, portMAX_DELAY); } @@ -65,16 +71,9 @@ namespace Internal { CHIP_ERROR SilabsConfig::Init() { -#ifndef BRD4325A // TODO: fix semaphore usage in nvm3_lock for siwx917. use weak implementation for that board instead - nvm3_Sem = xSemaphoreCreateBinaryStatic(&nvm3_SemStruct); - - if (nvm3_Sem == NULL) - { - return CHIP_ERROR_NO_MEMORY; - } - xSemaphoreGive(nvm3_Sem); -#endif // not BRD4325A - return MapNvm3Error(nvm3_open(nvm3_defaultHandle, nvm3_defaultInit)); + // nvm3_Sem is created in nvm3_lockBegin() + // nvm3_open() is called by nvm3_initDefault() in sl_platform_init() in SLC-generated sl_event_handler.c + return CHIP_NO_ERROR; } void SilabsConfig::DeInit() diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 53c27ef4ed0cff..2bc3f28d778850 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 53c27ef4ed0cff01ad913b9e25d57ccb58cd49f4 +Subproject commit 2bc3f28d778850417f34c7201cbe78bd72e3ee78 From 02deebdb74b83c0524fcdbc7e290e1245037349c Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Wed, 26 Apr 2023 15:43:44 -0400 Subject: [PATCH 2/2] Restore the call to nvm3_open(), it's safe to call multiple times --- src/platform/silabs/SilabsConfig.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/silabs/SilabsConfig.cpp b/src/platform/silabs/SilabsConfig.cpp index d4096726eb1bdc..950b6040490c0a 100644 --- a/src/platform/silabs/SilabsConfig.cpp +++ b/src/platform/silabs/SilabsConfig.cpp @@ -72,8 +72,8 @@ namespace Internal { CHIP_ERROR SilabsConfig::Init() { // nvm3_Sem is created in nvm3_lockBegin() - // nvm3_open() is called by nvm3_initDefault() in sl_platform_init() in SLC-generated sl_event_handler.c - return CHIP_NO_ERROR; + + return MapNvm3Error(nvm3_open(nvm3_defaultHandle, nvm3_defaultInit)); } void SilabsConfig::DeInit()