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

FDS file_ID and key_ID

Hello, i am trying to store a lot of informations in the flash in order to do this i separated my data in several arrays. I want to store all my arrays in with the same file_ID and different key_ID in the FDS. 

I use this funtion to update the data in the flash

uint32_t m_env_flash_meas_store(const m_meas_temp_t * p_data,uint16_t key)
{
	
    uint32_t            err_code;
    fds_record_t        record;
    fds_record_chunk_t  record_chunk;

    NRF_LOG_DEBUG("Storing measurements...\r\n");

    NULL_PARAM_CHECK(p_data);

    memcpy(&m_meas.data.meas_data, p_data, sizeof(m_meas_temp_t));
    m_meas.data.valid = ENV_FLASH_CONFIG_VALID;

    // Set up data.
    record_chunk.p_data         = &m_meas;
    record_chunk.length_words   = sizeof(m_env_flash_meas_t)/4;
    // Set up record.
    record.file_id              = ENV_FILE_MEAS_ID;
    record.key                  = key;
    record.data.p_chunks        = &record_chunk;
    record.data.num_chunks      = 1;
		
    err_code = fds_record_update(&m_record_meas_desc, &record);
		if (err_code == FDS_ERR_NO_SPACE_IN_FLASH)
		{
				//m_pending_gc = true;
				//err_code = fds_gc();
		}
    RETURN_IF_ERROR(err_code);
    
    return NRF_SUCCESS;
}

unfortulately when i write with the same file_ID and the different key it invalidates all the others records with the same key and they are deleted, do you know where this issue could come from ?

Parents
  • ok i found a solution now the write function looks like this : 

    uint32_t m_env_flash_meas_store(const m_meas_temp_t * p_data,uint16_t key)
    {  
    	fds_record_t record = {0};
      fds_record_desc_t record_desc = {0};
      fds_record_chunk_t record_chunk = {0};
      fds_find_token_t ftok = {0};
    		
    	m_fds_update_success = false;
    	
    	 record_chunk.p_data = p_data;
      record_chunk.length_words = sizeof(m_env_flash_meas_t)/4;;
    
      record.file_id = ENV_FILE_MEAS_ID;
      record.key = key;
      record.data.p_chunks = &record_chunk;
      record.data.num_chunks = 1;
    
      ret_code_t err_code = fds_record_find(ENV_FILE_MEAS_ID, key, &record_desc, &ftok);
    
    	if (err_code == FDS_SUCCESS) {
        NRF_LOG_INFO("Record Exist\r\n");
        err_code = fds_record_update(&record_desc, &record);
      } 
    	else if (err_code == FDS_ERR_NOT_FOUND) 
    	{
        NRF_LOG_INFO("Record Does Not Exist\r\n");
        err_code = fds_record_write(&record_desc, &record);
      }
    
      if (err_code != FDS_SUCCESS) 
    	{
        if (err_code == FDS_ERR_NO_SPACE_IN_FLASH) 
    		{
          NRF_LOG_INFO("No Space in Flash\n");
        } 
    		else 
    		{
          NRF_LOG_INFO("fds_record_write fail: %d\n", err_code);
        }
        return err_code;
      }
    	
    	while(!m_fds_update_success)
    	{
    			app_sched_execute();
    	}
    	NRF_LOG_INFO("flash updated\r\n");
    	
    	
      return NRF_SUCCESS;
    }

    I would like to make the function a blocking one this is why i added this code : 

    while(!m_fds_update_success)
    {
              app_sched_execute();
    }

    After launching the code it stays stuck in the while loop, the flag is changed in the fds_event_handler : 

    case FDS_EVT_UPDATE:
    if (p_fds_evt->result == FDS_SUCCESS)
    {
                 m_fds_update_success = true;
    }

    break;

    whithout the while loop the flag is changed, do you know how i can resolve this ?

  • Hi,

    In what interrupt context/priority are you calling m_env_flash_meas_store()?

Reply Children
  • Hello, sorry for the late answer, how can i know the context/priority of a function ?

    I found a way to update the flash anyway, i make the function a not blocking one and it works fine.

    I still sometimes get an error in the m_env_flash_meas_store(), i receive FDS_SUCCESS when i find the record then i get FDS_SUCCESS when i start the update but when the event FDS_UPDATE occurs it is linked with the error NRF_INVALID_FLAGS (FDS_ERR_NOT_FOUND).

    I use the bluetooth and the flash in my code and sometimes at the same time, do you think the error come from here ?

  • Hi,

    Albin said:
    I still sometimes get an error in the m_env_flash_meas_store(), i receive FDS_SUCCESS when i find the record then i get FDS_SUCCESS when i start the update but when the event FDS_UPDATE occurs it is linked with the error NRF_INVALID_FLAGS (FDS_ERR_NOT_FOUND). I use the bluetooth and the flash in my code and sometimes at the same time, do you think the error come from here ?

    No, this means that the old copy was not found. The first step of updating a record consists of locating the copy to be deleted. If the old copy couldn't be found for any reason, then the update will fail. This prevents duplicates when queuing multiple updates of the same record.

Related