This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

fds_record_find returns files that do not exist

Hi

I'm trying to use fds_record_find() to detect if a record exists in flash storage. After erasing the device (via nrfjprog), flashing the softdevice, flashing the program, and calling fds_file_delete(my_file_id), fds_record_find(my_file_id, my_record_key, &record_desc, &ftok) still returns a record with my_file_id and my_record_key. Am I not actually deleting the flash files, or is fds_record_find() finding records that don't actually exist? I think it's the latter because I can change my_file_id and my_record_key to values that have never been used before, and fds_record_find() still finds a record.

Related question: I know that fds_file_delete() is an asynchronous event. Does it produce an event when it successfully finishes a delete (FDS_EVT_DEL_FILE ?)? If so, where can I receive this event? Perhaps it's possible that fds_record_find() is finding a record before fds_record_delete() deletes it?

thanks

SDK14

  • If you have truly erased the chip, the flash would be cleared and there would be no records. So calling fds_file_delete() would be ineffective and there would be no records to find. If you didn't erase the chip, a successful fds_file_delete() would also prevent you from being able to find a record with that FILE_ID, even if you didn't use gc since the library marks the file as unavailable. The nRF will predominantly find a record faster than it can be deleted due to the asynchronous nature of deleting so you need to use a flag when calling fds_file_delete() that is then cleared in the fds_evt_handler before calling fds_record_find(). Something like this:

    static void my_fds_evt_handler(fds_evt_t const * const p_fds_evt)
    {
        switch (p_fds_evt->id)
        {
            case FDS_EVT_DEL_FILE:
                if (p_fds_evt->result == FDS_SUCCESS)
                {
    		        write_flag=1;
                }
                break;
    
            default:
                break;
        }
    }
    
  • Thanks. I was calling fds_record_find() almost immediately after power up. After waiting a couple seconds and calling the function as I normally would during operation, it functioned normally. I don't know if the early call to fds_record_find() exposed a bug in fds, or (probably more likely) moving the call changed something else in my code. Either way it works now.

Related