Commit bc7dd555 authored by 李茂军's avatar 李茂军

feat:擦除完成

parent 74238459
......@@ -4,6 +4,7 @@ idf_component_register(SRCS "app_BT_User.c" "bt_app_main.c" "bt_app_hf.c" "bt_ap
"Protocol_CRC16.c"
"Protocol_Lib.c"
"Protocol_User.c"
"mcudata.c"
"MCU_Core_Protocol.c"
"app_Ble_User.c"
"main_user.c"
......
......@@ -54,7 +54,8 @@ void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protoc
return;
}
extern Protocol_uint32_t UpdateBAT32A239Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len);
extern uint32_t SwitchMode;
/**
* @brief 串口协议服务函数,包括读取数据,解析数据,如在外部读取数据,可不调用此函数
*
......@@ -74,7 +75,15 @@ void Protocol_Service(void)
{
mDataBufLen += readNum;
// 解析协议
len = Protocol_Parse(mDataBufPtr, mDataBufLen);
if(SwitchMode==0)//处理升级协议
{
len = Protocol_Parse(mDataBufPtr, mDataBufLen);
}
else//处理应用协议
{
len = UpdateBAT32A239Protocol_Parse(mDataBufPtr, mDataBufLen);
}
if ( (len > 0) && (len < mDataBufLen) )
{
// 将未解析的数据移到头部
......
......@@ -389,8 +389,8 @@ void Prot_Send_Msg_Process(void )
//BAT32A239
UpdateProtocolStructure Update_Frame;
unsigned char _acBAT32A239dat[0x1000];
Protocol_uint32_t UpgradeStep =0xFF;//初始状态
const unsigned char _acBAT32A239dat[88016];
Protocol_uint32_t UpgradeStep =0x0;//初始状态
uint32_t Step_delayTime =0;
uint32_t Flash_Size =0;
uint32_t temp_Size =0;
......@@ -410,7 +410,7 @@ void SetUpgradeStart(void)
// Flash_Size+=(16-fills);//下载数据需要对齐16字节
// }
// UpgradeStep=0;
UpgradeStep=0;
}
void SetUpgradeFlashSize(uint32_t size)
......@@ -420,7 +420,7 @@ void SetUpgradeFlashSize(uint32_t size)
}
void Cache_data(unsigned char* p,uint32_t len)
{
memcpy(&_acBAT32A239dat[temp_Size],p,len);
// memcpy(&_acBAT32A239dat[temp_Size],p,len);
temp_Size+=len;
}
......@@ -498,7 +498,28 @@ void SendCmd_CrcCheckBAT32A239_Flash(void)
UpdateBAT32A239Protocol_Send(Update_Frame);
}
static uint32_t UpgradeBAT32A239_1ms_Cnt;
void Upgrade_BAT32A239_Task(void *arg)
{
while(1)
{
Protocol_Service();
if (UpgradeBAT32A239_1ms_Cnt < 1000)
{
UpgradeBAT32A239_1ms_Cnt++;
}
else
{
UpgradeBAT32A239_1ms_Cnt = 0;
}
if((UpgradeBAT32A239_1ms_Cnt + 2) % 50 == 0)
{
BAT32A239_MCU_Update();
}
Protocol_Send_Service();
vTaskDelay(pdMS_TO_TICKS(1));
}
}
void BAT32A239_MCU_Update(void)
{
......@@ -507,13 +528,13 @@ void BAT32A239_MCU_Update(void)
{
case 0 :
SendCmd_EraseBAT32A239_Chip();//发送擦除指令
UpgradeStep=6;
UpgradeStep=1;
Step_delayTime=0;
ESP_LOGI("MSI","UpgradeStep : %d Erase Chip \n",UpgradeStep);
break;
case 1 :
//Flash_Size =sizeof(_acBAT32A239dat);
Flash_Size =sizeof(_acBAT32A239dat);
Write_Counter = 0;
if (BAT32A239_ACK.CMDH == CMD_FLASH_ERASE)
{
......@@ -535,10 +556,10 @@ void BAT32A239_MCU_Update(void)
else
{
Step_delayTime++;
if (Step_delayTime>=10)
if (Step_delayTime>=2000)
{
ESP_LOGI("MSI","UpgradeStep : %d Erase Chip timeout\n",UpgradeStep);
//UpgradeStep=7; //超时停止
UpgradeStep=7; //超时停止
}
}
break;
......@@ -635,4 +656,71 @@ Protocol_uint32_t CalcCrc32(Protocol_uint8_t buf[], int Len)
return crc;
}
\ No newline at end of file
Protocol_uint32_t UpdateBAT32A239Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len)
{
Protocol_uint8_t remainLen = len; // 剩余数据长度 Remaining data length
Protocol_uint8_t dataLen; // 数据包长度 Packet length
Protocol_uint8_t frameLen=0; // 帧长度 Frame length
Protocol_uint8_t checksumXor=0;
int i = 0;
/**
* 以下部分需要根据协议格式进行相应的修改,解析出每一帧的数据
*/
while ( remainLen >= 7 )
{
// 找到一帧数据的数据头
// Find the data header of a frame of data
while ( (remainLen >= 2) && ((pData [ 0 ] != 0xAA) || (pData [ 1 ] != 0x55)) )
{
pData++;
remainLen--;
continue;
}
dataLen = pData [ 4 ];//实际是[4][5]小端排序,但实际么有那么多直接取低字节
// 0 1 2 3 4 5 6~n 6+n+1 6+n+2 6+n+3
//STA1 + STA2+{< CMD_H + CMD_L + LENL+LENH > + (DAT) + <CR1 + CR2> }+XOR
frameLen = dataLen;//准确的一帧数据长度
// if ( frameLen > remainLen )// 数据内容不全
// {
// #ifdef DEBUG_PRO_DATA
// printf("Incomplete data packet!!!!!!\n");
// #endif
// break;
// }
// checksumXor=pData[0];
/*在 BOOT V1.0 的版本(获取版本信息命令见章节 2.3.2),异或运算不对 CR2
运算,只对 CR2 前面的字节进行运算, 即(STA1 + STA2 + {< CMD_H + CMD_L
+ LEN > + (DAT) + <CR1 >})。
*/
if(remainLen==frameLen)
{
for ( i = 0; i < remainLen-1; i++)
{
checksumXor^=pData[i];
}
// printf("Dataxor =%2x-- pData[remainLen-2] = %2x",checksumXor,pData[remainLen-2] );
}
if (checksumXor!=pData[remainLen-1])//抛弃坏帧
{
// 打印一帧数据,需要时在CommDef.h文件中打开DEBUG_PRO_DATA宏
#ifdef DEBUG_PRO_DATA
for ( i = 0; i < frameLen; ++i )
{
printf("%x ", pData [ i ]);
}printf("\n");
#endif
break;
}
memcpy(&BAT32A239_ACK.CMDH,&pData[2],frameLen-1);
pData += frameLen;
remainLen -= frameLen;
}
return len - remainLen;
}
\ No newline at end of file
......@@ -24,9 +24,10 @@ typedef struct
extern Protocol_User_Ctrl_Struct Prot_User;
void Protocol_User_Ctrl_Init(void );
void BAT32A239_MCU_Update(void);
void Prot_Send_Msg_Process(void );
Protocol_uint32_t CalcCrc32(Protocol_uint8_t buf[], int Len);
extern Protocol_uint32_t UpdateBAT32A239Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len);
#ifdef UPGRADE_N32G031
#define CMD_SET_BR 0x01//设置串口波特率
......
......@@ -45,11 +45,16 @@ uint32_t Sys_1ms_Cnt;
uint32_t testcnt;
extern uint32_t SwitchMode;
static void Sys_Run_Tasks(void *arg)
{
uint8_t i = 0;
while(1)
{
if(SwitchMode!=0)
{
break;
}
if(Sys_1ms_Cnt < 499)
{
Sys_1ms_Cnt ++ ;
......@@ -120,21 +125,24 @@ static void Sys_Run_Tasks(void *arg)
vTaskDelay(1);
}
// vTaskDelete(NULL);
vTaskDelete(NULL);
}
TaskHandle_t wifi_service_hdl=NULL;
extern uint32_t SwitchMode;
extern void wifiServiceStart(void);
extern void Upgrade_BAT32A239_Task(void *arg);
static void wifi_service_task(void *arg)
{
while (1)
{
// if(SwitchMode == 1)
// {
// delele_tasks();
// //delele_tasks();
// xTaskCreatePinnedToCore(Upgrade_BAT32A239_Task, "Upgrade_BAT32A239_Task", 1024 * 4, NULL, 5, NULL, 1);
// SwitchMode=2;
// }
wifi_service_timer();
// wifi_service_timer();
wifi_service();
vTaskDelay(pdMS_TO_TICKS(100));
}
......@@ -142,17 +150,18 @@ static void wifi_service_task(void *arg)
TaskHandle_t Sys_Run_Taskshdl=NULL;
void app_main(void)
{
Protocol_User_Ctrl_Init();
BT_User_Init();
Ble_User_Init();
Get_Mac_Init();
bsp_BT_Init();
bsp_Ble_Init();
// Protocol_User_Ctrl_Init();
// BT_User_Init();
// Ble_User_Init();
// Get_Mac_Init();
// bsp_BT_Init();
// bsp_Ble_Init();
bsp_Uart_Init();
printf("KL30 INIT OVER~~~~~~\r\n");
xTaskCreatePinnedToCore(Sys_Run_Tasks, "Sys_Run_Tasks", 4096, NULL, 3, Sys_Run_Taskshdl, 1);
xTaskCreatePinnedToCore(wifi_service_task, "wifi_service_task", 4096, NULL, 5, &wifi_service_hdl, 1);
// xTaskCreatePinnedToCore(wifi_service_task, "wifi_service_task", 4096, NULL, 5, &wifi_service_hdl, 1);
xTaskCreatePinnedToCore(Upgrade_BAT32A239_Task, "Upgrade_BAT32A239_Task", 1024 * 4, NULL, 5, NULL, 1);
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -701,6 +701,8 @@ 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
......
......@@ -147,63 +147,63 @@ static esp_err_t app_post_handler(httpd_req_t *req)
return ESP_OK;
}
static esp_err_t assert_post_handler(httpd_req_t *req)
{
int ret, remaining = req->content_len;
while (remaining > 0)
{
/* Read the data for the request */
if ((ret = httpd_req_recv(req, buf, MIN(remaining, sizeof(buf)))) <= 0)
{
if (ret == HTTPD_SOCK_ERR_TIMEOUT)
{
/* Retry receiving if timeout occurred */
continue;
}
return ESP_FAIL;
}
remaining -= ret;
// ESP_LOGI(TAG, "=========== RECEIVED DATA ==========");
// 数据处理代码
// ESP_LOGI(TAG, "====================================");
}
// End response
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
static esp_err_t storage_post_handler(httpd_req_t *req)
{
int ret, remaining = req->content_len;
while (remaining > 0)
{
/* Read the data for the request */
if ((ret = httpd_req_recv(req, buf, MIN(remaining, sizeof(buf)))) <= 0)
{
if (ret == HTTPD_SOCK_ERR_TIMEOUT)
{
/* Retry receiving if timeout occurred */
continue;
}
return ESP_FAIL;
}
remaining -= ret;
// ESP_LOGI(TAG, "=========== RECEIVED DATA ==========");
// 数据处理代码
// ESP_LOGI(TAG, "====================================");
}
// End response
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
// static esp_err_t assert_post_handler(httpd_req_t *req)
// {
// int ret, remaining = req->content_len;
// while (remaining > 0)
// {
// /* Read the data for the request */
// if ((ret = httpd_req_recv(req, buf, MIN(remaining, sizeof(buf)))) <= 0)
// {
// if (ret == HTTPD_SOCK_ERR_TIMEOUT)
// {
// /* Retry receiving if timeout occurred */
// continue;
// }
// return ESP_FAIL;
// }
// remaining -= ret;
// // ESP_LOGI(TAG, "=========== RECEIVED DATA ==========");
// // 数据处理代码
// // ESP_LOGI(TAG, "====================================");
// }
// // End response
// httpd_resp_send_chunk(req, NULL, 0);
// return ESP_OK;
// }
// static esp_err_t storage_post_handler(httpd_req_t *req)
// {
// int ret, remaining = req->content_len;
// while (remaining > 0)
// {
// /* Read the data for the request */
// if ((ret = httpd_req_recv(req, buf, MIN(remaining, sizeof(buf)))) <= 0)
// {
// if (ret == HTTPD_SOCK_ERR_TIMEOUT)
// {
// /* Retry receiving if timeout occurred */
// continue;
// }
// return ESP_FAIL;
// }
// remaining -= ret;
// // ESP_LOGI(TAG, "=========== RECEIVED DATA ==========");
// // 数据处理代码
// // ESP_LOGI(TAG, "====================================");
// }
// // End response
// httpd_resp_send_chunk(req, NULL, 0);
// return ESP_OK;
// }
/*上传文件名是BAT32A239dat.bin的处理函数*/
static esp_err_t nation_post_handler(httpd_req_t *req)
......@@ -238,7 +238,7 @@ static esp_err_t nation_post_handler(httpd_req_t *req)
// 数据处理代码
// ESP_LOGI(TAG, "====================================");
}
SetUpgradeStart(); // 启动升级
//SetUpgradeStart(); // 启动升级
ESP_LOGI(TAG, "---- 国民技术程序文件: 接收完成");
// End response
httpd_resp_send_chunk(req, NULL, 0);
......
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