Hello,
I configured watchdog to run from LPO clock source on MK20DN512VLL10. However, I get watchdog reset everytime when the configured watchdog timeout passes, despite of refreshing the watchdog.
When I change the watchdog to run from BUS clock, it behaves as expected
Are there any precautions when running watchdog from LPO?
Hi Martin
Thank you for the patience.
I do a test based on TWR-K60D100M board with mask set 2N22D.
I use below test code to set WDOG clock source is LPO and it works as expected.
Please check my test code below:
void test_wdog_lpo(void)
{
wdog_unlock();
/* WDOG_TOVALH: TOVALHIGH=0x0C00 */
WDOG_TOVALH = 0x0; /* Setup time-out value register high */
/* WDOG_TOVALL: TOVALLOW=2 */
WDOG_TOVALL = 0x270F; /* Setup time-out value register low */
/* WDOG_PRESC: ??=0,??=0,??=0,??=0,??=0,PRESCVAL=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0 */
WDOG_PRESC = WDOG_PRESC_PRESCVAL(0x00); /* Setup status register */
/* WDOG_STCTRLL: INTFLG=1,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=1 */
WDOG_STCTRLL = (WDOG_STCTRLL_INTFLG_MASK | 0x01U); /* Setup status register */
/* WDOG_STCTRLH: ??=0,DISTESTWDOG=1,BYTESEL=0,TESTSEL=0,TESTWDOG=0,??=0,??=1,WAITEN=1,STOPEN=1,DBGEN=0,ALLOWUPDATE=0,WINEN=0,IRQRSTEN=1,CLKSRC=1,WDOGEN=1 */
WDOG_STCTRLH = 0x1F1;
}
void wdog_unlock(void)
{
/* NOTE: DO NOT SINGLE STEP THROUGH THIS FUNCTION!!! */
/* There are timing requirements for the execution of the unlock. If
* you single step through the code you will cause the CPU to reset.
*/
/* This sequence must execute within 20 clock cycles, so disable
* interrupts will keep the code atomic and ensure the timing.
*/
DisableInterrupts;
/* Write 0xC520 to the unlock register */
WDOG_UNLOCK = 0xC520;
/* Followed by 0xD928 to complete the unlock */
WDOG_UNLOCK = 0xD928;
/* Re-enable interrupts now that we are done */
EnableInterrupts;
}
I use below code to refresh the WDOG:
/* Write 0xA602 to the refresh register */
WDOG_REFRESH = 0xA602;
/* Followed by 0xB480 to complete the refresh */
WDOG_REFRESH = 0xB480;
Without refresh WDOG, it will generate chip reset every 10 seconds.
Wish it helps.
Hi Martin,
I am checking with this issue, I will be back when I could get any updated info.
Thank you for the patience.
B.R.
Ma Hui