diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 54137bc281562b..c4ccd625b9cda7 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -209,6 +209,10 @@ config NVS_LOOKUP_CACHE_SIZE config SETTINGS_NVS_SECTOR_SIZE_MULT default 1 +# Set sector counter of NVS +config SETTINGS_NVS_SECTOR_COUNT + default 10 + # Enable OpenThread config NET_L2_OPENTHREAD diff --git a/examples/lock-app/telink/prj.conf b/examples/lock-app/telink/prj.conf index 791e7ba8a4783c..738b4090c8be80 100755 --- a/examples/lock-app/telink/prj.conf +++ b/examples/lock-app/telink/prj.conf @@ -42,9 +42,6 @@ CONFIG_CHIP_ENABLE_PAIRING_AUTOSTART=y # Disable CHIP shell support CONFIG_CHIP_LIB_SHELL=n -# Set NVM sector -CONFIG_SETTINGS_NVS_SECTOR_COUNT=10 - # Disable factory data support CONFIG_CHIP_FACTORY_DATA=n CONFIG_CHIP_FACTORY_DATA_BUILD=n diff --git a/examples/lock-app/telink/src/LockManager.cpp b/examples/lock-app/telink/src/LockManager.cpp index a4dbc9e9aa0aab..529e1aa557fa7c 100644 --- a/examples/lock-app/telink/src/LockManager.cpp +++ b/examples/lock-app/telink/src/LockManager.cpp @@ -667,33 +667,21 @@ bool LockManager::SetCredential(chip::EndpointId endpointId, uint16_t credential #if LOCK_MANAGER_CONFIG_USE_NVM_CREDENTIAL_STORAGE CHIP_ERROR err; - for (uint8_t i = 0; i < kNumCredentialTypes; i++) - { - // Save credential information in NVM flash - err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_Credential[i], - reinterpret_cast(&mLockCredentials[i]), - sizeof(EmberAfPluginDoorLockCredentialInfo) * kMaxCredentials); - if (err != CHIP_NO_ERROR) - { - ChipLogError( - Zcl, - "Failed to write kConfigKey_Credential(%d). User data will be resetted during reboot. Not enough storage space \n", - i); - break; - } + // Save credential information in NVM flash + err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_Credential[to_underlying(credentialType)], + reinterpret_cast(&mLockCredentials[to_underlying(credentialType)]), + sizeof(EmberAfPluginDoorLockCredentialInfo) * kMaxCredentials); + if (err != CHIP_NO_ERROR) + ChipLogError( + Zcl, "Failed to write kConfigKey_Credential. User data will be resetted during reboot. Not enough storage space \n"); - err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_CredentialData[i], - reinterpret_cast(&mCredentialData[i]), - kMaxCredentials * kMaxCredentialSize); - if (err != CHIP_NO_ERROR) - { - ChipLogError(Zcl, - "Failed to write kConfigKey_CredentialData(%d). User data will be resetted during reboot. Not enough " - "storage space \n", - i); - break; - } - } + err = ZephyrConfig::WriteConfigValueBin(LockSettingsStorage::kConfigKey_CredentialData[to_underlying(credentialType)], + reinterpret_cast(&mCredentialData[to_underlying(credentialType)]), + kMaxCredentials * kMaxCredentialSize); + if (err != CHIP_NO_ERROR) + ChipLogError( + Zcl, + "Failed to write kConfigKey_CredentialData. User data will be resetted during reboot. Not enough storage space \n"); #endif ChipLogProgress(Zcl, "Successfully set the credential [credentialType=%u]", to_underlying(credentialType));