MCU V2.4
authorkyz <kyz@kyz.pub>
Wed, 15 Jan 2025 12:49:17 +0000 (20:49 +0800)
committerkyz <kyz@kyz.pub>
Thu, 16 Jan 2025 01:34:31 +0000 (09:34 +0800)
修复上位机升级MCU固件串口通信问题

STM32/code/app/app_ver.h
STM32/code/flat/usart.c
STM32/code/mcu_com/mcu_com.c
STM32/code/mcu_com/mcu_com_hard.c
STM32/code/mcu_com/mcu_com_ota.c
STM32/win32/ZD_Download/yn_download.py

index 3a5044e18eedaa80564fb1447b9efa62f7be5b87..f22ac0d43c66ced215ae425e46e0d1f54d8bfc7c 100644 (file)
@@ -2,6 +2,6 @@
 #define __APP_VER_H__
 
 #define SW_VER_MAJOR  2
-#define SW_VER_MINOR  3
+#define SW_VER_MINOR  4
 
 #endif //__APP_VER_H__
index 32be03bc7423d8c9c019a813d135dd731f57c550..e5bd17dc57415f7795dccc01aef897a3e38d9b3d 100644 (file)
@@ -112,7 +112,7 @@ static void _Set_UART_BASE_INFO(UART_HandleTypeDef *huart, BYTE index)
   {
       huart->Init.BaudRate = 9600;
   }else if( index == 1 ){
-    huart->Init.BaudRate = 1000000; //µ÷ÊÔ´úÂ룬 Ç¿ÖÆ1MËÙÂÊ
+    huart->Init.BaudRate = 1000000; //ÉÏλ»úͨÐŹ̶¨1000000
   }
   else
   {
index 09dc05c1b88abd70f5a5a8d12c5ef89fe2f030e3..76f4e7417c7104d5ab31c452e651788038b326ab 100644 (file)
@@ -1157,8 +1157,12 @@ void Task_LedBuzzer_State(void)
         return;
     }
     LedBuzzer_Data_state();
-    McuArm_LedBuzzer_Send(LED_STATE, &Mcu_to_Arm_state.led_state);
-    McuArm_Alarm_Send();
+
+    if( !is_ota_start() ){
+        McuArm_LedBuzzer_Send(LED_STATE, &Mcu_to_Arm_state.led_state);
+        McuArm_Alarm_Send();
+    }
+
     if(Arm_to_Mcu_state.DS_TempRequest !=false)
     {
         McuCom_Send_DsTemp_Request();
index 0877b4ad90f493117f7e9935fb470f559c660db2..906f06625b5bf15fa27d7a8930c0558658a86b2c 100644 (file)
@@ -177,7 +177,7 @@ void ComHard_Uart2_Analy(void)
     WORD txlen;
     McuCom_Head_t *McuCom_Head;
     uint8_t data;
-    uint8_t head_len;
+    uint16_t head_len;
     // ½«Öжϻº³å¶ÓÁÐÊý¾Ý¿½±´µ½Ó¦Óûº³åÇø
     Port_Get_One_Rx_Frame(PORT_UART_IFACE_WIFI, &frame, &len);
 
index 5bdca69cf0aaab2781444b4fcfa216fddef0c097..0f4afaa6bc9036b4e0ac2dac268a504973f8ad81 100644 (file)
@@ -100,8 +100,10 @@ void ota_write( int32_t port, uint8_t* data, uint16_t len )
     uint32_t off;
     uint8_t *p;
     uint32_t data_crc;
+    uint32_t need_reboot = 0;
 
     ota.act_time = HAL_GetTick(); //update active time
+    
 
 /*
 MCU»ØÓ¦ Ò»¸ö×Ö½Ú£º
@@ -137,8 +139,7 @@ MCU
                         printf( "MCU img data crc ok!\n" );
                         resp = 1;
                         Update_Over( ota.img_size );
-                        ota_reboot_notify(); //notify host
-                        SetRunFlag(TCM_FLAG_HARD_INIT, FLAG_SET);      //¸´Î»
+                        need_reboot = 1;
                     }else{
                         printf( "MCU img data crc fail  %x / %x!\n", crc, data_crc );
                     }
@@ -166,6 +167,10 @@ MCU
     mcucom_ota_ack( port, 3, &resp, 1 );
     //TODO£º add ack before reboot 
     HAL_Delay(20);
+    if( need_reboot ){
+        ota_reboot_notify(); //notify host
+        SetRunFlag(TCM_FLAG_HARD_INIT, FLAG_SET);      //¸´Î»
+    }
 }
 
 int32_t is_ota_start( void )
index 9336cbfe032554570500d7c76b4dca1f7d8c7812..db64ad5d17079e69aa5ebaab09c8f5ec4635c685 100644 (file)
@@ -152,17 +152,25 @@ class yn_download(QThread):
                        self.rx_event.set()
 
        def transmit(self,  tx,  timeout = 5,  retry=1, verbose=1  ):
+               wait_timeout = time.time() + timeout
                while retry>0:
                        retry -= 1
-                       self.rx_event.clear()
                        try:
                                print( "发送[%d]: %s ..."%( len(tx), tx[:64].hex()))
                                self.s.write( tx )
-                               if  self.rx_event.wait( timeout= timeout ):
-                                       print( "接收[%d]: %s ..."%( len(self.rx_pkt), self.rx_pkt[:64].hex() ) )
-                                       return True
-                               elif verbose:
-                                       self.log_add( '数据传输超时!',  'error')
+                               while time.time() < wait_timeout:
+                                       self.rx_event.clear()
+                                       if  self.rx_event.wait( timeout= timeout ):
+                                               print( "接收[%d]: %s ..."%( len(self.rx_pkt), self.rx_pkt[:64].hex() ) )
+                                               if self.rx_pkt[2] == tx[2]:
+                                                       print( "get pkt %02X resp"%(tx[2]))
+                                                       return True
+                                               else:
+                                                       print( "get pkt %02X != %02X resp, wait again..."%( self.rx_pkt[2],tx[2]))
+                                                       continue
+                                       elif verbose:
+                                               self.log_add( '数据传输超时!',  'error')
+                                               break
                        except:
                                if verbose:
                                    self.log_add( '数据发送失败!',  'error')