Watchdog refresh not working

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

Watchdog refresh not working

1,657 Views
m4l490n
Contributor V

I'm having problems with the watchdog module. I don't know if it is the configuration or what is really happening. I added the watchdog peripheral driver and I have the following configuration for it:

m4l490n_0-1611184027155.png

The generated code for initializing it looks like this:

 

const wdog_config_t Watchdog_config = {
  .clockSource = kWDOG_LpoClockSource,
  .prescaler = kWDOG_ClockPrescalerDivide1,
  .timeoutValue = 1000UL,
  .enableWindowMode = false,
  .windowValue = 0UL,
  .enableUpdate = true,
  .enableWdog = true,
  .workMode = {
    .enableWait = true,
    .enableStop = false,
    .enableDebug = false
  }, 
  .enableInterrupt = false
};

static void Watchdog_init(void) {
  /* WDOG peripheral initialization */
  WDOG_Init(WATCHDOG_PERIPHERAL, &Watchdog_config);
}

 

 

The code is executing that initialization correctly.

I have the following in main:

 

int main(void)
{
    if (RCM_GetPreviousResetSources(RCM) & kRCM_SourceWdog)
    {
        while (1);
    }

    /* Init board hardware. */
    BOARD_InitBootPins ();
    BOARD_InitBootClocks ();
    BOARD_InitBootPeripherals ();

#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL
    /* Init FSL debug console. */
    BOARD_InitDebugConsole ();
#endif

    PRINTF ("Hello World\n");

    /* Force the counter to be placed into memory. */
    volatile static int i = 0;
    /* Enter an infinite loop, just incrementing a counter. */
    while (1)
    {
        WDOG_Refresh(WATCHDOG_PERIPHERAL);

        i++;
        /* 'Dummy' NOP to allow source level single stepping of
         tight while() loop */
        __asm volatile ("nop");
    }
    return 0;
}

 

 

I let the code run and put a breakpoint inside the if (RCM_GetPreviousResetSources(RCM) & kRCM_SourceWdog) then after 1 second, which is my watchdog timeout, the execution hits my breakpoint despite calling WDOG_Refresh(WATCHDOG_PERIPHERAL); inside the while loop.

Also, I can verify that the watchdog timed out by looking at the peripheral view:

m4l490n_1-1611184447312.png

I also noticed that the watchdog value is not changing when running the code. It stays at 0x3e8 (1000) all the time.

m4l490n_0-1611253956140.png

But that doesn't make sense, shouldn't it be decrementing and then resetting the board when it reaches 0? Or does that register only holds the value that the watchdog timer references to?

What am I missing?

0 Kudos
5 Replies

1,617 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @m4l490n,

Only to check the module functionality, could you try the SDK example to check if this works correctly?

Alexis_A_0-1611630802928.png

Best Regards,

Alexis Andalon

0 Kudos

1,613 Views
m4l490n
Contributor V

@Alexis_A thanks for helping!

The wdog example seems to be working but is confusing.

It seems that the example is performing three tests. The first test is if (wdog_reset_count == 0). The second test is else if (wdog_reset_count == 1). The third test is else if (wdog_reset_count == 2).

I don't need those tests and it is not clear to me what piece of code to use as a reference for what I need. The only thing I need is to be able to do this:

while (1)
{
    WDOG_Refresh(WATCHDOG_PERIPHERAL);
    PRINTF ("i = %lu\n", (uint32_t)i);
    i++;
    /* 'Dummy' NOP to allow source level single stepping of tight while() loop */
    __asm volatile ("nop");
}

Inside main and keep the processor from getting reset by the watchdog.

What makes the example more confusing is that it is not using the peripheral config tool for configuring the wdog as I am and the only similar thing I can identify the example is doing is what it is on the second test which is

    else if (wdog_reset_count == 1)
    {
        PRINTF("--- Quick test done ---\r\n");
    /*
     * config.enableWdog = true;
     * config.clockSource = kWDOG_LpoClockSource;
     * config.prescaler = kWDOG_ClockPrescalerDivide1;
     * config.enableUpdate = true;
     * config.enableInterrupt = false;
     * config.enableWindowMode = false;
     * config.windowValue = 0U;
     * config.timeoutValue = 0xFFFFU;
     */
        WDOG_GetDefaultConfig(&config);
        config.timeoutValue = 0x7ffU;
        /* wdog refresh test in none-window mode */
        PRINTF("\r\n--- None-window mode refresh test start---\r\n");
        WDOG_Init(wdog_base, &config);
        WaitWctClose(wdog_base);
        for (uint32_t i = 0; i < 10; i++)
        {
            WDOG_Refresh(wdog_base);
            PRINTF("--- Refresh wdog %d time ---\r\n", i + 1);

            while (GetTimerOutputValue(wdog_base) < (config.timeoutValue >> 3U))
            {
            }
        }
        /* wait for wdog timeout reset */
        while (1)
        {
        }
    }

That piece of code contains the call to WDOG_Init that I have in BOARD_InitBootPeripherals generated by the config tool but it is using WDOG_GetDefaultConfig instead of a generated config structure like I have.

Another difference I notice is that the example is calling WaitWctClose(wdog_base) and it is executing this while (GetTimerOutputValue(wdog_base) < (config.timeoutValue >> 3U)) right after refreshing the wdog. Do I need to do this as well? Maybe that's the problem, but I'm not sure.

0 Kudos

1,592 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @m4l490n,

Have you tried using the WaitWctClose(wdog_base) before doing the refresh?

Best Regards,

Alexis Andalon

0 Kudos

1,586 Views
m4l490n
Contributor V

I already solved this, but actually, that sounds better than what I did. The problem is that I can't find that function.

Where is it?

0 Kudos

1,577 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hello @m4l490n

You can found this API in the wdog example.

Best Regards,

Alexis Andalon