My watchdog on AT91SAM7X256 does not reset the processor

Discussion about SAM7 Series and ARM7TDMI based products.

Moderator: nferre

RafaelA
Posts: 6
Joined: Fri Oct 03, 2014 4:44 pm

My watchdog on AT91SAM7X256 does not reset the processor

Mon Jul 06, 2015 4:14 pm

Hi, below you will find a piece of code showing my implementation of the watchdog as I want to use it. The timer is 5000 milliseconds. If I force some "while(true);" in any of the "doTask#()" the processor does not reset as I would expect thanks to the watchdog timer that elapses before being able to be reset. Am I doing something wrong that I have missed? Thanks in advance!

#define WATCHDOG_KEY (0xA5 << 24)

int main(void)
{
    doSomeInits(); // pseudo-code
    watchdogEnable(5000);

    while (true)
    {
        doTask1(); // pseudo-code
        doTask2(); // pseudo-code
        doTask3(); // pseudo-code
        doTask4(); // pseudo-code
        watchdogReset();
    }
    
    return 0;
}

void watchdogEnable(int milliseconds)
{
    int period = (milliseconds * 256) / 1000;
    AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDRSTEN |
                                                              AT91C_WDTC_WDDBGHLT |
                                                              AT91C_WDTC_WDIDLEHLT |
                                                              ((period << 16 ) & AT91C_WDTC_WDD) |
                                                              (period & AT91C_WDTC_WDV);
}

void watchdogReset()
{
  AT91C_BASE_WDTC->WDTC_WDCR = WATCHDOG_KEY | AT91C_WDTC_WDRSTT;
}
gerhardf
Posts: 552
Joined: Thu Dec 02, 2004 2:28 pm

Re: My watchdog on AT91SAM7X256 does not reset the processor

Tue Jul 07, 2015 8:28 am

hello,
eventually the watchdog was already initialized in some start-up code?
keep in mind the following information:
The Watchdog Mode Register (WDT_MR) can be written only once. Only a processor reset resets it.

regards
gerhard
RafaelA
Posts: 6
Joined: Fri Oct 03, 2014 4:44 pm

Re: My watchdog on AT91SAM7X256 does not reset the processor

Tue Jul 07, 2015 9:22 am

Thanks a lot gerhardf for your reply.

The Watchdog Mode Register (WDT_MR) is written only once by my code (instruction AT91C_BASE_WDTC->WDTC_WDMR = ...).

I suspected that the watchdog was already initialized in some start-up code (not mine, but from some included API), and I deleted both my initialization and my watchdog reset, but the processor reset never happens so I guess there was no such initialization in any API.

Any other idea? It is really frustrating following carefully the datasheet and not getting the expected behaviour. Help! :)
gerhardf
Posts: 552
Joined: Thu Dec 02, 2004 2:28 pm

Re: My watchdog on AT91SAM7X256 does not reset the processor

Wed Jul 08, 2015 10:51 am

hello,
do you have a debugger?
if yes read out the Watchdog Timer Mode Register before and after your code. so you can check if your code is the first one who write to the mode register.

regards
gerhard
RafaelA
Posts: 6
Joined: Fri Oct 03, 2014 4:44 pm

Re: My watchdog on AT91SAM7X256 does not reset the processor

Wed Jul 08, 2015 1:08 pm

Hello,

Yes, I do. I have read out the watchdog before and after my code as you suggest and I get 32768 (bit 15 set 1 and all the others 0) in both cases :S

Of course the bit 15 is Watchdog Disable... strange!

Why is not my instruction setting the values in the watchdog Timer Mode Register, am I missing any other enabling?
gerhardf
Posts: 552
Joined: Thu Dec 02, 2004 2:28 pm

Re: My watchdog on AT91SAM7X256 does not reset the processor

Thu Jul 09, 2015 12:38 pm

RafaelA wrote: Yes, I do. I have read out the watchdog before and after my code as you suggest and I get 32768 (bit 15 set 1 and all the others 0) in both cases :
from my point of view there seems to be another code,which was running after power-up reset and before your code and was setting the Watchdog Timer Mode Register.
is SAM-BA Boot active? what's the state of GPNVM bit 2?

regards
gerhard
RafaelA
Posts: 6
Joined: Fri Oct 03, 2014 4:44 pm

Re: My watchdog on AT91SAM7X256 does not reset the processor

Tue Jul 14, 2015 4:02 pm

GPNVM bit 2 is set to 1, the device boots from the Flash.

How does this affect the watchdog behaviour?

Thanks!
gerhardf
Posts: 552
Joined: Thu Dec 02, 2004 2:28 pm

Re: My watchdog on AT91SAM7X256 does not reset the processor

Tue Jul 14, 2015 4:58 pm

RafaelA wrote: How does this affect the watchdog behaviour?
SAM-BA is initializing the watchdog, take a look at chapter "21.3 Device Initialization"

but if gpnvm 2 is set, the device should boot from flash and SAM-BA shouldn't be active.

so your problem seems to be located at the code which is executed from flash.
did you check the whole start-up code?
Is the start-up code written by your own?

regards
gerhard

Return to “SAM7 ARM7TDMI MCU”

Who is online

Users browsing this forum: No registered users and 1 guest