This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SIMPLELINK-CC2640R2-SDK: WatchDog problems

Part Number: SIMPLELINK-CC2640R2-SDK
Other Parts Discussed in Thread: CC2640R2F

Hi,

i am using SableX R2 on a custom board with CC2640R2 chip 5x5 on it. I am using the latest SDK_1_50_00_58.

I have noticed that once the watchdog has fired and reset was set to on, the device dont reset and stays in an unkown state.

I have also to disable reset and set a watchdog callback function to hard reset the software if its fired.

This  function is never called even if i uncomment "watchdog_clear(...)". (debug/jtag not attached)

To make the watchdog fire the interrupt to go to the callback function, i have to add a "while(1){};" loop in my task.

Then i can see that every time it enters the callback function it turns the LED on and reset the controller.

But if i dont have the while loop, the function gets never called.

Any idea?

void iniWatchDog(void)
{
    Watchdog_Params params;

   /* Call board init functions */
   Watchdog_init();
   /* Create and enable a Watchdog with resets disabled */
   Watchdog_Params_init(&params);
   params.callbackFxn = (Watchdog_Callback)watchdogCallback;
   params.resetMode = Watchdog_RESET_OFF;
   //params.debugStallMode = Watchdog_DEBUG_STALL_ON;
   watchdogHandle = Watchdog_open(Board_WATCHDOG0, &params);
  // if(watchdogHandle!=NULL)
     //  Watchdog_setReload(watchdogHandle, Watchdog_convertMsToTicks(watchdogHandle,10000));//90000 mseconds
}
/*
 *  ======== watchdogCallback ========
 *  Watchdog interrupt callback function.
 */
