Setting Watchdog From Code

Discussion to talk about hardware related topics only.
Post Reply
stevep
Posts: 16
Joined: Fri Apr 25, 2008 6:34 am

Setting Watchdog From Code

Post by stevep »

I have been trying to enable the watchdog timer on a CB34EX, from code, and I can't get it to work. I can enable/disable the watchdog with the monitor, just not from code.

The posts about the watchdog timer module, here and at the Yahoo site, seem to indicate that watchdog cannot be enabled through code, but ONLY with the monitor.

Can anyone tell me if that is correct?
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Setting Watchdog From Code

Post by rnixon »

Sometimes a processor will only allow the register that has the watchdog option (among others) to be written one time. The problem is that the watchdog enable is not separate and is part of a register with functions that must be written by the monitor for the processor to boot. A write-once would prevent inadvertent disabling of the watchdog. I don't know it that is the case with the 5234 processor, but you should be able to check the freescale manual to see if that is the case.
User avatar
lgitlitz
Posts: 331
Joined: Wed Apr 23, 2008 11:43 am
Location: San Diego, CA
Contact:

Re: Setting Watchdog From Code

Post by lgitlitz »

The stand-alone "watchdog peripheral" ( not core wd timer ) is the primary wd that is used on the MCF5234 and all other NetBurner processors that have this peripheral.... 5234/70/82. This WD timer is enabled by default at reset by the processor. There is an option in the boot monitor settings to enable/disable the watchdog. Our factory preset is to have the watchdog disabled. The control register (wcr) is write-once so when it is disabled by our boot monitor it can never be re-enabled in your application at runtime.

If you wish to use the watchdog you need to enable the watchdog monitor setting. You can access this setting by typing 'A' at boot, then type 'setup' to see the boot settings and then type 'W' for the watchdog setting. You can also access these settings from your application by reading/writing to the configuration record, this is detailed in the NNDK programmers manual. This is a good option if you have a large production so you dont manually have to change our factory settings for each board you program. Basically at the beginning of your application read the config record, if watchdog is not enabled then re-write the config and call a software reset for the WD setting to take effect. This config record write will then only happen the first time the board boots with your application.

When you set this option to be enabled in the boot monitor there will be no writes performed on the WCR register during boot. I suggest writing to the WCR register at the start of your application to "lock" the watchdog in enabled mode. If you dont write to this register then stray code could easily disabled the WD at any time with a write of 0 to the WCR register... not a good thing for a WD timer.

You might also want to take a look at the following example in the NNDK:
C:\Nburn\examples\AutoUpdateFeatures
This example shows a very basic watchdog service routine. It also shows how to point our on-board flash writing function to use your watchdog service routine. This will allow you to write flash, such as auto-updates or standard file system, without danger of the watchdog resetting the processor during flash writes.

-Larry
roland.ames

Re: Setting Watchdog From Code

Post by roland.ames »

lgitlitz wrote:The stand-alone "watchdog peripheral" ( not core wd timer ) is the primary wd that is used on the MCF5234 and all other NetBurner processors that have this peripheral.... 5234/70/82. This WD timer is enabled by default at reset by the processor. There is an option in the boot monitor settings to enable/disable the watchdog. Our factory preset is to have the watchdog disabled. The control register (wcr) is write-once so when it is disabled by our boot monitor it can never be re-enabled in your application at runtime.

If you wish to use the watchdog you need to enable the watchdog monitor setting. You can access this setting by typing 'A' at boot, then type 'setup' to see the boot settings and then type 'W' for the watchdog setting. You can also access these settings from your application by reading/writing to the configuration record, this is detailed in the NNDK programmers manual. This is a good option if you have a large production so you dont manually have to change our factory settings for each board you program. Basically at the beginning of your application read the config record, if watchdog is not enabled then re-write the config and call a software reset for the WD setting to take effect. This config record write will then only happen the first time the board boots with your application.

When you set this option to be enabled in the boot monitor there will be no writes performed on the WCR register during boot. I suggest writing to the WCR register at the start of your application to "lock" the watchdog in enabled mode. If you dont write to this register then stray code could easily disabled the WD at any time with a write of 0 to the WCR register... not a good thing for a WD timer.

You might also want to take a look at the following example in the NNDK:
C:\Nburn\examples\AutoUpdateFeatures
This example shows a very basic watchdog service routine. It also shows how to point our on-board flash writing function to use your watchdog service routine. This will allow you to write flash, such as auto-updates or standard file system, without danger of the watchdog resetting the processor during flash writes.

-Larry
The MCF54415 has only a Core Watchdog (no stand-alone watchdog module). Can you explain how the watchdog enable / disable in the boot monitor is done for the MOD54415, is the RO bit set by the monitor?? Attached is some source that I think may work, can someone from NB comment?
Attachments
netburner_watchdog.c
source for watchdog control
(2.33 KiB) Downloaded 438 times
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Setting Watchdog From Code

Post by rnixon »

Hello Roland, have you tried your code? What behavior does it have?
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Setting Watchdog From Code

Post by rnixon »

Had a quick look at the manual. Seems pretty straight forward. Just write the appropriate bits

13.2.1 Core Watchdog Control Register (CWCR)
The CWCR controls the software watchdog timer, time-out periods, and software watchdog timer
interrupt. The register can be read or written at any time. At power on reset, the software watchdog timer
is disabled.


The do a better job of describing the bits than I can do here. Set CWRI bits to 10, timeout bits 0-3, then set CWE to 1. Just guessing since I'm not running it.
roland.ames

Re: Setting Watchdog From Code

Post by roland.ames »

I haven't tried the MOD54415 code yet.

I have looked at the freescale manual covering the Core Watchdog.

What I am mainly interested in is what the boot monitor does before my app runs, in the two cases of watchdog enabled or disabled.
Specifically, does it set the RO bit, does it use interrupt or reset. Now I know I could just get my app to read the CWCR register, but I thought NB may have some documentation on this :lol: .
Post Reply