Пример #1
0
void WWDG_IRQHandler(void)
{
	u8 i;
	WWDG_SetCounter(WWDG_CNT); //重设窗口看门狗值
	WWDG_ClearFlag();          //清除提前唤醒中断标志	
	for(i=0;i<4;i++);          //此处延时一下,等寄存器稳定
}
Пример #2
0
/*************************************************************
 * WWDT Initialization
**************************************************************/
void WWDG_Init()
{

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
	
    // Deinitializes WWDG peripheral registers 
	#if(STRCMP($ResetEn$, DISABLE) == 0)
	   WWDG_DeInit();
	#endif
	

    // Sets Prescaler value of the WWDG.
    WWDG_SetPrescaler($PreValue$);

    // Sets Window value of the WWDG.
    WWDG_SetWindowValue($WindowValue$);

    // Sets Counter value of the WWDG.
    WWDG_SetCounter($CounterValue$);
	
    // Enable WWDG and set counter value
    WWDG_Enable($CounterValue$);

	   //Enable EW interrupt
	#if((STRCMP($IntEn$,DISABLE)) == 0)
    WWDG_ClearFlag();
    WWDG_EnableIT();
	#endif
    

}
Пример #3
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     

  /* Initialize LED1 and Key Button mounted on STM3210X-EVAL board */       
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI);


  /* Check if the system has resumed from WWDG reset */
  if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
  { 
    /* WWDGRST flag set */
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);

    /* Clear reset flags */
    RCC_ClearFlag();
  }
  else
  {
    /* WWDGRST flag is not set */
    /* Turn off LED1 */
    STM_EVAL_LEDOff(LED1);
  }

  /* NVIC configuration */
  NVIC_Configuration();

  /* WWDG configuration */
  /* Enable WWDG clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

/* On Value line devices, WWDG clock counter = (PCLK1 (24MHz)/4096)/8 = 732 Hz (~1366 æs)  */
/* On other devices, WWDG clock counter = (PCLK1(36MHz)/4096)/8 = 1099 Hz (~910 æs)  */
  WWDG_SetPrescaler(WWDG_Prescaler_8);

  /* Set Window value to 65 */
  WWDG_SetWindowValue(65);

  /* On Value line devices, Enable WWDG and set counter value to 127, WWDG timeout = ~1366 æs * 64 = 87.42 ms */
  /* On other devices, Enable WWDG and set counter value to 127, WWDG timeout = ~910 æs * 64 = 58.25 ms */
  WWDG_Enable(127);

  /* Clear EWI flag */
  WWDG_ClearFlag();

  /* Enable EW interrupt */
  WWDG_EnableIT();

  while (1)
  {
  }
}
Пример #4
0
/*
*********************************************************************************************************
*	函 数 名: bsp_InitWwdg
*	功能说明: 初始化窗口看门狗。
*	形    参:  
*	返 回 值: 无
*********************************************************************************************************
*/
static void bsp_InitWwdg(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;
    /* 打开窗口看门狗时钟,APB1低速时钟36MHz*/
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG , ENABLE);
    
    /* 使能看门狗中断 */
    NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 10;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    
    /* 设置窗口看门狗时钟为 WWDG_CLK = (PCLK1 (36MHz)/4096)/8 = 1152 Hz (~868 us), 最大超时时间: 780 * 64 = 58.25ms */
    WWDG_SetPrescaler(WWDG_Prescaler_8);
    /* 设置窗口看门狗窗口上限, 计数器小于0x50时,才能重装载计数器 */  
    /* Enable WWDG and set counter value to 127。In this case the refresh window is: 
						WWDG_FRQ = 1/WWDG_CLK;
           ~WWDG_FRQ * (WWDG_RELOAD_VALUE-WWDG_RELOAD_WTIME_VALUE) < refresh window < ~WWDG_FRQ * (WWDG_RELOAD_VALUE-0x3F)
    */
    WWDG_SetWindowValue(WWDG_RELOAD_WTIME_VALUE);
    /* 使能窗口看门狗计数器,并设置计数初值为0x7F */
    WWDG_Enable(WWDG_RELOAD_VALUE);
    /* 清除窗口看门狗标志 */
    WWDG_ClearFlag();
    /* 使能窗口看门狗中断 */
    WWDG_EnableIT();
		/* 置位窗口看门口标志 */
		WWDG_EN_MARK = 1;
}
Пример #5
0
/*}*/
void WWDG_IRQHandler(void)
{
    WWDG_SetCounter(0x7F);
    WWDG_ClearFlag();
    PRINTD ("wdg irq\n\r");
    /* led1_toggle(); */
}
Пример #6
0
/*
*********************************************************************************************************
*	函 数 名: Wwdg_ISR
*	功能说明: 窗口看门狗超时提前中断。
*	形    参:  
*	返 回 值: 无
*********************************************************************************************************
*/
void Wwdg_ISR(void)
{
	WWDG_ClearFlag();
	/*
	    处理窗口看门狗超时。
	*/
	Wwdg_Feed();
}
Пример #7
0
void WWDG_IRQHandler(void)
{
  /* Update WWDG counter */
  WWDG_SetCounter(0x50);
	
  /* Clear EWI flag */
  WWDG_ClearFlag(); 
}
void WWDG_IRQHandler(void)
	{
	// Update WWDG counter
	WWDG_SetCounter(0x7F);	  //当禁掉此句后,窗口看门狗将产生复位
	// Clear EWI flag */
	WWDG_ClearFlag();	  //清除提前唤醒中断标志位
	// Toggle GPIO_Led pin 7 */
	LED1=!LED1;
	}
