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?

  • I think that it's just the description of capability of Persistent Storage Module interface, but for now SDK implementation is not supporting this functionality.

  • Hi!

    After trying to use that same solution which worked before in another project, I discovered a problem with getting NRF_ERROR_INVALID_LENGTH error code as a result of:

    retval = pstorage_update(&block_handle, shutter_state, 4 , 0);
    

    shutter_state is declared as:

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

    and initialized as:

    		shutter_state[FULL_MOVE_UP_COUNT_EE_POS] 	= s->fullMoveUpCount;
    	shutter_state[FULL_MOVE_DOWN_COUNT_EE_POS] = s->fullMoveDownCount;
    	shutter_state[CURRENT_POSITION_EE_POS] 		= s->currentPosition;
    	shutter_state[DESIRED_POSITION_EE_POS] 		= 0;
    

    What can cause that error?

    Thanks!:)

  • What if you try to call pstorage_update() at the beginning in the main at initialization? NRF_ERROR_INVALID_LENGTH error can only be returned from sd_flash_write() and I don't know what can be the problem.

  • Hi!

    That's wired, but it works when I use it on before load_stored_data. When I moved it (exactly that same function) to another part of program it stopped working.

    What can cause it?

    Thanks, Patriko

  • Now I recognized that the problem occurs only when the function pstorage_update is called from function declared in another file, so probably there is something wrong with data structure declaration.

    I've all variables associated with pstorage declared in "data_structure.h" included in both files.

    data_strtucture.h contains:

    #include "pstorage.h"
    static pstorage_handle_t persistant_memory_handle;
    static uint32_t retval;
    static pstorage_handle_t block_handle;
    
    static uint8_t shutter_state[4] __attribute__((aligned(4)));
    
    #define FULL_MOVE_UP_COUNT_EE_POS			0
    #define FULL_MOVE_DOWN_COUNT_EE_POS		1
    #define CURRENT_POSITION_EE_POS				2
    #define DESIRED_POSITION_EE_POS				3
    

    So it should work from both files, shouldn't it?

Related