This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

pstorage issues

Hi

I'm trying to use pstorage to save some info (device name, and user info). I've found the following links with examples: infocenter.nordicsemi.com/index.jsp

devzone.nordicsemi.com/.../

Which have code that looks rather straightforward. But I'm having issues, where in some cases it either can only write, or only erase and I can't figure out what is the issue. Here is my code:

Init (in main):

retval = pstorage_init();
param.block_size  = 16;
param.block_count = 1;
param.cb          = store_cb_handler;
	
pstorage_register(&param, &handle);
pstorage_block_identifier_get(&handle, 0, &block_handle);

Then at some point manually call read, write and clear functions:

Read:

retval = pstorage_load(tempstr, &block_handle, 16, 0);				
if (retval == NRF_SUCCESS)
{
	ble_nus_string_send(&m_nus, tempstr, 16);
}
else
{
    ble_nus_string_send(&m_nus, "no", 3);
}

Write:

retval =pstorage_store(&block_handle, "Tostertostost000", 16, 0);
			
if (retval == NRF_SUCCESS)
{
    ble_nus_string_send(&m_nus, "ok", 3);
}
else
{
    ble_nus_string_send(&m_nus, "no", 3);
}

Clear:

pstorage_clear(&block_handle, 16);

So if I use &block_handle clear works, and if I put just &handle then store works. What could be the issue here?

  • Oh yes, I did see it. When looking just at the basic parts, its the same thing: pstorage_init(); pstorage_register(&param, &handle); pstorage_block_identifier_get(&handle, 0, &block_0_handle); pstorage_clear(&block_0_handle, 48);
    pstorage_store(&block_0_handle, source_data_0, 16, 0); pstorage_load(dest_data_0, &block_0_handle, 16, 0);

    And that are all the pstorage functions that are being used which are the same in the code I posted above.

    Tho what really is the issue with my current solution? I'm using the limited 32k version, so I have plenty of unused space after the code segment. Can't I just access it raw if it is unused?

  • Could you explain some more what the issue is?

    "where in some cases it either can only write, or only erase "

    you are not able to read? or are you not able to do both write and erase?

    is retval not returning NRF_SUCCESS ?

    Note that page clearing/storing operation is asynchronous when softdevice is enabled, while pstorage_load() does not use the SoftDevice Flash API.

  • Yes, I am getting NRF_SUCCESS. Read always works, but its the write and clear that don't. Sometimes I could just clear what was written, but not write it again. Sometimes I could just write but not clear. When writing I could just write over the existing, until I got all zeroes in the byte which is normal operation for flash. At some point I got them both working, went away for 20 mins and when I came back one of the two was not working again. Also before I was having issues with the scope of variables that were used to forward the write data, so I ended up using a global variable since local variables did not work.

Related