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

Bonding Information not stored in Flash memory

I am using nrf52 with SDK 14.2.0 and SD is S132.

The issue I am facing is that after Central is paired with one peripheral and bonding is done, the bonding information is not stored by central and so the next time when the already bonded peripheral tries to connect with the Central, it follows pairing and bonding procedure. Below are the peer manager events that I am getting:

1. PM_EVT_CONN_SEC_PARAMS_REQ

2. PM_EVT_CONN_SEC_SUCCEEDED

3. PM_EVT_CONN_SEC_PARAMS_REQ

4. PM_EVT_CONN_SEC_SUCCEEDED

The above events are coming for new device as well as already paired device.

Also, one issue I think is I am never getting PM_EVT_PEER_DATA_UPDATE_SUCCEEDED event even after bonding is done. Also one more strange behavior is that my system event handler, which I registered using NRF_SDH_SOC_OBSERVER, is never called.

Can you please help me to resolve this issue?

Parents
  • Debugging further I found that inside the SDK, /peer_data_storage.c file has registered fds_evt_handler. This handler is called only twice, one for INIT event and once for GC (Garbage Collection) event. This both are done before pairing started. I doubt the issue is with FDS? Not sure though.

  • I think it would be best if you could provide a stripped down version of the project as Matt suggested earlier. But please try the following:

    1. Place a breakpoint in peer_data_storage -> pds_peer_data_store() to see if it is being called after BLE_GAP_EVT_AUTH_STATUS. Make sure that any bond info is erased on both devices before you do the test.

    2. Check the pm_evt_t::pm_conn_sec_procedure_t value when you receive the PM_EVT_CONN_SEC_SUCCEEDED event. 

    3. If you have a BLE sniffer, try to capture the initial bonding procedure. 

  • That's good,  it's trying to store the data at least. 

    The fstorage backend registers its own observer instance so it is not necessary add a new observer. All observers should however receive the same events.

    Have you registered other FDS/fstorage instances in your app, or is it just the peer manager that uses it?Also, have you tried to see if  the fds callback for the PM receives any write/update events (peer_data_storage.c->fds_evt_handler)? 

  • Yes I have fstorage instance in my app. The FDS call back of peer manager does get the INIT and GC events only. No any read write event. Also as I asked in my question, i am using device with softdevice 2 as peripheral and soft device 5.0 as central. Can that be an issue?

  • There's a bug in the fstorage module that prevents multiple instances from being initialized correctly. I suspect that this could be the problem. You can modify the init function nrf_fstorage.sd so that p_flash_info is always set when a new instance is registered :

    static ret_code_t init(nrf_fstorage_t * p_fs, void * p_param)
    {
        UNUSED_PARAMETER(p_param);
        
       p_fs->p_flash_info = &m_flash_info;
    
        if (!nrf_atomic_flag_set_fetch(&m_flags.initialized))
        {
            
       /*p_fs->p_flash_info = &m_flash_info;*/ 
    #if NRF_SDH_ENABLED
            m_flags.sd_enabled = nrf_sdh_is_enabled();
    #endif
    
            (void) NRF_ATFIFO_INIT(m_fifo);
        }
    
        return NRF_SUCCESS;
    }

    Fix will be included in upcoming SDK release.

    It's should not be a problem that you are using an older softdevice on the peripheral.

  • I already did this. I found this bug from another ticket on nordic devzone and I put the

    "p_fs->p_flash_info = &m_flash_info;" line outside if condition. The issue is still present after this. I can see that pds_peer_data_store is called, and it returned success, then why would FDS handler of peer manager not be called?

  • Just be sure, is nrf_sdh_soc.c included in your build? Just realized that's possible to build a project without this source file as there are no compile time dependencies for it. This could explain why you are not seeing SD soc events.  

Reply Children
Related