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

nRF52 RESETREAS register

I'm using an nRF52832 (QFAAB0) on a custom PCB, nRF5 SDK, S132 v2.0.

I'm occasionally encountering spontaneous resets and want to tract down the source. I found the RESETREAS register and the SDK function to access it (sd_power_reset_reason_get). However, I think either I'm not using it correctly or something's going wrong. I have this code in main():

uint32_t reset_reason;
sd_power_reset_reason_get(&reset_reason);
printf("Reset reason = 0x%08x\r\n", reset_reason);
sd_power_reset_reason_clr(0xFFFFFFFF);

However, this always prints out a register value that makes no sense to me: usually something like 0x99bdae6c, which would indicate a ton of reset reasons (including NFC field detect -- I don't have an antenna connected!)

Are there any issues with the RESETREAS register in this device, or are there any examples available for proper usage?

EDIT: I learned that the resets are probably happening because of the BLE advertisement window timing out (i.e. my APP_ADV_TIMEOUT_IN_SECONDS value), if this makes a difference. Still, I'd like to know how to get that reported in RESETREAS.

  • Does the function return an error? Yes I know it's documented not to but if the softdevice isn't enabled, it still will. In that case it would not have updated &reset_reason which would be full of whatever junk was left on the stack at function entry.

    Or just read the register yourself and write it yourself too.

    uint32_t reset_reason = NRF_POWER->RESETREAS;
    NRF_POWER->RESETREAS = 0xffffffff;
    
  • Just to add to RK's reply. You can only access POWER registers if the softdevice is not enabled. If it is enabled then on the latest versions of softdevice (from S132v2.0.0) if softdevice enabled, then accessing POWER and CLOCK registers directly will cause a hardfault.

  • Thanks for the replies, RK & Aryan. Based on this suggestion, I looked at the return value of sd_power_reset_reason_get, which was equal to 2 (NRF_ERROR_SOFTDEVICE_NOT_ENABLED). With that in mind, I realized that the issue is that I was calling the function before initializing the SoftDevice. I moved it below my call to ble_stack_init() and it now seems to be working fine. I would recommend adding this to the docs, which list the only possible return value for this function as NRF_SUCCESS.

Related