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.

TMS320F28379D: Watchdog reset

Other Parts Discussed in Thread: C2000WARE

Hi,

Currently I don't use the watchdog; How can I enable watchdog to cause reset?

I've tried to insert the code below in my program but it doesn't works, nothing happens.

//Init.c
//
// Allow to change the state of the Watchdog disable (WDDIS)   
//
    EALLOW;
    WdRegs.SCSR.all = 0x0001;
    EDIS;


// Main.c

//
// Enable the watchdog and write 1,0 1 in WDCHK
//
    EALLOW;
    WdRegs.WDCR.all = 0x0028;
    EDIS;


//
// Reset the core ?!
//

    EALLOW;
    WdRegs.WDCR.bit.WDCHK = 0; // Example, I write another value
    EDIS;


What is wrong?

Regards,

  • Hi,

    I separated the Flash and watchdog thread and opened this post for you.

    C2000Ware has examples that can show you watchdog reset usage.

    Ex 1: Below code is from \C2000Ware_x_xx_xx_xx\driverlib\f28004x\examples\flash\flashapi_ex2_ldfu.c.

    //
    // Set the watchdog to generate a reset signal instead of an
    // interrupt signal
    //
    SysCtl_setWatchdogMode(SYSCTL_WD_MODE_RESET);

    //
    // Enable the watchdog
    //
    SysCtl_enableWatchdog();

    Ex 2: Below code is from \C2000Ware_x_xx_xx_xx\driverlib\f2837xd\examples\dual\nmi\nmi_ex1_cpu2wdreset.c

    //
    // Set the watchdog to generate an interrupt signal instead of a
    // reset signal
    //
    if(SysCtl_isWatchdogInterruptActive()==false)
    SysCtl_setWatchdogMode(SYSCTL_WD_MODE_RESET);
    else
    {
    SysCtl_serviceWatchdog();
    SysCtl_setWatchdogMode(SYSCTL_WD_MODE_RESET);
    }

    //
    // Reset the watchdog counter
    //
    SysCtl_serviceWatchdog();

    //
    // Enable the watchdog
    //
    SysCtl_enableWatchdog();

    I can assign our system control expert if you have further questions. Please let me know.

    Thanks and regards,

    Vamsi

  • Hi Vamsi,

    I've tried the example "watchdog_ex1_service" ; I've understood how the program works.
    Then I've tried to implement this code in my program ;

    //1. Disable the Watchdog
    
        EALLOW;
        WdRegs.WDCR.all = 0x0040; // Disable the watchdog;
        EDIS;
    
    //2. Configure the Watchdog to generate a reset signal
    
        EALLOW;
        WdRegs.SCSR.bit.WDENINT = 0; // Generate a reset signal
        EDIS;
    
        EINT;
        ERTM;
    
    //3. Reset the Watchdog counter
    
        EALLOW;
        WdRegs.WDKEY.bit.WDKEY = 0x55; // Clear the WDCNTR bits
        WdRegs.WDKEY.bit.WDKEY = 0xAA; // Clear the WDCNTR bits
        EDIS;
    
    //4. Enable the watchdog
    
    // I've added this line because WDOVERRIDE was 0 ; even with this line, WDOVERRIDE = 0; it's very strange
        EALLOW;
        WdRegs.SCSR.bit.WDOVERRIDE = 1; // Allow to change the state of WDDIS
        EDIS;
    
        EALLOW;
        WdRegs.WDCR.all = 0x0028; // Enable the watchdog
        EDIS;

    I cannot enable the Watchdog, and I don't know why.
    Program is on my Flash, could it be a problem?

    Regards

  • Hi,

    In your disable WD code you are not writing the KEY value so that code is not working as expected it may cause device to get reset after executing that code. You need to write 0x68 there.

    //1. Disable the Watchdog

        EALLOW;
        WdRegs.WDCR.all = 0x0068; // Disable the watchdog;
        EDIS;

    Regards,

    Vivek Singh

  • Hi Vivek,

    Thanks for your replies.

    I've modified my code (stupid mistake f), but nothing changes. 
    Watchdog is still disabled, even after enable.

    Regards,

  • That is strange. Can you try to write the register directly from CCS register view and see if that is working?

    Vivek Singh

  • Vivek Singh said:

    That is strange. Can you try to write the register directly from CCS register view and see if that is working?

    Vivek Singh

    I cannot write directly from CCS register view.

    //
    // Included Files
    //
    #include "F28x_Project.h"
    
    //
    // Function Prototypes
    //
    
    uint32_t loopCount;
    
    //
    // Main
    //
    void main(void)
    {
    
        InitSysCtrl();
    
    /*  EALLOW;
        WdRegs.WDCR.all = 0x0068; // Disable the watchdog (done in InitSysCtrl() )
        EDIS;
    */
        loopCount = 0;
    
        EALLOW;
        WdRegs.SCSR.bit.WDENINT = 0; // Generate a reset signal
        EDIS;
    
        EINT;
        ERTM;
    
        EALLOW;
        WdRegs.WDKEY.bit.WDKEY = 0x55; // Clear the WDCNTR bits
        WdRegs.WDKEY.bit.WDKEY = 0xAA; // Clear the WDCNTR bits
        EDIS;
    
        EALLOW;
        WdRegs.SCSR.bit.WDOVERRIDE = 1; // Allow to change the state of WDDIS
    
        WdRegs.WDCR.all = 0x0028; // Enable the watchdog
        EDIS;
    
    
        while(1)
        {
            loopCount++;
        }
    }
    //
    // End of file
    //

    With this program, WDOVERRIDE is always 0 and watchdog always disabled. loopCount never increase.

    Unlike watchdog_ex1_service.c, my program in on the FLASH ; can it be the problem?

    Regards,

  • WDOVERRIDE should not be '0'. If it is '0' then user can not change this to '1'. It only get set to '1' by reset. Are you changing that bit to '0' in your code ?

    Regards,

    Vivek Singh

  • My full code is the program above (I want to test with a simple program), so I never change WDOVERRIDE bit to '0'.

    Regards,

  • You have this code -

    //2. Configure the Watchdog to generate a reset signal
        EALLOW;
        WdRegs.SCSR.bit.WDENINT = 0; // Generate a reset signal
        EDIS;
    This is read-modify-write operation which will read the OVERRIDE bit as '1' (default value is '1') and then write '1' hence will clear the OVERRIDE (it's write '1' to clear bit). Please change this code to write full register with updating only field which is needed.
    We have this note in TRM in section "3.15.4.1 SCSR Register (Offset = 22h) [reset = 5h]"
    "It is recommended to only use 16 bit accesses to write to this register. Use a read-modify-write instruction

    may inadvertently clear other bits."

    That should fix the issue.
    Regards,
    Vivek Singh
  • Vivek,

    In my case, after watchdog disable, I'm in the goodconfiguration (WDENINT = 0, WDOVERRIDE  = 1), so I don't have to modify SCSR register.
    But to try what you've said, I've tried to write WDENINT = 1 by 2 ways :

    • Writing the full register : WdRegs.SCSR.all = 0x0003;
    • or
    • Using a "or" to update only field which is needed : WdRegs.SCSR.all |= 0x0002;

    In both case, WDOVERRIDE  change to '0' after this line. 
    What's the right way to do it?

    Regards,

  • Both method will clear the bit because you are writing '1' to WDOVERRIDE bit. You need to write '0' to WDOVERRIDE bit when updating other bits.

    Please see below snapshot of this register bit definition in TRM.

    Hope this helps.

    Regards.,

    Vivek Singh

  • Hi Vivek,

    Thanks for your answer.

    I've did a little program to see if the reset works correctly, but it doesn't work.

    Program is simple :

    - During initialization, I'm toggling a led every 5 sec (to identify when I'm in initialization phase)
    - In my main program :
             - 1st step is a quick blinking (every second about) of the led when variable < 50
             - 2nd step (when variable = 50) is to write a wrong value in order to not reset WDCNTR and have an overflow which produce a reset.

    After the reset normally, I'm going in initialization phase (toggle every 5 sec), but it doesn't work.
    When I am in the condition (if variable ==50), then variable is initialized to 0, but after nothing happens.
    Could you tell me what I am missing ? 

    //
    // Included Files
    //
    #include "F28x_Project.h"
    
    #include "Init.h"
    
    uint32_t WDCounter;
    unsigned int variable;
    //
    // Main
    //
    void main(void)
    {
    
        CpuSysRegs.RESC.bit.WDRSn = 1;
    
        Initialization(); // InitSysCtrl();
    
        WDCounter = 0;
        variable = 0;
    
        EALLOW;
        WdRegs.SCSR.all = 0x0000; // Generate a reset signal
        EDIS;
    
        GpioDataRegs.GPBDAT.bit.GPIO34 = 0;
        DELAY_US(5000000);
        GpioDataRegs.GPBDAT.bit.GPIO34 = 1;
        DELAY_US(5000000);
        GpioDataRegs.GPBDAT.bit.GPIO34 = 0;
        DELAY_US(5000000);
        GpioDataRegs.GPBDAT.bit.GPIO34 = 1;
        DELAY_US(5000000);
    
        EINT;                      // Enable Global interrupt INTM
        ERTM;
    
        EALLOW;
        WdRegs.WDKEY.all = 0x0055; // Clear the WDCNTR bits
        WdRegs.WDKEY.all = 0x00AA; // Clear the WDCNTR bits
        EDIS;
    
        EALLOW;
        WdRegs.WDCR.all = 0x0028; // Enable the watchdog
        EDIS;
    
    
        while(1)
        {
            if (variable < 50)
            {
                EALLOW;
                WdRegs.WDKEY.all = 0x0055; // Clear the WDCNTR bits
                WdRegs.WDKEY.all = 0x00AA; // Clear the WDCNTR bits
                EDIS;
    
                WDCounter ++;
    
                if ( WDCounter > 3500000 )
                {
                    GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;
                    WDCounter = 0;
                    variable++;
                }
            }
    
            if (variable == 50)
            {
                EALLOW;
                WdRegs.WDKEY.all = 0x0055; // Do not clear the WDCNTR bits to have overflow
                WdRegs.WDKEY.all = 0x0000; // Do not clear the WDCNTR bits to have overflow
                EDIS;
            }
        }
    }
    //
    // End of file
    //
    

    Thank you.

    Regards

  • Sorry for late reply.

    When I am in the condition (if variable ==50), then variable is initialized to 0, but after nothing happens.

    If variable is getting initialize to '0' then it means device got reset and main() is getting executed again. Right? Which part is not working here ?

    Regards,

    Vivek Singh

  • Hi Vivek,

    I'm agree with you, variable is getting initialize to '0', but after my software doesn't restart (no initialization phase with around 5 seconds blinking, then no 2nd phase with 1 second blinking). 

    How can I verify where my software is after a restart?

    If I have a reset signal in Debug mode, my target must appears disconnected on Code Composer?

    Regards,

  • If you have CCS connected then device will boot as per emulation BOOT after watchdog reset. If emulation boot mode is not set correctly (BOOT to Flash , I am assuming you are loading the code in flash) then CPU will get stuck in BOOTROM code itself hence your code will not re-run after reset.

    You can set the emulation flash boot by using CCS option as shown below. You need to select this before running the code.

    Regards,

    Vivek Singh

  • Hi Vivek,

    Thanks for your answer.

    Yes of course, I load the code in Flash.
    Ok, I've understood. So if I want my device boot after a watchdog reset in debug mode, I need to choose "EMU_BOOT_FLASH". I'll do the test tomorrow or Thursday.

    But I've to proceed like this only in debug mode if I have CCS connected?

    If I want the same operation but without CCS connected and not in debug mode (in standalone mode), how must I proceed?

    Regards,

  • Hi,

    If I want the same operation but without CCS connected and not in debug mode (in standalone mode), how must I proceed?

    In standalone it'll work fine as long as you have BOOTMODE pin setting proper to run application code after reset.

    Regards,

    Vivek Singh

  • Vivek,

    Yes, I'm agree.
    It's another topic ; that's why I've opened a new thread, but I've no news from your colleague:

    Any idea?

    Thank you very much for your support.

    Regards,

  • Hi,

    Siddharth will reply on that post in detail but one quick thing you can do to debug the non working code is, load the code and instead of running after loading, issue debug reset (from CCS) and then set the BOOTMODE to EMU_BOOT_FLASH, set breakpoint on main() function and then run and see if CPU halts at main(). If not then you have some issue in entry point which is causing the issue.

    Regards,

    Vivek Singh

  • Hi Vivek,

    So I've proceed like you've said :

    - Load the code
    - Run --> Reset --> CPU Reset
    - "EMU_BOOT_FLASH"
    - Set breakpoint on main()
    - And finally, Run

    The CPU halts at main, so issue isn't the entry point? What's the issue?( just for information, I've saw one thing ; even if I didn't set the BOOTMODE to EMU_BOOT_FLASH, the CPU halts at main)

    Any idea about this issue?

    Thank you.

    Regards

  • Can you check your map file to see if there is anything mapped in RAM?

    Regards,

    Vivek Singh

  • Hi,

    In my 2837xD_FLASH_lnk_cpu1.cmd, things which are mapped in RAM are :

       /* Allocate uninitalized data sections: */
       .stack              : > RAMM1        PAGE = 1					/* stack space */
       .ebss               : >> RAMLS5 | RAMGS0 | RAMGS1       PAGE = 1 /* global and static variables */
       .esysmem            : > RAMLS5       PAGE = 1               		/* memory for far malloc functions */
       .cio                : > RAMLS5     PAGE = 1
    
        IQmath : > RAMGS2, PAGE = 1
        IQmathTables : > RAMGS2, PAGE = 1

    Do I need to map everything on FLASH? Can it be a cause for my issue?

    Regards, 

  • This look ok.  I assume your WD issue is resolved.

    Vivek Singh

  • Hi Vivek,

    No it's not resolved at all.

    When I proceed like you've said, CPU halts at main on the breakpoint. So it means there's not an entry point issue.

    When I proceed like follow, my CPU doesn't restart and I don't know where I am in the software (there's no breakpoint) :

    - Load the code
    - "EMU_BOOT_FLASH"
    - Run
    - Disconnect Target
    - Switching OFF the power supply
    - Switching ON the power supply

    How can I proceed?

    Thank you.

    Regards,

  • Hi,

    When you switch off and switch on the power supply, CCS will be disconnected and you'll not be able to trace your SW so not sure what do you mean by "don't know where I am in the software (there's no breakpoint) :"

    When CCS is disconnected, device will boot based on BOOTMODE pin settings which need to be set to BOOT to Flash. So please check the BOOTMODE pin setting.

    Regards,

    Vivek Singh

  • Hi Vivek,

    There're two different topics, I did not want any confusion, so please forget my last message :

    • First one is the current subject : I want watchdog to reset the CPU, that's why I did this program : 
    //
    // Included Files
    //
    #include "F28x_Project.h"
    
    #include "Init.h"
    
    uint32_t WDCounter;
    unsigned int variable;
    //
    // Main
    //
    void main(void)
    {
    
        CpuSysRegs.RESC.bit.WDRSn = 1;
    
        Initialization(); // InitSysCtrl();
    
        WDCounter = 0;
        variable = 0;
    
        EALLOW;
        WdRegs.SCSR.all = 0x0000; // Generate a reset signal
        EDIS;
    
        GpioDataRegs.GPBDAT.bit.GPIO34 = 0;                                  // First loop blinking every 5 secs
        DELAY_US(5000000);
        GpioDataRegs.GPBDAT.bit.GPIO34 = 1;                                  // First loop blinking every 5 secs
        DELAY_US(5000000);
        GpioDataRegs.GPBDAT.bit.GPIO34 = 0;                                  // First loop blinking every 5 secs
        DELAY_US(5000000);
        GpioDataRegs.GPBDAT.bit.GPIO34 = 1;                                  // First loop blinking every 5 secs
        DELAY_US(5000000);
    
        EINT;                      // Enable Global interrupt INTM
        ERTM;
    
        EALLOW;
        WdRegs.WDKEY.all = 0x0055; // Clear the WDCNTR bits
        WdRegs.WDKEY.all = 0x00AA; // Clear the WDCNTR bits
        EDIS;
    
        EALLOW;
        WdRegs.WDCR.all = 0x0028; // Enable the watchdog
        EDIS;
    
    
        while(1)
        {
            if (variable < 50)
            {
                EALLOW;
                WdRegs.WDKEY.all = 0x0055; // Clear the WDCNTR bits
                WdRegs.WDKEY.all = 0x00AA; // Clear the WDCNTR bits
                EDIS;
    
                WDCounter ++;
    
                if ( WDCounter > 3500000 )
                {
                    GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1;
                    WDCounter = 0;
                    variable++;
                }
            }
    
            if (variable == 50)
            {
                EALLOW;
                WdRegs.WDKEY.all = 0x0055; // Do not clear the WDCNTR bits to have overflow
                WdRegs.WDKEY.all = 0x0000; // Do not clear the WDCNTR bits to have overflow
                EDIS;
            }
        }
    }
    //
    // End of file
    //

    At the end of the software, "variable" is initialized to zero, but my software doesn't restart (in the first loop of led blinking every 5 seconds).

    It's strange because when I'm following your procedure (see below), software halt at the breakpoint, so I haven't an entry point issue : 

    - Load the code
    - Run --> Reset --> CPU Reset
    - "EMU_BOOT_FLASH"
    - Set breakpoint on main()
    - And finally, Run

    So do you know why after the reset (when "variable" is initialized to zero), my first loop (see below) never restart?(I've removed the breakpoint of course)

        GpioDataRegs.GPBDAT.bit.GPIO34 = 0;
        DELAY_US(5000000);
        GpioDataRegs.GPBDAT.bit.GPIO34 = 1;
        DELAY_US(5000000);
        GpioDataRegs.GPBDAT.bit.GPIO34 = 0;
        DELAY_US(5000000);
        GpioDataRegs.GPBDAT.bit.GPIO34 = 1;
        DELAY_US(5000000);

    • Second topic topic is the why, after a power supply switch off, my software doesn't restart on Flash?

    BOOTMODE pin are set to BOOT to Flash. I've explain the issue in the following topic, but I have no news of Siddharth.

    https://e2e.ti.com/support/microcontrollers/c2000/f/171/p/892945/3312547#3312547

    Thanks for your answer.

    Regards,

  • Hi,

    Sorry, but I am not clear what is not working in this case. You have to follow the procedure which I mentioned to restart your application after watchdog reset and you confirmed that it is working fine. CPU halts at main after WD reset. So what is not working ?

    Regards,

    Vivek Singh

  • Hi Vivek,

    Sorry if it's not clear, sometimes my English is not very good.

    If I just follow your procedure :

    - Load the code
    - Run --> Reset --> CPU Reset
    - "EMU_BOOT_FLASH"
    - Set breakpoint on main()
    - And finally, Run

    Reset is done by the instruction :  "Run --> Reset --> CPU Reset" and its done before I'm running the code. So when I'm running my code, it stops immediately to the breakpoint, it's logical.

    If I execute the full program above, reset is done by these instructions :

        EALLOW;
        WdRegs.WDKEY.all = 0x0055; // Do not clear the WDCNTR bits to have overflow
        WdRegs.WDKEY.all = 0x0000; // Do not clear the WDCNTR bits to have overflow
        EDIS;

    Then, program restart and "variable" is initialized to zero :

    variable = 0;

    But after, my led never blinks :

    EALLOW;
    WdRegs.SCSR.all = 0x0000; // Generate a reset signal
    EDIS;
    
    GpioDataRegs.GPBDAT.bit.GPIO34 = 0;                                  // First loop blinking every 5 secs
    DELAY_US(5000000);
    GpioDataRegs.GPBDAT.bit.GPIO34 = 1;                                  // First loop blinking every 5 secs
    DELAY_US(5000000);
    GpioDataRegs.GPBDAT.bit.GPIO34 = 0;                                  // First loop blinking every 5 secs
    DELAY_US(5000000);
    GpioDataRegs.GPBDAT.bit.GPIO34 = 1;                                  // First loop blinking every 5 secs
    DELAY_US(5000000);

    Do you understand my issue?

    Regards,

  • May be you can attach your project and I can try running it on our setup and see if we could reproduce the issue you are seeing.

  • Hi Vivek,

    Can I send it you in private? If I attach the project, Anyone can open it, no?

    Regards

  • I'll send you a friend request and then you should be able to send me in private message. Please make sure there is nothing in your code which you can not share it with TI.

    Regards,

    Vivek Singh

  • I have not received the code from you. If this issue is fixed, please mark it resolved.

    Regards,

    Vivek Singh

  • Hi Vivek,

    Sorry for the wait, I send you the software.

    Regards

  • This issue was resolved offline.

    Regards,

    Vivek Singh