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.