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

Manage Multiple Records by using FDS

Hello,

   I am using NRF52832, nRF5_SDK_15.2.0 for product.

   I am using FDS library to manage some files.

   Here is situation I met.

   I created 2 records( Record 1: CONFIG_FILE1 (0xF010), REC_KEY_1 (0x7010), 

                                    Record 2:CONFIG_FILE2 (0xF0A0),REC_KEY_2 (0x70A0))

  

  It shows initial state after created 2 records in below image.

      

  I updated content of second record. It looks Okay. It shows that new file is created and old 2nd one is invalidated in images below.

And, I updated contents of first file. Image below shows new file is created and old 1st one is invalidated.

But, After It is updated 1st file,  It couldn't find 2nd file, even though it still exist as image below.

I use fds_record_find() to find record. In my code, If record is not exist, it creates new one. so another new one is created as below.

Do I miss something? Is there any special way to manage multiple record in FDS?

Please help me to resolve this issue.

Thanks,

   Chongchun Moon

Parents
  • Hi,

    fds_record_find() should return the record if it's available. Could you share the code for your project?

    Best regards

    Jared

  • Hello,

     Yes, I also expected it should find the record if it it's available.  

     Here is my code in my project.

         

    static void fds_initialize()
    {
        ret_code_t err_code;
        
        NRF_LOG_INFO("fds_initialize");
    
        /* Register first to receive an event when initialization is complete. */
        (void) fds_register(fds_evt_handler);
    
        err_code = fds_init();
        APP_ERROR_CHECK(err_code);
    
        /* Wait for fds to initialize. */
        wait_for_fds_ready();
    
        fds_stat_t stat = {0};
    
        err_code = fds_stat(&stat);
        APP_ERROR_CHECK(err_code);
        
        fds_record_desc_t desc = {0};
        fds_find_token_t  tok  = {0};
    
        if(stat.dirty_records >100)
        {
            err_code = fds_gc();
            APP_ERROR_CHECK(err_code);
        }
    
        err_code = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);
    
        if (err_code == FDS_SUCCESS)
        {
            /* A config file is in flash. Let's update it. */
            fds_flash_record_t config = {0};
    
            /* Open the record and read its contents. */
            err_code = fds_record_open(&desc, &config);
            APP_ERROR_CHECK(err_code);
    
            /* Close the record when done reading. */
            err_code = fds_record_close(&desc);
            APP_ERROR_CHECK(err_code);
            NRF_LOG_INFO("dev record found!!");
        }
        else
        {
            /* System config not found; write a new one. */
            //NRF_LOG_INFO("Writing config file...");
    
            err_code = fds_record_write(&desc, &m_dev_record);
            APP_ERROR_CHECK(err_code);
        }
        
        //2nd record
        err_code = fds_record_find(CART_CONFIG_FILE, CART_REC_KEY, &desc, &tok);
    
        if (err_code == FDS_SUCCESS)
        {
            /* A config file is in flash. Let's update it. */
            fds_flash_record_t config = {0};
    
            /* Open the record and read its contents. */
            err_code = fds_record_open(&desc, &config);
            APP_ERROR_CHECK(err_code);
    
            /* Close the record when done reading. */
            err_code = fds_record_close(&desc);
            APP_ERROR_CHECK(err_code);
            
            asm("NOP");
            NRF_LOG_INFO("record found~~");
        }else {
            err_code = fds_record_write(&desc, &m_cart_record);
            APP_ERROR_CHECK(err_code);
            asm("NOP");
            NRF_LOG_INFO("write new~~");
        }
    }

      Thanks,

          Chongchun Moon

  • Hi,

    Are you using a Custom board? I tried modifying the main file in the flash_fds example similarly to you and fds_record_find() found both records after they had been created and saved in flash. Could you try initializing desc and tok again, before you call the fds_record_find()?

    Best regards

    Jared 

Reply Children
Related