From a5a14679f32045777f11e470ef8645846218e0ed Mon Sep 17 00:00:00 2001 From: Razvalyaev Date: Tue, 4 Mar 2025 09:39:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20watchdog=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Inc/iwdg.h | 52 +++++++++++++++++++ Core/Inc/py32f002b_hal_conf.h | 2 +- Core/Modbus/modbus_data.h | 4 +- Core/Src/iwdg.c | 55 ++++++++++++++++++++ Core/Src/main.c | 2 + Core/Src/py32f002b_it.c | 3 +- MDK-ARM/PY32Dallas.uvoptx | 94 ++++++++++++++++++++++------------- MDK-ARM/PY32Dallas.uvprojx | 10 ++++ 8 files changed, 183 insertions(+), 39 deletions(-) create mode 100644 Core/Inc/iwdg.h create mode 100644 Core/Src/iwdg.c diff --git a/Core/Inc/iwdg.h b/Core/Inc/iwdg.h new file mode 100644 index 0000000..ad5fa0a --- /dev/null +++ b/Core/Inc/iwdg.h @@ -0,0 +1,52 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file iwdg.h + * @brief This file contains all the function prototypes for + * the iwdg.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2024 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __IWDG_H__ +#define __IWDG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern IWDG_HandleTypeDef hiwdg; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_IWDG_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __IWDG_H__ */ + diff --git a/Core/Inc/py32f002b_hal_conf.h b/Core/Inc/py32f002b_hal_conf.h index 8fd2522..567bb31 100644 --- a/Core/Inc/py32f002b_hal_conf.h +++ b/Core/Inc/py32f002b_hal_conf.h @@ -42,7 +42,7 @@ //#define HAL_COMP_MODULE_ENABLED #define HAL_FLASH_MODULE_ENABLED #define HAL_GPIO_MODULE_ENABLED -//#define HAL_IWDG_MODULE_ENABLED +#define HAL_IWDG_MODULE_ENABLED #define HAL_TIM_MODULE_ENABLED //#define HAL_LPTIM_MODULE_ENABLED #define HAL_PWR_MODULE_ENABLED diff --git a/Core/Modbus/modbus_data.h b/Core/Modbus/modbus_data.h index 0ba0942..adf9a0d 100644 --- a/Core/Modbus/modbus_data.h +++ b/Core/Modbus/modbus_data.h @@ -45,7 +45,7 @@ typedef struct uint16_t Location; uint16_t ROM[4]; uint16_t Resolution; - uint16_t Enable; + uint16_t Status; }MB_SensorParamsTypeDef; /** * @brief Регистры хранения @@ -124,7 +124,7 @@ typedef struct //MB_DataCoilsTypeDef #define C_CONTROL_QNT 3 #define C_FLAGS_ADDR 16 -#define C_FLAGS_QNT 5 +#define C_FLAGS_QNT 2 /** MODBUS_DATA_COILS_DEFINES * @} diff --git a/Core/Src/iwdg.c b/Core/Src/iwdg.c new file mode 100644 index 0000000..d0ed87f --- /dev/null +++ b/Core/Src/iwdg.c @@ -0,0 +1,55 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file iwdg.c + * @brief This file provides code for the configuration + * of the IWDG instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2024 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "iwdg.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +IWDG_HandleTypeDef hiwdg; + +/* IWDG init function */ +void MX_IWDG_Init(void) +{ + + /* USER CODE BEGIN IWDG_Init 0 */ + + /* USER CODE END IWDG_Init 0 */ + + /* USER CODE BEGIN IWDG_Init 1 */ + + /* USER CODE END IWDG_Init 1 */ + hiwdg.Instance = IWDG; + hiwdg.Init.Prescaler = IWDG_PRESCALER_32; + hiwdg.Init.Reload = 100; + if (HAL_IWDG_Init(&hiwdg) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN IWDG_Init 2 */ + + /* USER CODE END IWDG_Init 2 */ + +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/Core/Src/main.c b/Core/Src/main.c index 4e0832b..6608625 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -25,6 +25,7 @@ #include "gpio.h" #include "tim.h" #include "usart.h" +#include "iwdg.h" #include "pch_sensors.h" #include "rs_message.h" @@ -49,6 +50,7 @@ int main(void) /* System clock configuration */ APP_SystemClockConfig(); + MX_IWDG_Init(); MX_GPIO_Init(); MX_TIM1_Init(); MX_TIM14_Init(); diff --git a/Core/Src/py32f002b_it.c b/Core/Src/py32f002b_it.c index 08dbf89..c35222b 100644 --- a/Core/Src/py32f002b_it.c +++ b/Core/Src/py32f002b_it.c @@ -66,12 +66,13 @@ void SVC_Handler(void) void PendSV_Handler(void) { } - +#include "iwdg.h" /** * @brief This function handles System tick timer. */ void SysTick_Handler(void) { + HAL_IWDG_Refresh(&hiwdg); HAL_IncTick(); } diff --git a/MDK-ARM/PY32Dallas.uvoptx b/MDK-ARM/PY32Dallas.uvoptx index 67e1608..b5806ef 100644 --- a/MDK-ARM/PY32Dallas.uvoptx +++ b/MDK-ARM/PY32Dallas.uvoptx @@ -449,6 +449,18 @@ 0 0 0 + ..\Core\Src\iwdg.c + iwdg.c + 0 + 0 + + + 2 + 11 + 1 + 0 + 0 + 0 ..\Core\Src\py32f002b_it.c py32f002b_it.c 0 @@ -456,7 +468,7 @@ 2 - 11 + 12 1 0 0 @@ -476,7 +488,7 @@ 0 3 - 12 + 13 1 0 0 @@ -488,7 +500,7 @@ 3 - 13 + 14 1 0 0 @@ -500,7 +512,7 @@ 3 - 14 + 15 1 0 0 @@ -512,7 +524,7 @@ 3 - 15 + 16 1 0 0 @@ -524,7 +536,7 @@ 3 - 16 + 17 1 0 0 @@ -536,7 +548,7 @@ 3 - 17 + 18 1 0 0 @@ -548,7 +560,7 @@ 3 - 18 + 19 1 0 0 @@ -560,7 +572,7 @@ 3 - 19 + 20 1 0 0 @@ -572,7 +584,7 @@ 3 - 20 + 21 1 0 0 @@ -584,7 +596,7 @@ 3 - 21 + 22 1 0 0 @@ -594,6 +606,18 @@ 0 0 + + 3 + 23 + 1 + 0 + 0 + 0 + ..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_iwdg.c + py32f002b_hal_iwdg.c + 0 + 0 + @@ -604,7 +628,7 @@ 0 4 - 22 + 24 1 0 0 @@ -616,7 +640,7 @@ 4 - 23 + 25 5 0 0 @@ -628,7 +652,7 @@ 4 - 24 + 26 1 0 0 @@ -640,7 +664,7 @@ 4 - 25 + 27 5 0 0 @@ -652,7 +676,7 @@ 4 - 26 + 28 1 0 0 @@ -664,7 +688,7 @@ 4 - 27 + 29 5 0 0 @@ -676,7 +700,7 @@ 4 - 28 + 30 1 0 0 @@ -688,7 +712,7 @@ 4 - 29 + 31 5 0 0 @@ -700,7 +724,7 @@ 4 - 30 + 32 1 0 0 @@ -712,7 +736,7 @@ 4 - 31 + 33 5 0 0 @@ -732,7 +756,7 @@ 0 5 - 32 + 34 1 0 0 @@ -744,7 +768,7 @@ 5 - 33 + 35 5 0 0 @@ -756,7 +780,7 @@ 5 - 34 + 36 1 0 0 @@ -768,7 +792,7 @@ 5 - 35 + 37 5 0 0 @@ -780,7 +804,7 @@ 5 - 36 + 38 1 0 0 @@ -792,7 +816,7 @@ 5 - 37 + 39 5 0 0 @@ -812,7 +836,7 @@ 0 6 - 38 + 40 5 0 0 @@ -824,7 +848,7 @@ 6 - 39 + 41 1 0 0 @@ -836,7 +860,7 @@ 6 - 40 + 42 5 0 0 @@ -848,7 +872,7 @@ 6 - 41 + 43 5 0 0 @@ -860,7 +884,7 @@ 6 - 42 + 44 5 0 0 @@ -872,7 +896,7 @@ 6 - 43 + 45 5 0 0 @@ -884,7 +908,7 @@ 6 - 44 + 46 5 0 0 @@ -896,7 +920,7 @@ 6 - 45 + 47 5 0 0 diff --git a/MDK-ARM/PY32Dallas.uvprojx b/MDK-ARM/PY32Dallas.uvprojx index 350f911..2e4fa08 100644 --- a/MDK-ARM/PY32Dallas.uvprojx +++ b/MDK-ARM/PY32Dallas.uvprojx @@ -435,6 +435,11 @@ 1 ..\Core\Src\usart.c + + iwdg.c + 1 + ..\Core\Src\iwdg.c + py32f002b_it.c 1 @@ -500,6 +505,11 @@ 1 ..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_uart.c + + py32f002b_hal_iwdg.c + 1 + ..\Drivers\PY32F002B_HAL_Driver\Src\py32f002b_hal_iwdg.c +