This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Flash FDS initialization failure

When the nRF52 micro-controller is programmed through batch file i.e. nrfjprog utility, the flash fds fails to initialize. Every time, flash fds initialization fails, I have code for soft_Reset.

Initialization fails 3 times and then Flash FDS initializes with success.

After a bit of debugging, I found out fds_register(flash_fds_evt_handler) returns with Success. fds_init() returns with Success.

But the flash_fds_evt_handler() never gets called in the first 3 attempts.

Any insight will be helpful.

I have attached the code snippet below. I am using nRF52932 microcontroller, SDK12.2.0, softdevice s132 v3.0.0

ble_stack_init();

// fds must be initialized after the Softdevice, as it uses the system event to run
flash_fds_init();           
// must wait for fds to initializ
while(!fds_init_complete)   
{
    power_led_red_on();
    nrf_delay_ms(1000);
    NVIC_SystemReset();
}
// use fds to get the auth params (first time though, this Writes the default auth params) 
load_auth_params();
  • I don't quite understand the logic behind the snippet that you posted.

    It seems to me that you attempt to initialize fds, which is an asynchronous operation. Then, immediately after returning from the call flash_fds_init() you check that the operation has completed, and if it has not you wait one second and reset. That doesn't make much sense to me.

    That code you posted will reset the chip until the initialization becomes a synchronous operation and you receive a callback before the flash_fds_init() function returns and thus the flag is already set when you check it.

    Did I explain it well enough? :)

    Regards, emdi

  • The rational behind waiting for the callback is make sure that the FDS is initialized and it is ok to load custom parameters for device name, etc.

    If I didn't wait and callback event handler is never called, BLE starts advertising without Device Name.

    I am trying to find-out why callback event handler is never called?

    I have added the original snippet below

    ble_stack_init();
    
    // fds must be initialized after the Softdevice, as it uses the system event to run
    flash_fds_init();           
    // must wait for fds to initializ
    while(!fds_init_complete)   
    {}
    // use fds to get the auth params (first time though, this Writes the default auth params) 
    load_auth_params();
    

    Any insight will be helpful.

  • Well , this looks more reasonable. I would add an 'sd_evt_wait()' call into the while loop. Does that work for you? Also, is the flag you are waiting on declared volatile? Some compilers require you to explicitely declare it as such.

  • fds_init_complete falg is volatile.

    I checked the m_cb_table and m_users, both show that my custom evt_handler is added. Adding sd_app_evt_wait() did not help. I didn't get any callback.

    Is there a way to check these evt_handlers were present in a queue or similar data-structure. Any insight will be helpful.

  • You forgot to add the fstorage system event handler. If you look at the main C file there should be a function called sys_evt_dispatch. Add a call to fs_sys_evt_handler() there and pass it the system event received in that function.

    This is not necessary after the new SoftDevice handler was introduced, but SDK 12.2 didn't have that.

Related