From: kyz Date: Wed, 15 Jan 2025 12:49:17 +0000 (+0800) Subject: MCU V2.4 X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=b2b8bc9574dcba5ed9d73134665025d6de658db9;p=zd%2Fzd-mcu.git MCU V2.4 修复上位机升级MCU固件串口通信问题 --- diff --git a/STM32/code/app/app_ver.h b/STM32/code/app/app_ver.h index 3a5044e1..f22ac0d4 100644 --- a/STM32/code/app/app_ver.h +++ b/STM32/code/app/app_ver.h @@ -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__ diff --git a/STM32/code/flat/usart.c b/STM32/code/flat/usart.c index 32be03bc..e5bd17dc 100644 --- a/STM32/code/flat/usart.c +++ b/STM32/code/flat/usart.c @@ -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 { diff --git a/STM32/code/mcu_com/mcu_com.c b/STM32/code/mcu_com/mcu_com.c index 09dc05c1..76f4e741 100644 --- a/STM32/code/mcu_com/mcu_com.c +++ b/STM32/code/mcu_com/mcu_com.c @@ -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(); diff --git a/STM32/code/mcu_com/mcu_com_hard.c b/STM32/code/mcu_com/mcu_com_hard.c index 0877b4ad..906f0662 100644 --- a/STM32/code/mcu_com/mcu_com_hard.c +++ b/STM32/code/mcu_com/mcu_com_hard.c @@ -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); diff --git a/STM32/code/mcu_com/mcu_com_ota.c b/STM32/code/mcu_com/mcu_com_ota.c index 5bdca69c..0f4afaa6 100644 --- a/STM32/code/mcu_com/mcu_com_ota.c +++ b/STM32/code/mcu_com/mcu_com_ota.c @@ -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 ) diff --git a/STM32/win32/ZD_Download/yn_download.py b/STM32/win32/ZD_Download/yn_download.py index 9336cbfe..db64ad5d 100644 --- a/STM32/win32/ZD_Download/yn_download.py +++ b/STM32/win32/ZD_Download/yn_download.py @@ -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')