K70 Watchdog does NOT reset some times.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K70 Watchdog does NOT reset some times.

982 Views
asmith
Contributor III

I am trying to impliment/Test the watchdog on a K70.

Code below.

I am getting the opposite problem most everyone else sees.

About 2/3 of the time the Watchog fires and restarts the system and I can verify that the WDOG_RSTCNT has incremented.

About 1/3 of the time the K70 hangs at while(1); forever.

static void

watchdog_unlock(void) {

    /* unlock watchdog */

    WDOG_UNLOCK = WDOG_UNLOCK_WDOGUNLOCK(0xC520); /* Key 1 */

    WDOG_UNLOCK = WDOG_UNLOCK_WDOGUNLOCK(0xD928); /* Key 2 */

}

static void

watchdog_delay(uint16_t nCount) {

    uint16_t delay = 0;

    for (delay=0;delay<nCount*10;delay++) {

        NULL;

    }

    return;

}

static void

watchdog_refresh(void) {

    _int_disable();

    WDOG_REFRESH = 0xA602;

    WDOG_REFRESH = 0xB480;

    _int_enable();

}

static uint32_t wdog_to = 125*2;

void

OS_WatchdogInitialize(void) {

    _int_disable();

    watchdog_unlock();

    watchdog_delay(1);

    WDOG_TOVALH = wdog_to >> 16;

    WDOG_TOVALL = wdog_to & 0xffff;

    WDOG_STCTRLH = WDOG_STCTRLH_DISTESTWDOG_MASK     // Disable functional test

            | WDOG_STCTRLH_WDOGEN_MASK;

    // 14 DISTESTWDOG

    // 12:13 BYTESEL

    // 11 TESTSEL

    // 10 TESTWDOG

    // 7 1 WAIT_EN = 0

    // 6 1 STOP_EN = 0

    // 5 0 DBG_EN = 0

    // 4 1 ALLOWUPDATE = 1

    // 3 0 WINEN = 0

    // 2 0 IRQSTEN = 0

    // 1 1 CLKSRC = 0

    // 0 1 WDOGEN = 0

    WDOG_WINL = WDOG_WINH = 0;

    WDOG_PRESC = 0x700;

    _int_enable();

    _time_delay(4);

}

void watchdog_test() {

    int lc = 0;

    OS_WatchdogInitialize();

    while (1) {

        watchdog_refresh();

        if (lc++ > 150) {

            while(1);

        }

    }

}

                                                                                                                                64,1          Bot

Labels (1)
0 Kudos
3 Replies

582 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello David Lynch:

Since you are configuring the LPO as watchdog clock source, then I think you are refreshing the watchdog too fast. The thread in the next link is a long discussion but the bottom line is that you need to wait for the refresh to take effect within the Watchdog clock domain:

WDOG ignoring refresh when using LPO clock

So the recommendation is to wait at least 4 WDOG clock cycles before refreshing again.

Regards!
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos

582 Views
asmith
Contributor III

I have tried with both the LPO and Bus clocks.

Getting the delays correct appears to be critical.

Though even that is not enough.

Regardless, or which I uses I end up with situations where on some restart cycles the WDOG fails to properly initialize.

Sometimes re-initializing fixes that,

Others it does not.

I can not incorporate the HW WDOG into our product unless it is robust.

I have worked with other HW WDOG's, the one in the K70 is the most difficult I have had to work with.

0 Kudos

582 Views
asmith
Contributor III

I have tried this both with the LPO and the Bus Clock.

Also the above is just a sample. In the actual application the watchdog_refreshes are about 300ms apart.

And finally my problem is not missing refreshes, but missing resets.

With a great deal of effort I now have something that appears to work.

Though I can not tell what exactly fixed it.

What I have done is:

In addition to refreshing the WatchDog, I am validating many of the watchdog registers at the top of my 300ms loop.

I am validating that the watchdog is enabled,

that the current count is not 0, that it is lower than the timeout value, that after delaying for 10ms the watchdog counter has incremented,

If any of my tests fail - I reinitialize the watchdog and test again.

If it fails a 2nd time I reset the system myself.

With all of the above I am getting the watchdog to trigger every time I forceably lock up the system - and that was not happening before.

And with my actual application I am getting 8 units on a test bench to run through a weekend, and the wathcdog is reseting them when the application code "locks up"

0 Kudos