Simblee Watchdog Timer & OTA Updates

We fell in love with RF Digital's RFDuino product when it hit the market a few years back, and their newest module, Simblee, is an impressive improvement. 

During hardware beta testing the last thing that we ever want is a device that locks up due to a software bug and becomes unusable. Most micro controllers include functionality to protect against this, a watchdog timer. The watchdog is configured with a certain time interval, say 10 seconds. If the watchdog is not 'petted' within that 10 second window the device is reset. This way any infinite loops or unintended lock ups can be mitigated. 

Configuring the Simblee's watchdog is fairly straight forward : 


'Petting' the watchdog is done with:

NRF_WDT->RR[0] = WDT_RR_RR_Reload;

So far so good, but, we were very interested in Simblee's new over-the-air firmware update functionality (OTA). This allows the device to accept new code, without being physically connected to a programmer. Very convenient for patching bugs and introducing new functionality when users already have devices in hand. However! Upon implementing OTA functionality in our firmware it consistently failed! After a bit of investigation we noticed that it was failing after exactly the amount of time that our watchdog timer was set to. It turns out that once the watchdog timer has been enabled, it can not be disabled until either the device has been power cycled, or a watchdog reset has been performed.

If you're looking to get OTA updates working with a watchdog timer here are the steps that you'll need to take:

  1. Send a custom command to initiate your OTA update method.
  2. Write a flag to persistent storage as a way of signaling to your program that you'd like to not enable the watchdog on startup, and move directly to the built-in Simblee OTA update. 
  3. Enter an infinite loop, and do not pet the watchdog inside this loop
  4. The device will be reset by the watchdog timer
  5. Read the flag you previously wrote to persistent storage. If it exists, go ahead and clear it, then start the OTA update without enabling the watchdog. Otherwise, enable the watchdog and move forward!

Hope this helps others on the same path move forward. 

As an additional tidbit, if you're interested in knowing why your Simblee reset, here's a bit of code that the RF Digital team shared with us:

void resetReason(){
if (NRF_POWER->RESETREAS & 0x00000001)
log(F("Reset from pin"));
if (NRF_POWER->RESETREAS & 0x00000002)
log(F("Reset from WDT"));
if (NRF_POWER->RESETREAS & 0x00000004)
log(F("Reset from software"));
if (NRF_POWER->RESETREAS & 0x00000008)
log(F("Reset from lockup"));
if (NRF_POWER->RESETREAS & 0x00010000)
log(F("Reset from Powerup"));
//Serial.println(NRF_POWER->RESETREAS,BIN); //Print binary value of Reset Reason
NRF_POWER->RESETREAS = 0xFFFFFFFF;//Clear reset reason register