# How to stop/reset the watchdog timer from low-power sleep mode on an STM32L0C8?

On an STM32L0C8 MCU, I have the watchdog enabled while executing. At certain points in execution, I would like the chip to go into low power sleep mode. When it goes into low-power sleep mode though, the watchdog timer remains activated and will reset the entire MCU after the timer goes to 0, making it seemingly impossible to use both the watchdog and low-power sleep mode at the same time.

My question is, how do I refresh the countdown timer while in low-power sleep mode or how do I disable the WDT to stop it from resetting the MCU?

I looked all around the reference manual linked below to figure out how to disable / refresh the timer but it seems like this isn't possible. On page 514 it says:

20.3.4 Behavior in Stop and Standby modes Once running, the IWDG cannot be stopped

(IWDG being the Independent Watchdog) but it doesn't say anything about low-power sleep mode. In multiple other areas it suggests the same thing, that the IWDG can't be stopped. Am I missing something? Are we not supposed to use the watchdog if we want to go into sleep mode? Is it possible to modify the watchdog countdown timers code to stop decrementing before entering sleep mode? Please let me know!

The watchdog is only stopped on system reset. This way you can't accidentally turn it off.

If you want to use sleep modes and watchdog, you will have to set the watchdog the slowest clock, and wake-up regularly to restart the watchdog.

This is valid for almost all microcontrollers on the market that have an independently clocked watchdog.

• Wouldn't it kind of defeat the purpose to wake up regularly for restarting the countdown timer? In other words, wouldn't the power consumption caused by waking up and sleeping constantly more or less be the same as power consumption in normal running mode? – Omnomnious May 26 '17 at 17:27
• @Omnomnious: No, of course not. It only takes a few tens of microseconds to wake up and kick the watchdog. The rest of the time, you are sleeping and saving power. If you really care about that last little trickle of power, then you shouldn't enable the watchdog in the first place. Make sure your application code is robust enough not to need it. – Dave Tweed May 26 '17 at 17:32
• @Omnomnious Think about it from the purpose of the watchdog timer. To revive the processor if it crashes. So if it expires something has gone wrong. – StainlessSteelRat May 26 '17 at 18:36

I know I'm a bit late with my answer but still.

1) On some MCU's (like L4-series) from ST you can actually stop Watchdog Timers in STOP or STANDBY mode - here, for example it's said it can by done by writing to FLASH_OPTR register.
That just means that ST acknowledges that you don't actually need Watchdog in stop mode :)

2) You can cheat and instead of going straight to the STOP or STANDBY mode, write a magic value to the flash or EEPROM and do software reset (NVIC_Reset()).
After reset, look for the magic value, erase it if it's present, don't start the watchdog and go to STOP or STANDBY.
If no magic value is present - proceed as you normally would.

I just checked it on my STM32L151 and it seems to work.

• There's no need to use flash or eeprom for the reset-to-clear idea, you can use the RTC mailbox registers or put a word in high RAM and protect it from the memory region in the linker map given to the C startup code to clear, or check it before that startup code gets at it. – Chris Stratton Dec 15 '18 at 17:26
• Well, it was the first that came to my mind; i wasn't sure what else can survive software reset. Thanks for idea :) – Amomum Dec 15 '18 at 21:21
• @ChrisStratton I just checked, RTC Backup Registers also seem to work. Dunno if you meant them when wrote about 'mailbox' registers. – Amomum Dec 16 '18 at 17:48