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

[PCA10040][SDK11] FDS unable to read [closed]

Hi

I have been able to successfully write using FDS but I'm unable to read back using the same keys. Here are my code snippets:

#define FILE_ID					0x1111
#define REC_START_ID			0x2222
uint32_t rec_count	= 0;

static void fds_timer_timeout_handler(void * p_context)
{
fds_record_t		record;
fds_record_desc_t	record_desc;
fds_record_chunk_t	record_chunk;

uint8_t temp[4] = {0,1,2,3};

record_chunk.length_words 	= 1;
record_chunk.p_data			= temp;

record.file_id		= FILE_ID;
record.key			= REC_START_ID+rec_count;
record.data.p_chunks = &record_chunk;
record.data.num_chunks = 1;

++rec_count;

ret_code_t	ret = fds_record_write(&record_desc, &record);

if(ret != FDS_SUCCESS)
{
	debug("[FDS] Write record fail, err_code: %d\n", ret);
	if(ret == FDS_ERR_NO_SPACE_IN_FLASH)
	{
		debug("max number of records %d\n", rec_count);
		nrf_delay_ms(100000);
	}
}

debug("[FDS] Writing Record key %d\n", REC_START_ID+rec_count-1);

if(rec_count == 10)
{
	app_timer_stop(m_fds_test_timer);
	debug("start reading data\n");
	for(int i=0; i<rec_count; i++)
	{
		fds_flash_record_t				flash_record;
		fds_record_desc_t				read_record_desc;
		fds_find_token_t				ftok;

		debug("[FDS] Looking for record id %d\n", REC_START_ID+i);
		ret_code_t	err_code = fds_record_find(FILE_ID, REC_START_ID+i, &read_record_desc, &ftok);
		if(err_code == FDS_SUCCESS)
		{
			if(fds_record_open(&read_record_desc, &flash_record) == FDS_SUCCESS)
			{
				uint8_t * data;
				data = (uint8_t *)flash_record.p_data;
				debug("[FDS] found record id %d\n", read_record_desc.record_id);
				for(int i=0; i<flash_record.p_header->tl.length_words; i++)
				{
					debug("[FDS] Data is 0x%8x \n", data[i]);
				}
			}
			else
			{
				debug("[FDS] Opening record failed\n");
			}

			if(fds_record_close(&read_record_desc) == FDS_SUCCESS)
			{
				debug("[FDS] Closing record success\n");
			}
			else
			{
				debug("[FDS] Closing record failed\n");
			}
		}
		else
		{
			debug("[FDS] Could not find the record, err_code: %d\n", err_code);
		}
	}
}
}

static void fds_evt_handler(fds_evt_t const * const p_fds_evt)
{
switch(p_fds_evt->id)
{
	case FDS_EVT_INIT:
		if(p_fds_evt->result != FDS_SUCCESS)
		{
			debug("[FDS] Initialization Failed, error: %x\n", p_fds_evt->result);
		}
		debug("[FDS] Initialization Success\n");
		break;

	case FDS_EVT_WRITE:
		if(p_fds_evt->result != FDS_SUCCESS)
		{
			debug("[FDS] Write Failed, error: %x\n", p_fds_evt->result);
		}
		else
		{
			debug("[FDS] Write Successful and record id is %d\n",p_fds_evt->write.record_id);
		}
		break;

	case FDS_EVT_GC:
		break;

	case FDS_EVT_DEL_FILE:
		debug("[FDS] File deleted successfully\n");
		break;

	default:
		break;
}
}

Thanks in advance :)


[EDIT]

Here is the main file of code main.c


[EDIT]

I've removed the timer but still I'm getting the same problem. I've modified the main.c file to wait till the file is deleted. main.c

Here is my debug output:

start.....
[FDS] Initialization Success
[FDS] Deleting File
[FDS] Writing Record key 8738
[FDS] File deleted successfully
[FDS] Write Successful and record id is 4066 start reading data [FDS] Looking for record id 8738 [FDS] Could not find the record, err_code: 10

Related