yincheng.zhong
昨天 c8240d55741f0ed86099a0a8c616f4fc68372134
STM32H743/APL/PathTest.c
@@ -421,12 +421,35 @@
void OTATest_Poll(void)
{
    HIDO_UINT32 current_tick = HIDO_TimerGetTick();
    E_OTAState ota_state = OTA_GetState();
    
    // OTA模块需要周期调用(处理解密任务)
    OTA_Poll();
    
    // 限制检查频率
    if (current_tick - s_ota_test_ctx.last_check_tick < TEST_CHECK_INTERVAL) {
    // 超时检测:如果状态卡在中间状态超过一定时间,触发失败
    static HIDO_UINT32 s_u32StateStartTick = 0;
    static E_OTATestState s_eLastState = OTA_TEST_STATE_IDLE;
    if (s_ota_test_ctx.state != s_eLastState) {
        s_u32StateStartTick = current_tick;
        s_eLastState = s_ota_test_ctx.state;
    }
    // 检查状态超时(除了IDLE、COMPLETE、FAILED)
    if (s_ota_test_ctx.state != OTA_TEST_STATE_IDLE &&
        s_ota_test_ctx.state != OTA_TEST_STATE_COMPLETE &&
        s_ota_test_ctx.state != OTA_TEST_STATE_FAILED) {
        if (current_tick - s_u32StateStartTick > 60000) {  // 60秒超时
            HIDO_Debug("[OTATest] State timeout! State=%d, OTAState=%d\r\n",
                       s_ota_test_ctx.state, ota_state);
            s_ota_test_ctx.state = OTA_TEST_STATE_FAILED;
        }
    }
    // 限制检查频率(但下载完成时立即检查)
    HIDO_BOOL bForceCheck = (s_ota_test_ctx.state == OTA_TEST_STATE_DOWNLOADING &&
                             ota_state == OTA_STATE_DOWNLOAD_COMPLETE);
    if (!bForceCheck && (current_tick - s_ota_test_ctx.last_check_tick < TEST_CHECK_INTERVAL)) {
        return;
    }
    s_ota_test_ctx.last_check_tick = current_tick;
@@ -488,7 +511,7 @@
 */
static void OTATest_StartDownload(void)
{
    const HIDO_CHAR *url = "http://123.57.87.125:7001/hfs/STM32H743.Bin";
    const HIDO_CHAR *url = "http://39.99.43.227:8866/api/file/download/STM32H743.Bin";
    HIDO_INT32 ret;
    
    HIDO_Debug("[OTATest] ===== Starting OTA Firmware Download =====\r\n");
@@ -547,12 +570,13 @@
static void OTATest_CheckDecryptStatus(void)
{
    E_OTAState ota_state = OTA_GetState();
    HIDO_UINT8 progress = OTA_GetProgress();
    
    // 进度变化时打印
    if (progress != s_ota_test_ctx.last_progress && progress % 10 == 0) {
        HIDO_Debug("[OTATest] Decrypt progress: %u%%\r\n", progress);
        s_ota_test_ctx.last_progress = progress;
    // Check for retry (state went back to downloading or idle)
    if (ota_state == OTA_STATE_DOWNLOADING || ota_state == OTA_STATE_IDLE) {
         HIDO_Debug("[OTATest] OTA retry detected. Switching back to DOWNLOADING state.\r\n");
         s_ota_test_ctx.state = OTA_TEST_STATE_DOWNLOADING;
         s_ota_test_ctx.last_progress = 0;
         return;
    }
    
    if (ota_state == OTA_STATE_DECRYPT_COMPLETE) {
@@ -580,6 +604,14 @@
{
    E_OTAState ota_state = OTA_GetState();
    
    // Check for retry (state went back to downloading or idle)
    if (ota_state == OTA_STATE_DOWNLOADING || ota_state == OTA_STATE_IDLE) {
         HIDO_Debug("[OTATest] OTA retry detected. Switching back to DOWNLOADING state.\r\n");
         s_ota_test_ctx.state = OTA_TEST_STATE_DOWNLOADING;
         s_ota_test_ctx.last_progress = 0;
         return;
    }
    if (ota_state == OTA_STATE_VERIFY_SUCCESS) {
        ST_OTAInfo info;
        OTA_GetInfo(&info);