Commit 887ec44c authored by 李秉薇's avatar 李秉薇

fix:调试修改数据发送

parent bc7dd555
......@@ -311,7 +311,8 @@ Protocol_uint32_t UpdateBAT32A239Protocol_Send(UpdateProtocolStructure SendPd)
return 0;
}
frameLen += 7;
frameLen = SendPd.LEN + 7;
dataBuf [ 0 ] = 0xAA;
dataBuf [ 1 ] = 0x55; // 同步帧头 Sync frame header
......@@ -323,14 +324,14 @@ Protocol_uint32_t UpdateBAT32A239Protocol_Send(UpdateProtocolStructure SendPd)
if(SendPd.CMDH == CMD_FLASH_DWNLD)
{
if(SendPd.LEN > 0)
if(SendPd.LEN > 4)
{
memcpy(&dataBuf[6],&SendPd.DAT[0],SendPd.LEN);
DAT_CRC=CalcCrc32(&SendPd.DAT[16], SendPd.LEN );//计算Address + Data的CRC 32
dataBuf[6+SendPd.LEN-4]=(Protocol_uint8_t)(DAT_CRC);
dataBuf[7+SendPd.LEN-4]=(Protocol_uint8_t)(DAT_CRC>>8);
dataBuf[8+SendPd.LEN-4]=(Protocol_uint8_t)(DAT_CRC>>16);
dataBuf[9+SendPd.LEN-4]=(Protocol_uint8_t)(DAT_CRC>>24);
memcpy(&dataBuf[6],&SendPd.DAT[0],SendPd.LEN - 4);
DAT_CRC=CalcCrc32(&SendPd.DAT[0], SendPd.LEN - 4 );//计算Address + Data的CRC 32
dataBuf[frameLen-5]=(Protocol_uint8_t)(DAT_CRC);
dataBuf[frameLen-4]=(Protocol_uint8_t)(DAT_CRC>>8);
dataBuf[frameLen-3]=(Protocol_uint8_t)(DAT_CRC>>16);
dataBuf[frameLen-2]=(Protocol_uint8_t)(DAT_CRC>>24);
}
}
......@@ -339,6 +340,8 @@ Protocol_uint32_t UpdateBAT32A239Protocol_Send(UpdateProtocolStructure SendPd)
checksumXor^=dataBuf[i];
}
dataBuf[frameLen - 1]=(Protocol_uint8_t)checksumXor;
printf("dataBuf[frameLen - 1] = %2x\n", dataBuf[frameLen - 1]);
printf("frameLen = %d\n", frameLen);
if ( UARTSend_Cbk != Protocol_NULL )
{
return UARTSend_Cbk(dataBuf, frameLen);
......
......@@ -389,7 +389,7 @@ void Prot_Send_Msg_Process(void )
//BAT32A239
UpdateProtocolStructure Update_Frame;
const unsigned char _acBAT32A239dat[88016];
extern const unsigned char _acBAT32A239dat[88016];
Protocol_uint32_t UpgradeStep =0x0;//初始状态
uint32_t Step_delayTime =0;
uint32_t Flash_Size =0;
......@@ -437,7 +437,7 @@ uint32_t StartAddr = 0;
uint32_t Write_Size=0;
uint32_t SendCmd_WriteBAT32A239_Flash(void)
{
uint32_t Offset=0;
//uint32_t Offset=0;
if (Flash_Size>Write_Counter)
{
......@@ -447,34 +447,33 @@ uint32_t SendCmd_WriteBAT32A239_Flash(void)
if(Write_Counter == 0)
{
StartAddr = 0;
StartAddr |= _acBAT32A239dat[4];
StartAddr |= _acBAT32A239dat[8];
StartAddr <<= 8;
StartAddr |= _acBAT32A239dat[5];
StartAddr |= _acBAT32A239dat[9];
StartAddr <<= 8;
StartAddr |= _acBAT32A239dat[6];
StartAddr |= _acBAT32A239dat[10];
StartAddr <<= 8;
StartAddr |= _acBAT32A239dat[7];
StartAddr += 16;
StartAddr |= _acBAT32A239dat[11];
//StartAddr += 16;
}//确定下载起始地址
if ((Flash_Size-Write_Counter)>=128)
{
Update_Frame.LEN= 128+4;//0x94;
Update_Frame.LEN= 128+8;//0x94;
Write_Size=128;
}
else
{
Update_Frame.LEN = (Flash_Size - Write_Counter) + 4;//剩余数量
Update_Frame.LEN = (Flash_Size - Write_Counter) + 8;//剩余数量
Write_Size = Flash_Size - Write_Counter;
}
Write_Counter += Write_Size; //写入指针增加
memcpy(&Update_Frame.DAT[4],&_acBAT32A239dat[Offset],Write_Size); //拷贝需要写入的数据到发送结构
memcpy(&Update_Frame.DAT[4],&_acBAT32A239dat[Write_Counter + 16],Write_Size); //拷贝需要写入的数据到发送结构
Offset += StartAddr;//转换为下载 FLASH 的实际起始地址
Update_Frame.DAT[0] = (Protocol_uint8_t)(Offset >> 24);
Update_Frame.DAT[1] = (Protocol_uint8_t)(Offset >> 16);
Update_Frame.DAT[2] = (Protocol_uint8_t)(Offset >> 8);
Update_Frame.DAT[3] = (Protocol_uint8_t)(Offset >> 0);
//Write_Counter += StartAddr;//转换为下载 FLASH 的实际起始地址
Update_Frame.DAT[0] = (Protocol_uint8_t)(StartAddr >> 24);
Update_Frame.DAT[1] = (Protocol_uint8_t)(StartAddr >> 16);
Update_Frame.DAT[2] = (Protocol_uint8_t)(StartAddr >> 8);
Update_Frame.DAT[3] = (Protocol_uint8_t)(StartAddr >> 0);
UpdateBAT32A239Protocol_Send(Update_Frame);//发送
}
......@@ -534,7 +533,8 @@ void BAT32A239_MCU_Update(void)
break;
case 1 :
Flash_Size =sizeof(_acBAT32A239dat);
Flash_Size =sizeof(_acBAT32A239dat) - 16;
//ESP_LOGI("MSI","Flash_Size : %ld \n",Flash_Size);
Write_Counter = 0;
if (BAT32A239_ACK.CMDH == CMD_FLASH_ERASE)
{
......@@ -559,7 +559,7 @@ void BAT32A239_MCU_Update(void)
if (Step_delayTime>=2000)
{
ESP_LOGI("MSI","UpgradeStep : %d Erase Chip timeout\n",UpgradeStep);
UpgradeStep=7; //超时停止
UpgradeStep = 4; //超时停止
}
}
break;
......@@ -575,6 +575,7 @@ void BAT32A239_MCU_Update(void)
{
BAT32A239_ACK.dat.download.CR1=0xFF;
Write_Counter += Write_Size;
StartAddr += Write_Size;
if (Write_Counter==Flash_Size)//下载完成
{
UpgradeStep=3;
......
const unsigned char _acN32G031dat[88016] = {
const unsigned char _acBAT32A239dat[88016] = {
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x70, 0x00, 0x00, 0x01, 0x57, 0xC0,
0xCB, 0x35, 0xDE, 0x23, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x47, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
......
......@@ -701,8 +701,6 @@ CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD=20
CONFIG_BTDM_RESERVE_DRAM=0xdb5c
CONFIG_BTDM_CTRL_HLI=y
# end of Controller Options
# CONFIG_BT_HCI_LOG_DEBUG_EN is not set
# end of Bluetooth
# CONFIG_BLE_MESH is not set
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment