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.

TM4C129ENCPDT: Watchdog

Part Number: TM4C129ENCPDT
Other Parts Discussed in Thread: EK-TM4C1294XL, UNIFLASH, SYSBIOS

Hi 

How can i configure a watch dog timer in ti rtos. so that i can refresh watchdog timer in specified time. I have found an example of watch dog in ti rtos, but i couldn't  find any ways to control it. could some one help me out to fix this issue.Any documents or tutorials which says about it are welcomed 

thanks in advance!

  • Hi,

      Today is a US public holday. Please expect delayed respoonse. 

  • Hi,

    How can i configure a watch dog timer in ti rtos. so that i can refresh watchdog timer in specified time.

      I suppose you are asking how to configure the WD timer value. Please look at EK-TM4C1294XL.c in the project. By default, the reload value is set to 120000000 for 1 second timeout. You can change it per your application. 

    /*
    * =============================== Watchdog ===============================
    */
    /* Place into subsections to allow the TI linker to remove items properly */
    #if defined(__TI_COMPILER_VERSION__)
    #pragma DATA_SECTION(Watchdog_config, ".const:Watchdog_config")
    #pragma DATA_SECTION(watchdogTivaHWAttrs, ".const:watchdogTivaHWAttrs")
    #endif

    #include <ti/drivers/Watchdog.h>
    #include <ti/drivers/watchdog/WatchdogTiva.h>

    WatchdogTiva_Object watchdogTivaObjects[EK_TM4C1294XL_WATCHDOGCOUNT];

    const WatchdogTiva_HWAttrs watchdogTivaHWAttrs[EK_TM4C1294XL_WATCHDOGCOUNT] = {
    {
    .baseAddr = WATCHDOG0_BASE,
    .intNum = INT_WATCHDOG,
    .intPriority = (~0),
    .reloadValue = 120000000 // 1 second period at default CPU clock freq
    },
    };

  • Hi Charles,

    Thanks for your reply, i have got an problem  with the watchdog firmware.after running the firmware unable to debug or connect to any other tool. i have tried in uniflash tool to erase the flash but unsuccessful.the message what i have received while try to debug is "CORTEX_M4_0: Error connecting to the target "

    here is my code.

    * ======== watchdog.c ========
    */

    #include <stdbool.h>

    /* XDCtools Header files */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>

    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>

    /* TI-RTOS Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/Watchdog.h>

    /* Example/Board Header files */
    #include "Board.h"

    #define TASKSTACKSIZE 512

    bool flag = false;

    Task_Struct task0Struct;
    Char task0Stack[TASKSTACKSIZE];
    Watchdog_Handle watchdogHandle;

    /*
    * ======== watchdogCallback ========
    * Watchdog interrupt callback function. It toggles and LED, and if a button
    * has not been pressed, clears the watchdog interrupt flag.
    */
    void watchdogCallback(uintptr_t unused)
    {
    /* Clear watchdog interrupt flag */
    System_printf("dog bite...");
    System_flush();
    Watchdog_clear(watchdogHandle);
    GPIO_toggle(Board_LED0);
    }

    /*
    * ======== gpioButtonFxn ========
    * Callback function for the GPIO interrupt on Board_BUTTON0.
    */
    void gpioButtonFxn(unsigned int index)
    {
    flag ^= true;
    GPIO_write(Board_LED0, Board_LED_ON);
    }

    /*
    * ======== taskFxn ========
    * Sets a flag and clears the watchdog timer if the button has been pressed.
    */
    Void taskFxn(UArg arg0, UArg arg1)
    {

    while (true) {
    /* Prevent Watchdog ISR trigger if button was pushed */
    if (flag) {
    Watchdog_clear(watchdogHandle);
    }
    }
    }

    /*
    * ======== main ========
    */
    int main(void)
    {
    Task_Params taskParams;
    Watchdog_Params params;

    /* Call board init functions */
    Board_initGeneral();
    Board_initGPIO();
    Board_initWatchdog();

    /* Construct BIOS objects */
    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, taskFxn, &taskParams, NULL);

    /* Turn on user LED */
    GPIO_write(Board_LED0, Board_LED_ON);

    /* Install Button callback */
    GPIO_setCallback(Board_BUTTON0, gpioButtonFxn);

    /* Enable interrupts */
    GPIO_enableInt(Board_BUTTON0);

    System_printf("Starting the Watchdog example\nSystem provider is set to "
    "SysMin. Halt the target to view any SysMin contents in"
    " ROV.\n");

    /* SysMin will only print to the console when you call flush or exit */
    System_flush();

    /* Create and enable a Watchdog with resets disabled */
    Watchdog_Params_init(&params);
    params.callbackFxn = (Watchdog_Callback)watchdogCallback;
    params.resetMode = Watchdog_RESET_ON;

    watchdogHandle = Watchdog_open(Board_WATCHDOG0, &params);
    if (watchdogHandle == NULL) {
    System_abort("Error opening Watchdog!\n");
    }
    Watchdog_setReload(watchdogHandle, 2000); // Set timeout to 5 seconds
    // uint32_t ticks = (milliseconds * Clock_tickPeriod) / 1000;
    /* Start BIOS */
    BIOS_start();

    return (0);
    }

  • Watchdog_setReload(watchdogHandle, 2000); // Set timeout to 5 seconds

    While your comment says 5 seconds timeout, you actually put in 2000 as in CPU cycles which is equal 16.5uS at 120MHz. This means it is going to assert WD reset every 16.5us. This time is probably too short for the debugger to connect.  If you can press Board_BUTTON0 fast enough right before WD expires, you might have a chance to stop WD from generating future reset. But I don't know your chance of success. You might need to use a function generator to force Board_BUTTON0 low instead of using your finger. 

    You can also try to unlock the device to bring the device to its factory setting. I also don't know the success rate here as explained that the WD reset comes just too quickly. Follow section 5.3.2 in this app note to use dbgjtag.exe to unlock the device if you are using XDS debug probe. https://www.ti.com/lit/pdf/spma075

    If you can unlock the device then I will suggest in the future you add some code that will rely on the state of an GPIO input pin before you enable WD. If the expected pin state is not met, it will just spin and won't proceed further. This way you have a way to prevent any erroneous WD setting causing debugger unable to connect. 

  • Hi charles,

    Thank you for your response, Im using custom development board . So how can i get back to factory setting in that case?

  • Hi,

      What debug probe to you have? In my last reply, I said that you could use dbgjtag.exe to unlock your device if use debug probe such as XDS200. Refer to section 5.3.2 of the app note again. https://www.ti.com/lit/pdf/spma075

      Also refer to the same app note in section 4.8 where you can use a LaunchPad to debug out your custom board. When you use LaunchPad, you can use LM flash programmer or Uniflash to unlock the device by selecting ICDI debug probe. 

  • Hi, Charles,

    Thanku for your response. I was able to erase flash by adding and reset button.But there is still some issue with my code code get stuck over " Task_SupportProxy_swap((Ptr)&prevTask->context,
    (Ptr)&Task_module->curTask->context);". 

    This is my code,

    void watchdogCallback(uintptr_t unused)
    {
    /* Clear watchdog interrupt flag */
    Watchdog_clear(watchdogHandle);
    System_printf("dog bite...");
    System_flush();
    UartWrite((char*)"\n\rdog bite...\n\r");
    Watchdog_setReload(watchdogHandle, 600000000); // Set timeout to 5 seconds((120000000*5000/1000)) = 600000000
    GPIO_write(Board_LED0, 1);
    }

    Void taskFxn(UArg arg0, UArg arg1)
    {

    while (1)
    {
    Watchdog_clear(watchdogHandle);
    GPIO_toggle(Board_LED1);
    UartWrite((char*)"\n\rHello from task function...\n\r");
    Watchdog_setReload(watchdogHandle, 600000000); // Set timeout to 5 seconds((120000000*5000/1000)) = 600000000

    }
    }

    /*
    * ======== main ========
    */
    int main(void)
    {
    /* Call board init functions */
    Board_initGeneral();
    Board_initGPIO();
    Board_initWatchdog();
    Watchdog_init();


    /* Construct BIOS objects */
    Task_Params_init(&taskParams);
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, taskFxn, &taskParams, NULL);

    GPIO_setConfig(Board_LED1, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_HIGH);
    GPIO_setConfig(Board_LED0, GPIO_CFG_OUTPUT | GPIO_CFG_OUT_HIGH);

    GPIO_write(Board_LED0, 1);
    GPIO_write(Board_LED1, 0);

    System_printf("Starting the Watchdog example\nSystem provider is set to "
    "SysMin. Halt the target to view any SysMin contents in"
    " ROV.\n");

    /* SysMin will only print to the console when you call flush or exit */
    System_flush();
    /* Create and enable a Watchdog with resets disabled */
    Watchdog_Params_init(&params);
    params.callbackFxn = (Watchdog_Callback)watchdogCallback;
    params.resetMode = Watchdog_RESET_ON;

    watchdogHandle = Watchdog_open(Board_WATCHDOG0, &params);
    if (watchdogHandle == NULL) {
    System_abort("Error opening Watchdog!\n");
    }
    Watchdog_setReload(watchdogHandle, 600000000); // Set timeout to 5 seconds((120000000*5000/1000)) = 600000000
    // uint32_t ticks = (milliseconds * Clock_tickPeriod) / 1000;
    /* Start BIOS */
    BIOS_start();


    return (0);

    }

    could you please help me to solve this

  • In your taskFxn, you are in a forever while loop constantly clearing watchdog, toggling GPIO and send data to UART. You will crash the system. There is no synchronization with any event in this function. Why don't you try the stock example and just change the watchdog timeout to 5 seconds using Watchdog_setReload. Get the basic to work first and gradually modify per your application requirements.

    Void taskFxn(UArg arg0, UArg arg1)
    {

    while (1)
    {
    Watchdog_clear(watchdogHandle);
    GPIO_toggle(Board_LED1);
    UartWrite((char*)"\n\rHello from task function...\n\r");
    Watchdog_setReload(watchdogHandle, 600000000); // Set timeout to 5 seconds((120000000*5000/1000)) = 600000000

    }