[其他ST产品] STM32之关门狗

[复制链接]
2030|62
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:36 | 显示全部楼层
配置NVIC 12948650a93071e6cb.png
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:37 | 显示全部楼层
配置WWDG 36412650a932a5c9bf.png
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:37 | 显示全部楼层
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:38 | 显示全部楼层
配置工程名称、工程路径
43794650a93445d515.png
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:38 | 显示全部楼层
选择固件库
40968650a93584f285.png
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:38 | 显示全部楼层
生成工程
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:38 | 显示全部楼层
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:38 | 显示全部楼层
main函数编写
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2023 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. #include "wwdg.h"
  22. #include "gpio.h"

  23. /* Private includes ----------------------------------------------------------*/
  24. /* USER CODE BEGIN Includes */

  25. /* USER CODE END Includes */

  26. /* Private typedef -----------------------------------------------------------*/
  27. /* USER CODE BEGIN PTD */

  28. /* USER CODE END PTD */

  29. /* Private define ------------------------------------------------------------*/
  30. /* USER CODE BEGIN PD */
  31. /* USER CODE END PD */

  32. /* Private macro -------------------------------------------------------------*/
  33. /* USER CODE BEGIN PM */

  34. /* USER CODE END PM */

  35. /* Private variables ---------------------------------------------------------*/

  36. /* USER CODE BEGIN PV */

  37. /* USER CODE END PV */

  38. /* Private function prototypes -----------------------------------------------*/
  39. void SystemClock_Config(void);
  40. /* USER CODE BEGIN PFP */

  41. /* USER CODE END PFP */

  42. /* Private user code ---------------------------------------------------------*/
  43. /* USER CODE BEGIN 0 */

  44. //窗口看门狗的提前唤醒中断的中断处理函数
  45. void HAL_WWDG_EarlyWakeupCallback(WWDG_HandleTypeDef *hwwdg)
  46. {
  47.     HAL_WWDG_Refresh(hwwdg);  //及时喂狗防止程序复位
  48.     HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_9);
  49. }

  50. /* USER CODE END 0 */

  51. /**
  52.   * @brief  The application entry point.
  53.   * @retval int
  54.   */
  55. int main(void)
  56. {
  57.   /* USER CODE BEGIN 1 */

  58.   /* USER CODE END 1 */

  59.   /* MCU Configuration--------------------------------------------------------*/

  60.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  61.   HAL_Init();

  62.   /* USER CODE BEGIN Init */

  63.   /* USER CODE END Init */

  64.   /* Configure the system clock */
  65.   SystemClock_Config();

  66.   /* USER CODE BEGIN SysInit */

  67.   /* USER CODE END SysInit */

  68.   /* Initialize all configured peripherals */
  69.   MX_GPIO_Init();
  70.   MX_WWDG_Init();
  71.   /* USER CODE BEGIN 2 */
  72.    
  73.     HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET);
  74.     HAL_Delay(500);
  75.     HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_SET);
  76.     HAL_Delay(500);
  77.    
  78.   /* USER CODE END 2 */

  79.   /* Infinite loop */
  80.   /* USER CODE BEGIN WHILE */
  81.   while (1)
  82.   {
  83.     /* USER CODE END WHILE */

  84.     /* USER CODE BEGIN 3 */
  85.         
  86.         //如果没喂狗的话,就不会执行该循环,即LED1不会常亮
  87.         HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET);
  88.     }
  89.    
  90.   /* USER CODE END 3 */
  91. }

  92. /**
  93.   * @brief System Clock Configuration
  94.   * @retval None
  95.   */
  96. void SystemClock_Config(void)
  97. {
  98.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  99.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  100.   /** Initializes the RCC Oscillators according to the specified parameters
  101.   * in the RCC_OscInitTypeDef structure.
  102.   */
  103.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  104.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  105.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  106.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  107.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  108.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  109.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  110.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  111.   {
  112.     Error_Handler();
  113.   }

  114.   /** Initializes the CPU, AHB and APB buses clocks
  115.   */
  116.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  117.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  118.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  119.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  120.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  121.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  122.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  123.   {
  124.     Error_Handler();
  125.   }
  126. }

  127. /* USER CODE BEGIN 4 */

  128. /* USER CODE END 4 */

  129. /**
  130.   * @brief  This function is executed in case of error occurrence.
  131.   * @retval None
  132.   */
  133. void Error_Handler(void)
  134. {
  135.   /* USER CODE BEGIN Error_Handler_Debug */
  136.   /* User can add his own implementation to report the HAL error return state */
  137.   __disable_irq();
  138.   while (1)
  139.   {
  140.   }
  141.   /* USER CODE END Error_Handler_Debug */
  142. }

  143. #ifdef  USE_FULL_ASSERT
  144. /**
  145.   * @brief  Reports the name of the source file and the source line number
  146.   *         where the assert_param error has occurred.
  147.   * @param  file: pointer to the source file name
  148.   * @param  line: assert_param error line source number
  149.   * @retval None
  150.   */
  151. void assert_failed(uint8_t *file, uint32_t line)
  152. {
  153.   /* USER CODE BEGIN 6 */
  154.   /* User can add his own implementation to report the file name and line number,
  155.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  156.   /* USER CODE END 6 */
  157. }
  158. #endif /* USE_FULL_ASSERT */
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:39 | 显示全部楼层
独立看门狗和窗口看门狗的异同点
IWDG最适合应用于那些需要看门狗作为一个在主程序之外,能够完全独立工作,并且对时间精度要求较低的场合。

WWDG最适合那些要求看门狗在精确计时窗口起作用的应用程序。
 楼主| 烟雨蒙蒙520 发表于 2023-9-20 14:40 | 显示全部楼层
AloneKaven 发表于 2023-9-20 21:54 | 显示全部楼层
关门狗跟看门狗有啥区别啊
我喜欢打游戏 发表于 2024-4-28 16:44 | 显示全部楼层
没进来之前关门狗给我惊到了
中国龙芯CDX 发表于 2024-4-29 16:54 | 显示全部楼层
关门狗和看门狗是一个意思吗?
Pulitzer 发表于 2024-9-6 07:30 | 显示全部楼层

在信号线中串联小电阻其主要目的是对引脚的保护
童雨竹 发表于 2024-9-6 09:26 | 显示全部楼层

驱动脉冲变压器原边时,
Wordsworth 发表于 2024-9-6 10:29 | 显示全部楼层

并且衡量电阻受温度影响大小的物理量是温度系数
公羊子丹 发表于 2024-9-6 12:25 | 显示全部楼层

开模的话,模具不会塌踏。。
万图 发表于 2024-9-6 13:28 | 显示全部楼层

就导通接地放掉
Uriah 发表于 2024-9-6 14:31 | 显示全部楼层

需要靠近在外部添加一个钳位二极管
帛灿灿 发表于 2024-9-6 16:27 | 显示全部楼层

ESD电压通过接地放掉
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 在线客服 返回列表 返回顶部