Ver Fonte

ota升级擦除问题 0xFFF,全部擦除通过

CHENJIE-PC\QiXiang_CHENJIE há 4 anos atrás
pai
commit
0861a53fdb
6 ficheiros alterados com 128 adições e 40 exclusões
  1. 1 1
      inc/Fota.h
  2. 5 5
      inc/TcpTask.h
  3. 11 5
      inc/app.h
  4. 83 12
      src/Fota.c
  5. 13 1
      src/MainTask.c
  6. 15 16
      src/TcpTask.c

+ 1 - 1
inc/Fota.h

@@ -10,7 +10,6 @@
 #define Fota_Addres_Begin (0x2A0000)
 typedef struct _Fota_Type
 {
-    bool Fota_update_flag ;
     bool Fota_update_error ;
     UINT32 Fota_All_Data_Len ;
     UINT32 Fota_Current_Addres ;
@@ -20,4 +19,5 @@ typedef struct _Fota_Type
     UINT8 Fota_CRC ;
 
 }Fota_Type;
+extern volatile bool Fota_update_flag;
 void Fota_Func(UINT8 *DataPtr,INT32 connectId);

+ 5 - 5
inc/TcpTask.h

@@ -6,7 +6,7 @@
  * History:      2021-03-07
  *
  ****************************************************************************/
-
+#include "app.h"
 extern UINT32 TcpService;
 
 #define PROC_TCP_TASK_STACK_SIZE           (2048)
@@ -66,8 +66,8 @@ typedef struct BattInfoType
 	UINT8	battCellTemp[BATT_TEMP_NUM];
 	UINT8	battWorkState;
 	UINT8	battHeatState;
