Watchdog cannot be enabled (AT91SAM3X)

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

FocusPaul
Posts: 29
Joined: Thu Mar 29, 2012 5:19 pm

Watchdog cannot be enabled (AT91SAM3X)

Fri Nov 14, 2014 3:55 pm

Hello!

I'm having some problems with my custom AT91SAM3X8E board.
Although the scenario is short and bulletproof, the watchdog is not working as intented.

Watchdog is enabled right after start-up with 1 s timeout. In case of error (timeout), an interrupt is generated. The main program will run into an infinite while(1) loop to make the watchdog "bark" right after the initialization.

By debugging I can see the code looping _inside_ the while(1) (Assembler: b #-4). I checked by setting breakpoints that neither the IRQ routine is called, nor the program gets restarted.

Code: Select all

/*
 * Include header files for all drivers that have been imported from
 * Atmel Software Framework (ASF).
 */
#include <asf.h>


int main (void)
{
	/* Configure WDT to trigger an interrupt (or reset). */
	unsigned int wdt_mode = WDT_MR_WDFIEN |	/* Enable WDT fault interrupt. */
				WDT_MR_WDRPROC |	/* WDT fault resets processor only. */
				WDT_MR_WDDBGHLT |	/* WDT stops in debug state. */
				WDT_MR_WDIDLEHLT;	/* WDT stops in idle state. */
	/* Initialize WDT with the given parameters. */
	wdt_init(WDT, wdt_mode, 256, 256);
	
	/* Configure and enable WDT interrupt. */
	NVIC_DisableIRQ(WDT_IRQn);
	NVIC_ClearPendingIRQ(WDT_IRQn);
	NVIC_SetPriority(WDT_IRQn, 0);
	NVIC_EnableIRQ(WDT_IRQn);

	while (1); /* waiting for watchdog */
}

/**
 * Interrupt routine called whenever watchdog fault (underflow or error) occurred.
 */
void
WDT_Handler(void) {

	const int reason = WDT->WDT_SR & 0x3;
	if (reason > 5) {
                /* bogus check to prevent unused var "reason" */
		NVIC->ICER[0] = (1 << WDT_IRQn);
	}
}
jharley
Posts: 238
Joined: Thu Dec 06, 2012 6:40 am

Re: Watchdog cannot be enabled (AT91SAM3X)

Fri Nov 14, 2014 9:59 pm

FocusPaul wrote:

Code: Select all

...
	WDT_MR_WDDBGHLT |	/* WDT stops in debug state. */
...
If you are debugging i believe this flag disables the WDT.
You might try commenting out this line if you want the WDT to be running during debug.
FocusPaul
Posts: 29
Joined: Thu Mar 29, 2012 5:19 pm

Re: Watchdog cannot be enabled (AT91SAM3X)

Mon Nov 17, 2014 8:20 am

I didn't suspect WDT_MR_WDDBGHLT bit, because I assume it will only stop the watchdog while you are on a breakpoint. At least that's how the AT91SAM7X worked, if I remember correctly.

Well, today I powered the device and everything was running fine and as expected - with and without debugging module attached and/or started. It seems the watchdog hickup did settle while the device was not powered for a while.

Thank you!

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: Google [Bot] and 1 guest