void watchdogCallback(uintptr_t unused)
{
    /* Clear watchdog interrupt flag */
    Watchdog_clear(watchdogHandle);
    /* Insert timeout handling code here. */
    PIN_setOutputValue(hGpioPin,CC2640R2_LAUNCHXL_PIN_GLED,0);
    delay_ms(5000);

    //HAL_SYSTEM_RESET();
    SysCtrlSystemReset() ;
}

  • Hello Michael,
    It is not clear from the information provided what is triggering the watchdog. It sounds like when you have the while(1) loop the intended trigger happens and not otherwise.
    If you have not already please refer to this example
    dev.ti.com/.../

    Regards,
    Prashanth
  • Hi Michael,

    Remove the Watchdog_clear() in the watchdogCallback(). After that it should work as expected.

    At the watchdog example program the Watchdog_clear() is in the watchdogCallback(). That is just so you can try the example program again and again.

    -kel
  • Hi Markel,

    I did copy the watchdog sdk example to my simple_peripheral project.

    What’s weird is that the watchdog is never trigger only if it really hangs in a task. Does the stack clears the watchdog or who is doing it?  Because I am not clearing to test it.

    Is there a way to print the watchdog counter value?

    Or a way to debug this?

    The other thing is when I enable reset on watchdog and uncomment the callback function as parameter and ad a while loop the watch does a reset but stays in a unknown state. It doesn’t really start the program code again.

    Is there a simple way to add a really reliable watchdog on simple_peripheral project that it works?

    Here my code:

    void iniWatchDog(void)
    {
        Watchdog_Params params;
    
       /* Call board init functions */
       Watchdog_init();
       /* Create and enable a Watchdog with resets disabled */
       Watchdog_Params_init(&params);
       params.callbackFxn = (Watchdog_Callback)watchdogCallback;
       params.resetMode = Watchdog_RESET_OFF;
       //params.debugStallMode = Watchdog_DEBUG_STALL_ON;
       watchdogHandle = Watchdog_open(Board_WATCHDOG0, &params);
      // if(watchdogHandle!=NULL)
         //  Watchdog_setReload(watchdogHandle, Watchdog_convertMsToTicks(watchdogHandle,10000));//90000 mseconds
    }
    /*
     *  ======== watchdogCallback ========
     *  Watchdog interrupt callback function.
     */
    void watchdogCallback(uintptr_t unused)
    {
        /* Clear watchdog interrupt flag */
       // Watchdog_clear(watchdogHandle);
        /* Insert timeout handling code here. */
        PIN_setOutputValue(hGpioPin,CC2640R2_LAUNCHXL_PIN_GLED,0);
        delay_ms(5000);
    
        //HAL_SYSTEM_RESET();
        SysCtrlSystemReset() ;
    }

    Obs: If i leave the debug attached and debug the code with CCS  without the while loop, the watchdogcallback gets called. But if i disconnect the debug jtag it never gets called.

  • Hi Michael,

        This is my Watchdog implementation at my project. I have set the Watchdog Reload value to 5000 msec at the board file. If Watchdog_RESET_ON is set and there is no code in the Callback, what happens is after 5 seconds it will go to the Watchdog__Callback() then after 5 seconds it will do a WARM RESET. It is mentioned at Technical docs that WARM Reset is not recommended and implement a code to convert WARM Reset to SYSTEM Reset. So that I would not need to implement that code, I just call HAL_SYSTEM_RESET() at the Callback. To test this. put a breakpoint at HAL_SYSTEM_RESET() and comment out Watchdog_Clear() at the main task. Do CCS Debug Run and after 5 seconds it goes to HAL_SYSTEM_RESET(). To test this without CCS debug uncomment Watchdog_Clear() put a while(1) in your task or somewhere else in your code will also work. Place a led blinking indicator at initialization. Load the program. You will notice that the led blinking happens every 5 seconds, meaning the watchdog works. If you notice I still set Watchdog_RESET_ON, this is just for fail safe if for whatever reason it does not go to Watchdog__Callback() it will still do a WARM Reset at second timeout. Which from my testing is still somehow does the same as a SYSTEM Reset.

    static void BLE_XXXX_init(void)
    {
    
        Watchdog_Init();
    
    }
    
    static void BLE_XXXX_taskFxn(UArg a0, UArg a1)
    {
        // Initialize application
        BLE_XXXX_init();
    
        // Application main loop
        for (;;)
        {
            uint32_t events;
    
            // Waits for an event to be posted associated with the calling thread.
            // Note that an event associated with a thread is posted when a
            // message is queued to the message receive queue of the thread
            events = Event_pend(syncEvent, Event_Id_NONE, SBP_ALL_EVENTS,
                                ICALL_TIMEOUT_FOREVER);
    
            Watchdog_clear(WatchdogHandle);
    
    
    }
    
    void Watchdog__Callback(uintptr_t unused)
    {
        HAL_SYSTEM_RESET();
    }
    
    static void Watchdog_Init(void)
    {
        Watchdog_Params params;
    
        Watchdog_init();
    
        Watchdog_Params_init(&params);
        params.callbackFxn = (Watchdog_Callback)Watchdog__Callback;
        params.resetMode = Watchdog_RESET_ON;
        WatchdogHandle = Watchdog_open(Board_WATCHDOG0, &params);
    
        if (WatchdogHandle == NULL) {
            /* Error opening Watchdog */
            while (1);
        }
    }

    -kel

  • I Markel,
    does your code works if you only uncomment the watchdog clear on your task?
    Because my code it doesn’t, callback gets never called. I have to really put a while loop so that it hangs in the task and than I see that led is blinking and device is resets every 10 seconds. I have also change the time directly on board files. So it is normal if i don’t set a while loop callback is never called? Or is this an issue?
  • Hi Michael,

    My project works with Watchdog_Clear() uncommented. If Watchdog_Clear() is not called it should go to the Callback.

    If Watchdog_RESET_ON is set actually you do not need to set at a Callback Function. If you put a while(1) in your code it will do a WARM Reset at second timeout. You can see sample initialization at Watchdog.h.

    -kel
  • Hi Markel,

    are you using 5x5 package and SDK 1.50.00.58?
    So there is a problem then with my watchdog because it never enters the callback if i dont set a while loop.
    Maybe i need a extra task just for the watchdog?

    OBs: If i debug it always enter in callback. Without debugging it doenst.

  • I have implemented Watchdog at 5x5 SDK v1.40 and also CC2640R2F Launchpad SDK v1.50. I will re-verify later. But, maybe the Callback is not called because of its placement in your code file. Can you put a Watchdog Callback function declaration at top of the code file. Something like this below.

    void Watchdog__Callback(uintptr_t unused);
    
    void Watchdog__Callback(uintptr_t unused)
    {
        HAL_SYSTEM_RESET();
    }

    -kel

  • Hi Markel,

    i have moved the function right on top like you said,  but no success.

    I lefted the device running for a long time and the watchdog callback function was really called and device was succesfully reseted!

    But why is it taking so long to reset?

    Here is my board file code:

    const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC2640R2_LAUNCHXL_WATCHDOGCOUNT] = {
        {
            .baseAddr    = WDT_BASE,
            .reloadValue = 1000 /* Reload value in milliseconds */
        },
    };

    It is set to 1000ms right? Why is it taking more then 10 minutes?

    Anyway i think it is working and if any reason it get stuck somewhere it will be reseted. I have checked with a  while loop and without it.

  • Hi Michael,

    When I implemented Watchdog at 5x5 using SDK v1.40, I was using IAR Embedded Workbench. But just now I implemented Watchdog at SDK v1.40 using CCSv8 and I am experiencing different debugging results. But if I put a while loop it does reset. The reset takes a while to happen probably because the device go to standby mode. When the device goes to standby mode the Watchdog countdown stops.

    -kel
  • Hi Markel,

    so this may be a CCS bug or the counter takes more time when sleeping, is there a way to report a bug to TI?

    I am sending the device 5 seconds to sleep and 5 seconds to advertise. Like you said, the watchdog counter stops.

    But adding a while loop simulates that the watchdog callback gets called and that means it will work in a real occasion.

  • HI Michael,

    TI Engineers are looking at this post so consider this bug reported. Anyway this is intriguing to me as I did not have this problem working with IAR Embedded Workbench. Anyway, I will also look into it at my free time.

    -kel
  • Hi Michael,

         I have finally got into look into this in much detail, by implementing the Watchdog to Simple Peripheral Off-Chip OAD Example Program from SDK v1.40. Which is what I used for my recent CC2640R2F Product Development. Here are my testing results below using CCSV8. Using IAR Embedded Workbench I did not have any problems.

    1. Using CCSV8 the code goes to Watchdog Callback even if you call Watchdog_clear().
    2. Using CCSV8 even if debug stall is set it goes to Watchdog Callback.

         So, debugging the Watchdog using CCSV8 is useless. Hopefully TI Engineers will look into this.

         However, the watchdog still works from my recent tests. At my test I do not call Watchdog_clear() and put a while loop at GAPROLE_CONNECTED. So when I connect using Smartphone Bluetooth App it will countdown at my set watchdog reload value of 5 seconds.

         After connecting with my Smartphone Bluetooth App the device resets every 5 seconds. I set the leds to indicate that the CC2640R2F resets.

         Also, take note when you stop advertising it goes to Standby Mode and the Watchdog Countdown stops.

    -kel

  • Hi Markel,

    thanks for looking in to this. I hope TI can fix this issue.