-	UINT8 	battMosTemp;
-	UINT8 	battEnvTemp;
+	UINT8 	battotherTempNum;
+	UINT8 	battotherTemp[BATT_OTHER_TEMP_NUM];
 }BattInfoType;
 typedef struct BattMsgtoTcpType
 {	
@@ -114,8 +114,8 @@ typedef struct _VerInfoType
 	UINT8	msgCollectionTimeUTC[6];
 	UINT8	ICCID[20];
 	UINT8	IMEI[15];
-	UINT8	BMSHwVersion;
-	UINT8	BMSSwVersion;
+	UINT8	BMSHwVersion[2];
+	UINT8	BMSSwVersion[4];
 	UINT8	NBHwVersion[2];
 	UINT8	BLVersion[4];
 	UINT8	DRVVersion[4];

+ 11 - 5
inc/app.h

@@ -13,22 +13,28 @@
 extern "C" {
 #endif
 //全局定义声明区
-//#define BAT4830
+#define BMS_MANUFACTURE (1) //BMS制造商表示1-超力源,2-美顺
+#define BAT4830
+//#define BAT6060
 #ifdef  BAT4830
     #define BATT_CELL_VOL_NUM  (14)
     #define BATT_TEMP_NUM  (3)
-#else
+    #define BMS_INFO  (1)
+    #define BATT_OTHER_TEMP_NUM  (2)
+#elif defined BAT6060
     #define BATT_CELL_VOL_NUM  (17)
     #define BATT_TEMP_NUM  (5)
+    #define BMS_INFO  (2)
+    #define BATT_OTHER_TEMP_NUM  (2)
 #endif
 #define BATT_CELL_VOL_NUM_2 (BATT_CELL_VOL_NUM*2)
 #define BATT_SN_LEN           17
  
-#define HWVERSION		    0x0102    //NB硬件主版本,现为V1.2板
+#define HWVERSION		    0x0102    //硬件主版本,现为V1.2板
 #define	BLSWVERSION		0x01020000    //BootLoader版本号V1.2.0.0
 #define	DRVSWVERSION		0x01030000     //驱动层版本号V1.3.0.0
-#define	APPSWVERSION		0x01020102       
-#define APP_CONFIG_FILE_LATEST_VERSION 2
+#define	APPSWVERSION		0x01020101       
+#define APP_CONFIG_FILE_LATEST_VERSION 1
 #define APP_CONFIG_FILE_NAME  "qxappconfig.nvm"
 //--------------------------------------------------------------------------------
 typedef struct AppNVMDataType

+ 83 - 12
src/Fota.c

@@ -12,18 +12,20 @@
 #include "MainTask.h"
 #include "TcpTask.h"
 #include "os_exception.h"
+#include "flash_ec616_rt.h"
 extern AppNVMDataType AppNVMData;
 static Fota_Type Fota_S;
 static UINT8 bcc_chk_fota(UINT8* data, UINT8 length);
 static UINT8 Fota_crc_chk(UINT8* data,UINT8 length);
+volatile bool Fota_update_flag = FALSE; //可以升级标志
 void Fota_Func(UINT8 *DataPtr,INT32 connectId)
 {
     UINT8 Fota_Answer[42];
     UINT8 Fota_Cmd;
+    INT8 ret;
     Fota_S.Fota_Flash_Addres = Fota_Addres_Begin;
     if(*(DataPtr+30)==0x01)
     {
-        Fota_S.Fota_update_flag = true;
         Fota_Cmd = *(DataPtr+31);
         Fota_Answer[0] = TCP_START_SYM1;
         Fota_Answer[1] = TCP_START_SYM2;
@@ -41,7 +43,8 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
                 Fota_Answer[23] = 0x12;
                 memcpy(&Fota_Answer[24],(DataPtr+24),18);
                 Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,41);
-                tcpipConnectionSend(connectId,Fota_Answer,42,0,0,0);
+                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
+                BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START, 0x78000); //512k-32k = 480k -> 0x75300
                 break;
             }
             case 0x02:
@@ -49,13 +52,59 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
                 Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
                 Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
                 Fota_S.Fota_Recv_Data_Len = *(DataPtr+41);
+                memset(Fota_S.Fota_Recv_Data,0x00,100);
                 memcpy(Fota_S.Fota_Recv_Data,(DataPtr+42),*(DataPtr+41));
                 Fota_S.Fota_CRC = Fota_crc_chk(Fota_S.Fota_Recv_Data,Fota_S.Fota_Recv_Data_Len);
+                #ifdef USING_PRINTF1
+                    printf("\Data_Add:%x,Crc:%x,%x\n",Fota_S.Fota_Current_Addres,Fota_S.Fota_CRC,*(DataPtr+Fota_S.Fota_Recv_Data_Len+42));
+                    UINT8 temp[5] = {0x01,0x02,0x03,0x04,0x05};
+                    ret = BSP_QSPI_Write_Safe(temp,Fota_S.Fota_Flash_Addres+0xffe,5);
+                    UINT8 tPtr[1];
+                        printf("test:\n");
+                        for(UINT32 i = 0;i<5;i++)
+                        {
+                            BSP_QSPI_Read_Safe(tPtr,Fota_S.Fota_Flash_Addres+0xffe+i,1);
+                            printf("%x ",tPtr[0]);
+                        }
+                        printf("\ndata end\n");
+                #endif
                 if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42))
                 {
-                    BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
-                    BSP_QSPI_Write_Safe(Fota_S.Fota_Recv_Data,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
-                    Fota_Answer[3] = 0x01;
+                    if(Fota_S.Fota_Recv_Data_Len%4!=0)
+                    {
+                    Fota_S.Fota_Recv_Data_Len = Fota_S.Fota_Recv_Data_Len + 4-(Fota_S.Fota_Recv_Data_Len%4);
+                    }
+                    
+                    #ifdef USING_PRINTF
+                        printf("\nlen:%x,%xFota_Data_Recv :",Fota_S.Fota_Recv_Data_Len,Fota_S.Fota_Current_Addres);
+                        for(UINT32 i = 0;i<Fota_S.Fota_Recv_Data_Len;i++)
+                        {
+                            printf("%x ",Fota_S.Fota_Recv_Data[i]);
+                        }
+                        printf("\ndata Recv end\n");
+                    #endif
+                    ret = BSP_QSPI_Write_Safe(Fota_S.Fota_Recv_Data,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
+                    #ifdef USING_PRINTF
+                        printf("\nret:%d\n",ret);
+                    #endif
+                    if(ret==QSPI_OK)
+                    {
+                        Fota_Answer[3] = 0x01;
+                    }
+                    else
+                    {
+                        Fota_Answer[3] = 0x02;
+                    }
+                    #ifdef USING_PRINTF
+                        UINT8 Ptr[1];
+                        printf("\nlen:%x,%xFota_Data :",Fota_S.Fota_Recv_Data_Len,Fota_S.Fota_Current_Addres);
+                        for(UINT32 i = 0;i<Fota_S.Fota_Recv_Data_Len;i++)
+                        {
+                            BSP_QSPI_Read_Safe(Ptr,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres+i,1);
+                            printf("%x ",Ptr[0]);
+                        }
+                        printf("\ndata end\n");
+                    #endif
                 }
                 else//数据校验失败
                 {
@@ -67,23 +116,45 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
                 Fota_Answer[23] = 0x12;
                 memcpy(&Fota_Answer[24],(DataPtr+24),18);
                 Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,41);
-                tcpipConnectionSend(connectId,Fota_Answer,42,0,0,0);
+                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
                 break;
             }
             case 0x03:
             {
+                Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
+                Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
+                Fota_Answer[3] = 0x01;
+                memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
+                Fota_Answer[21] = TCP_ENCPT_DISABLE;
+                Fota_Answer[22] = 0x00;
+                Fota_Answer[23] = 0x12;
+                memcpy(&Fota_Answer[24],(DataPtr+24),18);
+                Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,41);
+                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
+                if(Fota_S.Fota_All_Data_Len==Fota_S.Fota_Current_Addres)
+                {
+                    Fota_update_flag = TRUE;
+                    #ifdef USING_PRINTF1
+                        UINT8 *Ptr;
+                        printf("\nlen:%x,%xFota_Data :",Fota_S.Fota_All_Data_Len,Fota_S.Fota_Current_Addres);
+                        for(UINT32 i = 0;i<Fota_S.Fota_All_Data_Len;i++)
+                        {
+                            BSP_QSPI_Read_Safe(Ptr,Fota_Addres_Begin+i,1);
+                            printf("%x ",*(Ptr));
+                        }
+                        printf("\ndata end\n");
+                    #endif
+                }
+                else
+                {
+                    Fota_update_flag = FALSE;
+                }
                 break;
             }
             default:
                 break;
         }
     }
