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 Reply Children
  • Hi,

    ChinmayDixit97 said:
    1. I am using 3 fstorage locations as 0x3e000, 0x3e004 and 0x3e008. What is the width of the data in fstorage? Can I store uin32_t data in 0x3e000,0x3e001 and 0x3e002? 

    Fstorage just provide direct access to the flash, so there are no headers etc. It simply gives you a API for writing to flash and erasing flash pages that is the same regardless of if you are using a SoftDevice or not, and ensures that you stay within the region you have defined. As you only write to a small part of the page at 0x3e000, you should reserve that page for fstorage, but not anything more. And nothing else should use that page. So in this case it would make sense to set the end address to 0x3ffff.  Moreover, you need to have full control over your memory layout. What does your flash cosists of, and where is every part located? Many things need to be placed at exact locations, and some (like your fstorage page) could be anywhere, as long as it does not overlap with anything else. If you see unpredictable behaviour, this is the first thing I would check (perhaps you are overwriting parts of the application or similar?).

    ChinmayDixit97 said:
    2. Is fds pages starts automatically from where the fstorage ends? I can see, The fds has the last address as 0x80000 which is the last location in flash.

    No. The FDS pages are located either at the very end of the flash, or right below the bootloader (if you are using that). The number of pages being used is defined by the FDS_VIRTUAL_PAGES define in sdk_config.h (the default in most examples is 3). Have a look at the memory layout figure in the bootloader documentation to get an overview.

Related