Hi,
I just found, fds initialization sequence is important for fds_event_handler to be called.
My scenario: nrf52832
SDK 12.2.0
MDK
My sequence to call fds initialisation is as follows:
-
User fds_register
-
user fds_init
-
ble_stack_init
-
pm_init
-
pm fds_register
-
pm_fds_init
BTW, there is fs_sys_event_handler in sys_evt_dispatch().
Then, in my ble_enable() user function, I have to wait the flash ready event, and in user fds_event_handler, I check whether flash writing count is 0 or not. If flash writing count is 0, I will start advertising.
Unfortunately, user fds_event_handler is never called(and event pm fds_event_handler). My flash writing operations before BLE started are quite a lot.
I believe this is a sequence issue. So I updated the sequence a bit:
-
User fds_register
-
pm fds_register
-
user fds_init
-
ble_stack_init
-
pm_init
-
pm_fds_init
I changed peer_data_storage.c code a bit. like this:
ret_code_t pds_init()
{
ret_code_t ret;
// Check for re-initialization if debugging.
NRF_PM_DEBUG_CHECK(!m_module_initialized);
// ret = fds_register(fds_evt_handler);
// if (ret != NRF_SUCCESS)
// {
// return NRF_ERROR_INTERNAL;
// }
ret = fds_init();
if (ret != NRF_SUCCESS)
{
return NRF_ERROR_STORAGE_FULL;
}
...
And also declare pm fds_event_handler as external so I can set it into fds_register() in step 2.
After that, each event is recieved successfully. However, I do not think it is a good solution, it is ugly since I need to change nordic internal pm code.
May I ask, is there a better solution for this?
By the way, I need to initialise user fds before BLE stack init - I need to determine which mode I am using from flash, eg, central mode or peripheral mode.
Thanks, Vincent