-    else
-    {
-        Fota_S.Fota_update_flag = false;
-
-    }
-
 }
 static UINT8 bcc_chk_fota(UINT8* data, UINT8 length)
 {

+ 13 - 1
src/MainTask.c

@@ -29,7 +29,8 @@
 #include "app.h"
 #include "MainTask.h"
 #include "TcpTask.h"
-
+#include "Fota.h"
+extern volatile bool Fota_update_flag;
 CHAR BattSN[BATT_SN_LEN] = "GY606000000000001";//SN仍在测试
 //全局变量
 UINT32 Timer_count;//每100ms加1
@@ -145,6 +146,10 @@ static void MainTask(void* arg)
             case PROCESS_STATE_SLEEP:
             {
                 Sleep_flag = true;
+                if(AppNVMData.appDataModify)
+                {
+                    appSaveNVMData();
+                }
                 osDelay(5000);
                 xTimerStop(work_timer, 0);
                 slpManSlpState_t State;
@@ -170,6 +175,12 @@ static void MainTask(void* arg)
                 #ifdef USING_PRINTF
                     printf("which slpstate can go now :%d \n",slpstate);
                 #endif
+                if(Fota_update_flag)
+                {
+                    appSetCFUN(0);
+                    osDelay(1000);
+                    EC_SystemReset();
+                }
                 slpManDeepSlpTimerStart(deepslpTimerID, AppNVMData.sleepTime*1000*60);
                 while(1)
                 {
@@ -347,6 +358,7 @@ static void appSaveConfig(void)
     /*
      * write the file body
     */
+    AppNVMData.appDataModify = FALSE;
     writeCount = OsaFwrite(&AppNVMData, sizeof(AppNVMData), 1, fp);
     if (writeCount != 1)
     {

+ 15 - 16
src/TcpTask.c

@@ -27,7 +27,6 @@
 #include "ec_tcpip_api.h"
 #include "MainTask.h"
 #include "TcpTask.h"
-#include "app.h"
 #include "UartTask.h"
 #include "GpsTask.h"
 #include "Fota.h"
@@ -220,7 +219,7 @@ static void TcpDataInfoAssembleSend()
     UINT16 BattU;
     UINT8 temp=0;
     UINT8 TEMP_NUM=0;
-    TEMP_NUM = BATT_TEMP_NUM+2;//TEMP_NUM为温度总检测数量
+    TEMP_NUM = BATT_TEMP_NUM+2;//TEMP_NUM为BMS温度总检测数量
     UINT16 DataLen;
     //if(send_counter%1==0)
     if(0)
@@ -291,8 +290,9 @@ static void TcpDataInfoAssembleSend()
 	    }
         BattToTcpInfo.battInfo.battWorkState =UartReadMsg.data[(0x03+BATT_CELL_VOL_NUM)*2+1]&0x03;//电池状态,0表示静置,1表示放电,2表示充电
         BattToTcpInfo.battInfo.battHeatState = UartReadMsg.data[(0x1C+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1];
-        BattToTcpInfo.battInfo.battMosTemp = UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+BATT_TEMP_NUM)*2+1];
-        BattToTcpInfo.battInfo.battEnvTemp = UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+1)*2+1];
+        BattToTcpInfo.battInfo.battotherTempNum = BATT_OTHER_TEMP_NUM;//其他温度编号(包含环境温度mos温度以及接插件温度)2021-03-24其他温度修改
+        BattToTcpInfo.battInfo.battotherTemp[0] = UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+BATT_TEMP_NUM)*2+1];
+        BattToTcpInfo.battInfo.battotherTemp[1] = UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+1)*2+1];
         BattToTcpInfo.CRC = bcc_chk((UINT8 *)&BattToTcpInfo, sizeof(BattMsgtoTcpType)-1 );
         osMutexRelease(UartMutex);
         tcpipConnectionSend(socContext.id, (UINT8 *)&BattToTcpInfo, sizeof(BattToTcpInfo), 0, 0, 0);
@@ -365,9 +365,13 @@ static void TcpDataInfoAssembleSend()
         VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[5] = ((TimeStracture.UTCtimer2) >> 8 ) & 0xFF;
         memcpy(VerMsgToTcpInfo.VerInfo.ICCID,iccid,20);
         memcpy(VerMsgToTcpInfo.VerInfo.IMEI,imei,15);
-        osMutexAcquire(UartMutex, osWaitForever);
-        VerMsgToTcpInfo.VerInfo.BMSHwVersion = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1];
-        VerMsgToTcpInfo.VerInfo.BMSSwVersion = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2];
+        osMutexAcquire(UartMutex, osWaitForever);//Bms版本号上传2021-03-24修改
+        VerMsgToTcpInfo.VerInfo.BMSHwVersion[0] = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]/10;
+        VerMsgToTcpInfo.VerInfo.BMSHwVersion[1] = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]%10;
+        VerMsgToTcpInfo.VerInfo.BMSSwVersion[0] = 0;
+        VerMsgToTcpInfo.VerInfo.BMSSwVersion[1] = 0;
+        VerMsgToTcpInfo.VerInfo.BMSSwVersion[2] = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2]/10;
+        VerMsgToTcpInfo.VerInfo.BMSSwVersion[3] = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2]%10;
         osMutexRelease(UartMutex);
         VerMsgToTcpInfo.VerInfo.NBHwVersion[0] = (HWVERSION>>8)& 0xFF;
         VerMsgToTcpInfo.VerInfo.NBHwVersion[1] = (HWVERSION)& 0xFF;
@@ -383,8 +387,8 @@ static void TcpDataInfoAssembleSend()
         VerMsgToTcpInfo.VerInfo.APPVersion[1] = (APPSWVERSION>>16)& 0xFF;
         VerMsgToTcpInfo.VerInfo.APPVersion[2] = (APPSWVERSION>>8)& 0xFF;
         VerMsgToTcpInfo.VerInfo.APPVersion[3] = (APPSWVERSION)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.BmsType = 'C';
-        VerMsgToTcpInfo.VerInfo.BmsInfo = 'A';
+        VerMsgToTcpInfo.VerInfo.BmsType = BMS_MANUFACTURE;
+        VerMsgToTcpInfo.VerInfo.BmsInfo = BMS_INFO;
         VerMsgToTcpInfo.CRC = bcc_chk((UINT8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo)-1 );
         tcpipConnectionSend(socContext.id, (UINT8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo), 0, 0, 0);
     }
@@ -411,12 +415,7 @@ static void TcpDataInfoRecvHandle()
     UINT8 *Ptr;
     if(TcpRecvData != PNULL)
     {
-        #ifdef USING_PRINTF
         Ptr = TcpRecvData->data;
-        printf("TcpDataInfoRecvHandle socket connection %u receive length %u data:", TcpRecvData->connectionId, TcpRecvData->length);
-        for(int i = 0;i<TcpRecvData->length;i++)
-            printf("%d-%x  ",i,*(Ptr+i));
-        #endif
         if((*(Ptr+0)==TCP_START_SYM1)&&(*(Ptr+1)==TCP_START_SYM2))//服务器起始信息
         {
             Tcp_Cmd = *(Ptr+2);//命令标志
@@ -592,12 +591,12 @@ static void socketAppConnectionCallBack(UINT8 connectionEventType, void *bodyEve
             rcvInd = (TcpipConnectionRecvDataInd *)bodyEvent;
             if(rcvInd != PNULL)
             {
-                uint8_t* Ptr;
                 rcvbuffer = malloc(sizeof(TcpipConnectionRecvDataInd));
                 memcpy(rcvbuffer,rcvInd,sizeof(TcpipConnectionRecvDataInd));
                 osMessageQueuePut(TcpRecvHandle,&rcvbuffer,0,1000);
                 sendQueueMsg(QMSG_ID_SOCK_RECVPKG, 0);
-                #ifdef USING_PRINTF
+                #ifdef USING_PRINTF1
+                    uint8_t* Ptr;
                     Ptr=rcvInd->data;
                     printf("socketAppConnectionCallBack socket connection %u receive length %u data:", rcvInd->connectionId, rcvInd->length);
                     for(int i = 0;i<rcvInd->length;i++)