lpcware

Watchdog - a bug in implementation or documentation typo

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by wella-tabor on Fri Jul 03 00:37:18 MST 2015
Hello,

I am facing an unexpected behavior while playing with the watchdog peripheral.

int main()
{

// Disable all interrupts
__disable_irq();

// Time for debugger to catch.
for (int i = 0; i < 0xFFFF; i++)
{
__NOP();
}

// Init spi and spi flash
debug_print_text("wdg test init");
debug_print_newline(1);

/* Initialize WWDT*/
Chip_WWDT_Init(LPC_WWDT);
/* Set watchdog feed time constant to 0.1s */

/* Set maximum timeout, about  2 minutes 14 seconds ~217 milliseconds */
Chip_WWDT_SetTimeOut(LPC_WWDT, 0xFFFFFFUL);

/* Configure WWDT to reset on timeout */
Chip_WWDT_SetOption(LPC_WWDT, WWDT_WDMOD_WDRESET);

/* Set warning 0 tick before reset */
Chip_WWDT_SetWarning(LPC_WWDT, 0);

/* Clear watchdog warning and timeout interrupts */
Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF | WWDT_WDMOD_WDINT);

/* Start watchdog */
Chip_WWDT_Start(LPC_WWDT);

// Enable WD protect
Chip_WWDT_SetOption(LPC_WWDT, WWDT_WDMOD_WDPROTECT);

// feed ---- reset in this function
Chip_WWDT_Feed(LPC_WWDT);

// We should  be here.
debug_print_text("Done spi uploading");
debug_print_newline(1);
while (1)

return EXIT_FAILURE;
}


However the LPC1788 is reset during the first feed sequence (not the feed in Chip_WWDT_Start). I am trying to protect the TC by enabling WDPROTECT.

From the UM10470:

0 The watchdog reload value (WDTC) can be changed at any time.
1 The watchdog reload value (WDTC) can be changed only after the counter
is below the value of WDWARNINT and WDWINDOW. Note: this mode is
intended for use only when WDRESET =1.
WDPROTECT

This provides additional protection by essentially only allowing the watchdog reload value
to be changed during the interrupt service of the Watchdog. The Watchdog must be
running (set up and the first feed performed) before WDPROTECT is set.


As I am not changing the TC (reload) value, the reset should not occur.
If I remove the line
Chip_WWDT_SetOption(LPC_WWDT, WWDT_WDMOD_WDPROTECT);
the watchod is behaving as expected from the documentation.


There is a possibility that I misread the WDT description, English is not my mother tongue.


BR
Martin



Outcomes