|
@@ -56,7 +56,8 @@ void send_upgrade_start_response(uint8_t func_code, uint16_t reg_addr, uint8_t s
|
|
|
// DEBUG_PRINTF("\r\n");
|
|
|
|
|
|
// HAL_GPIO_WritePin(GPIOB, RS485_RE_Pin, GPIO_PIN_SET);
|
|
|
- HAL_UART_Transmit_DMA(&huart1, tx_buf, len);
|
|
|
+// HAL_UART_Transmit_DMA(&huart1, tx_buf, len);
|
|
|
+ uart485send(tx_buf, len);
|
|
|
if(Systemmode != releasemode)
|
|
|
taskprinttx(tx_buf,len);
|
|
|
}
|
|
@@ -96,7 +97,8 @@ void send_upgrade_data_response(uint8_t func_code, uint16_t reg_addr, uint8_t st
|
|
|
// DEBUG_PRINTF("\r\n");
|
|
|
|
|
|
// HAL_GPIO_WritePin(GPIOB, RS485_RE_Pin, GPIO_PIN_SET);
|
|
|
- HAL_UART_Transmit_DMA(&huart1, tx_buf, len);
|
|
|
+// HAL_UART_Transmit_DMA(&huart1, tx_buf, len);
|
|
|
+ uart485send(tx_buf, len);
|
|
|
if(Systemmode != releasemode)
|
|
|
taskprinttx(tx_buf,len);
|
|
|
}
|
|
@@ -136,7 +138,8 @@ void send_upgrade_end_response(uint8_t func_code, uint16_t reg_addr, uint8_t sta
|
|
|
// DEBUG_PRINTF("\r\n");
|
|
|
|
|
|
// HAL_GPIO_WritePin(GPIOB, RS485_RE_Pin, GPIO_PIN_SET);
|
|
|
- HAL_UART_Transmit_DMA(&huart1, tx_buf, len);
|
|
|
+// HAL_UART_Transmit_DMA(&huart1, tx_buf, len);
|
|
|
+ uart485send(tx_buf, len);
|
|
|
if(Systemmode != releasemode)
|
|
|
taskprinttx(tx_buf,len);
|
|
|
}
|
|
@@ -176,7 +179,7 @@ void handle_upgrade_start_frame(uint8_t *data)
|
|
|
send_upgrade_start_response(0x42, 0xAABB, 0x02,0x0000); // 文件过大
|
|
|
return;
|
|
|
}
|
|
|
-// erase_APPdata_buffer = true; // 擦除APP2缓存区
|
|
|
+ erase_APPdata_buffer = true; // 擦除APP2缓存区
|
|
|
|
|
|
upgrade_offset = 0;
|
|
|
current_packet_index = 0;
|
|
@@ -234,32 +237,25 @@ void handle_upgrade_data_frame(uint8_t *data)
|
|
|
if ((data[4] << 8 | data[5]) != 0x4001) return;
|
|
|
|
|
|
data4001_last_data_time = HAL_GetTick(); // 每次收到数据更新时间戳
|
|
|
-
|
|
|
uint16_t index = data[6] << 8 | data[7];
|
|
|
if (index != current_packet_index) {
|
|
|
send_upgrade_data_response(0x42, 0xAABB, 0x04, 0x0000 );
|
|
|
reset_upgrade_state();
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
Flash_Write64(IAPDataBuffer_ADDR + upgrade_offset, (uint64_t*)&data[8], PACKET_SIZE / 8);
|
|
|
-
|
|
|
upgrade_offset += PACKET_SIZE;
|
|
|
current_packet_index++;
|
|
|
-
|
|
|
send_upgrade_data_response(0x42, 0xAABB, 0x00, current_packet_index);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
// 处理结束帧 (0x4002)
|
|
|
void handle_upgrade_end_frame(void)
|
|
|
{
|
|
|
- DEBUG_PRINTF("0x4002 start\r\n");
|
|
|
-
|
|
|
uint8_t result_md5[16];
|
|
|
MD5_CTX context;
|
|
|
|
|
|
- send_upgrade_end_response(0x42, 0xAABB, 0x00, 0x0000); // 应答表示收到结束帧
|
|
|
+ send_upgrade_end_response(0x42, 0xAABB, 0x00, 0x0000); // 应答表示收到结束帧
|
|
|
|
|
|
bool md5_pass = false;
|
|
|
|
|
@@ -319,10 +315,17 @@ void handle_upgrade_end_frame(void)
|
|
|
{
|
|
|
DEBUG_PRINTF(" MD5 check passed \r\n");
|
|
|
|
|
|
- JsRoot.iapLoadStatus = 300;
|
|
|
+ JsRoot.iapLoadStatus = 300;
|
|
|
DB_SaveUInt(DB_ID_SNAPSHOT, KV_KEY_IAP_LOAD , JsRoot.iapLoadStatus ); // 存入到SNAPSHOT数据库
|
|
|
|
|
|
- osDelay(300);
|
|
|
+ // 将每个字节转换为两位16进制字符
|
|
|
+ for(int i = 0; i < 4; i++) {
|
|
|
+ sprintf(&JsRoot.iapMd5[i*2], "%02X", result_md5[i]);
|
|
|
+ }
|
|
|
+ JsRoot.iapMd5[8] = '\0';
|
|
|
+ DB_SaveChar(DB_ID_SNAPSHOT, KV_KEY_IAP_MD5 , JsRoot.iapMd5 ); // 存入MD5到SNAPSHOT数据库
|
|
|
+
|
|
|
+ osDelay(500);
|
|
|
NVIC_SystemReset();
|
|
|
|
|
|
} else {
|
|
@@ -333,7 +336,7 @@ void handle_upgrade_end_frame(void)
|
|
|
}
|
|
|
|
|
|
reset_upgrade_state(); // 清除相关升级状态标志
|
|
|
- DEBUG_PRINTF("0x4002 end\r\n");
|
|
|
+// 4.09.06
|
|
|
}
|
|
|
// 清除升级状态(在失败或完成后调用)
|
|
|
void reset_upgrade_state(void)
|
|
@@ -377,26 +380,26 @@ void app_jump_check_and_jump(void) // 初始化完成之后,检查状态是否
|
|
|
}
|
|
|
|
|
|
if (JsRoot.iapLoadStatus == 2) {
|
|
|
-
|
|
|
+ printf ("\r\n valid APP2. Run APP2\r\n");
|
|
|
if (!JumpToApp(APP2_ADDR)) {
|
|
|
|
|
|
- printf("\r\n Jump failed. Keep Run FACTORY" );
|
|
|
+ printf("\r\n Jump failed. Run APP1" );
|
|
|
}
|
|
|
|
|
|
} else if(JsRoot.iapLoadStatus == 0){
|
|
|
- // 运行当前FACTORY程序
|
|
|
- printf ("\r\n No valid APP2. Keep Run FACTORY\r\n");
|
|
|
+ // 运行当前 APP1 程序
|
|
|
+ printf ("\r\n No valid APP2. Run APP1\r\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool JumpToApp(uint32_t addr)
|
|
|
{
|
|
|
- // FACTORY: sp = 0x200092F8 ; pc = 0x08014281;
|
|
|
- // APP2: sp = 0x200092F8 ; pc = 0x08000281;
|
|
|
- uint32_t sp = *(volatile uint32_t*)addr;// *(volatile uint32_t*)addr;// 0x200092F8;//
|
|
|
+ // APP1: sp = 0x100037A8 ; pc = 0x08014281;
|
|
|
+ // APP2: sp = 0x100037A8 ; pc = 0x08000281;
|
|
|
+ uint32_t sp = *(volatile uint32_t*)addr;// *(volatile uint32_t*)addr;// 0x100037A8;//
|
|
|
uint32_t pc = *(volatile uint32_t*)(addr + 4);// *(volatile uint32_t*)(addr + 4);// 0x08014281;//
|
|
|
|
|
|
- if( sp ==0x200092F8 && pc == 0x08014281) // 跳转到APP1区域
|
|
|
+ if( sp ==0x100037A8 && pc == 0x08014281) // 跳转到APP2区域
|
|
|
{
|
|
|
DEBUG_PRINTF("\r\n Jumping app_address. SP=0x%08X, PC=0x%08X \r\n", sp, pc);
|
|
|
DEBUG_PRINTF("\r\n Jumping app_address success");
|