From 51393af87f6dc09a00e78d71dbff8a15721c1198 Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期二, 18 二月 2025 10:29:46 +0800 Subject: [PATCH] V1.9 增加看门狗 --- Src/main.c | 25 ++++++++++++++++++++++--- 1 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Src/main.c b/Src/main.c index cb8161e..bec22d6 100644 --- a/Src/main.c +++ b/Src/main.c @@ -10,7 +10,7 @@ * inserted by the user or by software development tools * are owned by their respective copyright owners. * - * COPYRIGHT(c) 2024 STMicroelectronics + * COPYRIGHT(c) 2025 STMicroelectronics * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: @@ -53,6 +53,8 @@ ADC_HandleTypeDef hadc1; DMA_HandleTypeDef hdma_adc1; +IWDG_HandleTypeDef hiwdg; + SPI_HandleTypeDef hspi1; TIM_HandleTypeDef htim1; @@ -84,6 +86,7 @@ static void MX_USART6_UART_Init(void); static void MX_TIM3_Init(void); static void MX_TIM1_Init(void); +static void MX_IWDG_Init(void); void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); @@ -136,6 +139,7 @@ MX_USART6_UART_Init(); MX_TIM3_Init(); MX_TIM1_Init(); + MX_IWDG_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_Base_Start_IT(&htim3); BSP_Init(); @@ -198,8 +202,9 @@ /**Initializes the CPU, AHB and APB busses clocks */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.LSIState = RCC_LSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 8; @@ -277,6 +282,20 @@ sConfig.Channel = ADC_CHANNEL_VREFINT; sConfig.Rank = 2; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) + { + _Error_Handler(__FILE__, __LINE__); + } + +} + +/* IWDG init function */ +static void MX_IWDG_Init(void) +{ + + hiwdg.Instance = IWDG; + hiwdg.Init.Prescaler = IWDG_PRESCALER_256; + hiwdg.Init.Reload = 4095; + if (HAL_IWDG_Init(&hiwdg) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } @@ -397,7 +416,7 @@ { huart1.Instance = USART1; - huart1.Init.BaudRate = 115200; + huart1.Init.BaudRate = 921600; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; -- Gitblit v1.9.3