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?

Parents
  • Change

    uint8_t dataToStore[3];
    

    to

    static uint8_t dataToStore[4] __attribute__((aligned(4)));
    

    Static because:

    pstorage_store

    No copy of the data is made, and hence memory provided for data source to be written to flash cannot be freed or reused by the application until this procedure is complete. End of this procedure is notified to the application using the notification callback registered by the application.

    And your buffer should be word aligned in ram.

  • Nikita - You're a legend!

    I have been beating my head on the desk as to why the persistent storage wasn't working and it was because the buffer needed to be word aligned in ram (which is not made clear in the SDK example).

    Thank you!

Reply
  • Nikita - You're a legend!

    I have been beating my head on the desk as to why the persistent storage wasn't working and it was because the buffer needed to be word aligned in ram (which is not made clear in the SDK example).

    Thank you!

Children
No Data
Related