stm32F4系列MCU,窗口看门狗 WWDG中的bug
时间:11-19
来源:互联网
点击:
s follow:- BaudRate = 115200 baud - Word Length = 8 Bits- One Stop Bit- No parity- Hardware flow control disabled (RTS and CTS signals)- Receive and transmit enabled*/USART_InitStructure.USART_BaudRate = 115200;USART_InitStructure.USART_WordLength = USART_WordLength_8b;USART_InitStructure.USART_StopBits = USART_StopBits_1;USART_InitStructure.USART_Parity = USART_Parity_No;USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;STM_EVAL_COMInit(COM1, &USART_InitStructure);/* Output a message on Hyperterminal using printf function */printf("\n\rUSART Printf Example\n\r");/* key configuration */key_init();/* WWDG configuration *//* Enable WWDG clock */RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);/* WWDG clock counter = (PCLK1 (42MHz)/4096)/8 = 1281 Hz (~780 us) */WWDG_SetPrescaler(WWDG_Prescaler_8);/* Set Window value to 80; WWDG counter should be refreshed only when the counteris below 80 (and greater than 64) otherwise a reset will be generated */WWDG_SetWindowValue(120);/* Enable WWDG and set counter value to 127, WWDG timeout = ~780 us * 64 = 49.92 ms In this case the refresh window is: ~780 * (127-80) = 36.6ms < refresh window < ~780 * 64 = 49.9ms*/WWDG_Enable(127);wwdg_nvic_config();WWDG->SR = 0;WWDG_EnableIT(); while (1){printf("%d\r\n", i++);delay(1000);}}void delay(int t){int i,j;for(i=0; iSR = 0;if (wwdg_clear_flag == 0) //wwdg_clear_flag 在按键中断中被设置为1{/* Update WWDG counter */WWDG->CR = 127 & 0x7F;delay(1);}}void wwdg_nvic_config(void) {NVIC_InitTypeDef NVIC_InitStructure;NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure); }static void key_gpio_init(void){GPIO_InitTypeDef GPIO_InitStructure;/* 使能时钟 */RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | \RCC_AHB1Periph_GPIOF | \RCC_AHB1Periph_GPIOD, ENABLE);GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;/* 初始化中断按键 */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;GPIO_Init(GPIOA, &GPIO_InitStructure);/* 初始化轮询按键 */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8| GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;GPIO_Init(GPIOF, &GPIO_InitStructure);/* 初始化LED引脚 */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;GPIO_Init(GPIOD, &GPIO_InitStructure);}static void key_exti_config(void){EXTI_InitTypeDef EXTI_InitStructure;/* 连接PA0到外部中断线0 */SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);/* 配置外部中断线0 */EXTI_InitStructure.EXTI_Line = EXTI_Line0;EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;EXTI_InitStructure.EXTI_LineCmd = ENABLE;EXTI_Init(&EXTI_InitStructure);}static void key_nvic_config(void){NVIC_InitTypeDef NVIC_InitStructure;/* 使能外部中断0 */NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x3;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x3;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);}void key_init(void){key_gpio_init();key_exti_config();key_nvic_config();}void EXTI0_IRQHandler(void){ extern int stop_feed_dog;/* 清除中断标志 */printf("key isr\r\n");wwdg_clear_flag = 1;EXTI_C
stm32F4系列MCU窗口看门狗bu 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)