前言
在看STM32H743I-EVAL2官方板子的demo, 看完了WWDG demo.
WWDG讲的是如何使用窗口看门狗(初始化狗,喂狗),并模拟了一个HardFault错误,使喂狗代码不可到达,使硬件狗重启MCU.
窗口狗的初始化window和counter有上下限(0x40~0x7f), 如果初始化狗参数不在这个范围内,会立即引起硬件狗复位。
ST官方给出了一个公式,可以算出不同初始化条件下,需要多少延时ms数能落在狗的喂狗窗口内。
试验
用CubeMx重建了一个工程,来重新实现WWDG.
重建工程的好处,如果对知识点没有理解清楚,重建demo后,会出现一些不科学的bug, 这时,就可以温习官方demo, 找出重建工程不对的地方,反复修正,直到重建的demo正常跑起来。
重建demo调试时,会发现一些官方原版demo上没说的东西。
e.g.
- 官方板子上留了JTAG/SWD接口,但是不好使。也没在官方文档上说如何设置(好像看到说要改焊桥, 这就算了)。所以只能使用板载的STLINK3
CubeMx配置
CubeMx默认始终源是使用HSI的,其他试验是可以的。但是看门狗试验,必须要使用HSE. 要不算出的delay值太大了。因为在喂狗之前,需要模拟干活的过程,用HAL_Delay(delay), 还没跑完,就会引起硬件狗复位。
HAL_Delay()参数是毫秒值。
这时,需要将时钟源配置为HSE 25MHZ
且将时钟配置如下:
The CPU at 400MHz
AXI at 200MHz
HCLK3 at 200MHz
AHB1 at 200MHz
AHB2 at 200MHz
AHB4 at 200MHz
APB3 at 100MHz
APB1 at 100MHz
APB2 at 100MHz
APB4 at 100MHz
这样配出的tick值默认是1ms
外部中断的配置
要用外部中断的响应来模拟HardFault, 所以要配置一个外部中断引脚。
NVIC的优先级查看
nvic即使不设置优先级,也有一个默认的顺序。可以勾选排序选项,让中断列表按照优先级从高到低的方式排列。
勾选时基中断和外部中断用HAL库实现。
重建的工程预览
当重复使用CubeMx时,因为会覆盖不在代码边界中的代码。因为不能保证自己手写的代码都在代码边界内。所以,还是要备份一下被CubeMx修改前的工程。当CubeMx生成代码后,用BC4合并2个工程,因为代码框架变化的很规则,合并代码到新框架,还是很顺利的。
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "wwdg.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
extern int gi_delay_food_wwdg;
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
__IO int i_rc = 0;
__IO int i_loop_cnt = 0;
/* 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();
i_rc = __HAL_RCC_GET_FLAG(RCC_FLAG_WWDG1RST); // i_rc 总是SET
if (RESET != i_rc) {
// 无法判断进入程序时,是否由重启引起
i_rc = i_rc;
}
MX_WWDG1_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
// 这里就不加指示灯翻转了, 就用STLINK3 在程序入口处, HardFault处, Errror_Handler处下断点.
// 如果程序跑起来后,这3处断点都不经过,那就是喂狗成功了
i_loop_cnt++; // 在watch窗口看i_loop_cnt的值,如果一直加1, 说明程序运行正常,喂窗口狗生效
// gi_delay_food_wwdg 是在MX_WWDG1_Init()中算出来的, 在gi_delay_food_wwdg ms之后喂窗口狗, 才有效
HAL_Delay(gi_delay_food_wwdg);
// @todo 这里根据情况, 决定是否喂狗. 如果不喂狗, H743就被狗重启了
if (HAL_WWDG_Refresh(&hwwdg1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 2;
RCC_OscInitStruct.PLL.PLLN = 64;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
do {
} while (1);
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* File Name : gpio.c
* Description : This file provides code for the configuration
* of all used GPIO pins.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "gpio.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure GPIO */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/** Configure pins
PC15-OSC32_OUT (OSC32_OUT) ------> RCC_OSC32_OUT
PC14-OSC32_IN (OSC32_IN) ------> RCC_OSC32_IN
PH1-OSC_OUT (PH1) ------> RCC_OSC_OUT
PH0-OSC_IN (PH0) ------> RCC_OSC_IN
*/
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = MY_EXTI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(MY_EXTI_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 1, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* File Name : WWDG.c
* Description : This file provides code for the configuration
* of the WWDG instances.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "wwdg.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
WWDG_HandleTypeDef hwwdg1;
/**
* @brief Timeout calculation function.
* This function calculates any timeout related to
* WWDG with given prescaler and system clock.
* @param timevalue: period in term of WWDG counter cycle.
* @retval None
*/
// 窗口狗喂时的ms数计算公式
static uint32_t TimeoutCalculation(uint32_t timevalue)
{
uint32_t timeoutvalue = 0;
uint32_t pclk1 = 0;
uint32_t wdgtb = 0;
/* Get PCLK1 value */
pclk1 = HAL_RCC_GetPCLK1Freq();
/* get prescaler */
switch(hwwdg1.Init.Prescaler)
{
case WWDG_PRESCALER_1: wdgtb = 1; break;
case WWDG_PRESCALER_2: wdgtb = 2; break;
case WWDG_PRESCALER_4: wdgtb = 4; break;
case WWDG_PRESCALER_8: wdgtb = 8; break;
case WWDG_PRESCALER_16: wdgtb = 16; break;
case WWDG_PRESCALER_32: wdgtb = 32; break;
case WWDG_PRESCALER_64: wdgtb = 64; break;
case WWDG_PRESCALER_128: wdgtb = 128; break;
default: Error_Handler(); break;
}
/* calculate timeout */
timeoutvalue = ((4096 * wdgtb * timevalue) / (pclk1 / 1000));
return timeoutvalue;
}
/* WWDG1 init function */
int gi_delay_food_wwdg = 0; // 喂狗的最大间隔ms数
void MX_WWDG1_Init(void)
{
hwwdg1.Instance = WWDG1;
hwwdg1.Init.Prescaler = WWDG_PRESCALER_128;
// 最长的窗口狗的喂时设置就是Window = 0x40, Counter = 0xf7
// 当 Prescaler = WWDG_PRESCALER_128 时, 喂时最大间隔 = 336ms
// WWDG_PRESCALER_128 时, 最小延时时间(Counter = 0x40, Window = 0x40) = 6ms
// WWDG_PRESCALER_128 时, 最大延时时间(Counter = 0x7f, Window = 0x40) = 336ms
// WWDG_PRESCALER_1 时, 最小延时时间(Counter = 0x40, Window = 0x40) = 1ms
// WWDG_PRESCALER_1 时, 最大延时时间(Counter = 0x7f, Window = 0x40) = 3ms
// Window 和 Counter 的有效范围都为 >= 0x40 && <= 0x7f
// 如果不在范围内,初始化窗口狗后,MCU立即就重启了
hwwdg1.Init.Window = 0x50; // !!! 窗口值不能在下边界0x40上,否则窗口狗生效后,会立即重启MCU
hwwdg1.Init.Counter = 0x7f;
hwwdg1.Init.EWIMode = WWDG_EWI_DISABLE;
gi_delay_food_wwdg = TimeoutCalculation((hwwdg1.Init.Counter - hwwdg1.Init.Window) + 1) + 1;
// 在其他任务中, 用 HAL_Delay(gi_delay_food_wwdg)之后, 来执行喂狗 HAL_WWDG_Refresh(&WwdgHandle)
if (HAL_WWDG_Init(&hwwdg1) != HAL_OK)
{
Error_Handler();
}
}
void HAL_WWDG_MspInit(WWDG_HandleTypeDef* wwdgHandle)
{
if(wwdgHandle->Instance==WWDG1)
{
/* USER CODE BEGIN WWDG1_MspInit 0 */
/* USER CODE END WWDG1_MspInit 0 */
/* WWDG1 clock enable */
__HAL_RCC_WWDG1_CLK_ENABLE();
/* USER CODE BEGIN WWDG1_MspInit 1 */
/* USER CODE END WWDG1_MspInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32h7xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32h7xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
/* USER CODE END NonMaskableInt_IRQn 0 */
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
/* USER CODE END NonMaskableInt_IRQn 1 */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
/* USER CODE END MemoryManagement_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
/* USER CODE END W1_MemoryManagement_IRQn 0 */
}
}
/**
* @brief This function handles Pre-fetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
/* USER CODE BEGIN BusFault_IRQn 0 */
/* USER CODE END BusFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
/* USER CODE END W1_BusFault_IRQn 0 */
}
}
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
/* USER CODE BEGIN UsageFault_IRQn 0 */
/* USER CODE END UsageFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
/* USER CODE END W1_UsageFault_IRQn 0 */
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
/* USER CODE BEGIN SVCall_IRQn 0 */
/* USER CODE END SVCall_IRQn 0 */
/* USER CODE BEGIN SVCall_IRQn 1 */
/* USER CODE END SVCall_IRQn 1 */
}
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
/* USER CODE END DebugMonitor_IRQn 0 */
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
/* USER CODE END DebugMonitor_IRQn 1 */
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn 0 */
/* USER CODE END PendSV_IRQn 0 */
/* USER CODE BEGIN PendSV_IRQn 1 */
/* USER CODE END PendSV_IRQn 1 */
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32H7xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32h7xx.s). */
/******************************************************************************/
/**
* @brief This function handles EXTI line[15:10] interrupts.
*/
void EXTI15_10_IRQHandler(void)
{
/* USER CODE BEGIN EXTI15_10_IRQn 0 */
/* USER CODE END EXTI15_10_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
/* USER CODE BEGIN EXTI15_10_IRQn 1 */
/* USER CODE END EXTI15_10_IRQn 1 */
}
/* USER CODE BEGIN 1 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
// 这里访问了一个无效的地址, 会导致HardFault
// HardFault级别高,陷进去就会死循环
// 导致主程序中无人喂窗口狗,硬件狗使MCU重启
/* As the following address is invalid (not mapped), a Hardfault exception
will be generated with an infinite loop and when the WWDG counter falls to 63
the WWDG reset occurs */
*(__IO uint32_t *) 0xA0003000 = 0xFF;
}
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : stm32h7xx_hal_msp.c
* Description : This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2);
/* System interrupt init*/
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
确定是否为1MS的tick
可以在HAL_InitTick()中下断点
/* Configure the SysTick to have interrupt in 1ms time basis*/
if (HAL_SYSTICK_Config(SystemCoreClock / (1000UL / (uint32_t)uwTickFreq)) > 0U) // bp this line
{
return HAL_ERROR;
}
如果 uwTickFreq 为 HAL_TICK_FREQ_1KHZ,说明tick就是1ms
总结
这个demo重建用了1天多。
中间出了一些问题。
因为尝试修改一些参数,导致初始化窗口狗后,MCU立刻重启了,试验没法往下作了。
后来发现,喂狗的初始化值,不能在边界上(不能是<= 0x40 或 >= 0x7f), 必须是0x40~0x7f中间的值。
还发现,自己手误,将喂狗初始值的counter写成0xf7了,找了好久才发现自己写错了,醉了.
因为窗口狗的喂狗时间最大不能超过336ms, 所以程序中就不能出现长时间关中断干活的事情。用来保证喂狗任务可以连续喂狗。
来源:CSDN
作者:LostSpeed
链接:https://blog.csdn.net/LostSpeed/article/details/104105387