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

FDS lifetime

Hi, I use SDK13.1 FDS example and have some questions about that. Is there any influence about the lifetime of Flash when i use FDS function to write and delete the records.If it has,how to calculate the lifetime of Flash.Thanks.

  • Hi,

    The flash in the nRF52 series should tolerate minimum 10,000 write/erase cycles (specs) and the FDS library has a basic wear leveling mechanism to avoid wearing down the flash too soon. The lifetime of the flash depends on how much flash you allocate to the FDS library. Say for example that you only allocate one single page. Then old data will have to be overwritten much sooner than if you allocated e.g. 5 pages, effectively reducing the lifetime. Note also that the FDS records has some overhead.

    Bottom line; assign as many pages you can to the FDS library, and try to minimize the effect of the overhead by storing as much data as you can in each record. In the end, how long your flash will last depends on your implementation and is hard to calculate without intimate knowledge of your application.

  • Hi,Martin,

    1. How can i write records in allocate Flash circularly by using FDS library?

    2. How can i get the status when the allocate is full?

    3. I write some code to deal with the proplem,is there any question about that?

      ret_code_t m_fds_write(uint16_t FileID,uint16_t RecordKey,uint32_t *rec_data,uint16_t length) { ret_code_t ret; fds_record_desc_t record_desc; fds_record_t fds_record; fds_find_token_t ftok = {0};
      fds_record_chunk_t record_chunk = {.p_data = (void *)rec_data, .length_words = length,};

       fds_record.file_id = FileID;
       fds_record.key     = RecordKey; 
       fds_record.data.p_chunks   = &record_chunk;
       fds_record.data.num_chunks = 1;
       WRITE_AGAIN:
       ret = fds_record_find(fds_record.file_id, fds_record.key, &record_desc, &ftok);     
       NRF_LOG_INFO("FDS Write Start(0x%04X)>>\r\n", ret);     
       if( ret == FDS_ERR_NOT_FOUND )
       {
       	ret = fds_record_write(&record_desc, &fds_record);
       }
       else
       {
       	ret = fds_record_update(&record_desc, &fds_record);
       }
      
       switch (ret)
       {
       	case FDS_SUCCESS:
       		while( m_fds_write_flag == false );
       		m_fds_write_flag = false;   
       		return NRF_SUCCESS;
      
       	case FDS_ERR_BUSY:
       	case FDS_ERR_NO_SPACE_IN_QUEUES:
       		return NRF_ERROR_BUSY;
      
       	case FDS_ERR_NO_SPACE_IN_FLASH:
       		ret = fds_gc();
       		if (ret)
       					{
       			NRF_LOG_ERROR("fds_gc fail: %d\n", ret);
       			return ret;
       		}    
       		goto WRITE_AGAIN;
       		return NRF_ERROR_STORAGE_FULL;
      
       	default:
       		return NRF_ERROR_INTERNAL;
       }       
      
       NRF_LOG_INFO("FDS write successfully\r\n");
       return ret;
      

      }

  • Q1. The FDS library handles this for you.

    If the flash is full you get the FDS_ERR_NO_SPACE_IN_FLASH error when trying to write to flash. In your code it seems like you are trying to handle this error by running a garbage collection, which is what you should do. However, fds_gc() is an asynchronous functions and you should wait for the FDS callback (as you do in the FDS_SUCCESS case) before trying to write again.

  • I get the FDS_ERR_NO_SPACE_IN_FLASH error when trying to write to flash, then call fds_gc() ,the FDS callback return FDS_SUCCESS ,but when i write to flash again,still FDS_ERR_NO_SPACE_IN_FLASH ,why?

  • Probably becase you don't have space in flash.

Related