NRF FDS Issue:

I am using Nrf52832 as my main microcontroller and in that, I am using fstorage as well as FDS. I have one structure that has several values in it. I want to store the copies of that structure one by one in FDS and size of one structure is 23 bytes. I want to save min 100 records of that. For one time data, I am using fstorage. I am able to write the data successfully. but when I am reading it nrf hangs and do nothing. There is no NRF_BREAKPOINT_ERROR or such, it just hangs. 

Here is my structure for NRF_FSTORAGE_DEF

NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
    /* Set a handler for fstorage events. */
    .evt_handler = fstorage_evt_handler,

    /* These below are the boundaries of the flash space assigned to this instance of fstorage.
     * You must set these manually, even at runtime, before nrf_fstorage_init() is called.
     * The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
     * last page of flash available to write data. */
    .start_addr =  0x3e000,
    .end_addr   = 0x80000,
};

I am reading the data as follows: 

void flash_read(inhaler_params  *data)
{
    uint32_t rc;

    uint32_t size = get_puff_count();

    memset(data,NULL,sizeof(inhaler_params)*size);

    for(int i=0;i<size;i++)
    {
        fds_record_desc_t desc = {0};
        fds_find_token_t  tok  = {0};
        rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY+i, &desc, &tok);


        //APP_ERROR_CHECK(rc);

        if (rc == NRF_SUCCESS)
        {
            rc = fds_record_open(&desc, &config);
            APP_ERROR_CHECK(rc);

           memcpy(data+i, config.p_data, sizeof(inhaler_params));
   
            rc = fds_record_close(&desc);
            APP_ERROR_CHECK(rc);
        } 

        //NRF_LOG_INFO("RC : %d",rc);

     }

} 
    
    NRF_LOG_INFO("Flash read done");

    //return data;
}

Inhaler_params is a structure pointer in which I am reading the data from flash. is there any efficient way to read the whole data at once?
please help me with that and let me know if you want any additional inputs from my side.

Parents
  • Hi,

    I do not immediately see the link between your direct use of fstorage and FDS, other than that your fstorage region is very large and overlaps with the pages used by FDS. It would probably make sense to reduce this region to what you actually intend to read/write to, to ensure that you do not accidentally touch the FDS pages.

    Regarding the reading, the code looks sensible. You write "it just hangs", but the PC will be somewhere, and you should be able to learn more by debugging. Where does it "hang"? What else do you find from debugging?

    is there any efficient way to read the whole data at once?

    If this data is in a single FDS record, it is consecutive in flash, so you can use memcpy just like I see you do. But separate records needs to be read separately (both because they could be scattered around the FDS pages, and because you have the headers in addition to the data, so you cannot simply copy data from more than one record in one go).

  • Sorry Einar. Could not see your reply. Will read and get back to you. 

    Thanks.

Reply Children
No Data
Related