Browse Source

平峰测试-0926

LAPTOP-KB7QFH2U\ChenJie-PC 2 years ago
parent
commit
c3cf126857
6 changed files with 88 additions and 27 deletions
  1. 6 6
      .cproject
  2. 1 1
      FreeRTOS/Source/include/FreeRTOSConfig.h
  3. 20 1
      src/AppTaskMain.c
  4. 51 15
      src/AppTaskUart1.c
  5. 9 3
      src/hal_adapter.c
  6. 1 1
      src/main.c

+ 6 - 6
.cproject

@@ -18,7 +18,7 @@
 						<toolChain id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.toolchain.debug.1669149124" name="NXP GCC 9.2 for Arm 32-bit Bare-Metal" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.toolchain.debug">
 							<option defaultValue="true" id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.addtools.printsize.1799663837" name="Print size" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.addtools.printsize" useByScannerDiscovery="false" valueType="boolean"/>
 							<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.option.compiler.path.434372331" name="Path" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.option.compiler.path" useByScannerDiscovery="false" value="${S32DS_K1_ARM32_GNU_9_2_TOOLCHAIN_DIR}" valueType="string"/>
-							<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.option.target.libraries.933777928" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.option.target.libraries.newlib_nano_noio" valueType="enumerated"/>
+							<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.option.target.libraries.933777928" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.option.target.libraries.newlib_hosted" valueType="enumerated"/>
 							<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.target.mcpu.912012235" name="Arm family" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.target.mcpu" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.target.mcpu.cortex-m4" valueType="enumerated"/>
 							<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.target.instructionset.775672044" name="Instruction set" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.target.instructionset" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.target.instructionset.thumb" valueType="enumerated"/>
 							<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.target.endianness.823522198" name="Endianness" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.target.endianness" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.option.target.endianness.little" valueType="enumerated"/>
@@ -35,7 +35,7 @@
 								<option id="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.optimization.functionsections.1916093778" name="Function sections (-ffunction-sections)" superClass="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.optimization.functionsections" useByScannerDiscovery="true" value="false" valueType="boolean"/>
 								<option id="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.optimization.datasections.499071697" name="Data sections (-fdata-sections)" superClass="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.optimization.datasections" useByScannerDiscovery="true" value="false" valueType="boolean"/>
 								<option id="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.debugging.format.155687014" name="Debug format" superClass="com.freescale.s32ds.cross.gnu.tool.c.compiler.option.debugging.format" useByScannerDiscovery="true"/>
-								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.libraries.334102120" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.libraries.newlib_nano_noio" valueType="enumerated"/>
+								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.libraries.334102120" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.libraries.newlib_hosted" valueType="enumerated"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.sysroot.2141010934" name="Sysroot" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.compiler.option.target.sysroot" useByScannerDiscovery="false" value="--sysroot=&quot;${S32DS_ARM32_NEWLIB_DIR}&quot;" valueType="string"/>
 								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.203066772" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
 									<listOptionValue builtIn="false" value="../FreeRTOS/Source/include"/>
@@ -85,7 +85,7 @@
 								<option id="com.freescale.s32ds.cross.gnu.tool.cpp.compiler.option.optimization.functionsections.685293854" name="Function sections (-ffunction-sections)" superClass="com.freescale.s32ds.cross.gnu.tool.cpp.compiler.option.optimization.functionsections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
 								<option id="com.freescale.s32ds.cross.gnu.tool.cpp.compiler.option.optimization.datasections.605720632" name="Data sections (-fdata-sections)" superClass="com.freescale.s32ds.cross.gnu.tool.cpp.compiler.option.optimization.datasections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
 								<option id="com.freescale.s32ds.cross.gnu.tool.cpp.compiler.option.debugging.format.1630021352" name="Debug format" superClass="com.freescale.s32ds.cross.gnu.tool.cpp.compiler.option.debugging.format" useByScannerDiscovery="true"/>
-								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.compiler.option.target.libraries.992408870" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.compiler.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.compiler.option.target.libraries.newlib_nano_noio" valueType="enumerated"/>
+								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.compiler.option.target.libraries.992408870" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.compiler.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.compiler.option.target.libraries.newlib_hosted" valueType="enumerated"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.compiler.option.target.sysroot.962316341" name="Sysroot" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.compiler.option.target.sysroot" useByScannerDiscovery="false" value="--sysroot=&quot;${S32DS_ARM32_NEWLIB_DIR}&quot;" valueType="string"/>
 								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.compiler.option.include.paths.1429489325" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
 									<listOptionValue builtIn="false" value="&quot;${PLATFORMSDK_S32K1_2021_08_S32K146_M4F_1.0.0_PATH}/SW32K1_RTD_4_4_1_0_0_D2108/Base_TS_T40D2M10I0R0/header&quot;"/>
