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

pstorage_store problem

Hi, I'm using nrf51822 board with SDK 10 and S110 softdevice. My application is based on uart over ble. It take 20 bytes data from a android device using nus, store that data and send a reply to the android that data is stored. First time when I store some data using pstorage_store(), It is stored successfully. Now second time I want to clear that data and store some new in place of that, so I first call pstorage_clear() and then again pstorage_store(). Now the problem arrived here, second time first 4 bytes becomes 0x0 and then remaining is my data. for example if my data is 12345678, it becomes like 00005678. I dont know what is going here. I'm using pstorage function like this and my function is defined in a pstorage_lock.c which is attached here. Please help me in this.

if(!pstorage_erase(0, 32))
{
	if(!pstorage_write(my_data, 0, 32))
	{
	 // some operation to do here
	}
}

my_data is an 20 bytes array in which data comes from android using nus.

Thanks. Amit

pstorage_lock.c

Parents
  • Hi Amit,

    Thank you for providing more information! That made it much easier to see what you are doing and what may solve the issues.

    Putting in an nrf_delay_ms(100) is not enough to be sure the clear operation in pstorage_erase() completes successfully. Rather, you must wait for the event callback and check the result of the operation (i.e. that result is NRF_SUCCESS in the PSTORAGE_CLEAR_OP_CODE case. of pstorage_cb_handler())

    The same goes for your other pstorage functions.

    I see that you have commented out a previous attempt using pstorage_wait_flag to signal that the operation is finished. You should do two more things in order for this to work: First, you should also signal whether the operation was successful, and handle the "unsuccessful" case. Second, you should make sure that pstorage_wait_flag is declared using the volatile keyword, to ensure that it is read from and written to memory each time it is used. If not declared volatile the value may be stored only in CPU registers, and in the worst case it is optimised away entirely.

    Regards, Terje

  • I commented pstorage_wait_flag because I did not receive the callback.

Reply Children
No Data
Related