I want use pstorage write and erase flash,as shown below:
//pstorage_init(); // device_manager_init have been called,so there's no need to call
err_code = pstorage_register(¶m, &wk_storage_handle);
if (err_code == NRF_SUCCESS)
{
wk_printfn(WK_DEBUG_LEVEL_INFO, "pstorage_register success!!");
}
else
{
wk_printfn(WK_DEBUG_LEVEL_INFO, "pstorage_register failed, err_code=0x%x!!", err_code);
return;
}
retval = pstorage_block_identifier_get(&wk_storage_handle, 0, &block_handle);
if (retval != NRF_SUCCESS)
{
wk_printfn(WK_DEBUG_LEVEL_INFO, "pstorage_block_identifier_get");
return;
}
wk_printfn(WK_DEBUG_LEVEL_INFO, "bid=0x%x, mid=0x%x",block_handle.block_id, block_handle.module_id );
#if 1
retval = pstorage_clear(&block_handle, 0x400);
if (retval != NRF_SUCCESS)
{
wk_printfn(WK_DEBUG_LEVEL_INFO, "pstorage_clear");
return;
}
#endif
nrf_delay_ms(1000);
retval = pstorage_block_identifier_get(&wk_storage_handle, 0, &block_handle);
retval = pstorage_load(dest_data, &block_handle, sizeof(dest_data), 0);
if (retval != NRF_SUCCESS)
{
wk_printfn(WK_DEBUG_LEVEL_INFO, "pstorage_load");
return;
}
nrf_delay_ms(1000);
for (int i = 0; i < sizeof(dest_data) / sizeof(dest_data[0]); ++i)
{
wk_printf2n("load step 1 [%d]=0x%x", i, dest_data[i]);
}
nrf_delay_ms(1000);
for (int i = 0; i < sizeof(dest_data2) / sizeof(dest_data2[0]); ++i)
{
dest_data2[i] = i + 1;
}
retval = pstorage_block_identifier_get(&wk_storage_handle, 0, &block_handle);
retval = pstorage_store(&block_handle, dest_data2, sizeof(dest_data2), 0);
if (retval != NRF_SUCCESS)
{
wk_printfn(WK_DEBUG_LEVEL_INFO, "pstorage_store failed");
return;
}
nrf_delay_ms(1000);
retval = pstorage_block_identifier_get(&wk_storage_handle, 0, &block_handle);
retval = pstorage_load(dest_data, &block_handle, sizeof(dest_data), 0);
if (retval != NRF_SUCCESS)
{
wk_printfn(WK_DEBUG_LEVEL_INFO, "pstorage_load failed");
return;
}
nrf_delay_ms(1000);
for (int i = 0; i < sizeof(dest_data) / sizeof(dest_data[0]); ++i)
{
wk_printf2n("after store [%d]=0x%x", i, dest_data[i]);
}
retval = pstorage_block_identifier_get(&wk_storage_handle, 0, &block_handle);
retval = pstorage_update(&block_handle, dest_data2, sizeof(dest_data2), 0);
if (retval != NRF_SUCCESS)
{
wk_printfn(WK_DEBUG_LEVEL_INFO, "pstorage_update failed");
return;
}
nrf_delay_us(50000);
retval = pstorage_load(dest_data, &block_handle, sizeof(dest_data), 0);
if (retval != NRF_SUCCESS)
{
wk_printfn(WK_DEBUG_LEVEL_INFO, "pstorage_load failed");
return;
}
nrf_delay_us(50000);
for (int i = 0; i < sizeof(dest_data) / sizeof(dest_data[0]); ++i)
{
wk_printf2n("after update [%d]=0x%x", i, dest_data[i]);
}
my question is after pstorage_clear, i called pstorage_load and got 0XFF whith is understandable. Then i called pstorage_store to store data (like 0x1 0x2 0x3 ... )to flash, and NRF_SUCCESS return, at this time i think the data have been stored in the flash memory. but unfortunately when I call pstorage_load again found data has been 0XFF, who can tell me why? My test environment is s110_nrf51822_7.0.0_softdevice.hex and nrf51_sdk_v6_0_0_43681