This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

fs_store data lost after power off

Hi

I'm using fs_storage function to read and write in flash memory. Value successfully stored in evt->store.p_data but after power off it value become 0

switch(evt->id)
    {
        case FS_EVT_STORE:
            if(result == FS_SUCCESS)
            {
                stored_data = evt->store.p_data;
            }
    }

I'm using sdk11 with nrf528122.

Parents
  • Hi Kapil,

    Sorry it was my mistake, I confused evt->store.p_data; with the pointer to the data to be stored ( evt->store.p_data points to p_dest not p_src).

    I guess you followed this guide here.

    There are some issues with your code:

    • You should call fs_init() before you call fs_store() or any other fs_ API.

    • When you retrieve the data, you should not call fs_store() again, this call will try to store &f_data to fs_config.p_start_addr again, if f_data is all zero at that point (when initialized), then you will have all zero. In addition, as the nature of the flash, you can only write to an address in flash once (bit change from 1 to 0 once). So if you keep writing to the same address you will get corrupted data. To update data at an address in flash, you need to an erase page first.

    • To retrieve data, you simply can point the stored_data to fs_config.p_start_addr (or where ever address you write your data in flash) instead and you should be able to retrieve the data with *stored_data. Don't call fs_store() again.

Reply
  • Hi Kapil,

    Sorry it was my mistake, I confused evt->store.p_data; with the pointer to the data to be stored ( evt->store.p_data points to p_dest not p_src).

    I guess you followed this guide here.

    There are some issues with your code:

    • You should call fs_init() before you call fs_store() or any other fs_ API.

    • When you retrieve the data, you should not call fs_store() again, this call will try to store &f_data to fs_config.p_start_addr again, if f_data is all zero at that point (when initialized), then you will have all zero. In addition, as the nature of the flash, you can only write to an address in flash once (bit change from 1 to 0 once). So if you keep writing to the same address you will get corrupted data. To update data at an address in flash, you need to an erase page first.

    • To retrieve data, you simply can point the stored_data to fs_config.p_start_addr (or where ever address you write your data in flash) instead and you should be able to retrieve the data with *stored_data. Don't call fs_store() again.

Children
No Data
Related