Reset reason to safely delete bonds of nRF52832

Hello,

We have a product which is a custom nRF52832 board, nRF5 SDK (didn't have time to upgrade to nRF Connect SDK), s132, BLE. 

We used to call delete_bonds() function in security failure event. This fault on our behalf of course, caused many problems, since security fail can happen for many reasons, the device erased bonding information often. Then clients had to delete bonds from the mobile device to be able to reconnect to nRF52832, and this behaviour is not user friendly.

On another ticket, I got the reply that we shouldn't call delete bonds anywhere, and to allow repairing. 

But, since we couldn't reproduce the error of the clients, and we want to be safe, we want to use the Reset button, as a "factory reset", which will reset the device and delete the bonds. 

I used this code:

int32_t reset_reason = NRF_POWER->RESETREAS;
NRF_LOG_INFO("Reset reason = 0x%x.\n", reset_reason);
NRF_POWER->RESETREAS = NRF_POWER->RESETREAS;

to retrieve the reason of the reset (after reset), and then if reset = 0x1 (pin reset) I called delete_bonds function.

as I found here: 

RESETREAS and here https://devzone.nordicsemi.com/f/nordic-q-a/48446/how-to-detect-cause-of-reset

The problem is that I tested all of the above and it worked fine, using debugger (connected the board on a DK) and having enabled NRF_LOG_ENABLED and NRF_LOG_BACKEND_RTT_ENABLED. 

When i disabled them and tried to test the board not connected to the debugger, the reset reason I get for soft-reset (error from the code) is 0x4 and sometimes it is 0x0. Also from pin-reset I get 0x0, which is supposed to be 0x1

The register doesn't work without the debugger? What could be wrong in this situation? 

Thank you in advance, and I would really appreciate if you can help me on how to achieve to safely rcognise pin-rest, to perform delete bonds only in this case of device reset. 

Best regards, 

Dimitra

Related