From ff9c225b0d6101d06147ff16314dd9cbe16d22de Mon Sep 17 00:00:00 2001 From: stark1898y <1658608470@qq.com> Date: Sat, 22 Feb 2025 18:05:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A2=E7=89=B9=E7=8E=87=E6=8B=89=E9=AB=98?= =?UTF-8?q?=E5=88=B02.5Mbps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 +- APP/include/peripheral.h | 10 +++ APP/peripheral_main.c | 148 ++++++++------------------------------- BSP/src/bsp_iwdg.c | 4 +- Ld/Link.ld | 2 +- 5 files changed, 45 insertions(+), 122 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8d5f378..e9d77c0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,6 +18,7 @@ "bsp_flash.h": "c", "bsp_valve.h": "c", "log.h": "c", - "hal.h": "c" + "hal.h": "c", + "bsp_iwdg.h": "c" } } diff --git a/APP/include/peripheral.h b/APP/include/peripheral.h index 554d723..02c0aa4 100644 --- a/APP/include/peripheral.h +++ b/APP/include/peripheral.h @@ -1,3 +1,13 @@ +/* + * @Author : stark1898y 1658608470@qq.com + * @Date : 2024-12-30 10:11:28 + * @LastEditors : stark1898y 1658608470@qq.com + * @LastEditTime : 2025-02-22 17:23:28 + * @FilePath : \BLE_TYQ_CH584M\APP\include\peripheral.h + * @Description : + * + * Copyright (c) 2025 by yzy, All Rights Reserved. + */ /********************************** (C) COPYRIGHT ******************************* * File Name : peripheral.h * Author : WCH diff --git a/APP/peripheral_main.c b/APP/peripheral_main.c index 134e858..c2ba55f 100644 --- a/APP/peripheral_main.c +++ b/APP/peripheral_main.c @@ -41,11 +41,9 @@ __attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4]; static uint8_t key_press_cnt = 0; -#if 0 void app_task_handler(TeAppEvtType app_evt_type) { BSP_BlockSleep(); - // BSP_BlockSleep(); BSP_RequestBoost(); switch (app_evt_type) @@ -120,88 +118,6 @@ void app_task_handler(TeAppEvtType app_evt_type) break; } } -#endif - -#if 1 -void app_task_handler(TeAppEvtType app_evt_type) -{ - BSP_BlockSleep(); - // BSP_BlockSleep(); - BSP_RequestBoost(); - - switch(app_evt_type) - { - case kKeyShort: - logDebug("button short press"); - key_press_cnt++; - logDebug("key_press_cnt = %d", key_press_cnt); - if (key_press_cnt == 1) - { - logDebug("LED显示状态"); - // tmos_set_event(led_task_id, LED_SHOW_START_EVT); - BSP_BlockSleep(); - BSP_RequestBoost(); - DelayMs(1); - ShowLed(); - // tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); - // tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); - } - else if (key_press_cnt == 2) - { - if (gValveData.switch_status == kClosed) - { - logDebug("kClosed-->kOpened"); - // tmos_set_event(led_task_id, LED_SHOW_START_EVT); - gValveData.switch_status = kOpened; - BSP_BlockSleep(); - BSP_RequestBoost(); - DelayMs(1); - ShowLed(); - // tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); - // tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); - } - else if (gValveData.switch_status != kClosed) - { - logDebug("kOpened-->kClosed"); - gValveData.switch_status = kClosed; - tmos_set_event(vavle_task_id, VAVLE_CLOSE_START_EVT); - - // tmos_set_event(led_task_id, LED_SHOW_START_EVT); - BSP_BlockSleep(); - BSP_RequestBoost(); - DelayMs(1); - ShowLed(); - // tmos_stop_task(led_task_id, LED_SHOW_ONCE_EVT); - // tmos_start_task(led_task_id, LED_SHOW_ONCE_EVT, 1000); - } - } - break; - - case kKeyLong: - logDebug("button long press"); - - break; - case kKeyRelease: - // BSP_KEY_EnterLowpower(); - // DelayMs(10); - key_press_cnt = 0; - // BSP_RequestSleep(); - // tmos_set_event(led_task_id, LED_SHOW_END_EVT); - - LED_ALL_OFF_DEINIT; - BEEP_OFF_DEINIT; - - BSP_NoNeedBoost(); - BSP_RequestSleep(); - - logDebug("gpio relase;BSP_RequestSleep"); - - break; - default: - break; - } -} -#endif /********************************************************************* * @fn Main_Circulation @@ -218,17 +134,6 @@ __attribute__((noinline)) void Main_Circulation() TMOS_SystemProcess(); KEY_ProcessLoop(); BSP_UART1_TxLoop(); - // if (GPIOB_ReadPortPin(KEY_B_PIN) == 0) - // { - // DelayMs(20); - // if (GPIOB_ReadPortPin(KEY_B_PIN) == 0) - // { - // logDebug("KEY_B_PIN short press"); - - // } - - // } - } } @@ -236,13 +141,13 @@ __attribute__((noinline)) void Main_Circulation() // 在连接间隔和广播间隔到来时,会进入该回调,可以在回调函数加上其他执行逻辑代码,如喂狗等。 void BLE_AdvertiseEventCB(uint32_t timeUs) { - // FEED_IWDG(); + FEED_IWDG(); logDebug("BLE_AdvertiseEventCB"); } void BLE_ConnectEventCB(uint32_t timeUs) { - // FEED_IWDG(); + FEED_IWDG(); logDebug("BLE_ConnectEventCB"); } @@ -266,24 +171,17 @@ int main(void) GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD); #endif #ifdef DEBUG - // 改成1500000波特率了 - BSP_UART1_Init(460800); - logDebug("Start @ChipID=%02X\n", R8_CHIP_ID); - logError("中文测试 %2.2f", 123.456); + // 改成 1500000 波特率了 + BSP_UART1_Init(2500000); #endif + DelayMs(1000 * 3); CH58x_BLEInit(); + HAL_Init(); + GAPRole_PeripheralInit(); + Peripheral_Init(); - LED_R_ON; - DelayMs(500); - - BSP_BEEP_LED_EMV_Init(); - - logDebug("%s\n", VER_LIB); - uint8_t MacAddr[6]; - GetMACAddress(MacAddr); - // 手机APP显示是倒序的[5-0],不是[0-5] - logDebug("MacAddr: %02X:%02X:%02X:%02X:%02X:%02X", MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]); + logDebug("GetSysClock = %d Hz", GetSysClock()); // extern void Peripheral_SetMacName(void); // Peripheral_SetMacName(); @@ -294,21 +192,28 @@ int main(void) BSP_FLASH_Init(); - DelayMs(100); + BSP_BEEP_LED_EMV_Init(); + + + logDebug("Start @ChipID=%02X\n", R8_CHIP_ID); + logError("中文测试 %2.2f", 123.456); + + logDebug("%s\n", VER_LIB); + uint8_t MacAddr[6]; + GetMACAddress(MacAddr); + // 手机APP显示是倒序的[5-0],不是[0-5] + logDebug("MacAddr: %02X:%02X:%02X:%02X:%02X:%02X", MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]); + // log打印编译时间和编译日期 + logDebug("Compile Time: %s %s", __DATE__, __TIME__); + GXHTC3C_Init(); BSP_KEY_Init(app_task_handler); - // IWDG_Init(1500); - DelayMs(1000 * 3); - BSP_ADC_Init(); BSP_VAVLE_Init(); - HAL_Init(); - GAPRole_PeripheralInit(); - Peripheral_Init(); BSP_BlockSleep(); BSP_RequestBoost(); @@ -321,6 +226,9 @@ int main(void) LED_ALL_OFF_DEINIT; BEEP_OFF_DEINIT; + // logDebug("IWDG_Init 0"); + // IWDG_Init(1500); + BSP_NoNeedBoost(); BSP_RequestSleep(); @@ -328,6 +236,10 @@ int main(void) // LL_AdvertiseEventRegister(BLE_AdvertiseEventCB); // LL_ConnectEventRegister(BLE_ConnectEventCB); + + // FEED_IWDG(); + // logDebug("IWDG_Init 1"); + Main_Circulation(); } diff --git a/BSP/src/bsp_iwdg.c b/BSP/src/bsp_iwdg.c index 9edc0c5..aaae803 100644 --- a/BSP/src/bsp_iwdg.c +++ b/BSP/src/bsp_iwdg.c @@ -2,8 +2,8 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-12-15 16:13:41 * @LastEditors : stark1898y 1658608470@qq.com - * @LastEditTime : 2024-12-15 16:13:42 - * @FilePath : \BLE_TYQ_CH584M - 副本\BSP\src\bsp_iwdg.c + * @LastEditTime : 2025-02-22 17:28:20 + * @FilePath : \BLE_TYQ_CH584M\BSP\src\bsp_iwdg.c * @Description : * * Copyright (c) 2024 by yzy, All Rights Reserved. diff --git a/Ld/Link.ld b/Ld/Link.ld index e847cdb..beedf6a 100644 --- a/Ld/Link.ld +++ b/Ld/Link.ld @@ -3,7 +3,7 @@ ENTRY( _start ) MEMORY { FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 448K - RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K } SECTIONS