From 1297819e2dd46cfd9b329261e03d08a16b2c1180 Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Tue, 24 Jan 2023 17:03:02 +0530 Subject: [PATCH] Fix the boot loop crash on M5Stack (#24607) * Fix the boot loop crash on M5Stack This is the regression from #24547, which is accessing the attributes even before Server is ready. Moved the lock initialization after service is initialized * Fix the typo for chip error format --- examples/all-clusters-app/esp32/main/AppTask.cpp | 14 +++++++++----- .../all-clusters-app/esp32/main/include/AppTask.h | 1 + examples/all-clusters-app/esp32/main/main.cpp | 7 +++++++ examples/platform/esp32/lock/BoltLockManager.cpp | 3 --- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/examples/all-clusters-app/esp32/main/AppTask.cpp b/examples/all-clusters-app/esp32/main/AppTask.cpp index 2111d7cb32df47..9a04b23c689d4c 100644 --- a/examples/all-clusters-app/esp32/main/AppTask.cpp +++ b/examples/all-clusters-app/esp32/main/AppTask.cpp @@ -161,6 +161,13 @@ void AppTask::ActionCompleted(BoltLockManager::Action_t aAction) } } +CHIP_ERROR AppTask::LockInit() +{ + ReturnErrorOnFailure(BoltLockMgr().InitLockState()); + BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted); + return CHIP_NO_ERROR; +} + CHIP_ERROR AppTask::Init() { /* Print chip information */ @@ -179,10 +186,7 @@ CHIP_ERROR AppTask::Init() (void *) this, // init timer id = app task obj context TimerEventHandler // timer callback handler ); - - CHIP_ERROR err = BoltLockMgr().InitLockState(); - - BoltLockMgr().SetCallbacks(ActionInitiated, ActionCompleted); + VerifyOrReturnError(sFunctionTimer != NULL, CHIP_ERROR_NO_MEMORY, ESP_LOGE(TAG, "Failed to create function selection timer")); statusLED1.Init(STATUS_LED_GPIO_NUM); // Our second LED doesn't map to any physical LEDs so far, just to virtual @@ -199,7 +203,7 @@ CHIP_ERROR AppTask::Init() InitDeviceDisplay(); #endif - return err; + return CHIP_NO_ERROR; } void AppTask::AppTaskMain(void * pvParameter) diff --git a/examples/all-clusters-app/esp32/main/include/AppTask.h b/examples/all-clusters-app/esp32/main/include/AppTask.h index 8a72b2d47e5777..779e7e990c12a7 100644 --- a/examples/all-clusters-app/esp32/main/include/AppTask.h +++ b/examples/all-clusters-app/esp32/main/include/AppTask.h @@ -39,6 +39,7 @@ class AppTask void PostEvent(const AppEvent * event); void ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction); static void ButtonPressedAction(AppEvent * aEvent); + CHIP_ERROR LockInit(); private: CHIP_ERROR Init(); diff --git a/examples/all-clusters-app/esp32/main/main.cpp b/examples/all-clusters-app/esp32/main/main.cpp index 1447638bcce0b1..62563025279cbf 100644 --- a/examples/all-clusters-app/esp32/main/main.cpp +++ b/examples/all-clusters-app/esp32/main/main.cpp @@ -115,6 +115,13 @@ static void InitServer(intptr_t context) emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false); InitBindingHandlers(); + + CHIP_ERROR err = GetAppTask().LockInit(); + if (err != CHIP_NO_ERROR) + { + ESP_LOGE(TAG, "Failed to initialize app task lock, err:%" CHIP_ERROR_FORMAT, err.Format()); + } + #if CONFIG_DEVICE_TYPE_M5STACK SetupPretendDevices(); #endif diff --git a/examples/platform/esp32/lock/BoltLockManager.cpp b/examples/platform/esp32/lock/BoltLockManager.cpp index 48c355f24eaca4..6115c15b1bf75d 100644 --- a/examples/platform/esp32/lock/BoltLockManager.cpp +++ b/examples/platform/esp32/lock/BoltLockManager.cpp @@ -764,7 +764,6 @@ CHIP_ERROR BoltLockManager::InitLockState() // Initial lock state chip::app::DataModel::Nullable state; chip::EndpointId endpointId{ 1 }; - chip::DeviceLayer::PlatformMgr().LockChipStack(); chip::app::Clusters::DoorLock::Attributes::LockState::Get(endpointId, state); uint8_t numberOfCredentialsPerUser = 0; @@ -816,8 +815,6 @@ CHIP_ERROR BoltLockManager::InitLockState() numberOfHolidaySchedules = 10; } - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - CHIP_ERROR err = BoltLockMgr().Init(state, ParamBuilder() .SetNumberOfUsers(numberOfUsers)