@@ -107,7 +107,7 @@
 							</tool>
 							<tool id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.tool.c.linker.1997644081" name="Standard S32DS C Linker" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.tool.c.linker">
 								<option id="com.freescale.s32ds.cross.gnu.tool.c.linker.option.gcsections.1484145597" name="Remove unused sections (-Xlinker --gc-sections)" superClass="com.freescale.s32ds.cross.gnu.tool.c.linker.option.gcsections" useByScannerDiscovery="false" value="false" valueType="boolean"/>
-								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.libraries.1478856746" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.libraries.newlib_nano_noio" valueType="enumerated"/>
+								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.libraries.1478856746" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.libraries.newlib_hosted" valueType="enumerated"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.sysroot.87857832" name="Sysroot" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.sysroot" useByScannerDiscovery="false" value="--sysroot=&quot;${S32DS_ARM32_NEWLIB_DIR}&quot;" valueType="string"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.mcpu.225477617" name="Arm family" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.mcpu" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.c.linker.option.target.mcpu.cortex-m4" valueType="enumerated"/>
 								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.freescale.s32ds.cross.gnu.tool.c.linker.option.scriptfile.1071620537" name="Script files (-T)" superClass="com.freescale.s32ds.cross.gnu.tool.c.linker.option.scriptfile" useByScannerDiscovery="false" valueType="stringList">
@@ -129,7 +129,7 @@
 							</tool>
 							<tool id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.tool.cpp.linker.2010049876" name="Standard S32DS C++ Linker" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.gnu.9.2.tool.cpp.linker">
 								<option id="com.freescale.s32ds.cross.gnu.tool.cpp.linker.option.gcsections.261623701" name="Remove unused sections (-Xlinker --gc-sections)" superClass="com.freescale.s32ds.cross.gnu.tool.cpp.linker.option.gcsections" value="true" valueType="boolean"/>
-								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.libraries.2133622679" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.libraries" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.libraries.newlib_nano_noio" valueType="enumerated"/>
+								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.libraries.2133622679" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.libraries" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.libraries.newlib_hosted" valueType="enumerated"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.sysroot.1660798688" name="Sysroot" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.sysroot" value="--sysroot=&quot;${S32DS_ARM32_NEWLIB_DIR}&quot;" valueType="string"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.mcpu.1496913249" name="Arm family" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.mcpu" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.mcpu.cortex-m4" valueType="enumerated"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.instructionset.1237595604" name="Instruction set" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.instructionset" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.cpp.linker.option.target.instructionset.thumb" valueType="enumerated"/>
@@ -142,7 +142,7 @@
 							<tool id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.339533218" name="Standard S32DS Assembler" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler">
 								<option id="com.freescale.s32ds.cross.gnu.tool.assembler.usepreprocessor.608521688" name="Use preprocessor" superClass="com.freescale.s32ds.cross.gnu.tool.assembler.usepreprocessor" useByScannerDiscovery="false" value="true" valueType="boolean"/>
 								<option defaultValue="gnu.c.debugging.level.max" id="com.freescale.s32ds.cross.gnu.tool.assembler.option.debugging.level.935781758" name="Debug Level" superClass="com.freescale.s32ds.cross.gnu.tool.assembler.option.debugging.level" useByScannerDiscovery="false" valueType="enumerated"/>
-								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.libraries.2115819142" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.libraries.newlib_nano_noio" valueType="enumerated"/>
+								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.libraries.2115819142" name="Libraries support" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.libraries" useByScannerDiscovery="false" value="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.libraries.newlib_hosted" valueType="enumerated"/>
 								<option id="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.sysroot.1519150514" name="Sysroot" superClass="com.nxp.s32ds.cle.arm.mbs.arm32.bare.tool.assembler.option.target.sysroot" useByScannerDiscovery="false" value="--sysroot=&quot;${S32DS_ARM32_NEWLIB_DIR}&quot;" valueType="string"/>
 								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.both.asm.option.include.paths.763521555" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
 									<listOptionValue builtIn="false" value="../FreeRTOS/Source/include"/>

+ 1 - 1
FreeRTOS/Source/include/FreeRTOSConfig.h

