stm32 independent watchdog

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_44951165/article/details/102642410

What is Watchdog:

         It is a dedicated microcontroller for monitoring the running state of the module or chip , commonly known as "watchdog."

Why Watchdog:

         In the microcomputer system consists of single-chip configuration, due to the work of the microcontroller are often subject to external electromagnetic interference, resulting in program runaway, into an infinite loop, the program does not run properly, causing the system controlled by the microcontroller can not continue to work, so in order to Real-time monitoring of the operating state of the single-chip , resulting in a "watchdog."

What is running out

         Program running means that the system is subject to some interference, the value of the program counter (PC) deviates from the given only change course, causing the program to deviations from the normal operating path. Runaway factors and consequences are often unpredictable. In many cases after, the program running the system will enter an infinite loop and cause crashes.
         This condition is called Runaway. Whereabouts after the program running there are two possibilities. One possibility is into some kind of meaningless cycle and get out. Another possibility is increasing the value PC when PC Switch to perform address after the value increases to 0xFFFFH value equivalent to restart the program from the control program 0x0000H began.

                                                                        - Source Wikipedia Sogou

Watchdog To solve the problem:

1. In the program starts running when the system can not be reset.
2. when the system is running out, reset, the program re-run.

Independent watchdog

Independent watchdog (the IWDG) driven by a dedicated low-speed clock (LSI), even if the master clock fails it is still valid.
IWDG most suitable for those who need the watchdog outside as a main program, the work can be completely independent, and the lower time accuracy of the case.

Functional Description:

Here Insert Picture Description
         Writing key register (IWDG_KR) in 0xCCCC, start enable independent watchdog; The counter begins counting down from its reset value 0xFFF. When the end of the time counter to 0x000, generates a reset signal (IWDG_RESET). Whenever the key register IWDG_KR 0xAAAA written, the value IWDG_RLR the counter will be reloaded, thus avoiding watchdog reset. In stm32 incomplete Manual more detailed description will be mentioned in Chapter 10 experiments.

How should be applied:

         Phenomenon SCM system will appear in Runaway outside interference results in an infinite loop, the watchdog circuit is to prevent this from happening. Watchdog role is within a certain time (implemented by the timer counter) DOG signal is not received (represented MCU has been linked), they automatically reset the processor to realize restart (reset signal transmission).
         For example, a program running time is 100ms, immediately followed by the dogs After running this program section, time-out time we set up an independent watchdog for 120ms, than we need to monitor the program a little more than 100ms, if more than 120ms also do not feed the dog, it shows that our monitoring program broke down and gets lost, it will produce a system reset, let the program run again.

int main()
{
		看门狗初始化;//调用初始化函数
		while(1)
		{
			被监测的代码段;
			喂狗;//调用喂狗函数
		}
}

The following code describes how to configure specific:

void IWDG_Init(u8 prer,u16 rlr) 
{
	IWDG->KR=0X5555;//使能对IWDG->PR和IWDG->RLR的写		 										  
  	IWDG->PR=prer;  //设置分频系数   
  	IWDG->RLR=rlr;  //重加载寄存器 IWDG->RLR  Tout=((4×2^prer) ×rlr) /40
  	//Tout即喂狗溢出时间,若超出时间,则表示异常										   
  	IWDG->KR=0XCCCC;//使能看门狗	
}
//喂独立看门狗
void IWDG_Feed(void)
{
	IWDG->KR=0XAAAA;//reload,将IWDG->RLR 的值给递减计数器											   
}

Specific details can be found stm32 incomplete manual.

And that, if inappropriate for an independent watchdog understanding, please place.

Guess you like

Origin blog.csdn.net/weixin_44951165/article/details/102642410