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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.mrs/launch.json b/.mrs/launch.json
index f3acb26..0b58c4e 100644
--- a/.mrs/launch.json
+++ b/.mrs/launch.json
@@ -10,7 +10,7 @@
"useLocalOpenOCD": true,
"executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
"configOptions": [
- "-f \"c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/wch-riscv.cfg\""
+ "-f \"c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/wch-riscv.cfg\" -c \"chip_id CH58x\""
],
"gdbport": 3333,
"telnetport": 4444,
diff --git a/.project b/.project
index 2aa28b2..38a9476 100644
--- a/.project
+++ b/.project
@@ -1,37 +1,34 @@
- BLE_TYQ_BJQ_CH584M
-
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.genmakebuilder
- clean,full,incremental,
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
- full,incremental,
-
-
-
-
-
- org.eclipse.cdt.core.cnature
- org.eclipse.cdt.managedbuilder.core.managedBuildNature
- org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
-
-
-
- 1602468250279
-
- 22
-
- org.eclipse.ui.ide.multiFilter
- 1.0-name-matches-false-false-*.wvproj
-
-
-
-
+ BLE_TYQ_BJQ_CH584M
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
+
+
+
+ 6
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-*.wvproj
+
+
+
+
\ No newline at end of file
diff --git a/.template b/.template
index e69de29..6a72012 100644
--- a/.template
+++ b/.template
@@ -0,0 +1,23 @@
+Vendor=WCH
+Toolchain=RISC-V
+Series=CH58X
+RTOS=NoneOS
+MCU=CH583M
+Link=WCH-Link
+PeripheralVersion=1.0
+Description=
+Mcu Type=CH58x
+Address=0x00000000
+Target Path=
+Exe Path=
+Exe Arguments=
+CLKSpeed=1
+DebugInterfaceMode=0
+Erase All=false
+Program=false
+Verify=false
+Reset=false
+SDIPrintf=false
+Disable Power Output=false
+Clear CodeFlash=false
+Disable Code-Protect=false
\ No newline at end of file
diff --git a/APP/multiCentral.c b/APP/multiCentral.c
index 34a3d8c..de3dc11 100644
--- a/APP/multiCentral.c
+++ b/APP/multiCentral.c
@@ -18,6 +18,7 @@
#define MASTER_DETECT_EVT (0X01 << 3)
uint8_t MasterCtrTaskId;
+uint8_t bt_conncet_cnt = 0;
/*********************************************************************
* MACROS
@@ -90,7 +91,7 @@ uint8_t MasterCtrTaskId;
#define DEFAULT_IO_CAPABILITIES GAPBOND_IO_CAP_NO_INPUT_NO_OUTPUT
// Default service discovery timer delay in 0.625ms
-#define DEFAULT_SVC_DISCOVERY_DELAY 10
+#define DEFAULT_SVC_DISCOVERY_DELAY 2
// Default parameter update delay in 0.625ms
#define DEFAULT_PARAM_UPDATE_DELAY 1600
@@ -1255,12 +1256,12 @@ int BSP_Master_Receive_Data(uint8_t task_id, uint8_t *data, uint16_t len)
// //有效数据长度
size_t data_len = (datalength + 5);
ret = data_len;
- if (data[index + 1] == kCmdCloseVavle) // 0x02 代表了其是控制阀门响应
+ if (data[index + 1] == 0x02) // 0x02 代表了其是控制阀门响应
{
// logDebug("BT 控制阀门响应包");
if (data[index + datalength + 2] == 1) // 响应数据位
{
- logInfo("关闭阀门成功");
+ logInfo("BT 控制阀门成功");
}
else
{
@@ -1337,6 +1338,12 @@ uint16_t Master_ProcessEvent(uint8_t task_id, uint16_t events)
if (Flash_Get_Valve_Num())
{
logDebug("有设备,尝试连接\r\n");
+ bt_conncet_cnt++;
+ if (bt_conncet_cnt > 60)//如果多次重试都不行,直接重启设备
+ {
+ bt_conncet_cnt = 0;
+ PFIC_SystemReset();
+ }
tmos_start_task(task_id, MASTER_CONNECT_EVT, 1600);
}
}
diff --git a/APP/multiCentral_main.c b/APP/multiCentral_main.c
index 97925fa..7c681fd 100644
--- a/APP/multiCentral_main.c
+++ b/APP/multiCentral_main.c
@@ -74,7 +74,7 @@ int main(void)
#if (defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE)
PWR_DCDCCfg(ENABLE);
#endif
- HSECFG_Capacitance(HSECap_18p);
+ HSECFG_Capacitance(HSECap_20p);
SetSysClock(CLK_SOURCE_HSE_PLL_62_4MHz);
#if (defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU);
@@ -96,15 +96,12 @@ int main(void)
logDebug("test log debug\n");
#endif
+
CH58x_BLEInit();
HAL_Init();
GAPRole_CentralInit();
Central_Init();
- logDebug("get_ticks %d", BSP_Get_Tick());
- DelayMs(2000);
- logDebug("get_ticks %d", BSP_Get_Tick());
-
BSP_FLASH_Init();
BSP_Valve_Init();
BSP_UART1_Init(); // BT UART
diff --git a/BLE_TYQ_BJQ_CH584M.launch b/BLE_TYQ_BJQ_CH584M.launch
new file mode 100644
index 0000000..482dea7
--- /dev/null
+++ b/BLE_TYQ_BJQ_CH584M.launch
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/BLE_TYQ_BJQ_CH584M.wvproj b/BLE_TYQ_BJQ_CH584M.wvproj
index 02d84e6..e30699b 100644
Binary files a/BLE_TYQ_BJQ_CH584M.wvproj and b/BLE_TYQ_BJQ_CH584M.wvproj differ
diff --git a/HAL/RTC.c b/HAL/RTC.c
index 0c6366a..3a01e15 100644
--- a/HAL/RTC.c
+++ b/HAL/RTC.c
@@ -172,13 +172,14 @@ void HAL_TimeInit(void)
Lib_Calibration_LSI();
#else
sys_safe_access_enable();
- R8_CK32K_CONFIG &= ~RB_CLK_INT32K_PON;
+ // R8_CK32K_CONFIG &= ~RB_CLK_INT32K_PON;
+ R8_CK32K_CONFIG |= RB_CLK_INT32K_PON;
sys_safe_access_disable();
sys_safe_access_enable();
R8_CK32K_CONFIG |= RB_CLK_OSC32K_XT | RB_CLK_XT32K_PON;
sys_safe_access_disable();
#endif
- RTC_InitTime(2020, 1, 1, 0, 0, 0); //RTCʱӳʼǰʱ
+ RTC_InitTime(2025, 5, 20, 0, 0, 0); //RTCʱӳʼǰʱ
tmos_memset( &conf, 0, sizeof(bleClockConfig_t) );
conf.ClockAccuracy = CLK_OSC32K ? 1000 : 50;
diff --git a/bsp/inc/bsp_uart.h b/bsp/inc/bsp_uart.h
index 4ca0ade..d65feca 100644
--- a/bsp/inc/bsp_uart.h
+++ b/bsp/inc/bsp_uart.h
@@ -13,15 +13,19 @@
#include "CH58x_common.h"
+#define DEVICE_TYPE_TYQ_LY
+
+
#define BT_START_EVT (0X01 << 0)
#define BT_REC_EVT (0X01 << 1)
#define BT_INFO_UPDATA_EVT (0X01 << 2)
#define BT_SEND_EVT (0X01 << 3)//
#define BT_REC_EVT_FINISH (0X01 << 4) //接收完成事件
+#ifdef DEVICE_TYPE_TYQ_LY
#define UART3_RX_PIN GPIO_Pin_20 //PB20
#define UART3_TX_PIN GPIO_Pin_21 // PB21
-
+#endif
#define BT_UART_TX_PIN GPIO_Pin_9 //PA9
#define BT_UART_RX_PIN GPIO_Pin_8 //PA8
diff --git a/bsp/src/bsp_tim.c b/bsp/src/bsp_tim.c
index 3582b35..7c782bb 100644
--- a/bsp/src/bsp_tim.c
+++ b/bsp/src/bsp_tim.c
@@ -11,7 +11,7 @@
#include "bsp_tim.h"
#include "HAL.h"
-volatile uint32_t tick_1ms_cnt = 0;
+// volatile uint32_t tick_1ms_cnt = 0;
/**
* @description:
@@ -25,15 +25,15 @@ uint32_t BSP_Get_Tick(void)
}
-__INTERRUPT
-__HIGH_CODE
-void SysTick_Handler()
-{
- static uint8_t cnt_ms = 0;
+// __INTERRUPT
+// __HIGH_CODE
+// void SysTick_Handler()
+// {
+// static uint8_t cnt_ms = 0;
- SysTick->SR = 0;
- tick_1ms_cnt++;
+// SysTick->SR = 0;
+// tick_1ms_cnt++;
- cnt_ms++;
-}
+// cnt_ms++;
+// }
diff --git a/bsp/src/bsp_uart.c b/bsp/src/bsp_uart.c
index 2fd4294..b3200dc 100644
--- a/bsp/src/bsp_uart.c
+++ b/bsp/src/bsp_uart.c
@@ -369,7 +369,7 @@ uint16_t BT_ProcessEvent(uint8_t task_id, uint16_t events)
}
else if (events & BT_REC_EVT)
{
- logDebug("BT_REC_EVT");
+ // logDebug("BT_REC_EVT");
if (bt_recv_end_flag)
{
bt_recv_end_flag = 0;
@@ -420,12 +420,16 @@ void BSP_UART1_Init(void)
/*调试接口*/
void BSP_UART3_Init(void)
{
- GPIOPinRemap(ENABLE, RB_PIN_UART3);
+#ifdef DEVICE_TYPE_TYQ_LY
+ GPIOPinRemap(ENABLE, RB_PIN_UART3);
/* 配置串口3:先配置IO口模式,再配置串口 */
GPIOB_SetBits(UART3_TX_PIN);
GPIOB_ModeCfg(UART3_RX_PIN, GPIO_ModeIN_PU); // RXD-配置上拉输入
GPIOB_ModeCfg(UART3_TX_PIN, GPIO_ModeOut_PP_5mA); // TXD-配置推挽输出,注意先让IO口输出高电平
+#endif
+
UART3_DefInit();
+
UART3_BaudRateCfg(460800);
UART3_ByteTrigCfg(UART_1BYTE_TRIG);
// 中断方式接收数据
diff --git a/bsp/src/bsp_valve.c b/bsp/src/bsp_valve.c
index 648e8e6..b8dfae6 100644
--- a/bsp/src/bsp_valve.c
+++ b/bsp/src/bsp_valve.c
@@ -275,7 +275,6 @@ void BSP_Bt_Valve_Updata(void)
{
return;
}
-
tmos_memset(&valve_list, 0, sizeof(valve_data_list_t));
for (int i = 1; i < MAX_VALVE_NUM; i++) // 这个循环是为了将数据拷贝到valve_list中, 并且保证id号和flash对应起来