Пример #9
0
void WWDG_IRQHandler(void)
{

    WWDG_SetCounter(0x7F);	  //当禁掉此句后,窗口看门狗将产生复位

    WWDG_ClearFlag();	  //清除提前唤醒中断标志位

    LED1=!LED1;
}
Пример #10
0
void WWDG_IRQHandler (void)
{	
	if(WWDG_GetFlagStatus())
	{
		WWDG_ClearFlag();
		WWDG_SetCounter(0x66);
	}
	uart_printf("WWDG interrupt OK!\r\n");	
}
Пример #11
0
void WWDG_Configuration(void)
{
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);	
  WWDG_SetPrescaler(WWDG_Prescaler_8);	              //  WWDG clock counter = (PCLK1/4096)/8 = 244 Hz (~4 ms)  
  WWDG_SetWindowValue(0x41);		                 // Set Window value to 0x41
  WWDG_Enable(0x50);		       // Enable WWDG and set counter value to 0x7F, WWDG timeout = ~4 ms * 64 = 262 ms 
  WWDG_ClearFlag();			       // Clear EWI flag
  WWDG_EnableIT();			       // Enable EW interrupt
}
Пример #12
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Setup the microcontroller system. Initialize the Embedded Flash Interface,
     initialize the PLL and update the SystemFrequency variable. */
  SystemInit();

  /* Initialize LED1 and Key Button mounted on STM3210X-EVAL board */       
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_PBInit(Button_KEY, Mode_EXTI);


  /* Check if the system has resumed from WWDG reset */
  if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
  { 
    /* WWDGRST flag set */
    /* Turn on LED1 */
    STM_EVAL_LEDOn(LED1);

    /* Clear reset flags */
    RCC_ClearFlag();
  }
  else
  {
    /* WWDGRST flag is not set */
    /* Turn off LED1 */
    STM_EVAL_LEDOff(LED1);
  }

  /* NVIC configuration */
  NVIC_Configuration();

  /* WWDG configuration */
  /* Enable WWDG clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

  /* WWDG clock counter = (PCLK1/4096)/8 = 1099 Hz (~910 µs)  */
  WWDG_SetPrescaler(WWDG_Prescaler_8);

  /* Set Window value to 65 */
  WWDG_SetWindowValue(65);

  /* Enable WWDG and set counter value to 127, WWDG timeout = ~910 µs * 64 = 58.25 ms */
  WWDG_Enable(127);

  /* Clear EWI flag */
  WWDG_ClearFlag();

  /* Enable EW interrupt */
  WWDG_EnableIT();

  while (1)
  {
  }
}
Пример #13
0
static void s_hal_watchdog_window_start(hal_watchdog_internal_item_t *intitem)
{
//    NVIC_InitTypeDef NVIC_InitStructure;
    // do something using s_hal_watchdog_theinternals.items[0].countdown etc.

    // acemor on 21oct11: taken from STM32F10x_StdPeriph_Lib_V3.2.0\Project\STM32F10x_StdPeriph_Examples\WWDG

//    // 1. init nvic
//    /* 1 bits for pre-emption priority and 3 bits for subpriority */
////    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
//
////    NVIC_SetPriority(EXTI9_5_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0,0));
//
//    /* Set WWDG interrupt vector Preemption Priority to 1 */
//    NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
//    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
//    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
//    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//    NVIC_Init(&NVIC_InitStructure);

    // 1b. wwdg clock
    /* WWDG configuration */
    /* Enable WWDG clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

    // 2. set prescaler
    /* On other devices, WWDG clock counter = (PCLK1(36MHz)/4096)/8 = 1099 Hz (909.918 us)  */
    WWDG_SetPrescaler(WWDG_Prescaler_8);

    // 3. set window
    /* Set Window value to 65 */
    WWDG_SetWindowValue(intitem->reload);
    //WWDG_SetWindowValue(65);


    // 4. set counter value and clear
    /* On Value line devices, Enable WWDG and set counter value to 127, WWDG timeout = ~1366 æs * 64 = 87.42 ms */
    /* On other devices, Enable WWDG and set counter value to 127, WWDG timeout = ~910 æs * 64 = 58.25 ms */
    WWDG_Enable(intitem->reload);
    
    /* Clear EWI flag */
    WWDG_ClearFlag();
    
    // 5. enable interrupt
    if(hal_int_priorityNONE != intitem->cfg.priority)
    {
        // enable irqs in nvic
        hal_sys_irqn_priority_set(WWDG_IRQn, intitem->cfg.priority);
        hal_sys_irqn_enable(WWDG_IRQn);

        /* Enable EW interrupt */
        WWDG_EnableIT();
    }

}
Пример #14
0
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
  debug();
