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

Nordic 51822, SDK5.0.0 and SD6.0.0, pstorage not work?

Hi, I am using pstorage to store and read back data in Nordic 51822 platform, with SDK5.0.0 and SD6.0.0, here is the code how I use the 'pstorage application':

				// Initialize pStorage & Clear if first boot
				retval = pstorage_init();
				if (retval == NRF_SUCCESS){
					//Module initialization successful
				}
				else {
					//Initialization failed, take corrective action
				}
				
				// pStorage registration
				retval = pstorage_register(&flashparam, &flashhandle);
				if (retval == NRF_SUCCESS){
					//Module initialization successful
				}
				else {
					//Initialization failed, take corrective action
				}
		
				retval = pstorage_clear(&flashhandle, 512*100);
				if (retval == NRF_SUCCESS){
					//Module initialization successful
				}
				else {
					//Initialization failed, take corrective action
				}
				
				// Get block handle
				retval = pstorage_block_identifier_get(&flashhandle, 0, &flash_block_handle);
				if (retval == NRF_SUCCESS){
					//Module initialization successful
				}
				else {
					//Initialization failed, take corrective action
				}
				
				// Use pstorage to store data
				uint8_t test_data[4] = {0x01,0x02,0x03,0x04};
				retval = pstorage_store(&flash_block_handle, test_data, 4, 0);
				if (retval == NRF_SUCCESS){
					//Module initialization successful
				}
				else {
					//Initialization failed, take corrective action
				}
				
				// Use pstorage to load data, for test check
				// Get block handle
				retval = pstorage_block_identifier_get(&flashhandle, 0, &flash_block_handle);
				if (retval == NRF_SUCCESS){
					//Module initialization successful
				}
				else {
					//Initialization failed, take corrective action
				}
				
				uint8_t load_data[4];
				retval = pstorage_load(load_data, &flash_block_handle, 4, 0);
				if (retval == NRF_SUCCESS){
					//Module initialization successful
					if ((load_data[0] == 0x01)&(load_data[1] == 0x02)&(load_data[2] == 0x03)&(load_data[3] == 0x04))
					{
						//BlinkLED(2,500,500);
					}
				}
				else {
					//Initialization failed, take corrective action
				}

The problem is: all the returned value from pstorage function gives me 'retval == NRF_SUCCESS', but the load_data read from flash is always {0xFF, 0xFF, 0xFF, 0xFF}, not the right values I wrote in.

Also another observation is, when use the function 'flash_page_erase' to erase all the flash content, it takes couple seconds to finish, but when use the pstorage_clear, it finishes very fast and gives me the successful feedback through handler, so I wonder if the pstorage API actually works or not? Or the way I use it is wrong?

If I want to store and readback data in 51822 with BLE working, what's the best way to do this? use pstorage or directly use the ble_flash.c API?

Thanks.

  • Hi,

    Couple of things to know before getting to specifics:

    a. Earlier flash_page_erase API was a blocking API, however, flash operations have now been moved to SoftDevice and are non blocking. Therefore even though the API returns immediately with a success, the operation is not complete unless an event is received from SoftDevice.

    b. PStorage API aim to to provide a consistent interfacing to any flash operation and do not access the flash itself. In the current one, it makes of SoftDevice API to have data stored persistently. Therefore, it is important that SoftDevice is enabled in order to access flash for PStorage to work as expected.

    c. Lastly, SoftDevice has restriction of permitting only one flash operation at a time. PStorage hence implements a queue which is serviced when SoftDevice notifies flash access to be complete. Hence, it is important 'pstorage_sys_event_handler' is called from system event dispatcher of the application. And it is very important that application registers to receive system event using 'softdevice_sys_evt_handler_set' API.

    Now getting to specifics, can you confirm that you are: a. Enabling SoftDevice and registering to receive System events? b. Ensuring that the system events are being dispatched to the PStorage module? c. Receiving events notifying the application of clear and store operations being successful apart API returning a success? Note: Load operation does not need any events and data is returned immediately to the application.

  • a. Enabling SoftDevice and registering to receive System events? Yes. I followed the heart rate example, enabled SD, also registered system evt and called 'pstorage_sys_event_handler' from system evt dispatcher. b. Ensuring that the system events are being dispatched to the PStorage module? Yes. c. Receiving events notifying the application of clear and store operations being successful apart API returning a success? Note: Load operation does not need any events and data is returned immediately to the application. Yes, I initialized a handler for operation completion notification. After I got the successful clear completion notification, store some data; after I got the successful store notification, load some data, but the data from pstorage_load is still all '0xFF'.

  • Hi again,

    I sit possible to confirm that you are issuing pstorage_load once you have received a successful event for 'store' operation? Else you would be reading stale data. Thanks!

  • I am having similar issues. Do you have a sample application that uses pstorage_load.

  • Yes, I wait for a successful event for 'store' operation, then load the data, but always '0xFF'

Related