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

Issue with resetting BLE Peripheral device after bonding (PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED)

Hi,

I have an issue with bonding and resetting my BLE Peripheral device (NRF52832) after the bonding process is complete. Currently I press a button that initiates the bonding procedure, after that the central device (e.g my smartphone) bonds with the the peripheral device. When the bonding is complete I tell the BLE Peripheral to reset itself and update the whitelist and advertise using the whitelist by fetching the bonding information from flash. That part works fine, however when I connect with the central device after the reset i get the error: PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED event inside the peer manager event handler. The central device can still connect though.

I dont get the error PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED if I: connect -> bond -> reconnect (without restart of BLE Peripheral). But if I do connect-> bond -> disconnect -> connect -> reset -> connect the error shows up again.

I've tried using timers to delay the reset since writing to flash is done asynchronously (thinking maybe the reset was done too quickly) but it did not help.

Quick Edit:

Im using SDK V15.0

Softdevice: S132 6.0

Hardware: nRF52832

  • Hi Anton, 

    Please clarify, you mentioned this sequence "connect-> bond -> disconnect -> connect -> reset -> connect " showed the error. But when exactly you trigger the reset ? On the first connection after bond or on the second ? In the sequence above, it's the second re-connection after bonding. 

    Do you see the same problem if you test using ble_app_proximity (adding code to do a reset) ? Which phone did you use for testing ? 

    The PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED error happens when we try to apply the system attribute (CCCD value) on a saved connection but it doesn't match with the attribute table. Suspecting corrupted flash operation. We need to find the place where we store the system attribute and try to avoid resetting before it's finished flashing. 

  • Hi Hung,

    I trigger the reset after the first connection after the bond.

    I have done some research and I think I have found the cause. I removed the initialization of Nordic UART Service (which also uses the QWR-module. After that I dont receive the error PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED after connecting after a reset.

    Can QWR or NUS interfere with writing to the flash?

  • I do the reset of the nRF52832 inside the PM_EVT_PEER_DATA_UPDATE_SUCCEEDED event with the two following preconditions

    p_evt->params.peer_data_update_succeeded.flash_changed
    && p_evt->params.peer_data_update_succeeded.data_id == PM_PEER_DATA_ID_BONDING
    

  • I don't think NUS or QWR has anything to do with flash.

    More likely since you comment out NUS, you don't have any CCCD value in your attribute table, so PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED won't appear.

    I don't think doing a reset inside PM_EVT_PEER_DATA_UPDATE_SUCCEEDED event handler is the best way. I would suggest to do a disconnect, and when you have Disconnected event, you can trigger a reset in main.c 

    May I ask why you want to do a reset after a bonding? 

  • Hi,

    I tried what you suggested, in PM_EVT_PEER_DATA_UPDATE_SUCCEEDED I disconnect the Central device using sd_ble_gap_disconnect and when I receive the disconnect event in the BLE event handler I perform the reset. I still get the PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED.

    Why a reset after bonding?
    It's quite hard to explain but the short version is that the nRF52832 is a slave device that has different modes, another MCU (master device) controls it and the transitions between different modes is done through resetting the nRF52832 and initializing only the components needed for that mode.

Related