Other Parts Discussed in Thread: SYSCONFIG, UNIFLASH
Tool/software:
Hii am writting some data in nvs by using the api
NVS_Handle nvsRegion;
NVS_Attrs regionAttrs;
NVS_Params nvsParams;
uint_fast16_t status;
uint8_t buffer[16];
uint8_t buffer2[1];
extern uint8_t aesKey[16];
extern uint8_t nvmExecutionFlagarray[1];
extern uint8_t nvmExecutionFlag[1];
uint8 flag;
// Initialize NVM
void NVM_INIT() {
// Initialize the NVS driver
NVS_init();
// Initialize NVS parameters
NVS_Params_init(&nvsParams);
// Open the NVS region
nvsRegion = NVS_open(CONFIG_NVS_0, &nvsParams);
if (nvsRegion == NULL) {
// Handle error if the region could not be opened
// Log or implement error handling
return;
}
// Get attributes of the NVS region
NVS_getAttrs(nvsRegion, ®ionAttrs);
// Erase the first sector of the NVS region
// status = NVS_erase(nvsRegion, 0, regionAttrs.sectorSize);
if (status != NVS_STATUS_SUCCESS) {
// Handle erase failure
// Log or implement error handling
return;
}
}
// Write AES key to NVM
void NVM_WRITE_AES_KEY()
{
// Write AES key to NVS
status = NVS_write(nvsRegion, 0x00, &aesKey, sizeof(aesKey), NVS_WRITE_POST_VERIFY);
if (status != NVS_STATUS_SUCCESS) {
// Handle write failure
// Log or implement error handling
return;
}
NVS_close(nvsRegion);
}
// Read AES key from NVM
void NVM_READ_AES_KEY()
{
// Read AES key from NVS
status = NVS_read(nvsRegion, 0x00, buffer, sizeof(buffer));
if (status != NVS_STATUS_SUCCESS) {
// Handle read failure
// Log or implement error handling
return;
}
NVS_close(nvsRegion);
}
//// Write execution flag to NVM
void NVM_WRITE_EXECUTION_FLAG()
{
// Write execution flag to NVS
status = NVS_write(nvsRegion, 0x16, &nvmExecutionFlagarray,sizeof(nvmExecutionFlagarray), NVS_WRITE_POST_VERIFY);
if (status != NVS_STATUS_SUCCESS) {
// Handle write failure
// Log or implement error handling
return;
}
flag=1;
NVS_close(nvsRegion);
}
//
//// Read execution flag from NVM
void NVM_READ_EXECUTION_FLAG()
{
// Read execution flag from NVS
if(flag)
{
status = NVS_read(nvsRegion, 0x16, buffer2,sizeof(buffer2));
}
flag=0;
if (nvmExecutionFlag[0] == 0xFF)
{
nvmExecutionFlag[0] = 0x00; // Set the flag to 0x00
status = NVS_write(nvsRegion, 16, nvmExecutionFlag, sizeof(nvmExecutionFlag), NVS_WRITE_POST_VERIFY);
if (status != NVS_STATUS_SUCCESS)
{
// Handle write failure
return;
}
if (status != NVS_STATUS_SUCCESS) {
// Handle read failure
// Log or implement error handling
return;
}
}
NVS_close(nvsRegion);
}
i have created this function to write and read the data from nvs it is working fine , but when the power is shutdown and again power is given it is not able to read the data stored in nvs.
any suggestions
i have also attached the sysconfig setting which i have done.