diff --git a/APP/peripheral_main.c b/APP/peripheral_main.c index ce1f903..bc077ba 100644 --- a/APP/peripheral_main.c +++ b/APP/peripheral_main.c @@ -291,6 +291,8 @@ int main(void) BSP_BEEP_LED_EMV_Init(); + PRINT("PRINT\r\n"); + logDebug("Start @ChipID=%02X\n", R8_CHIP_ID); logError("中文测试 %2.2f", 123.456); @@ -422,14 +424,14 @@ int main(void) IWDG_Init(IWDG_TIMEOUT_MS); + logDebug("123"); + DelayMs(1000); + logDebug("456"); + // 在连接间隔和广播间隔到来时,会进入回调中喂狗 // LL_AdvertiseEventRegister(BLE_AdvertiseEventCB); // LL_ConnectEventRegister(BLE_ConnectEventCB); - - // FEED_IWDG(); - // logDebug("IWDG_Init 1"); - Main_Circulation(); } diff --git a/BSP/inc/bsp_iwdg.h b/BSP/inc/bsp_iwdg.h index 7953ab4..f640a2d 100644 --- a/BSP/inc/bsp_iwdg.h +++ b/BSP/inc/bsp_iwdg.h @@ -2,17 +2,7 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-12-15 16:13:37 * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2025-05-16 14:17:34 - * @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_iwdg.h - * @Description : - * - * Copyright (c) 2024 by yzy, All Rights Reserved. - */ -/* - * @Author : stark1898y 1658608470@qq.com - * @Date : 2024-12-14 10:51:01 - * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2024-12-15 11:16:24 + * @LastEditTime : 2025-05-16 17:31:12 * @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_iwdg.h * @Description : * @@ -32,7 +22,7 @@ #define RB_IWDG_EN 0x80000000 // RO, watch-dog enable #define IWDG_TIMEOUT_MS (6000) -#define IWDG_FEED_MS (5000) +#define IWDG_FEED_MS (1000) #define IWIG_FEED_EVENT (0x01 << 0) diff --git a/BSP/inc/bsp_tim.h b/BSP/inc/bsp_tim.h index 3e2c84c..d4e466d 100644 --- a/BSP/inc/bsp_tim.h +++ b/BSP/inc/bsp_tim.h @@ -2,8 +2,8 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-12-15 15:01:15 * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2024-12-15 16:24:28 - * @FilePath : \BLE_TYQ_CH584M - 副本\BSP\inc\bsp_tim.h + * @LastEditTime : 2025-05-16 18:20:04 + * @FilePath : \BLE_TYQ_CH584M\BSP\inc\bsp_tim.h * @Description : * * Copyright (c) 2024 by yzy, All Rights Reserved. @@ -13,7 +13,7 @@ #include "CONFIG.h" - +uint32_t CH5XX_GetTimeStamp(uint16_t *tick); uint32_t BSP_Get_Tick(void); diff --git a/BSP/src/bsp_iwdg.c b/BSP/src/bsp_iwdg.c index 4c49d1f..d3df5c1 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 14:23:06 + * @LastEditTime : 2025-05-16 18:35:06 * @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_iwdg.c * @Description : * @@ -12,6 +12,7 @@ #include "bsp_uart.h" #include "log.h" +#include "bsp_tim.h" // https://www.cnblogs.com/debugdabiaoge/p/17580033.html // https://www.cnblogs.com/risc5-ble/p/17853714.html @@ -28,6 +29,10 @@ uint16_t IWDG_ProcessEvent(uint8_t task_id, uint16_t events) { if (events & IWIG_FEED_EVENT) { + // uint32_t seconds = 0; + // uint16_t tick_1sec = 0; + // seconds = CH5XX_GetTimeStamp(&tick_1sec); + // logDebug("seconds = %d.%d", seconds, tick_1sec * 1000 / 32768); FEED_IWDG(); logDebug("IWDG feed"); // 获取tmos系统堆的剩余内存大小 diff --git a/BSP/src/bsp_tim.c b/BSP/src/bsp_tim.c index 2577111..c21dfca 100644 --- a/BSP/src/bsp_tim.c +++ b/BSP/src/bsp_tim.c @@ -2,8 +2,8 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-12-15 15:01:15 * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2024-12-15 16:24:32 - * @FilePath : \BLE_TYQ_CH584M - \BSP\src\bsp_tim.c + * @LastEditTime : 2025-05-16 18:21:05 + * @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_tim.c * @Description : * * Copyright (c) 2024 by yzy, All Rights Reserved. @@ -13,6 +13,62 @@ // tick_1ms_cntSysTick_Handler()1ms +1 volatile uint32_t tick_1ms_cnt = 0; +#if 0 +// Ҫ32k +// һ +__HIGH_CODE +uint32_t plat_rtc_get(void) +{ + volatile uint32_t i; + do { + i = R32_RTC_CNT_32K; + } while (i != R32_RTC_CNT_32K); + return (i); +} + +__HIGH_CODE +uint32_t ch5xx_get_rtc_gap(uint32_t last, uint32_t current) +{ + if (current > last) + { + return (current - last); + } + else + { + return (32768 * 3600 * 24UL - last + current); + } +} + +uint32_t last_rtc_cnt = plat_rtc_get(); +// do sleep +uint32_t current_rtc_cnt = plat_rtc_get(); + +if (ch5xx_get_rtc_gap(last_rtc_cnt, current_rtc_cnt) > 32768 * 10) +{ + // do bat level sample +} +#endif + +// return local time in seconds, max 44 year +__HIGH_CODE +uint32_t CH5XX_GetTimeStamp(uint16_t *tick) +{ + uint32_t t, t32k; + uint16_t day, sec2; + do { + t32k = R32_RTC_CNT_32K; + day = R32_RTC_CNT_DAY & 0x3FFF; + sec2 = R16_RTC_CNT_2S; + } while (t32k != R32_RTC_CNT_32K); + + t = day * 86400 + (sec2 << 1) + ((t32k < 0x8000) ? 0 : 1); + if (tick != NULL) + { + *tick = t32k & 0X7FFF; + } + return t; +} + /** * @description: SysTick1msΪ * @return {uint32_t} @@ -21,7 +77,13 @@ uint32_t BSP_Get_Tick(void) { /* Platform implementation */ // current system clock (in 0.625ms) - return (uint32_t)((double)TMOS_GetSystemClock() / 1.6); + // return (uint32_t)((double)TMOS_GetSystemClock() / 1.6); + + uint32_t seconds = 0; + uint16_t tick_1sec = 0; + seconds = CH5XX_GetTimeStamp(&tick_1sec); + return (seconds * 1000 + (tick_1sec * 1000 / 32768)); + // logDebug("seconds = %d.%d", seconds, tick_1sec * 1000 / 32768); } // SysTickжϺ diff --git a/StdPeriphDriver/CH58x_sys.c b/StdPeriphDriver/CH58x_sys.c index 8f382ee..5190e12 100644 --- a/StdPeriphDriver/CH58x_sys.c +++ b/StdPeriphDriver/CH58x_sys.c @@ -460,6 +460,7 @@ __INTERRUPT __HIGH_CODE __attribute__((weak)) void HardFault_Handler(void) { +#if 0 uint32_t v_mepc, v_mcause, v_mtval; printf("hardfault\n"); @@ -478,6 +479,47 @@ __attribute__((weak)) void HardFault_Handler(void) sys_safe_access_enable(); R8_RST_WDOG_CTRL |= RB_SOFTWARE_RESET; sys_safe_access_disable(); +#endif + struct __MEMORY_CTL + { + struct __MEMORY_CTL *pNext; + uint16_t len; + uint16_t used; + }; + typedef struct __MEMORY_CTL MemoryCtl; + + extern MemoryCtl *MemCtlStart; + extern MemoryCtl *MemCtlEnd; + MemoryCtl *MemHead; + MemHead = MemCtlStart; + while (MemHead != MemCtlEnd) + { + printf("|%8x,%8x,%8d.....\n", MemHead->used, (uint32_t)MemHead, + (uint32_t)(MemHead->pNext) - (uint32_t)MemHead - sizeof(struct __MEMORY_CTL)); + MemHead = MemHead->pNext; + } + printf("\n"); + + uint32_t v_mepc, v_mcause, v_mtval; + printf("hardfault\n"); + + v_mepc = __get_MEPC(); + v_mcause = __get_MCAUSE(); + v_mtval = __get_MTVAL(); + + printf("mepc:%08x\n", v_mepc); + printf("mcause:%08x\n", v_mcause); + printf("mtval:%08x\n", v_mtval); + +#if 0 + FLASH_ROM_SW_RESET(); + sys_safe_access_enable(); + R16_INT32K_TUNE = 0xFFFF; + sys_safe_access_disable(); + sys_safe_access_enable(); + R8_RST_WDOG_CTRL |= RB_SOFTWARE_RESET; + sys_safe_access_disable(); +#endif while (1); }