@@ -72,7 +72,7 @@ PRIORITY THAN THIS! (higher priorities are lower numeric values. */
 /* Memory allocation related definitions. */
 #define configSUPPORT_STATIC_ALLOCATION             0
 #define configSUPPORT_DYNAMIC_ALLOCATION            1
-#define configTOTAL_HEAP_SIZE                       (( size_t ) 8192*4 )
+#define configTOTAL_HEAP_SIZE                       (( size_t ) 8192*8 )
 #define configAPPLICATION_ALLOCATED_HEAP            0
 
 /* Hook function related definitions. */

+ 20 - 1
src/AppTaskMain.c

@@ -6,6 +6,7 @@
  */
 
 #include "AppTaskMain.h"
+#include "hal_fls.h"
 static void vTimerCallback(TimerHandle_t pxTimer);
 void MainTask(void *pvParameters)
 {
@@ -25,6 +26,24 @@ void MainTask(void *pvParameters)
 	#if UARTPRINTF==1
 		create_ringBuffer(&printfRingBuffer,ringbuffer,sizeof(ringbuffer));
 	#endif
+//#if SEGGER_PRINTF==1
+//	uint8 temp[1024];
+//	uint32 dataLen = 1024;
+//	while(dataLen!=0x028f24)
+//	{
+//    	Hal_FlsRead(0x200 + dataLen, temp, 1024, 100);
+//    	for(uint16 i=0;i<dataLen;i++)
+//    	{
+//    		SEGGER_RTT_printf("%02X ",temp[i]);
+//    		if(i%16==0)
+//    		{
+//    			SEGGER_RTT_printf(",i=%d\r\n",i);
+//    		}
+//    	}
+//    	dataLen = min(1024,0x028f24-dataLen);
+//    }
+//    	SEGGER_RTT_printf("\r\n");
+//#endif
 	while(1)
 	{
 //#if SEGGER_PRINTF==1
@@ -42,7 +61,7 @@ void MainTask(void *pvParameters)
 		{
 			if(IsFeedWdg == TRUE)
 			{
-				WATCHDOG_HAL_Feed();
+				//WATCHDOG_HAL_Feed();
 			}
 		}
 		if(TimerCounter%200==0)

+ 51 - 15
src/AppTaskUart1.c

@@ -202,7 +202,7 @@ sint8 TcpDataSendFunc(sint8 ConnectId)
 	outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); //发送函数
 	if (pSendDataAddr != 0)
 	{
-		free((uint8 *)(pSendDataAddr));
+		vPortFree((uint8 *)(pSendDataAddr));
 	}
 	pSendDataAddr = 0;
 	return outValue;
@@ -728,7 +728,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		GPSInfo GpsRecvData;
 		GPSMsgtoTcpType GpsToTcpInfo;
 		*SendLen = sizeof(GpsToTcpInfo);
-		SendBuffer = malloc(*SendLen);
+		SendBuffer = pvPortMalloc(*SendLen);
 		uint16 tac = 0;
 		uint32 cellId = 0;
 		uint8 DataLen = (uint16)sizeof(GpsToTcpInfo.gpsInfo);
@@ -796,7 +796,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 	{
 		VersionMsgtoTcpType VerMsgToTcpInfo;
 		*SendLen = sizeof(VersionMsgtoTcpType);
-		SendBuffer = malloc(*SendLen);
+		SendBuffer = pvPortMalloc(*SendLen);
 		uint16 DataLen = 0;
 		DataLen = (uint16)sizeof(VerMsgToTcpInfo.VerInfo);
 		VerMsgToTcpInfo.startSymbol[0] = TCP_START_SYM1;
@@ -859,7 +859,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		uint16 ProtocolFluctedLen = AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp; //电池信息协议变动长度
 		uint16 DataLen;
 		*SendLen = ProtocolFixedLen + ProtocolFluctedLen;
-		SendBuffer = malloc(*SendLen);
+		SendBuffer = pvPortMalloc(*SendLen);
 		GetCSQValue(&CSQValue);
 		*(SendBuffer + 0) = TCP_START_SYM1;									 //起始码-1
 		*(SendBuffer + 1) = TCP_START_SYM2;									 //起始码-2
@@ -925,7 +925,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 	{
 		StorageInfoToTcp StorageInfo;
 		*SendLen = sizeof(StorageInfo);
-		SendBuffer = malloc(*SendLen);
+		SendBuffer = pvPortMalloc(*SendLen);
 		uint16 DataLen = 0;
 		DataLen = (uint16)sizeof(StorageInfo.StorageMsg);
 		StorageInfo.startSymbol[0] = TCP_START_SYM1;
@@ -962,7 +962,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 	{
 		StorageInfoToTcp2 StorageInfo2;
 		*SendLen = sizeof(StorageInfo2);
-		SendBuffer = malloc(*SendLen);
+		SendBuffer = pvPortMalloc(*SendLen);
 		uint16 DataLen = 0;
 		DataLen = (uint16)sizeof(StorageInfo2.StorageMsg2);
 		StorageInfo2.startSymbol[0] = TCP_START_SYM1;
@@ -1021,7 +1021,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 	{
 		AccInfoToTcp AccInfoToTcpMsg;
 		*SendLen = sizeof(AccInfoToTcpMsg);
-		SendBuffer = malloc(*SendLen);
+		SendBuffer = pvPortMalloc(*SendLen);
 		uint16 DataLen = 0;
 		DataLen = (uint16)sizeof(AccInfoToTcpMsg.AccMsg);
 		AccInfoToTcpMsg.startSymbol[0] = TCP_START_SYM1;
@@ -1188,6 +1188,7 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
                     memcpy(&TcpCmdAnswer[24], (Ptr + 24), 6);
                     TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer, 30);
 					tcpipConnectionSend(SocketId, TcpCmdAnswer, 31);
+					vTaskDelay(pdMS_TO_TICKS(1000));
 					Fota_Ftp(Ptr + 32);
 				}
                 else if (*(Ptr + 30) == 0x80) //远程锁定命令
@@ -1520,7 +1521,10 @@ void Fota_Ftp(uint8 *dataPtrIn)
 	        uint32 appReceviedCRC;
 	        uint16 getDataLenErrCount = 0;
 	        uint8 *UartData = NULL;
-	        UartData = malloc(512);
+	        uint8 *FlashData = NULL;
+	        uint8 *fileDataPtr = NULL;
+	        UartData = pvPortMalloc(512);
+	        FlashData = pvPortMalloc(512);
 #if SEGGER_PRINTF==1
     	SEGGER_RTT_printf("[%d]UartData1=%X\r\n",__LINE__,UartData);
 #endif
@@ -1541,9 +1545,11 @@ void Fota_Ftp(uint8 *dataPtrIn)
 					while(readLenAsk!=0)
 					{
 #if SEGGER_PRINTF==1
-    	SEGGER_RTT_printf("[%d]UartData2=%X\r\n",__LINE__,UartData);
+    	SEGGER_RTT_printf("[%d]UartData2=%X,FlashData=%X,err=%d\r\n",__LINE__,UartData,FlashData,getDataLenErrCount);
 #endif
 						memset(UartData,0x00,512);
+						memset(FlashData,0x00,512);
+						UART_Reset(UART_LPUART1);
 						memset(ATSendDataBuffer,0x00,sizeof(ATSendDataBuffer));
 						sprintf(ATSendDataBuffer, "AT+CFTRANTX=\"c:/%s\",%d,%d\r\n", filenamePtr,currentAddr, readLenAsk);
 						UART_Query_Data(UART_LPUART1, UART_LPUART1, ATSendDataBuffer, mstrlen(ATSendDataBuffer), UartData, &ReadLen, pdMS_TO_TICKS(5000));
@@ -1553,13 +1559,41 @@ void Fota_Ftp(uint8 *dataPtrIn)
 							retptr = (uint8 *)strstr((char *)UartData, findDataBuffer);
 							if (retptr)
 							{
-								uint8 *fileDataPtr = retptr+ 2 + mstrlen(findDataBuffer);
+								uint16 uartcrc = 0x00;
+								uint16 flashcrc = 0xff;
+								fileDataPtr = retptr+ 2 + mstrlen(findDataBuffer);
 								FotaRecvDataLen_8 = ((readLenAsk+7)/8)*8;
 								Hal_FlsWrite(FlashAddStart + currentAddr, fileDataPtr, FotaRecvDataLen_8, 100);
-								//数据处理区域
-								currentAddr = currentAddr + readLenAsk;
+								Hal_FlsRead(FlashAddStart + currentAddr, FlashData, FotaRecvDataLen_8, 100);
+								uartcrc = CRC16_Modbus(fileDataPtr,FotaRecvDataLen_8);
+								flashcrc = CRC16_Modbus(FlashData,FotaRecvDataLen_8);
+								if(flashcrc==uartcrc)
+								{
+									currentAddr = currentAddr + readLenAsk;
+									getDataLenErrCount = 0;
+								}
+								else
+								{
+#if SEGGER_PRINTF==1
+    	for(uint16 i=0;i<FotaRecvDataLen_8;i++)
+    	{
+    		SEGGER_RTT_printf("%02X-%02X ",*(fileDataPtr+i),*(FlashData+i));
+    	}
+    	SEGGER_RTT_printf("\r\n[%d]flashcrc=%X,uartcrc=%X,currentAddr = %d,fileDataPtr=%X,retptr=%X\r\n",__LINE__,uartcrc,flashcrc,currentAddr,fileDataPtr,retptr);
+#endif
+									uint32 secflash = (FlashAddStart + currentAddr) & 0xFFFFF000;
+									if(secflash>0)
+									{
+										currentAddr = secflash - FlashAddStart;
+									}
+									else
+									{
+										currentAddr = 0;
+									}
+									MemIf_JobResultType ret = Hal_FlsErase(secflash,4096, 100);
+									getDataLenErrCount++;
+								}
 								readLenAsk = min(fileLen-currentAddr,readLenAsk);
-								getDataLenErrCount = 0;
 							}
 							else
 							{
@@ -1570,11 +1604,12 @@ void Fota_Ftp(uint8 *dataPtrIn)
 						{
 							getDataLenErrCount++;
 						}
-						if(getDataLenErrCount>=50)
+						if(getDataLenErrCount>=100)
 						{
 							break;
 						}
 					}
+
 	                if(getDataLenErrCount<50&&Hal_FlsCheckIsTransferSucceed()==TRUE)
 	                {
 	                	ftp_process++;
@@ -1589,7 +1624,8 @@ void Fota_Ftp(uint8 *dataPtrIn)
 			{
 				ftp_EndFlg = 1;
 			}
-			free(UartData);
+			vPortFree(UartData);
+			vPortFree(FlashData);
 			break;
 		}
 		case 7://delete the bin and zl files

+ 9 - 3
src/hal_adapter.c

@@ -44,6 +44,7 @@ sint8 AtcmdDelayRecvFunc(uint8 recvChannel,char *ResultStrPtr,uint16 delayTime)
 		if (retptr)
 		{
 			outValue = 0;
+			break;
 		}
 		else
 		{
@@ -93,7 +94,7 @@ void clear_ringBuffer(ringbuffer_t *ringBuf)
 uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf)
 {
     uint32_t len            = 0;
-    uint32_t ringBuf_bw     = ringBuf->bw;
+    volatile uint32_t ringBuf_bw     = ringBuf->bw;
     uint32_t ringBuf_len    = ringBuf->length;
     uint8_t *ringBuf_source = ringBuf->source;
     if( (ringBuf_bw + size) <= ringBuf_len  )
@@ -114,7 +115,7 @@ uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf)
 uint32_t read_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf)
 {
     uint32_t len            = 0;
-    uint32_t ringBuf_br     = ringBuf->br;
+    volatile uint32_t ringBuf_br     = ringBuf->br;
     uint32_t ringBuf_len    = ringBuf->length;
     uint8_t *ringBuf_source = ringBuf->source;
 #if SEGGER_PRINTF==1
@@ -295,7 +296,12 @@ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32
 #if SEGGER_PRINTF==1
 					if(UartHalMsgRecv.Channel==1)
 					{
-						SEGGER_RTT_printf("[%d]Len=%d-%d,uart1_r=%s\r\n",__LINE__,recvSize,UartHalMsgRecv.value,RX_Buffer[UartHalMsgRecv.Channel]);
+						SEGGER_RTT_printf("uart1_recv= ");
+						for(uint16 i=0;i<recvSize;i++)
+						{
+							SEGGER_RTT_printf("%02X ",RX_Buffer[UartHalMsgRecv.Channel][i]);
+						}
+						SEGGER_RTT_printf("\r\n");
 					}
 #endif
 					T_timeout[UartHalMsgRecv.Channel] = 0;

+ 1 - 1
src/main.c

@@ -155,7 +155,7 @@ int main(void)
 	/* Enable the Gpt notification to periodically service the Wdg */
 	Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
 
-	WdgInit();
+	//WdgInit();
 	IP_LPUART0->CTRL |= LPUART_CTRL_ILT(1);
 	IP_LPUART1->CTRL |= LPUART_CTRL_ILT(1);
 	IP_LPUART2->CTRL |= LPUART_CTRL_ILT(1);