فهرست منبع

update iap upgrade

Signed-off-by: FuangCao <cavan.cao@foxmail.com>
FuangCao 5 سال پیش
والد
کامیت
58e4cd0baf

+ 14 - 10
Application/app/iap.c

@@ -2,14 +2,12 @@
 #include "app/iap.h"
 #include "bsp/fmc_flash.h"
 
-#define QWS_IAP_MAGIC_SUCCESS		0x11223344
-#define QWS_IAP_MAGIC_FLASH			0xAABBCCDD
-
 static int iap_write_image(uint8_t *data, int len);
 static int iap_check_image(uint8_t *data, int len);
-static void _reboot_timer_handler(shark_timer_t *t);
+void _reboot_timer_handler(shark_timer_t *t);
 void iap_read_string(can_frame_t *frame);
 
+static u8 _write_success = 0;
 static int _write_position = 0;
 static shark_timer_t _reboot_timer = {.handler = _reboot_timer_handler,};
 
@@ -23,9 +21,11 @@ void process_iap_message(can_frame_t *frame, int len){
 		case CAN_KEY_IAP_BEGIN:
 			fmc_erase_image();
 			_write_position = 0;
+			_write_success = 0;
 			protocol_send_ack(frame->head.can_addr, frame->key, 0);
 			break;
 		case CAN_KEY_IAP_WRITE:
+			_write_success = 0;
 			data_len = iap_write_image(frame->data, len);
 			data = frame->data;
 			break;
@@ -34,8 +34,11 @@ void process_iap_message(can_frame_t *frame, int len){
 			data = frame->data;
 			break;
 		case CAN_KEY_IAP_BOOT:
-			protocol_send_ack(frame->head.can_addr, frame->key, 0);
-			shark_timer_post(&_reboot_timer,1000);
+			if (_write_success) {
+				shark_timer_post(&_reboot_timer, 100);
+			} else {
+				protocol_send_ack(frame->head.can_addr, frame->key, 0);
+			}
 			break;
 		case CAN_EEY_IAP_READ_STRING:
 			iap_read_string(frame);
@@ -46,7 +49,7 @@ void process_iap_message(can_frame_t *frame, int len){
 	}
 }
 
-static void _reboot_timer_handler(shark_timer_t *t){
+void _reboot_timer_handler(shark_timer_t *t){
 	NVIC_SystemReset();
 }
 
@@ -54,10 +57,10 @@ static int iap_write_image(uint8_t *data, int len){
 	int w_pos = shark_decode_u24(data);
 	if (w_pos == _write_position) {
 		fmc_write_image(data + 3, len - 3);
-		_write_position += w_pos;
+		_write_position += len - 3;
 	}
 	data[0] = 0;
-	shark_encode_u24(data+1, w_pos);
+	shark_encode_u24(data+1, _write_position);
 	return 4;
 }
 
@@ -95,7 +98,8 @@ static int iap_check_image(uint8_t *data, int len) {
 		data[0] = 1;
 		return 1;
 	}
-	fmc_write_magic(size, checksum, QWS_IAP_MAGIC_FLASH);
+	fmc_write_magic(size, checksum, SHARK_IAP_MAGIC_FLASH);
+	_write_success = 1;
 	data[0] = 0;
 	return 1;	
 }

+ 4 - 0
Application/app/iap.h

@@ -1,5 +1,9 @@
 #pragma once
 #include <stdint.h>
 #include "protocol.h"
+
+#define SHARK_IAP_MAGIC_SUCCESS		0x11223344
+#define SHARK_IAP_MAGIC_FLASH			0x55667788
+
 void process_iap_message(can_frame_t *frame, int len);
 

+ 1 - 1
Application/bsp/fmc_flash.c

@@ -73,7 +73,7 @@ void fmc_write_magic(uint32_t length, uint32_t checksum, uint32_t magic){
 	buff[0] = length;
 	buff[1] = checksum;
 	buff[2] = magic;
-	buff[3] = _maigc_addr();
+	buff[3] = _image_addr();
 	_fmc_erase_addr(_maigc_addr(), sizeof(buff));
 	_fmc_write_data(_maigc_addr(), (uint8_t *)buff ,sizeof(buff));
 }

+ 4 - 0
Application/libs/shark_task.c

@@ -1,5 +1,7 @@
 #include "libs/shark_task.h"
 #include "bsp/shark_bsp.h"
+#include "bsp/fmc_flash.h"
+#include "app/iap.h"
 
 extern uint32_t get_system_sleep_time(void);
 
@@ -116,6 +118,8 @@ void shark_task_run(void)
 {
 	shark_task_t *head = &shark_task_head;
 
+	fmc_write_magic(0xFFFFFFFF, 0xFFFFFFFF, SHARK_IAP_MAGIC_SUCCESS);
+
 	/* setup systick timer for 1000Hz interrupts */
 	SysTick_Config(SystemCoreClock / 1000);
 	/* configure the systick handler priority */

+ 3 - 1
Librarys/CMSIS/GD32F3x0/Source/system_gd32f3x0.c

@@ -190,12 +190,14 @@ void SystemInit (void)
     
     /* configure system clock */
     //system_clock_config();
-    
+
+#ifndef CONFIG_CAN_IAP    
 #ifdef VECT_TAB_SRAM
     nvic_vector_table_set(NVIC_VECTTAB_RAM,VECT_TAB_OFFSET);
 #else
     nvic_vector_table_set(NVIC_VECTTAB_FLASH,VECT_TAB_OFFSET);
 #endif
+#endif
 }
 
 /*!

+ 1 - 1
Project/SP700.uvoptx

@@ -140,7 +140,7 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>JL2CM3</Key>
-          <Name>-U81480416 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO7 -FD20000000 -FC1000 -FN1 -FF0GD32F3x0.FLM -FS08000000 -FL010000 -FP0($$Device:GD32F330C8$Flash\GD32F3x0.FLM)</Name>
+          <Name>-U20080643 -O78 -S2 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO7 -FD20000000 -FC1000 -FN1 -FF0GD32F3x0.FLM -FS08000000 -FL010000 -FP0($$Device:GD32F330C8$Flash\GD32F3x0.FLM)</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>

+ 5 - 22
Project/SP700.uvprojx

@@ -10,14 +10,14 @@
       <TargetName>GD32F330C8</TargetName>
       <ToolsetNumber>0x4</ToolsetNumber>
       <ToolsetName>ARM-ADS</ToolsetName>
-      <pCCUsed>5060750::V5.06 update 6 (build 750)::.\ARMCC</pCCUsed>
+      <pCCUsed>5060750::V5.06 update 6 (build 750)::ARMCC</pCCUsed>
       <uAC6>0</uAC6>
       <TargetOption>
         <TargetCommonOption>
           <Device>GD32F330C8</Device>
           <Vendor>GigaDevice</Vendor>
           <PackID>GigaDevice.GD32F3x0_DFP.2.0.0</PackID>
-          <PackURL>http://gd32mcu.com/data/documents/pack/</PackURL>
+          <PackURL>http://gd32mcu.21ic.com/data/documents/yingyongruanjian/</PackURL>
           <Cpu>IRAM(0x20000000,0x02000) IROM(0x08000000,0x10000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
           <FlashUtilSpec></FlashUtilSpec>
           <StartupFile></StartupFile>
@@ -184,8 +184,6 @@
             <hadXRAM>0</hadXRAM>
             <uocXRam>0</uocXRam>
             <RvdsVP>2</RvdsVP>
-            <RvdsMve>0</RvdsMve>
-            <RvdsCdeCp>0</RvdsCdeCp>
             <hadIRAM2>0</hadIRAM2>
             <hadIROM2>0</hadIROM2>
             <StupSel>8</StupSel>
@@ -275,7 +273,7 @@
               </OCR_RVCT3>
               <OCR_RVCT4>
                 <Type>1</Type>
-                <StartAddress>0x8000000</StartAddress>
+                <StartAddress>0x8002000</StartAddress>
                 <Size>0x10000</Size>
               </OCR_RVCT4>
               <OCR_RVCT5>
@@ -337,7 +335,7 @@
             <v6Rtti>0</v6Rtti>
             <VariousControls>
               <MiscControls></MiscControls>
-              <Define>CONFIG_BOARD_SP700</Define>
+              <Define>CONFIG_BOARD_SP700,CONFIG_CAN_IAP</Define>
               <Undefine></Undefine>
               <IncludePath>..\Librarys\CMSIS\5.7.0\Include;..\Librarys\CMSIS\GD32F3x0\Include;..\Librarys\GD32F3x0_Drivers\include;..\Application\app;..\Application</IncludePath>
             </VariousControls>
@@ -352,7 +350,7 @@
             <NoWarn>0</NoWarn>
             <uSurpInc>0</uSurpInc>
             <useXO>0</useXO>
-            <ClangAsOpt>4</ClangAsOpt>
+            <uClangAs>0</uClangAs>
             <VariousControls>
               <MiscControls></MiscControls>
               <Define></Define>
@@ -700,19 +698,4 @@
     <files/>
   </RTE>
 
-  <LayerInfo>
-    <Layers>
-      <Layer>
-        <LayName>&lt;Project Info&gt;</LayName>
-        <LayDesc></LayDesc>
-        <LayUrl></LayUrl>
-        <LayKeys></LayKeys>
-        <LayCat></LayCat>
-        <LayLic></LayLic>
-        <LayTarg>0</LayTarg>
-        <LayPrjMark>1</LayPrjMark>
-      </Layer>
-    </Layers>
-  </LayerInfo>
-
 </Project>