How to handle watchdog reset flag in application code?

Hello,

I have been working on a custom PCB powered by the nRF52832 microcontroller. It has custom bootloader, softdevice s132 and application code present on board, since we need the custom bootloader to perform OTA updates to the controller. We have the watchdog timer setup in the application code to handle error cases in the application code. Though the watchdog does get triggered and the device gets reset, the NRF_POWER->RESETREAS register had the softreset flag high instead of watchdog reset flag in the application code. When I check the NRF_POWER->RESETREAS register in the bootloader and the watchdog reset flag was set there. I think this was due to the fact that the microcontroller enters the bootloader first after watchdog reset and the watchdog flag gets cleared there when the NVIC_systemreset() is called at the end of the bootloader. 

I have a few questions: 1. What's the best way to send the watchdog flag to the application code from the bootloader, since I would be needing to report the watchdog reset incident over the BLE to an external mobile app and softreset is unavoidable in bootloader (My understanding is that Softreset is required to enter the application code). Would processing the flag information in bootloader and passing over application code through RAM or flash using linker scripts? Is there an easier way other than this?

2. Is there any documentation on what the NVIC_systemreset() resets during the softreset? Would RAM be reset during this process?

3.I was able to find this thread which explains how to implement variable exchange b/w bootloader and application code: RAM variables exchange between bootloader and application - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com). Here in this thread, under Ketil's answer, he mentioned about using Flash API to write to memory allocated region through the custom struct. Where would we be able to find this Flash API? And how would we be able to modify the API to write to memory allocated region?

Any help is appreciated! Thank you so much!

Parents
  • Solution for this problem is using NRF_POWER->GPREGRET register in the bootloader when watchdog reset flag is set in the NRF_POWER->RESETREAS register. This works since the NVIC_systemreset() doesn't reset the GPREGRET register. The documentation on which registers get reset when NVIC_systemreset() is called would be very helpful for future reference.

    int reset_reason = NRF_POWER->RESETREAS;
    if (reset_reason & (1UL << 1)) { // 2nd bit for watchdog reset and 3rd bit for softreset
     // The watchdog timer caused the reset
     NRF_POWER->GPREGRET = 0x10; //Custom magic number chosen for watch dog reset
    }
Reply
  • Solution for this problem is using NRF_POWER->GPREGRET register in the bootloader when watchdog reset flag is set in the NRF_POWER->RESETREAS register. This works since the NVIC_systemreset() doesn't reset the GPREGRET register. The documentation on which registers get reset when NVIC_systemreset() is called would be very helpful for future reference.

    int reset_reason = NRF_POWER->RESETREAS;
    if (reset_reason & (1UL << 1)) { // 2nd bit for watchdog reset and 3rd bit for softreset
     // The watchdog timer caused the reset
     NRF_POWER->GPREGRET = 0x10; //Custom magic number chosen for watch dog reset
    }
Children
No Data
Related