【iCore4 雙核心板_ARM】例程六:IWDG看門狗實驗——復位ARM

XiaomaGee發表於2017-08-14

實驗原理:

  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 */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_IWDG_Init();

  /* USER CODE BEGIN 2 */

  /* 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_IWDG_Refresh(&hiwdg); 
        LED_RED_ON;
        LED_GREEN_OFF;
        LED_BLUE_OFF;
        HAL_Delay(500);
        LED_RED_OFF;
        LED_GREEN_ON;
        LED_BLUE_OFF;
        HAL_Delay(500);
        LED_RED_OFF;
        LED_GREEN_OFF;
        LED_BLUE_ON;
        HAL_Delay(500);
  }
  /* USER CODE END 3 */

}

原始碼下載連結:

連結:http://pan.baidu.com/s/1jI7lV74 密碼:16ht

iCore4連結:

相關文章