#endif

  /* System Clocks Configuration */
  RCC_Configuration();

  /* GPIO configuration */
  GPIO_Configuration();

  /* Check if the system has resumed from WWDG reset */
  if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
  { /* WWDGRST flag set */
    /* Set GPIO_LED pin 6 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_6);

    /* Clear reset flags */
    RCC_ClearFlag();
  }
  else
  { /* WWDGRST flag is not set */
    /* Reset GPIO_LED pin 6 */
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_6);
  }

  /* Configure Key Button EXTI Line to generate an interrupt on falling edge */
  EXTI_Configuration();

  /* NVIC configuration */
  NVIC_Configuration();

  /* WWDG configuration */
  /* Enable WWDG clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

  /* WWDG clock counter = (PCLK1/4096)/8 = 244 Hz (~4 ms)  */
  WWDG_SetPrescaler(WWDG_Prescaler_8);

  /* Set Window value to 65 */
  WWDG_SetWindowValue(65);

  /* Enable WWDG and set counter value to 127, WWDG timeout = ~4 ms * 64 = 262 ms */
  WWDG_Enable(127);

  /* Clear EWI flag */
  WWDG_ClearFlag();

  /* Enable EW interrupt */
  WWDG_EnableIT();

  while (1)
  {}
}
Пример #15
0
/**
  * @brief  初始化窗口看门狗
  * @param  tr   :T[6:0],计数器值 ,  wr   :W[6:0],窗口值
    @param  fprer:分频系数(WDGTB),仅最低2位有效 , Fwwdg=PCLK1/(4096*2^fprer).
  * @retval None
  */
void WWDG_Init(u8 tr, u8 wr, u32 fprer)
{
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);  //   WWDG时钟使能
    WWDG_CNT = tr & WWDG_CNT; //初始化WWDG_CNT.
    WWDG_SetPrescaler(fprer);////设置IWDG预分频值
    WWDG_SetWindowValue(wr);//设置窗口值
    WWDG_Enable(WWDG_CNT);	 //使能看门狗 ,	设置 counter .
    WWDG_ClearFlag();//清除提前唤醒中断标志位
    WWDG_NVIC_Init();//初始化窗口看门狗 NVIC
    WWDG_EnableIT(); //开启窗口看门狗中断
}
Пример #16
0
/*******************************************************************************
* Function Name  : WWDG_IRQHandler
* Description    : This function handles WWDG interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void WWDG_IRQHandler(void)
{
  /* Update WWDG counter */
  WWDG_SetCounter(0x7F);

  /* Clear EWI flag */
  WWDG_ClearFlag();

  /* Toggle GPIO_Led pin 7 */
  GPIO_WriteBit(GPIO_LED, GPIO_Pin_7, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIO_LED, GPIO_Pin_7)));
}
Пример #17
0
/**
  * @brief  This function handles WWDG interrupt request.
  * @param  None
  * @retval None
  */
