This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

pstorage can't work with SD7 and SDKV6 ?

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(&param, &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

Parents
  • Pstorage library works asynchronously. When pstorage_x functions return true, it says that the task is queued, not done. When a task is done, the storage_cb_handler callback is called with op_code parameter to specify which kind of task has been done.

    Also, because PStorage is asynchronous, your data to store MUST BE gobal. Else, it is possible that your are no longer in the same context of your data and the memory would be reallocated for others things.

    As John DeWitt specifies in comment, pstorage_load is not asynchronous because is is just a memory reading with some check before.

    Also, nrf_delay_ms function use 99% of the CPU. Therefore, your are waiting the number of ms you want wait, but almost nothing can be done during this time.

  • The one thing I would add to this answer is that pstorage_load is not asynchronous, it is a straight up memcpy call.

Reply Children
No Data
Related