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

Unable to read the flash when i want to update the value

Hi,

I am using nrf52840 DK and SDK version 17.0.2. I want to write data into particular address location(application area) of the flash using fstorage. It is
writing the data into selected location using nrf_fstorage_write() and reading the written data using nrf_fstorage_read(). It is reading the given value for the first time and when i try to write another
value/update the value at the same address location it is not reading the written value. I used
nrf_fstorage_erase() to erase the data written at that location,but unable to read the values which i
 written. How can i update/write the value at that location for the second time? please suggest me.For your reference i am
adding my code snippet

1st time values
uint32_t m_data  = 0x11111111;
uint32_t m_data1 = 0x22222222;
uint32_t m_data2 = 0x33333333;

2nd time values(i want to update)
uint32_t m_data  = 0x44444444;
uint32_t m_data1 = 0x55555555;
uint32_t m_data2 = 0x66666666;

uint32_t sensor_read,sensor_read1,sensor_read2;

    nrf_fstorage_erase(&fstorage, 0xF6000, sizeof(m_data),NULL);
    
    nrf_fstorage_write(&fstorage, 0xF6000, &m_data, sizeof(m_data), NULL);

    nrf_fstorage_write(&fstorage, 0xF6C00, &m_data1, sizeof(m_data), NULL);

    nrf_fstorage_write(&fstorage, 0xF60F0, &m_data2, sizeof(m_data), NULL);

    wait_for_flash_ready(&fstorage);

    nrf_fstorage_read(&fstorage, 0xF6000, &sensor_read, sizeof(sensor_read));

    nrf_fstorage_read(&fstorage, 0xF6C00, &sensor_read1, sizeof(sensor_read1));

    nrf_fstorage_read(&fstorage, 0xF60F0, &sensor_read2, sizeof(sensor_read2));

also suggest me how to erase the data written at particular location for update the values

Thank you in advance

  • Hi,

    The fstorage module is asynchronous, which means that you have to wait for each write to be executed before you try to read the data. Check your callback handler for fstorage events and wait for a NRF_FSTORAGE_EVT_WRITE_RESULT after a write and a NRF_FSTORAGE_EVT_ERASE_RESULT after an erase.

    It's also a good practice to check the return value from the function calls Slight smile

    regards
    Jared
Related