Skip to content

Commit

Permalink
Fix the boot loop crash on M5Stack (#24607)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
shubhamdp authored and pull[bot] committed Jun 26, 2023
1 parent 8c11122 commit 2428444
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
14 changes: 9 additions & 5 deletions examples/all-clusters-app/esp32/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
Expand All @@ -199,7 +203,7 @@ CHIP_ERROR AppTask::Init()
InitDeviceDisplay();
#endif

return err;
return CHIP_NO_ERROR;
}

void AppTask::AppTaskMain(void * pvParameter)
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/esp32/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions examples/platform/esp32/lock/BoltLockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,6 @@ CHIP_ERROR BoltLockManager::InitLockState()
// Initial lock state
chip::app::DataModel::Nullable<chip::app::Clusters::DoorLock::DlLockState> state;
chip::EndpointId endpointId{ 1 };
chip::DeviceLayer::PlatformMgr().LockChipStack();
chip::app::Clusters::DoorLock::Attributes::LockState::Get(endpointId, state);

uint8_t numberOfCredentialsPerUser = 0;
Expand Down Expand Up @@ -816,8 +815,6 @@ CHIP_ERROR BoltLockManager::InitLockState()
numberOfHolidaySchedules = 10;
}

chip::DeviceLayer::PlatformMgr().UnlockChipStack();

CHIP_ERROR err = BoltLockMgr().Init(state,
ParamBuilder()
.SetNumberOfUsers(numberOfUsers)
Expand Down

0 comments on commit 2428444

Please sign in to comment.