cancel
Showing results for 
Search instead for 
Did you mean: 

Hello all, I have configured IWDG by collecting data from ST community and reference manual, datasheet. But still wit is not working and also it is disturbing my running operation. Can anyone tell me proper way to configure IWDG and usage?

Umesh Shinde
Associate II

I have to design it for stm8afxx mcu

1 ACCEPTED SOLUTION

Accepted Solutions
Cristian Gyorgy
Senior III

First you need to decide how you start the IWDG: automatically at power on reset (through option bytes) or "manually" by software. I recommend the software mode, at least while you still learn....

The IWDG is quite simple. You set the timeout period writing the 2 registers IWDG_RLR and IWDG_PR (see ref. manual), than after you enable it, you just have to make sure you refresh it before it times out.

So, you need to generate a refreshing period, usually with a timer, that is lower than the IWDG timeout period. It is important if you generate the refreshing period within an interrupt that you don't reset the IWDG inside the interrupt routine - i.e. this would not brake an infinite loop if interrupts are enabled!

Below an example written in assembly, with 18ms timeout, you can easily pass/adapt it to any C compiler you use:

Start_Iwdg:
; Timeout = (1/38kHz)·PS·(RL+1) = 16·(RLR+1)/38 = 18 ms
; RLR = 18·38/16 -1 = 41,75 --> 42
; Timeout = 16·43/38 = 18,1 ms
			mov  IWDG_KR,  #0x55
			mov  IWDG_RLR, #42
			mov  IWDG_KR, #0x55
			mov  IWDG_PR, #0x02
			ld  A, #0xCC
			ld  IWDG_KR, A
			ret
 
 
....and somewhere in a 10 ms periodic handler reset iwdg
			mov IWDG_KR, #0xAA
....

View solution in original post

3 REPLIES 3
Cristian Gyorgy
Senior III

First you need to decide how you start the IWDG: automatically at power on reset (through option bytes) or "manually" by software. I recommend the software mode, at least while you still learn....

The IWDG is quite simple. You set the timeout period writing the 2 registers IWDG_RLR and IWDG_PR (see ref. manual), than after you enable it, you just have to make sure you refresh it before it times out.

So, you need to generate a refreshing period, usually with a timer, that is lower than the IWDG timeout period. It is important if you generate the refreshing period within an interrupt that you don't reset the IWDG inside the interrupt routine - i.e. this would not brake an infinite loop if interrupts are enabled!

Below an example written in assembly, with 18ms timeout, you can easily pass/adapt it to any C compiler you use:

Start_Iwdg:
; Timeout = (1/38kHz)·PS·(RL+1) = 16·(RLR+1)/38 = 18 ms
; RLR = 18·38/16 -1 = 41,75 --> 42
; Timeout = 16·43/38 = 18,1 ms
			mov  IWDG_KR,  #0x55
			mov  IWDG_RLR, #42
			mov  IWDG_KR, #0x55
			mov  IWDG_PR, #0x02
			ld  A, #0xCC
			ld  IWDG_KR, A
			ret
 
 
....and somewhere in a 10 ms periodic handler reset iwdg
			mov IWDG_KR, #0xAA
....

Hello Mr Cristian,

Its working fine in normal RUN mode.

I want to design functionality like after entering into halt mode, Reload value should be updated in IWDG to prevent resetting mcu in HALT mode.

Is it possible, if yes then please let me know.

Thank you and Regards,

Shinde Umesh

Cristian Gyorgy
Senior III

You would need to refresh the IWDG before entering halt mode. When the CPU is halted, it doesn't execute instructions anymore until it wakes up again - not may events can wake it up from halt!

Yes, you can use halt mode with the IWGD enabled, you just have to make sure it wakes up before IWDG timeout to refresh the IWDG. This means you cannot use timers to generate an event to refresh the IWDG, except for the RTC with active halt mode. If you don't use timers to generate the IWDG refresh event you need some external event to wake up the MCU, and refresh IWDG.