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

pstorage reading other values than writing

Hi!

Maybe I'm doing something wrong (very possible), but for example, when I want to store array of 3 uint8_t values I use:

uint8_t dataToStore[3];
dataToStore[0] = 11;
dataToStore[1] = 22;
dataToStore[2] = 33;

retval = pstorage_store(&block_handle, dataToStore, 3 , 0);
	if (retval == NRF_SUCCESS)
	{
			// Store successfully requested. Wait for operation result.
	}
	else
	{
			// Failed to request store, take corrective action.
	}

and when I want to read it from the memory to variable I use:

   retval = pstorage_block_identifier_get(&persistant_memory_handle, 0, &block_handle);
	if (retval == NRF_SUCCESS)
	{
		uint8_t           dest_data[3];
		 //Request to read 3 bytes from block at an offset of 0 bytes.
		retval = pstorage_load(dest_data, &block_handle, 3, 0);
		if (retval == NRF_SUCCESS)
		{
                         // here dest_data should be: 11, 22, 33 but it gets different values.
		}
		else
		{
				// Failed to load, take corrective action.
		}

Received value is always different than stored. What can be the reason?

    1. pstorage_update function can be called on clear place. In case on pstorage_update it's the same what I described in (2.) , but you don't need to temporary store your data in buffer before clearing manually, it'll be done inside pstorage_update operation.
  • Thanks for clarification. Just a (hopefully) last question. If i want to store block 1 of module a, i have to clear block 1, and then i can store block 1 again. Or do i really have to clear the whole allocated memory of module a?

  • You need to clear all the allocated memory of module, read in the link above: Clear operation results in clearing all storage blocks allocated to the application. Clearing a single storage block or certain blocks is not implemented. The size parameter of pstorage_clear is currently unused, any value provided will not have any impact on the behaviour of this API.

  • Thank you! It solved the problem :)

  • Hm.. now i read it, thanks.. But what does the third point mean? "- When using the clear operation the Persistent Storage Manager will use a swap area to conserve the blocks not affected. The data page backed up in the swap area, the data page is erased, the non affected blocks are copied back." So, it deletes the whole content, but it writes back the not affected blocks? Thanks a lot.. i was wondering why it didn't work.

Related