Hi,
i am having trouble to understand and use flash to store data. First of all as far as i understand ble_flash is obsolete and replaced by the pstorage module, correct?
What i want to achieve is, i want to save user settings to flash to be able to set my system to the same state after it has been e.g. reset. Therefore i need to write, erase, read and update existing settings to/in flash.
I read the following documentation part and used it as base of my own code: devzone.nordicsemi.com/.../a00018.html
Do i need to change any addresses in pstorage_platform to match it to my application? I was not sure whether i need to change code in pstorage_platform or not so i didn't changed anything.
The coded i copied from the documentation and the code i added is shown in the file attached.
The pstorage_init is called in my init_app_data_flash_manager function and after the ble_stack_init. Futhermore pstorage_init is called only once.
// Initialize in main
leds_init();
timers_init();
gpiote_init();
buttons_init();
ble_stack_init();
init_app_data_flash_manager();
scheduler_init();
gap_params_init();
services_init();
advertising_init();
conn_params_init();
sec_params_init();
My code does the following like descibed in the documentation. I register one block with specific size (in bytes) after pstorage_init. The handle generated while registering is saved and later used to read/write to get a block_handle using pstorage_block_identifier_get. Afterwards this block handle is used to read/write using pstorage_load and pstorage_store.
To test all this I write and read to flash after my device is disconnected (see BLE_GAP_EVT_DISCONNECTED). I also stop adversting to read and write to flash so radio should be inactiv.
case BLE_GAP_EVT_DISCONNECTED:
m_conn_handle = BLE_CONN_HANDLE_INVALID;
//advertising_start();
//test_app_system_settings is empty, test data is generated in save_settings_to_flash
save_settings_to_flash(&test_app_system_settings);
read_settings_from_flash(&test_app_system_settings);
break;
When i debug it the array i read in read_settings_from_flash is empty (just zero).
Can anyone tell me what i am doing wrong and/or help me get it working?
Regards
Edit: I almost forgot the maybe most importat thing: How do I manage to read and write to the same address every time cause the address i wrote to in the first place is gone after a reset and saving it to flash is not possible cuase this would require a address i dont know after reset as well?