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

Incorrect read from fds

I have used online fds example code to store and read values from flash. I can store the data without any problem. I am storing static uint8_t array[8] = {1,2,3,4,5,6,7,8}.

I've tried reading the data in two different ways:

The first was based on code I read online, but seems to corrupt the data somehow:

void read_flash_data() {
	fds_flash_record_t  flash_record;
	fds_record_desc_t   record_desc;
	fds_find_token_t    ftok;
	memset(&ftok, 0, sizeof(fds_find_token_t));
	while (fds_record_find(0x1111, 0x2222, &record_desc, &ftok) == FDS_SUCCESS)
	{
		if (fds_record_open(&record_desc, &flash_record) != FDS_SUCCESS)
		{
			// Handle error.
			NRF_LOG_DEBUG("Error opening flash record!");
		}
		uint8_t *data = (uint8_t *) flash_record.p_data;
		if (fds_record_close(&record_desc) != FDS_SUCCESS)
		{
			NRF_LOG_DEBUG("Error closing flash record!");
		}
	}
}

I set a breakpoint after *data is initialized and read that value. It's a pointer to the flash memory address 0x7e024, and examining in gdb with x /8b data gives me 0x7e024: 0x01 0x02 0x03 0x04 0x22 0x22 0x01 0x00, which is not the data I stored (but interestingly the first half is correct).

void read_flash_data() {
	fds_flash_record_t  flash_record;
	fds_record_desc_t   record_desc;
	fds_find_token_t    ftok;
	memset(&ftok, 0, sizeof(fds_find_token_t));
	while (fds_record_find(0x1111, 0x2222, &record_desc, &ftok) == FDS_SUCCESS)
	{
		
	}
	if (fds_record_open(&record_desc, &flash_record) != FDS_SUCCESS)
	{
		// Handle error.
		NRF_LOG_DEBUG("Error opening flash record!");
	}
	uint8_t *data = (uint8_t *) flash_record.p_data;
	if (fds_record_close(&record_desc) != FDS_SUCCESS)
	{
		NRF_LOG_DEBUG("Error closing flash record!");
	}
}

Again, I set a breakpoint after *data is initialized. It's a pointer to the flash memory address 0x7e880, and examining in gdb with x /8b data gives me 0x7e8a8: 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08, which is the correct data that I stored.

My questions:

  1. Why am I not getting the correct data in the first approach?
  2. What are the problems with the second approach? I imagine all of the code I've read online follows the first approach for a reason.

Many thanks.

SDK13 PCA10040 nRF52832

Parents Reply Children
No Data
Related