Watchdogs on the Photon

Hi,

we just published a new library for using the two HW watchdogs on the photon! For details look on on our blog or on the GitHub repository.

Live long, and prosper!

3 Likes

Your watchdog library may just be a nice fix for a problem I’m having.
What should happen in my program is :-
Wake up from 4 and half minutes of deep sleep , keep checking the clock to see if the minutes is now MOD 5 or 0, read a load of sensor data , send it to my server and back to sleep again , but a i2c sensor is fleezing my code.
So I m having to do a manual reset every few hours or days

What happens on a fleeze , a reset ?

Yeah, your code needs to call the tickle() function within a configured time period so the watchdogs will reset properly. If your code breaks/halts/gets stuck, the watchdogs will reset. Using deep sleep and the independent watchdog (IWDG) won’t work as far as I know (runs on own RC, cannot be stopped). So you can only depend on the window watchdog (WWDG). It is possible to pause and resume the watchdog, we already created and enhancement issue for that, and will implement it within the next week or so.

3 Likes

Very useful. Thanks folks!

@ampunix Did the pause and resume the watchdog feature even get tested successfully and added to your library?

I want to use the Watchdog to reset the Photon or P1 if it ever hangs or does not come out of deep sleep.

How exactly could the Window Watchdog be used to do that?

Any info is greatly appreciated!

1 Like

Also interested in a watchdog to reset in case of deep sleep wake up failure…

Any ideas on how this should be implemented would be welcomed!

Hello,
Does the library is designed to works only with Photon?
I imported the example in WebIDE from libraries.
While compiling the example for Electron I get the following error.

First, how have you imported the sample? By use of the USE THIS EXAMPLE button?
Since when I do this, I actually get a missing #include "SparkIntervalTimer/SparkIntervalTimer.h".
And after importing that library some system files are not found for the Electron but (revolving around stm32f2xx_wwdg.h and STM32F2xx_Peripheral_Libraries.a).
But for the Photon they seem to be present.

So maybe @mdma might be able to help with that.

Hi! I’m trying this library but I have problem with OTA…
Do you have the same problem? How do you fix it?
I try to start the update via curl but I never receive the start update event, but only a timeout after a few time.
Thanks, Flavio

That'd be hard to tell, since we don't know what your problem with OTA is.

I’m sorry, you are right :smiley: I can’t flash the photon via OTA. Flashing always end up with time out.
I can flash it only in DFU mode. If I remove the watchdog I can flash via OTA again.
It seems that the library doesn’t catch the updatesPending, or the disableUpdates doesn’t work, so it doesn’t disable the timer…
Thank, Flavio

It seems that the problem is if(System.updatesPending()), not called on the last firmware.
I fixed in this way:
removed this piece of code from _tickleWDGs:

// deactivate WWDG if OTA updates pending
If(System.updatesPending()) {
   if(PhotonWdgs::_wwdgRunning) {
       WWDG_DeInit();
   }
   System.enableUpdates();
   PhotonWdgs::_wdgTimer.end();
}

Added this line at the bottom of begin()

System.on(firmware_update_pending, handle_update);

Added this method:

void handle_update(system_event_t event, int param)
{
    Serial.println("UPDATE READY WDGS");
    if(PhotonWdgs::_wwdgRunning) {
        WWDG_DeInit();
    }
    System.enableUpdates();
    PhotonWdgs::_wdgTimer.end();
}

It seems to work, let me know if this is working also for you.
Flavio

Worked for me, as per https://github.com/raphitheking/photon-wdgs/issues/2

Hi flavio, I must be doing something wrong. Where do you add that line exactly?

void PhotonWdgs::begin(bool _enableWwdg,bool _enableIwdg,unsigned long _timeout, TIMid id)
{
    if(!_enableWwdg && !_enableIwdg) {
        // nothing to do ...
        return;
    }
    PhotonWdgs::_aliveCount = 0;
    PhotonWdgs::_timeoutval = _timeout / 10;

    RCC_LSICmd(ENABLE); //LSI is needed for Watchdogs

    PhotonWdgs::_wdgTimer.begin(PhotonWdgs::_tickleWDGs, 20, hmSec, id);
    // OTA updates won't work with watchdog enabled
    System.disableUpdates();
    PhotonWdgs::_wwdgRunning = _enableWwdg;
    if(_enableWwdg) {
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
        WWDG_SetPrescaler(WWDG_Prescaler_8);
        WWDG_SetWindowValue(0x7F);
        WWDG_Enable(0x7F);
    }
    PhotonWdgs::_iwdgRunning = _enableIwdg;
    if(_enableIwdg) {
        IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
        IWDG_SetPrescaler(IWDG_Prescaler_256);
        IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
        IWDG_SetReload(0xFFF);
        IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
        IWDG_Enable();
    }
    System.on(firmware_update_pending, handle_update);
    System.on(setup_begin, handle_setup_begin);
    System.on(setup_end, handle_setup_end);
}
1 Like

Thank you!