专栏中心

EEPW首页 > 专栏 > STM32独立看门狗与窗口看门狗

STM32独立看门狗与窗口看门狗

发布人:0750long 时间:2009-07-11 来源:工程师 发布文章
STM32独立看门狗与窗口看门狗

 

 

 

香水城:如何使用STM32的窗口看门狗

菜农:看门狗专栏

 


 

/*注:stm32f10x_stdperiph_lib_v3.0.0  编译器:MDK3.24A*/
/* Includes -----------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_wwdg.h"

/* Private function prototypes ----------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void SysTick_Configuration(void);
void IWDG_Configuration(void);
void WWDG_Configuration(void);

void Delay(__IO uint32_t nCount);
void Test(void);

 


 

/* Private functions --------------------------------------*/

/**===============================
  * @brief  Main program.
  * @param  None
  * @retval : None
  =================================*/
int main(void)
{
 RCC_Configuration();
 GPIO_Configuration();
 Test();
 NVIC_Configuration(); 
 SysTick_Configuration(); /* Generate an interrupt each 100ms */ 
 IWDG_Configuration();
 WWDG_Configuration();


 while (1) {
  ;
 }
}

/**---------------------------------------------------------
  * @brief  [测试]若由IWDG或WWDG引起复位,则Pin4闪一下(注:首次Pin4闪由上电引起,不是由看门狗复位引起);若不断复位,则Pin4不断闪烁。注: 可通过更改程序中的相关值而引起看门狗复位。
  * @param  None
  * @retval : None
  ------------------------------------------------------*/
void Test(void)
{
 GPIO_SetBits(GPIOC, GPIO_Pin_4);
 Delay(0xFFFFF);
 GPIO_ResetBits(GPIOC, GPIO_Pin_4); 
}

/**---------------------------------------------------------
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval : None
  ------------------------------------------------------*/

void RCC_Configuration(void)
{
 SystemInit();
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); 
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); 
}
/**------------------------------------------------
  * @brief  Configures the different GPIO ports.
  * @param  None
  * @retval : None
  ---------------------------------------------------*/
void GPIO_Configuration(void)
{
 GPIO_InitTypeDef GPIO_InitStructure;
 
 /* Configure GPIOC as Output push-pull */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6 | GPIO_Pin_7;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOC, &GPIO_InitStructure);
}
 /**----------------------------------------------------------------
  * @brief  Configures NVIC and Vector Table base location.
  * @param  None
  * @retval : None
  -------------------------------------------------------------------*/
void NVIC_Configuration(void)
{
 NVIC_InitTypeDef NVIC_InitStructure;
 
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
 
 NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 NVIC_Init(&NVIC_InitStructure);
 
 /* Set SysTick interrupt vector Preemption Priority to 1 */
 NVIC_SetPriority(SysTick_IRQn, 0x08);
}
/**--------------------------------------------------------------------
  * @brief  Configures SysTick to generate an interrupt.
  * @param  None
  * @retval : None
  ----------------------------------------------------------------------*/
void SysTick_Configuration(void)
{
 /* SysTick interrupt each 100ms */
 if (SysTick_Config(SystemFrequency / 10)){
  /* Capture error */
  while (1);
 }
}
/**-----------------------------------------------------------------
  * @brief  Inserts a delay time.
  * @param nCount: specifies the delay time length.
  * @retval : None
  ------------------------------------------------------------------*/

void Delay(__IO uint32_t nCount)
{
 for(; nCount != 0; nCount--);
}

/**-------------------------------
  * @brief  Configures IWDG
  * @param  None
  * @retval : None
  ------------------------------*/
void IWDG_Configuration(void)
{
 /* IWDG timeout equal to 200 ms (the timeout may varies due to LSI frequency dispersion) */
 /* Enable write access to IWDG_PR and IWDG_RLR registers */
 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); 
 /* IWDG counter clock: 40KHz(LSI) / 16 = ? KHz */
 IWDG_SetPrescaler(IWDG_Prescaler_16);
         
 /* Set counter reload value: (500)x16/40K=200msec */
 IWDG_SetReload(500);
                    
 /* Reload IWDG counter */
 IWDG_ReloadCounter();
  
 /* Enable IWDG (the LSI oscillator will be enabled by hardware) */
 IWDG_Enable(); 
}

/**-------------------------------
  * @brief  Configures WWDG
  * @param  None
  * @retval : None
  ------------------------------*/

void WWDG_Configuration(void)
{
 /* 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(); 
}

 



/* Includes -----------------------------------------*/
#include "stm32f10x_it.h"
#include "stm32f10x_wwdg.h"

 


/**--------------------------------------------------------
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval : None
  ------------------------------------------------------*/

void SysTick_Handler(void)
{
 /* Reload IWDG counter */
 IWDG_ReloadCounter();
 
 /* Toggle GPIO_LED pin 7 */
    GPIO_WriteBit(GPIOC, GPIO_Pin_7, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7)));
}

/**----------------------------------------------------------
  * @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 GPIO_Led pin 6 */
  GPIO_WriteBit(GPIOC, GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6)));
}

 


 

 

专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们

关键词:

相关推荐

月饼来也!

唐朝 2004-09-18

cirrus EP9315通用平台片上系统处理器

苹果最新“折叠iPhone”规格曝光? 分析师估惊人售价

连接世界的SOC设计

视频 2009-12-21

C8051F系列单片机的protel 99 PCB封装库

CAT24WC128 128K位I2C串行E2PROM

英飞凌边缘AI平台DEEPCRAFT™ Studio通过Ultralytics YOLO模型增加对计算机视觉的支持

物联网与RFID芯片

视频 2009-12-21

资产追踪和个人安全解决方案通过Nordic低功耗蓝牙技术精确定位员工和贵重物品

cm6800 单片PFC+PWM控制器

协作创新平台——IBM微电子和Power架构

视频 2009-12-21

英特尔澄清:Intel 18A制程产品将于今年下半年如期发布

e络盟“顶尖科技之声”新一期探讨“电气化竞赛”

Ceva与Arm和SynaXG合作重新定义高能效5G NR处理实现可持续LEO卫星和5G增强版本无线基础设施

英特尔陈葆立:以灵活算力配置为企业带来多元选择

电容式触控IC解决方案及产品发展状况

视频 2009-12-21

瑞萨和Altium联合推出“Renesas 365 Powered by Altium”——软件定义产品的突破性行业解决方案

理解发展哲理 领悟发展走向——关于硅技术的思考

CC1000极低功耗单片收发 IC 2.0

AMD基于Zen 6的台式机处理器可能具有多达24个内核

嵌入式系统 2025-03-10

使用示波器对三相电机驱动器进行测量(上)

更多 培训课堂
更多 焦点
更多 视频

技术专区