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]