WDOG Reconfigure

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

WDOG Reconfigure

1,695 Views
patrickfoley
Contributor I

I am trying to reconfigure the WDOG.  I have been trying to get the following code to work, but I end up getting a reset as soon as I try to write the first unlock value.  I can't figure out what is going on, any help would be appreciated.

/*********************************************************************            

*void WDOGInit(void)

**********************************************************************

*

*   Return: NONE

*

*   Parameters: NONE

*

*   Notes:

*

*********************************************************************/

void WDOGInit(void) {

/*Disable the interrupts*/   
asm("CPSID i");    

/*Unlock the WDOG to reconfigure it*/
WDOG_CNT = 0xC520;       /*First Unlock Word*/ 
WDOG_CNT = 0xD928;       /*Second Unlock Word*/                 
                    
/*Set the timeout value to 10 mS*/
WDOG_TOVAL = 1000;          
        
/*Set the clock to the 1KHz LPOCLK*/
//WDOG_CS2 = 0x01;
WDOG_CS2 = WDOG_CS2_CLK_MASK;

   

/*Enable the Dog*/
WDOG_CS1 = WDOG_CS1_EN_MASK;
   
/*Enable the interrupts*/
asm("CPSIE i");

   

} /* end void WDOGInit(void) */

/**********************************************************************/

/**********************************************************************/

Labels (1)
0 Kudos
7 Replies

1,031 Views
patrickfoley
Contributor I

Mark, Jorge,

Thank you for the responses.  As for WDOG in debug, I am setting the DBG bit within the WDOG_CS1 register.  My understanding is that this will enable the WDOG during debug.

pastedImage_0.png

The UPDATE bit

is set during the __init_hardware routine:

void __init_hardware()

{

    SCB_VTOR = (uint32_t)__vector_table; /* Set the interrupt vector table position */

  

    /* Disable the Watchdog because it may reset the core before entering main(). */

  

    WDOG_TOVAL = 0xE803; // setting timeout value

    WDOG_CS2 = WDOG_CS2_CLK_MASK; // setting 1-kHz clock source

    WDOG_CS1 = 0x23; // Watchdog disabled,

                     // Watchdog interrupts are disabled. Watchdog resets are not delayed,

                     // Updates allowed. Software can modify the watchdog configuration registers within 128 bus clocks after performing the unlock write sequence,

                     // Watchdog test mode disabled,

                     // Watchdog disabled in chip debug mode,

                     // Watchdog enabled in chip wait mode,

                     // Watchdog enabled in chip stop mode.

}

Once this routine is complete the TOVAL (BIG Endianess) is set @ 1000 for a 1 second (Supposedly, The value of CLKS is 0x03 (WDOG_CS2_CLK_MASK = 0x3u) so it is clocked by external NOT the 1 kHz internal LPOSC as described in comments by FS).  WDOG_CS2 - 0x03 setting the CLK source to the External Clock Source

pastedImage_2.png

WDOG_CS1 disables the WDOG, Allows updates at a future time, Enables WDOG in chip wait mode, and Enables WDOG in chip stop mode

pastedImage_3.png

pastedImage_4.png

please correct me if I am wrong at this point.  Mark,  I am assuming that the ALLOWUPDATE bit that is referenced in your post above is equivalent to the UPDATE bit I am using.

So, things are initialized and my main is entered.  The first thing I do is setup the ICS to run at roughly 16 MHz.  I verified this with an oscilloscope while the CLKOE bit was set, placing BUS Clock on PTH2.  Once the clock is setup, I "wiggle" pin PTC1 for 10 mS (roughly) which is connected to an LED on the TRK-KEA64 dev board I am working with.  I am also triggering off this line with my scope.  This give me an indicator that the IC is starting up.  I now enter my WDOGInit() routine:

/*********************************************************************           

*void WDOGInit(void)

**********************************************************************

*

*   Return:NONE

*

*   Parameters: NONE

*

*   Notes:

*

*********************************************************************/

void WDOGInit(void) {

/*Disable the interrupts*/  
asm("CPSID i"); 
/*Unlock the WDOG to reconfigure it*/
WDOG_CNT = 0x20C5;      /*First Unlock Word*/
WDOG_CNT = 0x28D9;      /*Second Unlock Word*/                
/*Set the timeout value to 100 mS*/
WDOG_TOVAL = 0x6400;         
/*Set the clock to the 1KHz LPOCLK*/
WDOG_CS2 = 0x01; 

  

#ifdef  WDOG_Debug
/*Enable the Dog*/
WDOG_CS1 = 0x84;

#else

/*Enable the Dog*/
WDOG_CS1 = 0x80;

#endif

 

/*Enable the interrupts*/
asm("CPSIE i");

  

} /* end void WDOGInit(void) */

/**********************************************************************/

/**********************************************************************/

Once I exit the WDOGInit routine I have another GPIO PTC2, also connected to an LED on the dev board, that I set to indicate successful return.  I then enter an infinite while loop that periodically toggles yet another GPIO PTC0, again, also tied to an LED.  I DO NOT service the WDOG during this loop, so the expected result is a system reset every 100 mS or so.

WDOGInit();

  

PSORC2 = 0x01;

  

/****************************************************************/
/****************************************************************/

  

  

PDDRC0 = (unsigned char)Output;
tmpCounter = 0x0000;

  

while(1) {
/* /*Disable the interrupts*//**/
/* asm("CPSID i");           */
/*                           */
/* WDOG_CNT = 0x02A6;        */
/* WDOG_CNT = 0x80B4;        */
/*                           */
/* /*Enable the interrupts*/ /**/
/* asm("CPSIE i");           */

  

if(++tmpCounter >= 0x0001FFFF) {
PTORC0 = 1;
tmpCounter = 0x0000;  
}else {     
}

  

} /* end while(1) */

  

return(0);

*****PLEASE NOTE THE WDOG SERVICE IS COMMENTED OUT*****

I launch CodeWarrior, and import my elf file that is generated.  I set a break point within my WDOGInit routine where I turn off the interrupts. And I run.

pastedImage_5.png

The WDOG registers are set as expected CS1 = 0x23, CS2 = 0x03, TOVAL = 0x03e8.

I try stepping into the next instruction but using the debugger I get a reset, so I place a breakpoint at the spot I re-enable the interrupts and allow the code to run.

pastedImage_6.png

Again the registers are setup as expected.  CSS1 = 0x84 (WDOG enabled, and WDOG enabled during debug),  CS2 has the CLK set to the 1KHz LPOSC, TOVAL is set at 100 for a reset @ 100 mS.  I then allow the code to run,  It then enteres the infinite loop and begins to toggle the LED connected to PTC0 and never show any sign of resetting, ("Wiggle" LED Signals).

I also tried using the OPEN SDA connection to upload just my hex file (allowing the code to NOT run in debug mode I am assuming),  and the result is the same as far as what I see on the scope and with the led's.

So, here is my question, what am I doing wrong?  Thank you for the previous replies but everything that you sent me is exactly what I was doing.  I thought that could be seen in the elf file.  As far as the differences yes I tried mirroring the unlock values because the Endianess is BIG Endianess for the CNT Register.  WDOG_CNTH is at a lower memory address than WDOG_CNTL.  Writing BIG Endianess style was causing a WDOG reset as soon as I tried to write the first unlock sequence.  Go figure that some registers that are BIG Endianess in memory are written to in Little Endianess fashion (WDOG_CNT) while others are written in BIG Endianess fashion (WDOG_TOVAL)  really sucks as a developer, cause it is usually left as an exercise to the developer to figure out WHICH ONES.  So anyway any help that you could provide will be GREATLY APPRECIATED.

As a side,  I was noticing in the debugger that the value of CNT was not increasing.  It appears to be 0x0000 all the time.  I checked and cannot find any gate control for the LPO within the SIM_SCGC register, so I am assuming that the 1KHz LPO is "always on".

0 Kudos

1,031 Views
Robinwithu
Senior Contributor I

Hi,

I think the values which you are setting for 10mse and 100msec are not correct.for 10 msec sec you just write in WDOG_TOVAL =10 as per 1Khz clock frequency and for 64  msec just 64 Decimal.

Thnanks and kind Regards

Robin

0 Kudos

1,031 Views
davidsherman
Senior Contributor I

Hi Patrick, glad to hear you got through the endianness issue with the WDOG_TOVAL register, I just went through that exercise myself.  One thing I discovered which I think is slightly misleading is the enable bit for debug.  I found that you may not want to enable it in debug, because the watchdog will actually do what it's supposed to do if disabled while debugging, despite what Jorge says.  I found that if that bit is enabled, the counter will continue running if you pause execution, so if you set a breakpoint or try stepping through code, the watchdog will reset it.  If you leave it disabled, the watchdog will still do what its supposed to do, but the counter is suspended if you stop execution so you can still debug.  At least on a KE06 that's what it does.

Since I made this mistake, are you single stepping through the lines where it's initialized?  It won't work because the bus clock still runs and the window to configure it will expire as soon as you pause execution.

These lines worked for me for setting a 1-second timeout.  I know that all the registers have to be written for the watchdog configuration to take effect, although if you are not enabling the windowing you don't have to write to the window registers.

WDOG_CNT = 0x20C5; //unlock sequence

WDOG_CNT = 0x28D9;

WDOG_TOVALL = 0xE8; //1-second timeout

WDOG_TOVALH = 0x03;

WDOG_CS2 = WDOG_CS2_CLK (0x01); //Use 1kHz clock

WDOG_CS1 = (WDOG_CS1_EN_MASK | WDOG_CS1_UPDATE_MASK);

Robin:  He's using the 1kHz clock, and 0x64 is 100 decimal.  Also, the WDOG_TOVAL register is backward, so you have swap the bytes of the 16-bit value for it to write correctly. 

0 Kudos

1,031 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Patrick:

The unlock values are mirrored. I think they should be:

WDOG_CNT = 0x20C5;

WDOG_CNT = 0x28D9;


Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,031 Views
patrickfoley
Contributor I

Jorge,

I tried writing the unlock sequence as 0x20c5, & 0x28D9, and I didn't get

a reset, but the WDOG also did not enable. After my call to the WDOG_Init

routine I pasted into the post, I enter an infinite loop and wait for the

watch dog to time out. This is to verify my WDOG time out is as expected.

Is an exception thrown if a value other than the unlock or refresh is

written to the cnt register?

Thank You,

Patrick Foley

Software Engineer

Magna Mirrors

Kraft Engineering Center

5085 Kraft Avenue, S.E.

Kentwood, MI 49512

Phone: (616) 786-7104

Fax: (616) 656-8594

Patrick.Foley@magnamirrors.com

0 Kudos

1,031 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Patrick:

How are you testing the reset, using a GPIO, or some visual indication?

I think you are using a KEAZN64, can you confirm this?

According to the reference manual, the watchdog is disabled by default in Debug mode. So if you are trying to get a watchdog reset while debugging, this will not happen.

Regards!

Jorge Gonzalez

0 Kudos

1,031 Views
mjbcswitzerland
Specialist V

Hi

wdog_unlock.PNG

If you are 're-configuring' the watchdog it is only possible when the ALLOWUPDATE was initially set in WDOG_STCTRLH.

Update.PNG

Regards

Mark

0 Kudos