AnsweredAssumed Answered

WDOG ignoring refresh when using LPO clock

Question asked by Jim Hollister on Oct 9, 2013
Latest reply on Apr 13, 2014 by zhaohuiliu

MCU: MK20DX128VLH5

Maskset: 1N86B

 

I'm trying to use the internal watchdog of a Kinetis K20, sourced from the LPO clock. My WDOG refresh operations seem to have no effect when I use the LPO clock, but if I use the Bus clock the refresh works fine. I've boiled my application down to a simple bare-metal C program generated by CodeWarrior, shown below. If PET_THE_DOG == 0, then both bus clock and LPO clock variations cause a reset in a few seconds. If PET_THE_DOG ==1, then the bus clock variation does not reset but the LPO clock variation still does reset.

 

I've seen some other discussions about a similar problem, but no resolution that's worked for me. Anybody know why the WDOG is treating the refresh differently when I run from the LPO clock?

 

void delay(int n)

{

  for (; n > 0; --n) {

  __asm("nop");

  __asm("nop");

  __asm("nop");

  __asm("nop");

  __asm("nop");

  __asm("nop");

  __asm("nop");

  __asm("nop");

  __asm("nop");

  __asm("nop");

  }

}

 

# define WDOG_LPO_CLOCK 1

# define PET_THE_DOG 1

 

int main(void)

{

  __asm("CPSID   i"); // Disable interrupts

 

  // Unlock watchdog for write-once register access

  WDOG_UNLOCK = 0xC520;

  WDOG_UNLOCK = 0xD928;

 

  #if WDOG_LPO_CLOCK == 1

  // Enable WDOG with 1kHz LPO clock

  WDOG_PRESC = WDOG_PRESC_PRESCVAL(0);

  WDOG_TOVALH = (3000 >> 16);

  WDOG_TOVALL = (3000 & 0xFFFF);

  // STCTRLH : WAITEN=1, STOPEN=1, ALLOWUPDATE=1, CLKSRC=0, WDOGEN=1

  WDOG_STCTRLH = 0x1D1;

  #else

  // Enable WDOG with 21MHz FEI clock

  WDOG_PRESC = WDOG_PRESC_PRESCVAL(3);

  WDOG_TOVALH = (21000000 >> 16);

  WDOG_TOVALL = (21000000 & 0xFFFF);

  // STCTRLH : WAITEN=1, STOPEN=1, ALLOWUPDATE=1, CLKSRC=1, WDOGEN=1

  WDOG_STCTRLH = 0x1D3;

  #endif

 

  __asm("CPSIE   i"); // Enable interrupts

 

  // Loop here. Periodically pet the WDOG.

  while(1) {

  #if PET_THE_DOG == 1

  WDOG_REFRESH = 0xA602;

  WDOG_REFRESH = 0xB480;

  #endif

  delay(1000);

  }

}

Outcomes