Feeding watch dog on LPC11U24

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

Feeding watch dog on LPC11U24

374 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tobias Zvonc on Thu Sep 25 08:19:32 MST 2014
Hi,

I'm working on a second bootloader for LPC11U24, which uses USB HID for writing application to flash. I'm using LPCopen driver for LPC11Uxx.

To make long story short, I initialize USB interface, watch dog and SysTick timer. The idea was to feed watch dog timer from SysTick interrupt handler every 100 ms (Watch dog timer constant is for 2 seconds WD timer period). However, if I do that, microcontroller is reseted for 2, 3 or more times as soon as it initializes. The worst part is that this varies - sometimes after reset everything is good, sometimes MCU is reseted for 2 or more times in a row.

If I remove feeding watch dog from SysTick interrupt handler and feed it from while() loop in main(), everything is good. And if I remove feeding watch dog, MCU is reseted exactly every two seconds, and that confirms that watch dog is initialized correctly.

Does anybody have experience with this? I spent a day an a half trying to figure this out, and it doesn't make sense at all.

Here is relevant part of the code:

void WDT_IRQHandler(void)
{
    if(Chip_WWDT_GetStatus(LPC_WWDT) & WWDT_WDMOD_WDTOF)
    {
        NVIC_SystemReset();
    }
}

void SysTick_Handler(void)
{
    // If we feed Watch dog from here, reset happens 2 or 3 (or more) times
    // in a row (every time different).
    //Chip_WWDT_Feed(LPC_WWDT);

    if ( _g_IAPStarted ){
        Chip_GPIO_SetPinToggle(LPC_GPIO, PIN_LED2_RED);
    }
    
    _g_BootloaderTimeout_100ms--;
}



int main(void)
{
    uint16_t calculatedCRC;
    volatile unsigned int delay;
    
    /* Initialize board and chip */
BoardInitialization();
    
    Reset_Signal();
    
    // LED signals we are in bootloader.
    LedOn();
    
    USBInit();

    #ifndef DEBUG
    WatchdogInitialize();
    #endif
    
    SysTick_Config(SystemCoreClock/10); // frequency of SysTick interrupt is 10 Hz (period = 100 ms)

    // Wait 5 seconds before attempting to start user-application
    while( _g_BootloaderTimeout_100ms ){
        Chip_WWDT_Feed(LPC_WWDT);
    }


....
} /* end main() */



void WatchdogInitialize(void)
{
    #define WD_TIMEOUT_SEC  ( 2 )
    
    // Clear WD timeout flag
    Chip_WWDT_ClearStatusFlag(LPC_WWDT, WWDT_WDMOD_WDTOF);
    
    /* Watchdog config */
    Chip_WWDT_Init(LPC_WWDT);
    // WD clk source - IRC oscilator (12 MHz)
    // wd_clk_freq = 12 MHz / 4 = 3 MHz
    // Watchdog timeout set to WD_TIMEOUT_SEC second
    Chip_WWDT_SetTimeOut( LPC_WWDT, (3000000*WD_TIMEOUT_SEC) );
    Chip_WWDT_SetWarning( LPC_WWDT, 0 );
    // Don't reset MCU, only generate an interrupt
    Chip_WWDT_Start(LPC_WWDT);    // (sets WD option WDEN)
    NVIC_ClearPendingIRQ(WDT_IRQn);
    NVIC_EnableIRQ(WDT_IRQn);
}


Labels (1)
0 Kudos
1 Reply

234 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tobias Zvonc on Sat Sep 27 02:57:05 MST 2014
Problem solved. :D

Watch dog feed from while() loop in main() was interrupted by feed from SysTick handler, which resulted with incorrect feed, leading to system reset. :)
0 Kudos