i continue my experiments with Persistent Storage and that's my results:
Case #1: I'm trying to store data, wait while my PS will be ready to read this data and try to read it, here is my code in main():
wait(5);
serial.printf("Warming up\r\n");
wait(5);
retval = pstorage_init();
if(retval == NRF_SUCCESS)
{
serial.printf("Module initialization successful\r\n");
pstorage_module_param_t param;
param.block_size = 100;
param.block_count = 10;
param.cb = example_cb_handler;
retval = pstorage_register(¶m, &handle); //register our pstorage and store store address in handle
if (retval == NRF_SUCCESS)
{
serial.printf("Registration successful.\r\n");
serial.printf("Module id: %u , block: %u \r\n", handle.module_id, handle.block_id);
retval = pstorage_store(&handle, source_data, sizeof(source_data), 0); //store test data in bloc 0
if (retval == NRF_SUCCESS)
{
serial.printf("Store successfully requested. Wait for operation result.\r\n");
savetime = time(NULL);
}
else {serial.printf("Failed to request store, take corrective action.\r\n");}
}
else {serial.printf("Failed to register, take corrective action.\r\n");}
}
else {serial.printf("Initialization failed, take corrective action.\r\n"); }
while (true) {
pstorage_access_status_get(&count);
if (count == 0)
{
loadtime = time(NULL);
serial.printf("No pending operations, time div: %d \r\n", (loadtime-savetime) );
retval = pstorage_load(dest_data, &handle, sizeof(dest_data), 0); //try to load test data
if (retval == NRF_SUCCESS)
{
serial.printf("STORE: %02x:%02x:%02x:%02x - %02x:%02x:%02x:%02x \r\n", source_data[0], source_data[1], source_data[2], source_data[3],source_data[4], source_data[5], source_data[6], source_data[7] );
serial.printf("LOAD: %02x:%02x:%02x:%02x - %02x:%02x:%02x:%02x \r\n", dest_data[0], dest_data[1],dest_data[2],dest_data[3], dest_data[4],dest_data[5],dest_data[6],dest_data[7] );
}
else {
serial.printf("Failed to load, take corrective action.\r\n");
}
break;
}
else
{
serial.printf("Storage access pending, wait!\r\n");
}
wait(1);
}
And here is the result of this code:
Warming up
Module initialization successful
Registration successful.
Module id: 0 , block: 260096
Store successfully requested. Wait for operation result.
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
Storage access pending, wait!
....
i'm waiting for 10 minutes... Storage access pending, wait!
Case #2: I'm trying to store data and then i add my load code in BLE Connection Callback, so i wait some time and try to connect to my BLE - on connection try to load data:
void connectionCallback(const Gap::ConnectionCallbackParams_t *params)
{
serial.printf("BLE Connected!\r\n");
pstorage_access_status_get(&count);
if (count == 0)
{
loadtime = time(NULL);
serial.printf("No pending operations, time div: %d \r\n", (loadtime-savetime) );
retval = pstorage_load(dest_data, &handle, sizeof(dest_data), 0); //try to load test data
if (retval == NRF_SUCCESS)
{
serial.printf("STORE: %02x:%02x:%02x:%02x - %02x:%02x:%02x:%02x \r\n", source_data[0], source_data[1], source_data[2], source_data[3],source_data[4], source_data[5], source_data[6], source_data[7] );
serial.printf("LOAD: %02x:%02x:%02x:%02x - %02x:%02x:%02x:%02x \r\n", dest_data[0], dest_data[1],dest_data[2],dest_data[3], dest_data[4],dest_data[5],dest_data[6],dest_data[7] );
}
else {
serial.printf("Failed to load, take corrective action.\r\n");
}
}
else
{
serial.printf("Storage access pending, wait!\r\n");
}
}
And here is the result for this case:
Warming up
Module initialization successful
Registration successful.
Module id: 0 , block: 260096
Store successfully requested. Wait for operation result.
BLE Connected!
Storage access pending, wait!
BLE Disconnected!
BLE Connected!
Storage access pending, wait!
BLE Disconnected!
Ammm, I'm confused, I do not know what to do and why storage is not working :(
I have to store some settings and data in persistent storage using my device, but can't do it using mbed USBMSD or LocalFileSystem – https://developer.mbed.org/forum/mbed/topic/16571/.
But nRF51 has the pstorage(more about this API here: https://developer.nordicsemi.com/nRF51_SDK/nRF51_SDK_v8.x.x/doc/8.1.0/s110/html/a00168.html#pstorage_init)
So i've tried to implement it in mbed and have this results:
BUT! I've tried to store 8 bytes, and operations was successful
then i tried load this 8 bytes, and operations was successful again:
but: source_data =! dest_data :( my dest_data was like {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
So! my questions are: