diff --git a/.vscode/settings.json b/.vscode/settings.json
index 2c3f921..579b074 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -7,6 +7,7 @@
"if_can.h": "c",
"board.h": "c",
"prot_uc.h": "c",
- "tran_for_slave.h": "c"
+ "tran_for_slave.h": "c",
+ "ewupdata.h": "c"
}
}
\ No newline at end of file
diff --git a/checher_slave.uvoptx b/checher_slave.uvoptx
index 2d8676c..0f354f2 100644
--- a/checher_slave.uvoptx
+++ b/checher_slave.uvoptx
@@ -299,7 +299,7 @@
1
0
- 0
+ 1
18
@@ -523,7 +523,7 @@
1
0
- 1
+ 0
18
@@ -1399,6 +1399,18 @@
0
0
0
+ .\source\elec_det\interface\EWUpdata.c
+ EWUpdata.c
+ 0
+ 0
+
+
+ 6
+ 55
+ 1
+ 0
+ 0
+ 0
.\source\elec_det\test\EW_TestUsartApp.c
EW_TestUsartApp.c
0
@@ -1406,7 +1418,7 @@
6
- 55
+ 56
1
0
0
@@ -1418,7 +1430,7 @@
6
- 56
+ 57
1
0
0
@@ -1430,7 +1442,7 @@
6
- 57
+ 58
1
0
0
@@ -1442,7 +1454,7 @@
6
- 58
+ 59
1
0
0
@@ -1454,7 +1466,7 @@
6
- 59
+ 60
1
0
0
@@ -1466,7 +1478,7 @@
6
- 60
+ 61
1
0
0
@@ -1478,7 +1490,7 @@
6
- 61
+ 62
1
0
0
@@ -1498,7 +1510,7 @@
0
7
- 62
+ 63
1
0
0
@@ -1510,7 +1522,7 @@
7
- 63
+ 64
1
0
0
@@ -1530,7 +1542,7 @@
0
8
- 64
+ 65
1
0
0
@@ -1542,7 +1554,7 @@
8
- 65
+ 66
1
0
0
@@ -1554,7 +1566,7 @@
8
- 66
+ 67
1
0
0
@@ -1566,7 +1578,7 @@
8
- 67
+ 68
1
0
0
@@ -1578,7 +1590,7 @@
8
- 68
+ 69
1
0
0
@@ -1590,7 +1602,7 @@
8
- 69
+ 70
1
0
0
@@ -1602,7 +1614,7 @@
8
- 70
+ 71
1
0
0
@@ -1614,7 +1626,7 @@
8
- 71
+ 72
1
0
0
@@ -1626,7 +1638,7 @@
8
- 72
+ 73
1
0
0
@@ -1638,7 +1650,7 @@
8
- 73
+ 74
1
0
0
@@ -1650,7 +1662,7 @@
8
- 74
+ 75
1
0
0
@@ -1662,7 +1674,7 @@
8
- 75
+ 76
1
0
0
@@ -1674,7 +1686,7 @@
8
- 76
+ 77
1
0
0
@@ -1686,7 +1698,7 @@
8
- 77
+ 78
1
0
0
@@ -1698,7 +1710,7 @@
8
- 78
+ 79
1
0
0
@@ -1710,7 +1722,7 @@
8
- 79
+ 80
1
0
0
@@ -1722,7 +1734,7 @@
8
- 80
+ 81
1
0
0
@@ -1734,7 +1746,7 @@
8
- 81
+ 82
1
0
0
@@ -1746,7 +1758,7 @@
8
- 82
+ 83
2
0
0
@@ -1766,7 +1778,7 @@
0
9
- 83
+ 84
1
0
0
@@ -1778,7 +1790,7 @@
9
- 84
+ 85
1
0
0
@@ -1790,7 +1802,7 @@
9
- 85
+ 86
1
0
0
@@ -1802,7 +1814,7 @@
9
- 86
+ 87
1
0
0
@@ -1814,7 +1826,7 @@
9
- 87
+ 88
1
0
0
@@ -1826,7 +1838,7 @@
9
- 88
+ 89
1
0
0
@@ -1838,7 +1850,7 @@
9
- 89
+ 90
1
0
0
@@ -1850,7 +1862,7 @@
9
- 90
+ 91
1
0
0
@@ -1862,7 +1874,7 @@
9
- 91
+ 92
1
0
0
@@ -1874,7 +1886,7 @@
9
- 92
+ 93
1
0
0
@@ -1886,7 +1898,7 @@
9
- 93
+ 94
1
0
0
@@ -1906,7 +1918,7 @@
0
10
- 94
+ 95
1
0
0
@@ -1918,7 +1930,7 @@
10
- 95
+ 96
1
0
0
@@ -1930,7 +1942,7 @@
10
- 96
+ 97
1
0
0
@@ -1942,7 +1954,7 @@
10
- 97
+ 98
1
0
0
@@ -1954,7 +1966,7 @@
10
- 98
+ 99
1
0
0
@@ -1974,7 +1986,7 @@
0
11
- 99
+ 100
1
0
0
@@ -1994,7 +2006,7 @@
0
12
- 100
+ 101
1
0
0
@@ -2006,7 +2018,7 @@
12
- 101
+ 102
1
0
0
@@ -2018,7 +2030,7 @@
12
- 102
+ 103
1
0
0
@@ -2030,7 +2042,7 @@
12
- 103
+ 104
1
0
0
@@ -2042,7 +2054,7 @@
12
- 104
+ 105
1
0
0
@@ -2054,7 +2066,7 @@
12
- 105
+ 106
1
0
0
@@ -2074,7 +2086,7 @@
0
13
- 106
+ 107
5
0
0
@@ -2094,7 +2106,7 @@
0
14
- 107
+ 108
5
0
0
@@ -2106,7 +2118,7 @@
14
- 108
+ 109
5
0
0
diff --git a/checher_slave.uvprojx b/checher_slave.uvprojx
index eabb1f5..94d9064 100644
--- a/checher_slave.uvprojx
+++ b/checher_slave.uvprojx
@@ -894,6 +894,11 @@
1
.\source\elec_det\interface\EWChecker.c
+
+ EWUpdata.c
+ 1
+ .\source\elec_det\interface\EWUpdata.c
+
EW_TestUsartApp.c
1
@@ -3450,6 +3455,11 @@
1
.\source\elec_det\interface\EWChecker.c
+
+ EWUpdata.c
+ 1
+ .\source\elec_det\interface\EWUpdata.c
+
EW_TestUsartApp.c
1
@@ -4894,6 +4904,11 @@
1
.\source\elec_det\interface\EWChecker.c
+
+ EWUpdata.c
+ 1
+ .\source\elec_det\interface\EWUpdata.c
+
EW_TestUsartApp.c
1
diff --git a/doc/JW3425_boot_v10.bin b/doc/JW3425_boot_v10.bin
deleted file mode 100644
index ec66ab8..0000000
Binary files a/doc/JW3425_boot_v10.bin and /dev/null differ
diff --git a/doc/JW3425_boot_v10.jwt b/doc/JW3425_boot_v10.jwt
deleted file mode 100644
index 2233395..0000000
Binary files a/doc/JW3425_boot_v10.jwt and /dev/null differ
diff --git a/doc/JW3425_boot_v11.bin b/doc/JW3425_boot_v11.bin
deleted file mode 100644
index 43b7f66..0000000
Binary files a/doc/JW3425_boot_v11.bin and /dev/null differ
diff --git a/doc/MS-10-30-1.bin b/doc/MS-10-30-1.bin
new file mode 100644
index 0000000..7a39982
Binary files /dev/null and b/doc/MS-10-30-1.bin differ
diff --git a/doc/MS-IEpro20231007.bin b/doc/MS-IEpro20231007.bin
deleted file mode 100644
index d29b306..0000000
Binary files a/doc/MS-IEpro20231007.bin and /dev/null differ
diff --git a/doc/creat_jwt_boot.py b/doc/creat_jwt_boot.py
index cd7a779..8a7dac2 100644
--- a/doc/creat_jwt_boot.py
+++ b/doc/creat_jwt_boot.py
@@ -6,8 +6,8 @@ import json
BOOT_PATH ="JW3425_boot_v12.bin"
-APP_PATH ="MS-IEpro20231007.bin"
-OUT_PATH = BOOT_PATH.split('.')[0]+".jwt"
+APP_PATH ="ms-10-30.bin"
+OUT_PATH = BOOT_PATH.split('.')[0]+APP_PATH.split('.')[0]+".jwt"
# 创建离线下载器的镜像
@@ -78,5 +78,11 @@ def creat():
if __name__ == "__main__":
creat()
+ # d=bytearray()
+ # with open("MS-10-30-1.bin","rb") as f:
+ # d+=f.read()
+ # with open("ms-10-30.bin","wb+") as f:
+ # f.write(d[4096:4096+9800])
+
diff --git a/doc/ms-10-30.bin b/doc/ms-10-30.bin
new file mode 100644
index 0000000..9017d57
Binary files /dev/null and b/doc/ms-10-30.bin differ
diff --git a/source/ReadMe.txt b/source/ReadMe.txt
index 57da295..6f38059 100644
--- a/source/ReadMe.txt
+++ b/source/ReadMe.txt
@@ -263,4 +263,6 @@
添加跳转到bootloader命令 jwt_app_runboot
解决 EW WriteMTP 命令异常
debug 输出设备改为 host
-
+2023.11.16
+ 完成方案中updata调试,支持不处于bootloader中时自动跳转至bootloader
+ 单块板验证成功,批量验证失败
diff --git a/source/elec_det/interface/EWChecker.c b/source/elec_det/interface/EWChecker.c
index 326baeb..c45783a 100644
--- a/source/elec_det/interface/EWChecker.c
+++ b/source/elec_det/interface/EWChecker.c
@@ -1,5 +1,6 @@
#include "EWChecker.h"
+#include "EWUpdata.h"
#include "driver/EWDriver.h"
#include "base/delay.h"
#include "hardware/adc_cfg.h"
@@ -12,15 +13,6 @@
#include "mystdlib.h"
-#define UPDATA_PACK_LEN 128
-#define UPDATA_BASE_ADDR 0x1000
-#define UPDATA_DATA_LEN (12*1024)
-#define UPDATA_FLAG_ADDR (0x7c)
-//#define UPDATA_FLAG ((uint8_t []){0x99,0x66,0xaa,0x55})
-#define UPDATA_FLAG ((uint8_t []){0xaa,0xbb,0xcc,0xdd})
-
-#define UPDATA_CRC_ALL ((uint32_t *)(MC_CODE_ADDR+16*1024))[0]
-#define UPDATA_CRC_APP ((uint32_t *)(MC_CODE_ADDR+16*1024))[1]
#define EW_CHECKER_RUN_BUF 32
@@ -29,365 +21,6 @@ uint8_t EW_Test_PWD[8]="FBCDabcd";
uint8_t EW_RunBuf[EW_CHECKER_RUN_BUF];
-// 擦除
-static uint8_t EW_bootErease(void)
-{
- uint8_t data[3]={0xfe,0x00,0x00};
- uint8_t read[4]={0};
- uint8_t ret=0;
- DMod_SendBytesXor(data,2,1);
- delay_ms(50);
- ret=DMod_ReadBytesXor(read,4,100);
- DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
- return ret;
-}
-static int cmd_jwt_boot_erase(list_def *argv)
-{
- int ret=0;
- ret=EW_bootErease();
- return ret;
-}
-commend_export(jwt_boot_erase,cmd_jwt_boot_erase,"jwt srase in boot")
-
-
-// 跳转
-static uint8_t EW_bootJump(void)
-{
- uint8_t data[3]={0xf9,0x00,0x00};
- uint8_t read[4]={0};
- uint8_t ret=0;
- DMod_SendBytesXor(data,2,1);
- ret=DMod_ReadBytesXor(read,4,100);
- DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
- return ret;
-}
-static int cmd_jwt_boot_jump(list_def *argv)
-{
- int ret=0;
- ret=EW_bootJump();
- return ret;
-}
-commend_export(jwt_boot_jump,cmd_jwt_boot_jump,"jwt jump in boot")
-
-
-// 充电
-static uint8_t EW_bootCharg(void)
-{
- uint8_t data[4]={0xf8,0x01,0x01,0x00};
- uint8_t read[4]={0};
- uint8_t ret=0;
- DMod_SendBytesXor(data,3,1);
- delay_ms(2);
- ret=DMod_ReadBytesXor(read,4,100);
- DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
- return ret;
-}
-static int cmd_jwt_boot_charg(list_def *argv)
-{
- int ret=0;
- ret=EW_bootCharg();
- return ret;
-}
-commend_export(jwt_boot_charg,cmd_jwt_boot_charg,"jwt charg in boot")
-
-
-
-// 放电
-static uint8_t EW_bootDisCharg(void)
-{
- uint8_t data[4]={0xf8,0x01,0x00,0x00};
- uint8_t read[4]={0};
- uint8_t ret=0;
- DMod_SendBytesXor(data,3,1);
- ret=DMod_ReadBytesXor(read,4,100);
- DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
- return ret;
-}
-static int cmd_jwt_boot_discharg(list_def *argv)
-{
- int ret=0;
- ret=EW_bootDisCharg();
- return ret;
-}
-commend_export(jwt_boot_discharg,cmd_jwt_boot_discharg,"jwt discharg in boot")
-
-
-
-// 发送数据
-// len 最长为128字节
-static uint8_t EW_bootWrite(uint16_t addr,uint8_t *d,uint16_t len)
-{
- uint8_t ret=0;
- uint8_t read[4]={0};
- uint8_t *buf=rt_malloc(len+2+2+1);
- if(buf==RT_NULL) return 1;
- buf[0]=0xfc;
- buf[1]=2+len;
- buf[2]=addr&0xff;
- buf[3]=addr>>8;
- rt_memcpy(&buf[4],d,len);
- LED2_Out=0;
- DMod_SendBytesXor(buf,len+2+2,1);
- LED2_Out=1;
- ret=DMod_ReadBytesXor(read,4,100);
- rt_free(buf);
- if(ret){
- DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
- }
- return ret;
-}
-
-
-
-// 校验
-static uint8_t EW_bootCheckCrc(uint16_t adr_start,uint16_t adr_end,uint32_t *crc)
-{
- uint8_t ret=0;
- uint8_t cmd[7]={0xfb,0x04,adr_start&0xff,adr_start>>8,adr_end&0xff,adr_end>>8};
- uint8_t read[4+4]={0};
- DMod_SendBytesXor(cmd,6,1);
- delay_ms(10);
- ret=DMod_ReadBytesXor(read,8,100);
- if(ret==0){
- if(crc){
- *crc=(read[3]<<24)|(read[4]<<16)|(read[5]<<8)|(read[6]<<0);
- }
- }
- DBG_LOG("addr_start=0x%04x,addr_end=0x%04x.",adr_start,adr_end);
- DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,",
- ret,read[0],read[1],read[2],read[3],read[4],read[5],read[6],read[7]);
- return ret;
-}
-static int cmd_jwt_boot_checkcrc(list_def *argv)
-{
- int ret=0;
- uint32_t crc=0;
- ret=EW_bootCheckCrc(UPDATA_BASE_ADDR,UPDATA_BASE_ADDR+UPDATA_DATA_LEN,&crc);
- cmd_print("jwt crc32=0x%04x.",crc);
- //crc=Crc32Calu((uint32_t *)(MC_CODE_ADDR+UPDATA_BASE_ADDR),UPDATA_DATA_LEN);
- crc=UPDATA_CRC_APP;
- cmd_print("local crc32=0x%04x.",crc);
- return ret;
-}
-commend_export(jwt_boot_checkcrc,cmd_jwt_boot_checkcrc,"jwt checkcrc in boot")
-
-
-
-// 读取
-static uint8_t EW_bootRead(uint16_t adr,uint8_t *buf,uint16_t len)
-{
- uint8_t ret=0;
- uint8_t cmd[7]={0xfa,0x03,adr&0xff,adr>>8,len};
- uint16_t read_len=2+len+1+1;
- uint8_t *read=rt_malloc(read_len);
- if(read==RT_NULL) return 1;
- DMod_SendBytesXor(cmd,6,1);
- ret=DMod_ReadBytesXor(read,read_len,100);
- rt_memset(buf,0,len);
- if(ret==0)
- {
- rt_memcpy(buf,&read[3],len);
- }
- DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
- rt_free(read);
- return ret;
-}
-
-
-
-
-
-// app:通信测试
-static int EW_appCommTest(void)
-{
- uint8_t data[4]={0x11,0x22};
- uint8_t ret;
- DBG_LOG("send:%02x,%02x.",data[0],data[1]);
- ret=EW_CommTest(data,2,300);
- DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,data[0],data[1],data[2],data[3]);
- return ret;
-}
-static int cmd_jwt_app_commtest(list_def *argv)
-{
- int ret=0;
- ret=EW_appCommTest();
- return ret;
-}
-commend_export(jwt_app_commtest,cmd_jwt_app_commtest,"jwt commtest in app")
-
-
-
-// app:读取数据
-static int EW_appRead(void)
-{
- uint8_t read_buf[4]={0};
- int ret=0;
- uint8_t addr=(uint8_t)(UPDATA_FLAG_ADDR/4);
- DBG_LOG("addr=0x%02x.",addr);
- ret=EW_ReadMTP(1,addr,read_buf,4);
- DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read_buf[0],read_buf[1],read_buf[2],read_buf[3]);
- return ret;
-}
-static int cmd_jwt_app_read(list_def *argv)
-{
- int ret=0;
- ret=EW_appRead();
- return ret;
-}
-commend_export(jwt_app_read,cmd_jwt_app_read,"jwt read in app")
-
-
-// app:runbootloader
-static void EW_appRunBoot(void)
-{
- EW_Charge(1,0,0);
- delay_ms(6000);
- EW_RunBootLoader(1,1);
- DBG_LOG("run boot");
-}
-static int cmd_jwt_app_runboot(list_def *argv)
-{
- int ret=0;
- EW_appRunBoot();
- return ret;
-}
-commend_export(jwt_app_runboot,cmd_jwt_app_runboot,"jwt turn to bootloader")
-
-
-
-
-// 升级
-void EW_Updata(void)
-{
- Checker_RunCfg_st *cfg=&checker_runcfg;
- uint16_t ret=0;
- uint8_t read_buf[4]={0};
- uint8_t *data=(uint8_t *)MC_CODE_ADDR+UPDATA_BASE_ADDR;
- uint16_t len=UPDATA_DATA_LEN;
- uint16_t addr=UPDATA_BASE_ADDR;
- uint8_t pack_len=UPDATA_PACK_LEN;
- uint32_t crc=0;
- uint32_t crc_module=0;
-
- // 充电时间 6000
- int time_charg=checker_runcfg.params[0];
- // 加载app时间 6000
- int time_loadapp=checker_runcfg.params[1];
- // 总线关断时间 1000
- int time_poweroff=checker_runcfg.params[2];
- // 升级模式,0,无app时升级;1,无条件升级
- int updata_mode=checker_runcfg.params[3];
-
- retry:
- delay_ms(100);
- ret=EW_bootCharg();
- if(ret){
- // 有可能在app中
- delay_ms(time_loadapp);
- EW_Charge(1,0,0);
- delay_ms(time_charg);
- if(EW_appCommTest()==0){
- if(updata_mode==1){
- delay_ms(50);
- EW_RunBootLoader(0,1);
- updata_mode=2;
- DBG_LOG("turn to bootloader,retry.");
- goto retry;
- }else if(updata_mode==2){
- // 已经重试过一次了,bootloader还是不能通信
- DBG_WARN("boot commit failed.");
- ret=12;
- goto err;
- }else if(updata_mode==0){
- // 有app的时候不需要升级
- DBG_WARN("no need updata.");
- ret=0;
- goto err;
- }
- }else{
- if(updata_mode!=2){
- // bootloader 和 app 都不能通信
- DBG_WARN("commit failed");
- delay_ms(50);
- EW_RunBootLoader(0,1);
- updata_mode=2;
- goto retry;
- }else{
- DBG_WARN("retry failed.");
- ret=13;
- goto err;
- }
- }
- }
- if(ret) {ret=1;goto err;}
- delay_ms(time_charg);
- ret=EW_bootErease();
- if(ret) {ret=2;goto err;}
- delay_ms(600);
- while(len>0){
- pack_len=len>UPDATA_PACK_LEN?UPDATA_PACK_LEN:len;
- LED1_Out=!LED1_Out;
- ret=EW_bootWrite(addr,data,pack_len);
- addr+=pack_len;
- data+=pack_len;
- len-=pack_len;
- if(ret) {ret=3;goto err;}
- delay_ms(1);
- }
- //crc=Crc32Calu((uint32_t *)(MC_CODE_ADDR+UPDATA_BASE_ADDR),UPDATA_DATA_LEN);
- crc=UPDATA_CRC_APP;
- DBG_LOG("local crc:0x%04x.",crc);
- ret=EW_bootCheckCrc(UPDATA_BASE_ADDR,UPDATA_BASE_ADDR+UPDATA_DATA_LEN,&crc_module);
- DBG_LOG("module crc:0x%04x.",crc_module);
- if(ret) {ret=4;goto err;}
- if(crc!=crc_module){ret=5;goto err;}
- delay_ms(50);
- ret=EW_bootJump();
- if(ret) {ret=6;goto err;}
- delay_ms(time_loadapp);
- ret=EW_EnWriteMTP(0,1);
- if(ret) {ret=7;goto err;}
- DBG_LOG("EW_EnWriteMTP success.");
- delay_ms(1);
-
- ret=EW_WriteMTP(1,(uint8_t)(UPDATA_FLAG_ADDR/4),UPDATA_FLAG,4);
- if(ret) {ret=8;goto err;}
- DBG_LOG("EW_WriteMTP success.");
- delay_ms(1);
- ret=EW_ReadMTP(1,(uint8_t)(UPDATA_FLAG_ADDR/4),read_buf,4);
- if(ret) {ret=9;goto err;}
- if(memcmp(read_buf,UPDATA_FLAG,4)!=0){
- DBG_LOG("read_buf=0x%02d,0x%02d,0x%02d,0x%02d.",read_buf[0],read_buf[1],read_buf[2],read_buf[3]);
- ret=10;goto err;
- }
- DBG_LOG("EW_ReadMTP check success.");
- delay_ms(1);
- XTBUS_OFF;
- delay_ms(time_poweroff);
- XTBUS_ON;
- delay_ms(time_loadapp);
- ret=EW_appCommTest();
- if(ret) {ret=11;goto err;}
- DBG_LOG("EW_appCommTest success.");
-
- err:
- DBG_LOG("ret=%d",ret);
- Checker_SetRtv(&ret,checker_runcfg.rtv_count);
- Checker_MaskResult(ret,checker_runcfg.task_info.runindex);
-}
-static int cmd_jwt_updata(list_def *argv)
-{
- int ret=0;
- checker_runcfg.params[0]=6000;
- checker_runcfg.params[1]=6000;
- checker_runcfg.params[2]=1000;
- checker_runcfg.params[3]=0;
- checker_runcfg.rtv_count=0;
- EW_Updata();
- return ret;
-}
-commend_export(jwt_updata,cmd_jwt_updata,"jwt updata")
-
/*
diff --git a/source/elec_det/interface/EWUpdata.c b/source/elec_det/interface/EWUpdata.c
new file mode 100644
index 0000000..a376ca7
--- /dev/null
+++ b/source/elec_det/interface/EWUpdata.c
@@ -0,0 +1,480 @@
+
+
+
+#include "base/define.h"
+#include "basechecker.h"
+#include "stdint.h"
+#include "EWUpdata.h"
+#include "driver/EWDriver.h"
+#include "base/delay.h"
+#include "hardware/adc_cfg.h"
+#include "base/utility.h"
+#include "hardware/power.h"
+#include "hardware/timer_cfg.h"
+#include "debug.h"
+#include "commend.h"
+#include "mystring.h"
+#include "mystdlib.h"
+
+
+
+
+
+#define UPDATA_PACK_LEN 128
+#define UPDATA_BASE_ADDR 0x1000
+#define UPDATA_DATA_LEN (12*1024)
+#define UPDATA_FLAG_ADDR (0x7c)
+#define BOOT_FLAG ((uint8_t []){0x99,0x66,0xaa,0x55})
+#define UPDATA_FLAG ((uint8_t []){0xaa,0xbb,0xcc,0xdd})
+
+#define UPDATA_CRC_ALL ((uint32_t *)(MC_CODE_ADDR+16*1024))[0]
+#define UPDATA_CRC_APP ((uint32_t *)(MC_CODE_ADDR+16*1024))[1]
+
+
+
+// 擦除
+static uint8_t EW_bootErease(void)
+{
+ uint8_t data[3]={0xfe,0x00,0x00};
+ uint8_t read[4]={0};
+ uint8_t ret=0;
+ DMod_SendBytesXor(data,2,1);
+ delay_ms(50);
+ ret=DMod_ReadBytesXor(read,4,100);
+ DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
+ return ret;
+}
+static int cmd_jwt_boot_erase(list_def *argv)
+{
+ int ret=0;
+ ret=EW_bootErease();
+ return ret;
+}
+commend_export(jwt_boot_erase,cmd_jwt_boot_erase,"jwt srase in boot")
+
+
+// 跳转
+static uint8_t EW_bootJump(void)
+{
+ uint8_t data[3]={0xf9,0x00,0x00};
+ uint8_t read[4]={0};
+ uint8_t ret=0;
+ DMod_SendBytesXor(data,2,1);
+ ret=DMod_ReadBytesXor(read,4,100);
+ DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
+ return ret;
+}
+static int cmd_jwt_boot_jump(list_def *argv)
+{
+ int ret=0;
+ ret=EW_bootJump();
+ return ret;
+}
+commend_export(jwt_boot_jump,cmd_jwt_boot_jump,"jwt jump in boot")
+
+
+// 充电
+static uint8_t EW_bootCharg(void)
+{
+ uint8_t data[4]={0xf8,0x01,0x01,0x00};
+ uint8_t read[4]={0};
+ uint8_t ret=0;
+ DMod_SendBytesXor(data,3,1);
+ delay_ms(2);
+ ret=DMod_ReadBytesXor(read,4,100);
+ DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
+ return ret;
+}
+static int cmd_jwt_boot_charg(list_def *argv)
+{
+ int ret=0;
+ ret=EW_bootCharg();
+ return ret;
+}
+commend_export(jwt_boot_charg,cmd_jwt_boot_charg,"jwt charg in boot")
+
+
+
+// 放电
+static uint8_t EW_bootDisCharg(void)
+{
+ uint8_t data[4]={0xf8,0x01,0x00,0x00};
+ uint8_t read[4]={0};
+ uint8_t ret=0;
+ DMod_SendBytesXor(data,3,1);
+ ret=DMod_ReadBytesXor(read,4,100);
+ DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
+ return ret;
+}
+static int cmd_jwt_boot_discharg(list_def *argv)
+{
+ int ret=0;
+ ret=EW_bootDisCharg();
+ return ret;
+}
+commend_export(jwt_boot_discharg,cmd_jwt_boot_discharg,"jwt discharg in boot")
+
+
+
+// 发送数据
+// len 最长为128字节
+static uint8_t EW_bootWrite(uint16_t addr,uint8_t *d,uint16_t len)
+{
+ uint8_t ret=0;
+ uint8_t read[4]={0};
+ uint8_t *buf=rt_malloc(len+2+2+1);
+ if(buf==RT_NULL) return 1;
+ buf[0]=0xfc;
+ buf[1]=2+len;
+ buf[2]=addr&0xff;
+ buf[3]=addr>>8;
+ rt_memcpy(&buf[4],d,len);
+ LED2_Out=0;
+ DMod_SendBytesXor(buf,len+2+2,1);
+ LED2_Out=1;
+ ret=DMod_ReadBytesXor(read,4,100);
+ rt_free(buf);
+ if(ret){
+ DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
+ }
+ return ret;
+}
+
+
+
+// 校验
+static uint8_t EW_bootCheckCrc(uint16_t adr_start,uint16_t adr_end,uint32_t *crc)
+{
+ uint8_t ret=0;
+ uint8_t cmd[7]={0xfb,0x04,adr_start&0xff,adr_start>>8,adr_end&0xff,adr_end>>8};
+ uint8_t read[4+4]={0};
+ DMod_SendBytesXor(cmd,6,1);
+ delay_ms(10);
+ ret=DMod_ReadBytesXor(read,8,100);
+ if(ret==0){
+ if(crc){
+ *crc=(read[3]<<24)|(read[4]<<16)|(read[5]<<8)|(read[6]<<0);
+ }
+ }
+ DBG_LOG("addr_start=0x%04x,addr_end=0x%04x.",adr_start,adr_end);
+ DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,",
+ ret,read[0],read[1],read[2],read[3],read[4],read[5],read[6],read[7]);
+ return ret;
+}
+static int cmd_jwt_boot_checkcrc(list_def *argv)
+{
+ int ret=0;
+ uint32_t crc=0;
+ ret=EW_bootCheckCrc(UPDATA_BASE_ADDR,UPDATA_BASE_ADDR+UPDATA_DATA_LEN,&crc);
+ cmd_print("jwt crc32=0x%04x.",crc);
+ //crc=Crc32Calu((uint32_t *)(MC_CODE_ADDR+UPDATA_BASE_ADDR),UPDATA_DATA_LEN);
+ crc=UPDATA_CRC_APP;
+ cmd_print("local crc32=0x%04x.",crc);
+ return ret;
+}
+commend_export(jwt_boot_checkcrc,cmd_jwt_boot_checkcrc,"jwt checkcrc in boot")
+
+
+
+// 读取
+static uint8_t EW_bootRead(uint16_t adr,uint8_t *buf,uint16_t len)
+{
+ uint8_t ret=0;
+ uint8_t cmd[7]={0xfa,0x03,adr&0xff,adr>>8,len};
+ uint16_t read_len=2+len+1+1;
+ uint8_t *read=rt_malloc(read_len);
+ if(read==RT_NULL) return 1;
+ DMod_SendBytesXor(cmd,6,1);
+ ret=DMod_ReadBytesXor(read,read_len,100);
+ rt_memset(buf,0,len);
+ if(ret==0)
+ {
+ rt_memcpy(buf,&read[3],len);
+ }
+ DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read[0],read[1],read[2],read[3]);
+ rt_free(read);
+ return ret;
+}
+
+
+
+// app:读取数据
+static int EW_appRead(void)
+{
+ uint8_t read_buf[4]={0};
+ int ret=0;
+ uint8_t addr=(uint8_t)(UPDATA_FLAG_ADDR/4);
+ DBG_LOG("addr=0x%02x.",addr);
+ ret=EW_ReadMTP(1,addr,read_buf,4);
+ DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,read_buf[0],read_buf[1],read_buf[2],read_buf[3]);
+ return ret;
+}
+static int cmd_jwt_app_read(list_def *argv)
+{
+ int ret=0;
+ ret=EW_appRead();
+ return ret;
+}
+commend_export(jwt_app_read,cmd_jwt_app_read,"jwt read in app")
+
+
+// app:通信测试
+static int EW_appCommTest(void)
+{
+// uint8_t data[4]={0x11,0x22};
+// uint8_t ret;
+// DBG_LOG("send:%02x,%02x.",data[0],data[1]);
+// ret=EW_CommTest(data,2,300);
+// DBG_LOG("ret=%d,dat=%02x,%02x,%02x,%02x,",ret,data[0],data[1],data[2],data[3]);
+// return ret;
+ return EW_appRead();
+}
+static int cmd_jwt_app_commtest(list_def *argv)
+{
+ int ret=0;
+ ret=EW_appCommTest();
+ return ret;
+}
+commend_export(jwt_app_commtest,cmd_jwt_app_commtest,"jwt commtest in app")
+
+
+
+
+
+// app:runbootloader
+static void EW_appRunBoot(void)
+{
+ EW_Charge(1,0,0);
+ delay_ms(6000);
+ EW_RunBootLoader(1,1);
+ DBG_LOG("run boot");
+}
+static int cmd_jwt_app_runboot(list_def *argv)
+{
+ int ret=0;
+ EW_appRunBoot();
+ return ret;
+}
+commend_export(jwt_app_runboot,cmd_jwt_app_runboot,"jwt turn to bootloader")
+
+
+
+
+typedef struct{
+ // 充电时间 6000
+ int time_charg;
+ // 加载app时间 6000
+ int time_loadapp;
+ // 总线关断时间 1000
+ int time_poweroff;
+ // 升级模式,0,无app时升级;1,无条件升级
+ int updata_mode;
+ // 模块状态
+ int state;
+}ew_updata_def;
+
+
+
+// 硬复位
+int EW_HardReset(ew_updata_def *e)
+{
+ EW_BUS_OFF;
+ delay_ms(e->time_poweroff);
+ EW_BUS_ON;
+ return 0;
+}
+
+
+// 判断模块在何种工作状态 1:boot 2:app
+// 3:boot失败且app也失败
+int EW_CheckState(ew_updata_def *e)
+{
+ uint16_t ret=0;
+ delay_ms(100);
+ ret=EW_bootCharg();
+ if(ret==0){
+ delay_ms(e->time_charg);
+ e->state=1;
+ }else{
+ EW_HardReset(e);
+ delay_ms(e->time_loadapp);
+ ret=EW_appCommTest();
+ delay_ms(5);
+ if(ret==0){
+ e->state=2;
+ }else{
+ e->state=3;
+ }
+ }
+ return e->state;
+}
+
+
+
+// 跳转到app的方式
+static int EW_TurnToBoot1(ew_updata_def *e)
+{
+ DBG_LOG("turn to boot1");
+ delay_ms(5);
+ EW_EnWriteMTP(0,1);
+ delay_ms(5);
+ EW_RunBootLoader(0,1);
+ delay_ms(500);
+ if(EW_bootCharg()==0)
+ return 0;
+ else
+ return 1;
+}
+static int EW_TurnToBoot2(ew_updata_def *e)
+{
+ DBG_LOG("turn to boot2");
+ delay_ms(5);
+ EW_EnWriteMTP(0,1);
+ delay_ms(5);
+ EW_WriteMTP(0,(uint8_t)(UPDATA_FLAG_ADDR/4),BOOT_FLAG,4);
+ delay_ms(5);
+ return 1;
+}
+
+// 跳转到bootloader
+int EW_TurnToBoot(ew_updata_def *e)
+{
+ typedef int (*turnfun)(ew_updata_def *e);
+ turnfun func_table[]={EW_TurnToBoot2,EW_TurnToBoot2};
+ int ret=0;
+ for(int i=0;i<2;i++){
+ if(e->state!=1){
+ ret=func_table[i](e);
+ if(ret){
+ EW_HardReset(e);
+ }
+ EW_CheckState(e);
+ }else{
+ break;
+ }
+ }
+ return e->state;
+}
+
+
+
+static void EW_ParamPrint(ew_updata_def *e)
+{
+ DBG_LOG("time_charg=%d",e->time_charg);
+ DBG_LOG("time_loadapp=%d",e->time_loadapp);
+ DBG_LOG("time_poweroff=%d",e->time_poweroff);
+ DBG_LOG("updata_mode=%d",e->updata_mode);
+}
+
+
+// 升级
+void EW_Updata(void)
+{
+ Checker_RunCfg_st *cfg=&checker_runcfg;
+ uint16_t ret=0;
+ uint8_t read_buf[4]={0};
+ uint8_t *data=(uint8_t *)MC_CODE_ADDR+UPDATA_BASE_ADDR;
+ uint16_t len=UPDATA_DATA_LEN;
+ uint16_t addr=UPDATA_BASE_ADDR;
+ uint8_t pack_len=UPDATA_PACK_LEN;
+ uint32_t crc=0;
+ uint32_t crc_module=0;
+
+ ew_updata_def ew_updata={0};
+ // 充电时间 6000
+ ew_updata.time_charg=checker_runcfg.params[0];
+ // 加载app时间 6000
+ ew_updata.time_loadapp=checker_runcfg.params[1];
+ // 总线关断时间 1000
+ ew_updata.time_poweroff=checker_runcfg.params[2];
+ // 升级模式,0,无app时升级;1,无条件升级
+ ew_updata.updata_mode=checker_runcfg.params[3];
+ EW_ParamPrint(&ew_updata);
+ PowerCalibration_set(200,120);
+ ret=EW_CheckState(&ew_updata);
+ if(ret==2){
+ // 在app中
+ if(ew_updata.updata_mode==0){
+ DBG_LOG("no need updata.");
+ ret=0;
+ goto err;
+ }
+ }
+ ret=EW_TurnToBoot(&ew_updata);
+ // ret!=1 跳转到bootloader失败
+ if(ret!=1) {
+ DBG_WARN("turn to boot bailed.ret=%d",ret);
+ ret=1;
+ goto err;
+ }
+ DBG_LOG("erase app");
+ ret=EW_bootErease();
+ if(ret) {ret=2;goto err;}
+ delay_ms(600);
+ while(len>0){
+ pack_len=len>UPDATA_PACK_LEN?UPDATA_PACK_LEN:len;
+ LED1_Out=!LED1_Out;
+ ret=EW_bootWrite(addr,data,pack_len);
+ addr+=pack_len;
+ data+=pack_len;
+ len-=pack_len;
+ if(ret) {ret=3;goto err;}
+ delay_ms(1);
+ }
+ //crc=Crc32Calu((uint32_t *)(MC_CODE_ADDR+UPDATA_BASE_ADDR),UPDATA_DATA_LEN);
+ crc=UPDATA_CRC_APP;
+ DBG_LOG("local crc:0x%04x.",crc);
+ ret=EW_bootCheckCrc(UPDATA_BASE_ADDR,UPDATA_BASE_ADDR+UPDATA_DATA_LEN,&crc_module);
+ DBG_LOG("module crc:0x%04x.",crc_module);
+ if(ret) {ret=4;goto err;}
+ if(crc!=crc_module){ret=5;goto err;}
+ delay_ms(50);
+ ret=EW_bootJump();
+ if(ret) {ret=6;goto err;}
+ delay_ms(ew_updata.time_loadapp);
+ ret=EW_EnWriteMTP(0,1);
+ if(ret) {ret=7;goto err;}
+ DBG_LOG("EW_EnWriteMTP success.");
+ delay_ms(1);
+
+ ret=EW_WriteMTP(1,(uint8_t)(UPDATA_FLAG_ADDR/4),UPDATA_FLAG,4);
+ if(ret) {ret=8;goto err;}
+ DBG_LOG("EW_WriteMTP success.");
+ delay_ms(1);
+ ret=EW_ReadMTP(1,(uint8_t)(UPDATA_FLAG_ADDR/4),read_buf,4);
+ if(ret) {ret=9;goto err;}
+ if(memcmp(read_buf,UPDATA_FLAG,4)!=0){
+ DBG_LOG("read_buf=0x%02d,0x%02d,0x%02d,0x%02d.",read_buf[0],read_buf[1],read_buf[2],read_buf[3]);
+ ret=10;goto err;
+ }
+ DBG_LOG("EW_ReadMTP check success.");
+ delay_ms(1);
+ XTBUS_OFF;
+ delay_ms(ew_updata.time_poweroff);
+ XTBUS_ON;
+ delay_ms(ew_updata.time_loadapp);
+ ret=EW_appCommTest();
+ if(ret) {ret=11;goto err;}
+ DBG_LOG("EW_appCommTest success.");
+
+ err:
+ DBG_LOG("ret=%d",ret);
+ Checker_SetRtv(&ret,checker_runcfg.rtv_count);
+ Checker_MaskResult(ret,checker_runcfg.task_info.runindex);
+}
+static int cmd_jwt_updata(list_def *argv)
+{
+ int ret=0;
+ checker_runcfg.params[0]=6000;
+ checker_runcfg.params[1]=6000;
+ checker_runcfg.params[2]=1000;
+ checker_runcfg.params[3]=0;
+ checker_runcfg.rtv_count=0;
+ EW_Updata();
+ return ret;
+}
+commend_export(jwt_updata,cmd_jwt_updata,"jwt updata")
+
+
+
+
diff --git a/source/elec_det/interface/EWUpdata.h b/source/elec_det/interface/EWUpdata.h
new file mode 100644
index 0000000..dce6f2b
--- /dev/null
+++ b/source/elec_det/interface/EWUpdata.h
@@ -0,0 +1,15 @@
+
+#ifndef EWUpdata_h__
+#define EWUpdata_h__
+
+
+
+void EW_Updata(void);
+
+
+
+
+
+#endif
+
+
diff --git a/source/main/compiler_info.h b/source/main/compiler_info.h
index d42d6de..d209367 100644
--- a/source/main/compiler_info.h
+++ b/source/main/compiler_info.h
@@ -6,7 +6,7 @@
-#define BUILD_DATE "2023-11-15 17:56:15"
+#define BUILD_DATE "2023-11-16 17:26:38"
#define SOFT_VERSION "2.06"