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

How to Design Flash Data storage Records in FDS module.

Hi Team,

My requirement is to Read and Write the data of the variables at specific Flash storage/ Flash data storage(FDS) address.

Eg;

__root const uint16_t FLA_kold_version @ (0x3e000) = 0x0000;

// Days date rollover started (Day only, not Ticks)
__root const uint16_t FLA_rollover_started @ (0x3e000 + 0x10) = 0x0000;

// Days date kold expires (Day only, not Ticks)
__root const uint16_t FLA_kold_day_expires @ (0x3e000+ 0x20) = 0x0000; 

etc..  like that we need to create the sequence of variables with fixed base address.

Is there any mechanism to create the variable in above manner in Flash storage section(FS) or Flash Data Storage(FDS) with out corrupting the other Record variables.

In FDS ,If we want to write the data as Records, what is the Min size of data we can write though one Record, we have various data sizes of variables like, 1 byte, 4bytes, array of bytes.How to handle different sizes of variables with FDS Records, we can write odd address( 0x3e001) variables as well, like in Flash storage it is not accepted to write odd address(address & 0x03).

How to split the Records in one page, we can create 'n' of records but sum of all record variable sizes must be with in the page size(4096) as per my knowledge.

Just we need the Records creation mechanism for above scenario. Suppose we have 120 different variables we need to create 120 unique records ?

Could any one suggest me the solution for above requirement. We Need to deliver this things to customer on high priority.

Regards,

Srinivas.V

