实验原理:
STM32内部包含窗口看门狗,通过看门狗可以监控程序运行,程序运行错误时,未在
规定时间喂狗(提前或超时),自动复位ARM,本实验通过按键按下,停止喂狗,从而产
生复位。
核心代码:
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ HAL_Delay(300); /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_WWDG_Init(); /* USER CODE BEGIN 2 */ LED_RED_ON; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ while(ARM_KEY_STATE == KEY_DOWN); HAL_Delay(30); //30msι¹·Ò»´Î HAL_WWDG_Refresh(&hwwdg); //ι¹· } /* USER CODE END 3 */ }
源代码下载链接:
链接:http://pan.baidu.com/s/1cizRjg 密码:2s6f
iCore4链接: