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

store array using fstorage

I've been trying to store an array  (SDK16,S332)

uint8_t my_data[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,.........0x23}

using fstorage I wrote an update function :

I hardcoded the size. There are a few odd behaviors that I noted.

If I use the my_data as above,(incrementing values) it does write and I can read back the data consistently. The application runs consistently. 

If I use pseudo random values, the program works once then crashes. It will store the values, but if the applications is run again, it will not run.

void update_data(uint8_t *my_data)
{
ret_code_t rc;
rc = nrf_fstorage_erase(&fstorage, 0x7f000, 1, NULL);
APP_ERROR_CHECK(rc);
wait_for_flash_ready(&fstorage);

rc = nrf_fstorage_write(&fstorage, 0x7f000,my_data,24, NULL);
APP_ERROR_CHECK(rc);
if (rc != NRF_SUCCESS)
{
NRF_LOG_INFO("nrf_fstorage_write() returned: %s\r\n",
nrf_strerror_get(rc));
}
wait_for_flash_ready(&fstorage);
}

Is there a limit as to the number of bytes that can be sent at once?

Parents
  • Hi,

    I do not immediately see any problem here. What happens when you write it crashed? Is an error returned from some of the function calls, or something else?

    Is there a limit as to the number of bytes that can be sent at once?

    The length passed to nrf_fstorage_write() must be a multiple of 4, but there are no other limitations on size.

  • Hi, 

    Thank you for responding. There is no error returned. The application does not run. When I I go into debug and try to step , it does not even start. The only recovery is to erase it and reprogram with NRF Connect. I am guessing that it gets stuck on wait_for_flash_ready. When I comment that out, I can step, but it does not work properly. 

    There is one thing I noted from today's experiment... When I pass the array to the function and I use sizeof(my_data)instead of the hardcoded "24"  it reports 4 bytes! If I use 4 bytes, it works, but the array is not 4 bytes long. 

  • Hi,

    I see. However, I am having problems getting a proper understanding of both your code and what happens. Can you share your project that reproduces this so that I can get an overview and test on my side if needed?

Reply Children
Related