Parents
  • Hi Srinivas, 

    Is there any mechanism to create the variable in above manner in Flash storage section(FS) or Flash Data Storage(FDS) with out corrupting the other Record variables.

     Yes, the FDS library will manage all the records for you. If you update an existing records the old record will be invalidated and a new record with the new data is created. 

    In FDS ,If we want to write the data as Records, what is the Min size of data we can write though one Record, we have various data sizes of variables like, 1 byte, 4bytes, array of bytes.How to handle different sizes of variables with FDS Records, we can write odd address( 0x3e001) variables as well, like in Flash storage it is not accepted to write odd address(address & 0x03).

     The FDS module manages the memory for you, you do not specify where the record should be stored, this is handled by the FDS module. You simply provide the data you want to store, in addition with a record key and a file ID and the FDS will retrun a record descriptor that you use to retreive or update the data with. 

    The records can have different sizes, the max size is limited to the virtual page size used in the FDS module, which is by default 4kB.

    How to split the Records in one page, we can create 'n' of records but sum of all record variable sizes must be with in the page size(4096) as per my knowledge.

    The FDS module will handle this for you. 

    Just we need the Records creation mechanism for above scenario. Suppose we have 120 different variables we need to create 120 unique records ?

    You will have to decide if you want to store multiple variables in one record or have one record for  each variable. Both approaches are viable

    As long as you set a side enough flash pages for the FDS module, i.e. set the FDS_VIRTUAL_PAGES to a number so that FDS_VIRTUAL_PAGES  x FDS_VIRTUAL_PAGE_SIZE > the total number  of 4-byte words you want to store, then you should not have any issues. 

    Could any one suggest me the solution for above requirement. We Need to deliver this things to customer on high priority.

     I recommend that you take a look at the Experimental: Flash Data Storage library documentation, specifically the Usage section. We also have a  Flash Data Storage Example you can test. 

  • Hi Spockeli,

    Thanks for your reply. We have implemented the code as per your suggestions and it is working fine.But we have observed one vague behavior in FDS Code.

    1. When we are reading he Record data by using unique "Recrod_Key" and common "File_id" some times we are missing the data and getting some garbage values.If We did the same after one or two resets in debug mode we are getting the correct values, we have cross checked the return values it is giving success only but data we are getting wrong.

    2 Here with i am giving my code snippet , could you please verify the same and please suggest me if anything is wrong in design.

    Eg:

        fds_flash_record_t flash_record = {0};

        #define FDS_FILE_ID 0x0000

         rc = fds_write(FDS_FILE_ID, 0x0010, &Rtc_Max_Key_Translate_Char, 12);

       if ((rc != NRF_SUCCESS) && (rc == FDS_ERR_NO_SPACE_IN_FLASH))
       {
           //Call the garbage collector to empty them, don't need to do this all the time, this is just for demonstration
          rc = fds_gc();

         if(rc != NRF_SUCCESS)
          {
              return rc;
           }
         return NRF_SUCCESS;
        }

          if(rc == NRF_SUCCESS)
           {
               rc = fds_read(FDS_FILE_ID, 0x0010, &flash_record);

              if(rc == NRF_SUCCESS)
               {
                   memcpy(&temp, flash_record.p_data, 12);
               }
       }

    After reading in "flash_record" it is not reflecting record structure values properly.

              flash_record.p_header->record_key;         //!< The record key.
             flash_record.p_header->length_words;          //!< The length of the record data (in 4-byte words).
             flash_record.p_header->file_id; 

              flash_record.p_data;

    Could you please suggest any suggestions for this issue.

    Regards,

    Srinivas.V

  • Hi Srinivas, 

     

    Srinivas V said:
    1. When we are reading he Record data by using unique "Recrod_Key" and common "File_id" some times we are missing the data and getting some garbage values.If We did the same after one or two resets in debug mode we are getting the correct values, we have cross checked the return values it is giving success only but data we are getting wrong.

     What is the result you get in the fds event handler you registered with fds_register()? In the FDS example in the SDK the fds_evt_handler looks like this. 

    static void fds_evt_handler(fds_evt_t const * p_evt)
    {
        if (p_evt->result == NRF_SUCCESS)
        {
            NRF_LOG_GREEN("Event: %s received (NRF_SUCCESS)",
                          fds_evt_str[p_evt->id]);
        }
        else
        {
            NRF_LOG_GREEN("Event: %s received (%s)",
                          fds_evt_str[p_evt->id],
                          fds_err_str(p_evt->result));
        }
    
        switch (p_evt->id)
        {
            case FDS_EVT_INIT:
                if (p_evt->result == NRF_SUCCESS)
                {
                    m_fds_initialized = true;
                }
                break;
    
            case FDS_EVT_WRITE:
            {
                if (p_evt->result == NRF_SUCCESS)
                {
                    NRF_LOG_INFO("Record ID:\t0x%04x",  p_evt->write.record_id);
                    NRF_LOG_INFO("File ID:\t0x%04x",    p_evt->write.file_id);
                    NRF_LOG_INFO("Record key:\t0x%04x", p_evt->write.record_key);
                }
            } break;
    
            case FDS_EVT_DEL_RECORD:
            {
                if (p_evt->result == NRF_SUCCESS)
                {
                    NRF_LOG_INFO("Record ID:\t0x%04x",  p_evt->del.record_id);
                    NRF_LOG_INFO("File ID:\t0x%04x",    p_evt->del.file_id);
                    NRF_LOG_INFO("Record key:\t0x%04x", p_evt->del.record_key);
                }
                m_delete_all.pending = false;
            } break;
    
            default:
                break;
        }
    }

    Calling fds_write will only schedule the flash operation and fds_evt_handler will be called when the flash operation is completed or have failed. Do you get a event where the p_evt->id == FDS_EVT_WRITE and p_evt->result == NRF_SUCCESS?

    Best regards

    Bjørn

  • Hi Bjorn,

    Thanks for your reply.

    1. I am getting 

                     rc = fds_register(fds_evt_handler); i am getting NRF_SUCCESS only.

                   if (rc != NRF_SUCCESS)
                      {
                          return rc;
                     }

    2. "fds_record_write" and  "fds_record_read" we are getting "NRF_SUCCESS" only. After fds_record_open() got success then only we are reading.But when we read the values it is giving wrong values like what i said in previous post,

             flash_record.p_header->record_key;         
            flash_record.p_header->length_words;

            flash_record.p_header->file_id;      

            flash_record.p_data;

    3. We need to read the data from "flash_record.p_data" before calling the "fds_record_close()" function or after calling this function also it will give correct values.

    Best Regards,

    Srinivas.V

  • When you call fds_record_write() you will get NRF_SUCCESS as the return value, which indicats if the flash operation was scheduled. The actual flash operation will not be completed until you get the FDS_EVT_WRITE in the fds_evt_handler. 

    Now, do you get the FDS_EVT_WRITE event and is the (p_evt->result == NRF_SUCCESS? Also are you using the same descriptor that was returned by fds_record_write when calling fds_record_open? 

    Note that the data must be aligned to a 4 byte boundary, and because it is not buffered internally, it must be kept in memory until the callback for the operation has been received.

  • Hi Bjorn,

    Thanks for your reply.

    We need to read the fds data once we got fds event write success (p_evt->result == NRF_SUCCESS), but for read operation there is no specific event in handler, means read always success.

    Data also we aligned with 4 byte boundary always, any we have check for this one, this case we not failing.

    We are suspecting SD or any delays required before read after write operation.

    Can we know exactly how much it will take to write 4 bytes to Fds or fs. or for one page write(256 bytes)

    Regards,

    Srinivas.V

  • Srinivas V said:
    We need to read the fds data once we got fds event write success (p_evt->result == NRF_SUCCESS), but for read operation there is no specific event in handler, means read always success.

    Can you list the order of FDS API calls you are doing when you read the wrong records value? 

    I would assume that its something like this: 

    1. Call fds_record_write
    2. Wait for the FDS_EVT_WRITE event where the result is NRF_SUCCESS 
    3. Call fds_record_open with the  same descriptor that was returned by fds_record_write in step one
    4. Call fds_record_close

    Are you frequently updating the record? Or do you write the record once and then you only read the record afterwards?

    Srinivas V said:
    Can we know exactly how much it will take to write 4 bytes to Fds or fs. or for one page write(256 bytes)

     The flash timing can be seen in the Flash programming section of the NVMC peripherals electrical specification. 

     

Reply
  • Srinivas V said:
    We need to read the fds data once we got fds event write success (p_evt->result == NRF_SUCCESS), but for read operation there is no specific event in handler, means read always success.

    Can you list the order of FDS API calls you are doing when you read the wrong records value? 

    I would assume that its something like this: 

    1. Call fds_record_write
    2. Wait for the FDS_EVT_WRITE event where the result is NRF_SUCCESS 
    3. Call fds_record_open with the  same descriptor that was returned by fds_record_write in step one
    4. Call fds_record_close

    Are you frequently updating the record? Or do you write the record once and then you only read the record afterwards?

    Srinivas V said:
    Can we know exactly how much it will take to write 4 bytes to Fds or fs. or for one page write(256 bytes)

     The flash timing can be seen in the Flash programming section of the NVMC peripherals electrical specification. 

     

Children
No Data
Related