void WWDG_IRQHandler(void)
{
  /* Update WWDG counter */
  WWDG_SetCounter(0x7F);

  /* Clear EWI flag */
  WWDG_ClearFlag();

  /* Toggle LED2 */
  STM_EVAL_LEDToggle(LED2);
}
Пример #18
0
void WWDG_IRQHandler(void)
{
    hal_watchdog_internal_item_t* intitem = s_hal_watchdog_theinternals.items[HAL_watchdog_id2index(hal_watchdog2_window)];

    // Clear EWI flag 
    WWDG_ClearFlag();

    if(NULL !=intitem->cfg.onwindowexpiry_cbk)
    {
        intitem->cfg.onwindowexpiry_cbk(intitem->cfg.onwindowexpiry_arg);
    }
}
Пример #19
0
/*
*********************************************************************************************************
*	函 数 名: bsp_InitWwdg
*	功能说明: 窗口看门狗配置 
*	形    参:
*             _ucTreg       : T[6:0],计数器值 	范围0x40 到 0x7F                                               
*             _ucWreg       : W[6:0],窗口值     必须小于 0x80
*            WWDG_Prescaler : 窗口看门狗分频	PCLK1 = 42MHz
*                             WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
*							  WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
*							  WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
*							  WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8 
*	返 回 值: 无		        
*********************************************************************************************************
*/
void bsp_InitWwdg(uint8_t _ucTreg, uint8_t _ucWreg, uint32_t WWDG_Prescaler)
{
	NVIC_InitTypeDef NVIC_InitStructure;
	
	/* 检测系统是否从窗口看门狗复位中恢复 */
	if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
	{ 	
		/* 清除复位标志 */
		RCC_ClearFlag();
	}
	else
	{
		/* WWDGRST 标志没有设置 */
	}
	
	/* 使能WWDG时钟 */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
	
	/* 
	   窗口看门狗分频设置:
	   比如选择WWDG_Prescaler_8
	   (PCLK1 (42MHz)/4096)/8 = 1281 Hz (~780 us)  
	*/
	WWDG_SetPrescaler(WWDG_Prescaler);
	
	/* 
	 设置窗口值是_ucWreg,用户必须在小于_ucWreg且大于0x40时刷新计数
	 器,要不会造成系统复位。
    */
	WWDG_SetWindowValue(_ucWreg);
	
	/* 
	 使能WWDG,设置计数器
	 比如设置_ucTreg=127 8分频时,那么溢出时间就是= ~780 us * 64 = 49.92 ms 
	 窗口看门狗的刷新时间段是: ~780 * (127-80) = 36.6ms < 刷新窗口看门狗 < ~780 * 64 = 49.9ms
	*/
	WWDG_Enable(_ucTreg);
	
	/* 清除EWI中断标志 */
	WWDG_ClearFlag();	

	/* 使能EW中断 */
	WWDG_EnableIT();

    /* 设置 WWDG 的NVIC */
	NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);	
}
Пример #20
0
 /*******************************************************************************
  * Function Name  : WWDG_IRQHandler
  * Description    : This function handles WWDG interrupt request.
  * Input          : None
  * Output         : None
  * Return         : None
  *******************************************************************************/
void WWDG_IRQHandler(void)
{
 	/* enter interrupt */
 	rt_interrupt_enter();

 	/* Clear EWI flag */
 	WWDG_ClearFlag();

 	/**
 	 *系统即将复位前的处理
 	 */

 	/* leave interrupt */
 	rt_interrupt_leave();
 }
Пример #21
0
//初始化窗口看门狗 	
//tr   :T[6:0],计数器值 
//wr   :W[6:0],窗口值 
//fprer:分频系数(WDGTB),仅最低2位有效 
//Fwwdg=PCLK1/(4096*2^fprer). 一般PCLK1=42Mhz
void WWDG_Init(u8 tr,u8 wr,u32 fprer)
{
 
	NVIC_InitTypeDef NVIC_InitStructure;
 
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG,ENABLE); //使能窗口看门狗时钟
	
	WWDG_CNT=tr&WWDG_CNT;   //初始化WWDG_CNT. 
	WWDG_SetPrescaler(fprer); //设置分频值
	WWDG_SetWindowValue(wr); //设置窗口值
	WWDG_Enable(WWDG_CNT);  //开启看门狗
	
	NVIC_InitStructure.NVIC_IRQChannel=WWDG_IRQn;  //窗口看门狗中断
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x03;  //抢占优先级为2
	NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x03;					//子优先级为3
	NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;  //使能窗口看门狗
	NVIC_Init(&NVIC_InitStructure);
	
	WWDG_ClearFlag();//清除提前唤醒中断标志位
  WWDG_EnableIT();//开启提前唤醒中断
}
Пример #22
0
/**-----------------------------------------------------------------------------
  * @brief  WWDG_IRQHandler
  */
void WWDG_IRQHandler(void)
{
	WWDG_ClearFlag();
	WDG_Tick();
}