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.

  • Are you using resident memory for the data source you provide to pstorage? No copy of data is made, hence it is required that 'test_data' contains valid data when flash write is actually executed.

    Is it also possible for you to use nrfjprog to dump the flash page being used? Flash page being used for your registered module will be flashhandle.block_id.

  • A related problem is debugger flash caching:

    If your pstorage_sys_event_handler receives an NRF_SUCCESS on the write operation, but the debugger claims that the flash area still unwritten, make sure the debugger isn't caching the old values.

    I'm using Segger J-Link over SWD, and the solution was to uncheck ☐ Allow caching of flash contents in the J-Link Control Panel (can be found in the system tray during debugging, if using Windows).

    Note: This is not the solution to OP's problem, since he is checking the result using pstorage_load. I'm leaving this here since it is one of the first Google hits for the search terms I was using.

Related