6.点击GENERATE CODE生成工程文件
二、KEIL程序 1.相关函数:
独立看门狗初始化函数,此函数初始化了在STM32CubeMX内设置的参数,系统已经处理好了,并已经添加在了main函数内;
MX_IWDG_Init(); //独立看门狗初始化 喂狗调用函数,这个需要我们自行添加到main函数的while内;
HAL_IWDG_Refresh(&hiwdg); 本例程的main.c
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(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_UART_Transmit_IT(&huart1 ,aTxBuffer,sizeof(aTxBuffer)); //sizeof()可读取目标数组长度 HAL_UART_Receive_IT(&huart1,aRxBuffer,1); printf("rnSTM32L051C8T6 开发板独立看门狗实验rn"); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { printf("nr 开始喂狗 !!!nr"); HAL_IWDG_Refresh(&hiwdg); printf("nr 喂狗成功 !!!nr"); HAL_Delay(500); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */} 2.编译文件,下载。即可,实现效果如下:
6.点击GENERATE CODE生成工程文件
二、KEIL程序 1.相关函数:
独立看门狗初始化函数,此函数初始化了在STM32CubeMX内设置的参数,系统已经处理好了,并已经添加在了main函数内;
MX_IWDG_Init(); //独立看门狗初始化 喂狗调用函数,这个需要我们自行添加到main函数的while内;
HAL_IWDG_Refresh(&hiwdg); 本例程的main.c
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(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_UART_Transmit_IT(&huart1 ,aTxBuffer,sizeof(aTxBuffer)); //sizeof()可读取目标数组长度 HAL_UART_Receive_IT(&huart1,aRxBuffer,1); printf("rnSTM32L051C8T6 开发板独立看门狗实验rn"); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { printf("nr 开始喂狗 !!!nr"); HAL_IWDG_Refresh(&hiwdg); printf("nr 喂狗成功 !!!nr"); HAL_Delay(500); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */} 2.编译文件,下载。即可,实现效果如下: