@@ -91,7 +91,7 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys
9191#include < platform/silabs/platformAbstraction/SilabsPlatform.h>
9292#include < platform/silabs/tracing/SilabsTracingMacros.h>
9393#if MATTER_TRACING_ENABLED
94- #include < platform/silabs/tracing/BackendImpl.h>
94+ #include < platform/silabs/tracing/BackendImpl.h> // nogncheck
9595#include < tracing/registry.h>
9696#endif // MATTER_TRACING_ENABLED
9797
@@ -248,13 +248,6 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
248248{
249249 using namespace chip ::DeviceLayer::Silabs;
250250
251- CHIP_ERROR err;
252- #ifdef SL_WIFI
253- // Because OpenThread needs to use memory allocation during its Key operations, we initialize the memory management for thread
254- // and set the allocation functions inside sl_ot_create_instance, which is called by sl_system_init in the OpenThread stack
255- // initialization.
256- mbedtls_platform_set_calloc_free (CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree);
257- #endif
258251 ChipLogProgress (DeviceLayer, " ==================================================" );
259252 ChipLogProgress (DeviceLayer, " %s starting" , appName);
260253 ChipLogProgress (DeviceLayer, " ==================================================" );
@@ -274,9 +267,11 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
274267
275268#ifdef SL_WIFI
276269 // Init Chip memory management before the stack
277- // See comment above about OpenThread memory allocation as to why this is WIFI only here.
270+ // Because OpenThread needs to use memory allocation during its Key operations, we initialize the memory management for thread
271+ // and set the allocation functions inside sl_ot_create_instance, which is called earlier by sl_system_init.
272+ mbedtls_platform_set_calloc_free (CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree);
278273 ReturnErrorOnFailure (chip::Platform::MemoryInit ());
279- ReturnErrorOnFailure (InitWiFi ());
274+ ReturnErrorOnFailure (WifiInterface::GetInstance (). InitWiFiStack ());
280275
281276#if CHIP_CONFIG_ENABLE_ICD_SERVER
282277 ReturnErrorOnFailure (WifiSleepManager::GetInstance ().Init (&WifiInterface::GetInstance (), &WifiInterface::GetInstance ()));
@@ -294,17 +289,29 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
294289 SetCommissionableDataProvider (&provision.GetStorage ());
295290 ChipLogProgress (DeviceLayer, " Provision mode %s" , provision.IsProvisionRequired () ? " ENABLED" : " disabled" );
296291
292+ // Create initParams with SDK example defaults here
293+ // TODO: replace with our own init param to avoid double allocation in examples
294+ static chip::CommonCaseDeviceServerInitParams initParams;
295+
297296#if CHIP_ENABLE_OPENTHREAD
298297 ReturnErrorOnFailure (InitOpenThread ());
298+
299+ // Set up OpenThread configuration when OpenThread is included
300+ chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams;
301+ nativeParams.lockCb = LockOpenThreadTask;
302+ nativeParams.unlockCb = UnlockOpenThreadTask;
303+ nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl ().OTInstance ();
304+ initParams.endpointNativeParams = static_cast <void *>(&nativeParams);
305+ #endif
306+ #ifdef SL_WIFI
307+ // This must be initialized after InitWiFiStack and InitChipStack which enable communication between the TA an M4
308+ // This is required for TA nvm access used by the sWifiNetworkDriver.
309+ ReturnErrorOnFailure (sWifiNetworkDriver .Init ());
299310#endif
300311
301312 // Stop Matter event handling while setting up resources
302313 chip::DeviceLayer::PlatformMgr ().LockChipStack ();
303314
304- // Create initParams with SDK example defaults here
305- // TODO: replace with our own init param to avoid double allocation in examples
306- static chip::CommonCaseDeviceServerInitParams initParams;
307-
308315 // Report scheduler and timer delegate instance
309316 static DefaultTimerDelegate sTimerDelegate ;
310317#if CHIP_CONFIG_SYNCHRONOUS_REPORTS_ENABLED
@@ -330,19 +337,11 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
330337#endif
331338
332339 // Initialize the remaining (not overridden) providers to the SDK example defaults
333- ( void ) initParams.InitializeStaticResourcesBeforeServerInit ();
340+ ReturnErrorOnFailure ( initParams.InitializeStaticResourcesBeforeServerInit () );
334341 initParams.dataModelProvider = CodegenDataModelProviderInstance (initParams.persistentStorageDelegate );
342+ initParams.appDelegate = &BaseApplication::sAppDelegate ;
335343
336- #if CHIP_ENABLE_OPENTHREAD
337- // Set up OpenThread configuration when OpenThread is included
338- chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams;
339- nativeParams.lockCb = LockOpenThreadTask;
340- nativeParams.unlockCb = UnlockOpenThreadTask;
341- nativeParams.openThreadInstancePtr = chip::DeviceLayer::ThreadStackMgrImpl ().OTInstance ();
342- initParams.endpointNativeParams = static_cast <void *>(&nativeParams);
343- #endif
344-
345- initParams.appDelegate = &BaseApplication::sAppDelegate ;
344+ CHIP_ERROR err = CHIP_NO_ERROR;
346345
347346 // [sl-only]: Configure Wi-Fi App Sleep Manager
348347#if SL_MATTER_ENABLE_APP_SLEEP_MANAGER
@@ -383,14 +382,6 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
383382 return CHIP_NO_ERROR;
384383}
385384
386- #ifdef SL_WIFI
387- CHIP_ERROR SilabsMatterConfig::InitWiFi (void )
388- {
389- sWifiNetworkDriver .Init ();
390- return WifiInterface::GetInstance ().InitWiFiStack ();
391- }
392- #endif // SL_WIFI
393-
394385// ================================================================================
395386// FreeRTOS Callbacks
396387// ================================================================================
0 commit comments