1

I recently bought a STM32 Value line discovery kit to work with STM32 devices. I'm working on a project now which requires a watchdog. It's called IWDG in STM32. But my problem is that I need an ISR when the watchdog is triggered.

Does anyone know how to implement this (or even have an example)?

unwind
  • 391,730
  • 64
  • 469
  • 606
Lars Jansen
  • 113
  • 1
  • 10
  • I actually did, for about a week now but I can't find it so I was wondering if it even is possible. – Lars Jansen Oct 09 '14 at 11:01
  • I am just searching for something that doesn't immediatly reset the microcontroller. It just needs to do some shutdown operation before it resets. – Lars Jansen Oct 09 '14 at 11:04
  • 1
    Why do you need an ISR? The watchdog is meant to perform a HW reset after a certain amount of time has elapsed. You just need to activate it once, and reset it every certain amount of time (smaller than the amount of time spent before it performs the HW reset). – barak manos Oct 09 '14 at 11:21
  • The whole purpose of a watchdog is to hard-reset your device if things have gone "terribly wrong". At that point, you should assume that nothing is guaranteed to work correctly anymore, hence you cannot "do some shutdown operation before it resets". Think of it this way - the SW isn't working anymore, the only thing left to do is to reset the HW. – barak manos Oct 09 '14 at 11:25
  • Now, if you still want a couple of functions for activating the watchdog and for resetting it, then please wave a white flag, high and clear, so as I can see it (Big Chris, Lock Stock). – barak manos Oct 09 '14 at 11:34

2 Answers2

4

You don't want a watchdog, since the whole purpose of the watchdog is to force a reset if the software has hung.

What you're after sounds more like simply a high-priority regular timer interrupt to me.

Set it up so that you restart the timer (pushing the interrupt event generation forwards in time) at regular intervals, so that the interrupt typically doesn't happen.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • Okay, thanks. That's clear now. But in my case the microcontroller needs to power a DSP up and shut it down the correct way. It also have to look if there is any power failure. If there is, it needs to shutdown the DSP. But say the microcontroller's software hangs and a power failure occurs. It can't shut it down the correct way, can it? So how do I have to program such a situation? To reset the microcontroller is not a good option because it will reset the values of some important pins too... – Lars Jansen Oct 09 '14 at 12:01
  • @LarsJansen: The DSP happens to be MSP430? – barak manos Oct 09 '14 at 12:06
  • 1
    @LarsJansen I think about the best you can do in software is to have a high-priority ("non-maskable") interrupt that does the supervision, and shuts down the DSP and perhaps also the STM if a fault is detected. If you make sure you don't have any code that disables interrupts, it can be pretty secure. – unwind Oct 09 '14 at 12:18
  • @unwind Okay. So you say (for my understanding) that I need an interrupt (instead of a while loop) for the powerfail-checking. – Lars Jansen Oct 09 '14 at 12:32
  • But say that my STM hangs. The interrupt will hang too, won't it? – Lars Jansen Oct 09 '14 at 12:32
  • @LarsJansen "It depends". Generally in software, "hang" means "getting stuck in an infinite loop somewhere". In that case, the timer interrupt will of course trigger anyway, and interrupt the loop. On the STM32 you can also get hard faults if you're not nice to the ARM core, but you can trap those too and run code if a fault happens. – unwind Oct 09 '14 at 12:45
  • @unwind Aaah, okay :) Do you have some terms to search for? Or do you have some example code? – Lars Jansen Oct 09 '14 at 12:51
  • is this possible to use timer? what is the different between them? – Hamid Jul 23 '16 at 17:31
0

There are two watchdogs (at least with stm32s10x).

IWDG, which is indepenent and resets stm without isr.

WWDG (window watchdog), which has a isr 1 tick before it will reset the stm32.