Using Watchdog for software reset

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

Using Watchdog for software reset

1,952 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by dbailey on Mon Apr 04 15:22:03 MST 2011
[FONT=Courier New][SIZE=2]I am trying to implement a software induced reset utilizing the watchdog timer on a LPC1758 processor.  I am debugging the code using lpcxpresso which is back ended with the gcc 4.4.1

The reset function I have implemetned simply turns off all interrupts, enables the watchdog timer and then waits for the watchdog to expire, causing a reset of the processor.

I have tested this with some code and it appeared to work.  However, sometimes I have seen this code not work.  I am trying to determine what has changed that would prevent it from working but I am not sure where to start.

When I run a LPCXpresso debugger with the code, I see the execution jump immediately after the LPC_WDT->WDFEED is set to 0x55.  The execution jumps to 0x1fff0080 which resides in ROM.  The execution never makes it back to the reset vector code. 

The reset code I have implemented is as follows:

void suicide_is_painless(void)
{
    asm("    cpsid i \n");
    SCB->VTOR = 0;
    if ((LPC_WDT->WDMOD & 3) != 3) {        /* If watchdog is not enabled */
        LPC_SC->PCLKSEL0     = ~(0x3);
        LPC_WDT->WDCLKSEL    =  0x80000000;    /* Lock in the RC clock source */
        LPC_WDT->WDTC         = 0xff;            /* Set minimum timer value */
        LPC_WDT->WDMOD         = 3;            /* Enable a reset watchdog */
    } else {
        LPC_WDT->WDTC         = 0xff;            /* Set minimum timer value */
    }
    LPC_WDT->WDFEED        = 0xAA;            /* Turn all this on */
    LPC_WDT->WDFEED        = 0x55;

    while(1)
    {}    /* We will wait to die in this function */
}

NOTE:  The LPC_WDT->WDMOD == 0 when this code is executed i.e. the watchdog has not been previously set.


Regards,
Doug Bailey
[/SIZE][/FONT]
0 Kudos
Reply
3 Replies

1,370 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_USA on Tue Apr 05 11:46:44 MST 2011
Hi Doug,

From the code you've posted it isn't clear why you need a time delay (as you're spinning in a loop and have interrupts disabled), can you elaborate?

If you don't really need a time delay and would like to reset the part programatically in software [without a delay] you can use the function:

void NVIC_SystemReset(void)

Note that as previously mentioned resetting the device while debugging may/will break the debugger connection.
0 Kudos
Reply

1,370 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Apr 05 10:11:09 MST 2011
Note that a watchdog triggering whilst debugging will break your debug connection, as you are resetting the system under the debugger's feet.

Regards,
CodeRedSupport
0 Kudos
Reply

1,370 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Tue Apr 05 08:47:05 MST 2011
Hi Doug,

What OS are you using?

If you can zip up and post a minimalized version of your project I can try it on an LPCXpresso1769.

[FONT=Courier New][SIZE=2]void suicide_is_painless(void) // M*A*S*H [/SIZE][/FONT][FONT=Courier New][SIZE=2]4077?[/SIZE][/FONT]

[FONT=Courier New][SIZE=2][FONT=Times New Roman][SIZE=3]Larry[/SIZE][/FONT][/SIZE][/FONT]
0 Kudos
Reply