From 5ef5c8842ac9625bca05cf3f729c39e1f72ea3fd Mon Sep 17 00:00:00 2001 From: stark1898y <1658608470@qq.com> Date: Fri, 16 May 2025 14:27:39 +0800 Subject: [PATCH] IWDG ok --- BSP/inc/bsp_iwdg.h | 6 +++--- BSP/src/bsp_iwdg.c | 21 ++++++++++++++------- HAL/MCU.c | 6 ++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/BSP/inc/bsp_iwdg.h b/BSP/inc/bsp_iwdg.h index 9a692ec..7953ab4 100644 --- a/BSP/inc/bsp_iwdg.h +++ b/BSP/inc/bsp_iwdg.h @@ -2,7 +2,7 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-12-15 16:13:37 * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2025-05-16 11:17:22 + * @LastEditTime : 2025-05-16 14:17:34 * @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_iwdg.h * @Description : * @@ -31,8 +31,8 @@ #define RB_WR_PROTECT 0x40000000 // RO, write protect #define RB_IWDG_EN 0x80000000 // RO, watch-dog enable -#define IWDG_TIMEOUT_MS (7000U) -#define IWDG_FEED_MS (3000U) +#define IWDG_TIMEOUT_MS (6000) +#define IWDG_FEED_MS (5000) #define IWIG_FEED_EVENT (0x01 << 0) diff --git a/BSP/src/bsp_iwdg.c b/BSP/src/bsp_iwdg.c index f8ca5f5..4c49d1f 100644 --- a/BSP/src/bsp_iwdg.c +++ b/BSP/src/bsp_iwdg.c @@ -2,7 +2,7 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-12-15 16:13:41 * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2025-05-16 12:29:30 + * @LastEditTime : 2025-05-16 14:23:06 * @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_iwdg.c * @Description : * @@ -30,6 +30,8 @@ uint16_t IWDG_ProcessEvent(uint8_t task_id, uint16_t events) { FEED_IWDG(); logDebug("IWDG feed"); + // 获取tmos系统堆的剩余内存大小 + // uint8_t* a = tmos_msg_allocate(1); logDebug("tmos_memory_getlen = %d" , tmos_memory_getlen()); tmos_start_task(task_id, IWIG_FEED_EVENT, MS1_TO_SYSTEM_TIME(IWDG_FEED_MS)); return (events ^ IWIG_FEED_EVENT); @@ -55,17 +57,22 @@ void IWDG_Init(uint16_t ms) // 解除IWDG保护 R32_IWDG_KR = 0x5555; - R32_IWDG_CFG = (RB_PR & (div << 12)) | (RB_STOP_EN) | (reload & RB_RLR); - // R32_IWDG_CFG |= (7 << 12); // 32K分频512,时钟62.5Hz - // R32_IWDG_CFG &= 0xFFFFF000; - // // R32_IWDG_CFG |= 0x7D * 3; // 看门狗时间约6 s(0x10/(32K/512)) - // R32_IWDG_CFG |= reload; + // R32_IWDG_CFG = (RB_PR & (div << 12)) | (RB_STOP_EN) | (reload & RB_RLR); + R32_IWDG_CFG |= (7 << 12); // 32K分频512,时钟62.5Hz + R32_IWDG_CFG &= 0xFFFFF000; + // R32_IWDG_CFG |= 0x7D * 3; // 看门狗时间约6 s(0x10/(32K/512)) + R32_IWDG_CFG |= reload; // 开启IWDG保护 R32_IWDG_KR = 0xCCCC; - + // uint32_t d = R32_IWDG_CFG; + // logHexDumpAll(d, 4); logDebug("IWDG = %d, %.1f ms", reload, (reload * 1000) / 62.5); + // sys_safe_access_enable(); + // R8_SAFE_LRST_CTRL |= RB_IWDG_RST_EN; + // sys_safe_access_disable(); + IWDGTaskId = TMOS_ProcessEventRegister(IWDG_ProcessEvent); // tmos_set_event(IWDGTaskId, IWIG_FEED_EVENT); tmos_start_task(IWDGTaskId, IWIG_FEED_EVENT, MS1_TO_SYSTEM_TIME(IWDG_FEED_MS)); diff --git a/HAL/MCU.c b/HAL/MCU.c index 202f8b6..9918efd 100644 --- a/HAL/MCU.c +++ b/HAL/MCU.c @@ -231,7 +231,7 @@ void HAL_Init() halTaskID = TMOS_ProcessEventRegister(HAL_ProcessEvent); HAL_TimeInit(); -#if 0 +#if 1 // Źǿƿڲ32Kǿ״̬ûиڲRC32KĴͬ // λʱǸڲRC32KĴ״̬ǷRC32K // رch584ڲ32KRC @@ -239,9 +239,7 @@ void HAL_Init() R8_CK32K_CONFIG |= RB_CLK_INT32K_PON; sys_safe_access_disable(); #endif - sys_safe_access_enable(); - R8_SAFE_LRST_CTRL |= RB_IWDG_RST_EN; - sys_safe_access_disable(); + #if(defined HAL_SLEEP) && (HAL_SLEEP == TRUE) HAL_SleepInit();