PDA

View Full Version : Watchdog initialization problem



froeber
03-19-2014, 06:37 PM
Hi all, I've been trying to get the Teensy3.0 watchdog timer to work with the low power oscillator (LPO) clock source. I was having no luck until I got hooked up to a Freescale support engineer who gave me some simple example code he said "worked for him". Well even that simple code didn't work for me. So I figured it must be a BSP setup difference between the Freescale "bare metal" environment he was using and the Teensy3 BSP.

I went through a bunch of code before coming to a key difference in the very first few lines of startup code. I found the Teensy3 code in the ResetHandler function in mk20dx128.c did:
WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;

Whereas the Freescale startup code did:

WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
WDOG_STCTRLH &= ~WDOG_STCTRLH_WDOGEN;

I changed the Teensy code to match the Freescale code and then the Watchdog worked with the LPO option. I think the issue is that the original Teensy code changed the watchdog to use the LPO option right away and that somehow caused problems. Anyways, it clearly would make more sense to use the Freescale code.

I'm still using release 1.16 of TeensyDuino but I figure this hasn't been changed in the newer releases. So I'm hoping Paul can fix it at some point.
Fred

JBeale
03-19-2014, 10:38 PM
Have you been following this thread about the watchdog setup and operation?
http://forum.pjrc.com/threads/25370-Teensy-3-0-Watchdog-Timer

froeber
03-20-2014, 01:50 AM
There is a post at https://community.freescale.com/message/382312 that has been in progress for a bit on using the LPO with the watchdog. I figured out how to get it to work yesterday but haven't posted the details. Main issue was fix I presented here.