简体   繁体   English

视窗看门狗定时器STM32F4

[英]window Watchdog Timer STM32F4

Edited DONE NOW .. I'll reconstruct the code, but now it's done and tested 现在完成编辑..我将重建代码,但是现在完成并测试了它

I need to implement a timer that checks for conditions every x sec .. the problem I face that the program doesn't reset when it enters infinite loop ( away for check like if the system has been halted) ... 我需要实现一个计时器,每隔x秒检查一次条件..我面临的问题是,程序进入无限循环时不会重置(检查系统是否已停止)。
these links helped me .. manual from page 74 http://www2.st.com/content/ccc/resource/technical/document/reference_manual/3d/6d/5a/66/b4/99/40/d4/DM00031020.pdf/files/DM00031020.pdf/jcr:content/translations/en.DM00031020.pdf .. 这些链接对我有帮助。.参考手册,来自第74页http://www2.st.com/content/ccc/resource/technical/document/reference_manual/3d/6d/5a/66/b4/99/40/d4/DM00031020。 pdf / files / DM00031020.pdf / jcr:content / translations / zh.DM00031020.pdf ..

and this link http://www.programmershare.com/3518407/ thanks in advance 和此链接http://www.programmershare.com/3518407/预先感谢

I currently have this code : 我目前有此代码:

#include "stm32f4xx.h"
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_wwdg.h>

void setup_Periph(void);
void Delay(unsigned long ms);


void Delay(unsigned long ms)
{ unsigned long i,j;
for(i=0;i<ms;i++)
    for(j=0;j<1450;j++);
 }


 void setup_Periph(void)
 {

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

 //port initialization
 GPIO_InitTypeDef GPIO_InitStructure;

 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
 GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
 GPIO_Init(GPIOD,&GPIO_InitStructure);

 }

 void ResetWatchdog(void)
 { WWDG_SetCounter(80);}

 void WWDG_IRQHandler(void)
 {

 if (WWDG_GetFlagStatus())
  {
   WWDG_SetCounter(0x7f);
   WWDG_ClearFlag();
   }

 }

 void FeedDog(float round)
{
while(round)
   { Delay (65);
    WWDG_SetCounter(127);
    round--;}
 }


 int main(void)
 {
 //RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

 //System Clock auf Watchdog
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

 WWDG_SetPrescaler(WWDG_Prescaler_8);    
 //WWDG clock counter = (PCLK1(30MHz)/4096)/1 = 7324 Hz (~137 us)

 WWDG_SetCounter(80);           //Werte 0x40 und 0x7F
 WWDG_SetWindowValue(80);         //0x80

                //Reset  < 120  > 64

 WWDG_Enable(127);            //WWDG timeout = ~137 us * (127-64) = 8.6ms

 WWDG_ClearFlag();
 WWDG_EnableIT();

 setup_Periph();
 //make sure the clk is stable
   RCC_HSEConfig(RCC_HSE_ON);
   while(!RCC_WaitForHSEStartUp());


 GPIO_SetBits(GPIOD, GPIO_Pin_1);
 Delay(10000); //10 ms
 GPIO_ResetBits(GPIOD, GPIO_Pin_1);
 Delay(10000); //100 ms

  while (1)
  {

          GPIO_SetBits(GPIOD, GPIO_Pin_0);
            Delay(10000); //10 ms

            GPIO_ResetBits(GPIOD, GPIO_Pin_0);
            Delay(10000); //100 ms

            void ResetWatchdog(void);
            WWDG_SetCounter(80);
        FeedDog(8);
            for(;;) {}

      }
}

There are several things very obviously wrong here. 这里有几件事很明显是错误的。 Most troubling among them are: 其中最令人困扰的是:

  1. Your Delayms() function does not implement any kind of delay. 您的Delayms()函数不会实现任何形式的延迟。 It appears to configure one of the LEDs to flash. 似乎将其中一个LED配置为闪烁。

  2. You are never calling InitWatchdog() . 您永远不会调用InitWatchdog() (Instead, you are declaring its prototype within main() for some reason.) (相反,出于某种原因,您正在main()中声明其原型。)

I don't want this to sound too harsh, but: do you know C? 我不想听起来太刺耳,但是:你知道C吗? This code reads as though it's been put together by copying and pasting pieces from examples without understanding them. 这段代码看起来好像是通过复制和粘贴示例中的片段而不理解它们而组合在一起的。 If you do not know C, attempting to develop software for an embedded system is not an effective way to learn it, especially without guidance. 如果您不了解C,那么尝试为嵌入式系统开发软件并不是学习它的有效方法,尤其是在没有指导的情况下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM