Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
RT200T_ESP32
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
RT200T
RT200T_ESP32
Commits
a85cf15e
Commit
a85cf15e
authored
Jun 04, 2024
by
李秉薇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:打开wifi升级
parent
887ec44c
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
205 additions
and
54 deletions
+205
-54
QJ500_7C_partitions_two_ota.csv
RT200T_2_ESP32/QJ500_7C_partitions_two_ota.csv
+6
-5
CMakeLists.txt
RT200T_2_ESP32/main/CMakeLists.txt
+2
-2
Protocol_User.c
RT200T_2_ESP32/main/Protocol_User.c
+76
-28
main_user.c
RT200T_2_ESP32/main/main_user.c
+1
-1
mcudata.c
RT200T_2_ESP32/main/mcudata.c
+3
-1
CMakeLists.txt
RT200T_2_ESP32/source/wifi/CMakeLists.txt
+1
-1
http_server.c
RT200T_2_ESP32/source/wifi/http_server.c
+112
-14
http_server.h
RT200T_2_ESP32/source/wifi/http_server.h
+4
-2
No files found.
RT200T_2_ESP32/QJ500_7C_partitions_two_ota.csv
View file @
a85cf15e
...
@@ -5,3 +5,4 @@ otadata, data, ota, , 0x2000,
...
@@ -5,3 +5,4 @@ otadata, data, ota, , 0x2000,
phy_init, data, phy, , 0x1000,
phy_init, data, phy, , 0x1000,
ota_0, app, ota_0, , 0x800K,
ota_0, app, ota_0, , 0x800K,
ota_1, app, ota_1, , 0x800K,
ota_1, app, ota_1, , 0x800K,
assert, data, spiffs, , 300K,
\ No newline at end of file
RT200T_2_ESP32/main/CMakeLists.txt
View file @
a85cf15e
# Embed the server root certificate into the final binary "simple_ota_example.c"
# Embed the server root certificate into the final binary "simple_ota_example.c"
idf_build_get_property
(
project_dir PROJECT_DIR
)
idf_build_get_property
(
project_dir PROJECT_DIR
)
idf_component_register
(
SRCS
"app_BT_User.c"
"bt_app_main.c"
"bt_app_hf.c"
"bt_app_core.c"
"gatts_table_creat_demo.c"
idf_component_register
(
SRCS
"
mcudata.c"
"
app_BT_User.c"
"bt_app_main.c"
"bt_app_hf.c"
"bt_app_core.c"
"gatts_table_creat_demo.c"
"Protocol_CRC16.c"
"Protocol_CRC16.c"
"Protocol_Lib.c"
"Protocol_Lib.c"
"Protocol_User.c"
"Protocol_User.c"
"mcudata.c"
"MCU_Core_Protocol.c"
"MCU_Core_Protocol.c"
"app_Ble_User.c"
"app_Ble_User.c"
"main_user.c"
"main_user.c"
...
...
RT200T_2_ESP32/main/Protocol_User.c
View file @
a85cf15e
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#include <string.h>
#include <string.h>
#include <stdbool.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include "http_server.h"
...
@@ -389,12 +390,16 @@ void Prot_Send_Msg_Process(void )
...
@@ -389,12 +390,16 @@ void Prot_Send_Msg_Process(void )
//BAT32A239
//BAT32A239
UpdateProtocolStructure
Update_Frame
;
UpdateProtocolStructure
Update_Frame
;
extern
const
unsigned
char
_acBAT32A239dat
[
88016
];
//
extern const unsigned char _acBAT32A239dat[88016];
Protocol_uint32_t
UpgradeStep
=
0x
0
;
//初始状态
Protocol_uint32_t
UpgradeStep
=
0x
FF
;
//初始状态
uint32_t
Step_delayTime
=
0
;
uint32_t
Step_delayTime
=
0
;
uint32_t
Flash_Size
=
0
;
uint32_t
Flash_Size
=
0
;
uint32_t
temp_Size
=
0
;
uint32_t
temp_Size
=
0
;
uint32_t
Write_Counter
=
0
;
uint32_t
Write_Counter
=
0
;
uint32_t
StartAddr
=
0
;
uint32_t
BackupStartAddr
=
0
;
uint32_t
DataTotalLen
=
0
;
uint32_t
BackupDataTotalLen
=
0
;
void
SetUpgradeStart
(
void
)
void
SetUpgradeStart
(
void
)
{
{
// uint32_t fills;
// uint32_t fills;
...
@@ -410,14 +415,25 @@ void SetUpgradeStart(void)
...
@@ -410,14 +415,25 @@ void SetUpgradeStart(void)
// Flash_Size+=(16-fills);//下载数据需要对齐16字节
// Flash_Size+=(16-fills);//下载数据需要对齐16字节
// }
// }
UpgradeStep
=
0
;
UpgradeStep
=
4
;
}
}
void
SetUpgradeFlashSize
(
uint32_t
size
)
void
SetUpgradeFlashSize
(
uint32_t
size
,
uint32_t
len
)
{
{
Flash_Size
=
size
-
16
;
DataTotalLen
=
size
-
16
;
BackupDataTotalLen
=
DataTotalLen
;
temp_Size
=
0
;
temp_Size
=
0
;
StartAddr
=
len
;
BackupStartAddr
=
StartAddr
;
Write_Counter
=
0
;
ESP_LOGI
(
"MSI"
,
"DataTotalLen : %ld
\n
"
,
DataTotalLen
);
ESP_LOGI
(
"MSI"
,
"BackupDataTotalLen : %ld
\n
"
,
BackupDataTotalLen
);
ESP_LOGI
(
"MSI"
,
"StartAddr : %ld Erase Chip
\n
"
,
StartAddr
);
ESP_LOGI
(
"MSI"
,
"BackupStartAddr : %ld Erase Chip
\n
"
,
BackupStartAddr
);
}
}
void
Cache_data
(
unsigned
char
*
p
,
uint32_t
len
)
void
Cache_data
(
unsigned
char
*
p
,
uint32_t
len
)
{
{
// memcpy(&_acBAT32A239dat[temp_Size],p,len);
// memcpy(&_acBAT32A239dat[temp_Size],p,len);
...
@@ -432,8 +448,6 @@ void SendCmd_EraseBAT32A239_Chip(void)
...
@@ -432,8 +448,6 @@ void SendCmd_EraseBAT32A239_Chip(void)
memset
(
Update_Frame
.
DAT
,
0
,
16
);
memset
(
Update_Frame
.
DAT
,
0
,
16
);
UpdateBAT32A239Protocol_Send
(
Update_Frame
);
UpdateBAT32A239Protocol_Send
(
Update_Frame
);
}
}
uint32_t
StartAddr
=
0
;
uint32_t
Write_Size
=
0
;
uint32_t
Write_Size
=
0
;
uint32_t
SendCmd_WriteBAT32A239_Flash
(
void
)
uint32_t
SendCmd_WriteBAT32A239_Flash
(
void
)
{
{
...
@@ -444,18 +458,7 @@ uint32_t SendCmd_WriteBAT32A239_Flash(void)
...
@@ -444,18 +458,7 @@ uint32_t SendCmd_WriteBAT32A239_Flash(void)
Update_Frame
.
CMDH
=
CMD_FLASH_DWNLD
;
Update_Frame
.
CMDH
=
CMD_FLASH_DWNLD
;
Update_Frame
.
CMDL
=
0x00
;
Update_Frame
.
CMDL
=
0x00
;
Update_Frame
.
LEN
=
0
;
Update_Frame
.
LEN
=
0
;
if
(
Write_Counter
==
0
)
{
StartAddr
=
0
;
StartAddr
|=
_acBAT32A239dat
[
8
];
StartAddr
<<=
8
;
StartAddr
|=
_acBAT32A239dat
[
9
];
StartAddr
<<=
8
;
StartAddr
|=
_acBAT32A239dat
[
10
];
StartAddr
<<=
8
;
StartAddr
|=
_acBAT32A239dat
[
11
];
//StartAddr += 16;
}
//确定下载起始地址
if
((
Flash_Size
-
Write_Counter
)
>=
128
)
if
((
Flash_Size
-
Write_Counter
)
>=
128
)
{
{
Update_Frame
.
LEN
=
128
+
8
;
//0x94;
Update_Frame
.
LEN
=
128
+
8
;
//0x94;
...
@@ -467,7 +470,7 @@ uint32_t SendCmd_WriteBAT32A239_Flash(void)
...
@@ -467,7 +470,7 @@ uint32_t SendCmd_WriteBAT32A239_Flash(void)
Write_Size
=
Flash_Size
-
Write_Counter
;
Write_Size
=
Flash_Size
-
Write_Counter
;
}
}
memcpy
(
&
Update_Frame
.
DAT
[
4
],
&
_acBAT32A239dat
[
Write_Counter
+
16
],
Write_Size
);
//拷贝需要写入的数据到发送结构
memcpy
(
&
Update_Frame
.
DAT
[
4
],
&
buf
[
Write_Counter
],
Write_Size
);
//拷贝需要写入的数据到发送结构
//Write_Counter += StartAddr;//转换为下载 FLASH 的实际起始地址
//Write_Counter += StartAddr;//转换为下载 FLASH 的实际起始地址
Update_Frame
.
DAT
[
0
]
=
(
Protocol_uint8_t
)(
StartAddr
>>
24
);
Update_Frame
.
DAT
[
0
]
=
(
Protocol_uint8_t
)(
StartAddr
>>
24
);
...
@@ -490,7 +493,7 @@ void SendCmd_CrcCheckBAT32A239_Flash(void)
...
@@ -490,7 +493,7 @@ void SendCmd_CrcCheckBAT32A239_Flash(void)
uint32_t
crc
=
0
;
uint32_t
crc
=
0
;
uint32_t
start
=
0x08000000
;
uint32_t
start
=
0x08000000
;
uint32_t
lenght
=
Flash_Size
;
uint32_t
lenght
=
Flash_Size
;
crc
=
CalcCrc32
(
&
_acBAT32A239dat
[
0
],
lenght
);
//减掉CRC和前16字节DAT
//
crc=CalcCrc32(&_acBAT32A239dat[0],lenght);//减掉CRC和前16字节DAT
Update_Frame
.
CMDH
=
CMD_DATA_CRC_CHECK
;
Update_Frame
.
CMDH
=
CMD_DATA_CRC_CHECK
;
Update_Frame
.
CMDL
=
0x00
;
Update_Frame
.
CMDL
=
0x00
;
Update_Frame
.
LEN
=
0x00
;
Update_Frame
.
LEN
=
0x00
;
...
@@ -523,6 +526,8 @@ void Upgrade_BAT32A239_Task(void *arg)
...
@@ -523,6 +526,8 @@ void Upgrade_BAT32A239_Task(void *arg)
void
BAT32A239_MCU_Update
(
void
)
void
BAT32A239_MCU_Update
(
void
)
{
{
double
percent
=
0
.
0
;
double
percent
=
0
.
0
;
const
char
*
partition_label
=
"assert"
;
const
esp_partition_t
*
assert_update_partition
=
esp_partition_find_first
(
ESP_PARTITION_TYPE_DATA
,
ESP_PARTITION_SUBTYPE_ANY
,
partition_label
);
switch
(
UpgradeStep
)
switch
(
UpgradeStep
)
{
{
case
0
:
case
0
:
...
@@ -533,7 +538,6 @@ void BAT32A239_MCU_Update(void)
...
@@ -533,7 +538,6 @@ void BAT32A239_MCU_Update(void)
break
;
break
;
case
1
:
case
1
:
Flash_Size
=
sizeof
(
_acBAT32A239dat
)
-
16
;
//ESP_LOGI("MSI","Flash_Size : %ld \n",Flash_Size);
//ESP_LOGI("MSI","Flash_Size : %ld \n",Flash_Size);
Write_Counter
=
0
;
Write_Counter
=
0
;
if
(
BAT32A239_ACK
.
CMDH
==
CMD_FLASH_ERASE
)
if
(
BAT32A239_ACK
.
CMDH
==
CMD_FLASH_ERASE
)
...
@@ -559,13 +563,20 @@ void BAT32A239_MCU_Update(void)
...
@@ -559,13 +563,20 @@ void BAT32A239_MCU_Update(void)
if
(
Step_delayTime
>=
2000
)
if
(
Step_delayTime
>=
2000
)
{
{
ESP_LOGI
(
"MSI"
,
"UpgradeStep : %d Erase Chip timeout
\n
"
,
UpgradeStep
);
ESP_LOGI
(
"MSI"
,
"UpgradeStep : %d Erase Chip timeout
\n
"
,
UpgradeStep
);
UpgradeStep
=
4
;
//超时停止
UpgradeStep
=
5
;
//超时停止
}
}
}
}
if
(
BAT32A239_ACK
.
CMDH
==
CMD_FLASH_DWNLD
)
{
SendCmd_WriteBAT32A239_Flash
();
//下载shou'zhen
UpgradeStep
=
2
;
}
break
;
break
;
case
2
:
case
2
:
//ESP_LOGI("MSI","BAT32A239_ACK.CMDH : %d\n",BAT32A239_ACK.CMDH);
if
(
BAT32A239_ACK
.
CMDH
==
CMD_FLASH_DWNLD
)
if
(
BAT32A239_ACK
.
CMDH
==
CMD_FLASH_DWNLD
)
{
{
//ESP_LOGI("MSI","xxxxxxx");
if
(
BAT32A239_ACK
.
dat
.
download
.
CR1
==
0x01
)
if
(
BAT32A239_ACK
.
dat
.
download
.
CR1
==
0x01
)
{
{
ESP_LOGI
(
"MSI"
,
"Download failed, request to re-download the package"
);
ESP_LOGI
(
"MSI"
,
"Download failed, request to re-download the package"
);
...
@@ -576,9 +587,13 @@ void BAT32A239_MCU_Update(void)
...
@@ -576,9 +587,13 @@ void BAT32A239_MCU_Update(void)
BAT32A239_ACK
.
dat
.
download
.
CR1
=
0xFF
;
BAT32A239_ACK
.
dat
.
download
.
CR1
=
0xFF
;
Write_Counter
+=
Write_Size
;
Write_Counter
+=
Write_Size
;
StartAddr
+=
Write_Size
;
StartAddr
+=
Write_Size
;
if
(
Write_Counter
==
Flash_Size
)
//下载完成
//ESP_LOGI("MSI","Flash_Size : %ld verification OK !\n",Flash_Size);
//ESP_LOGI("MSI","Write_Counter : %ld verification OK !\n",Write_Counter);
if
(
Write_Counter
==
Flash_Size
)
//下载完成
{
{
UpgradeStep
=
3
;
UpgradeStep
=
4
;
Write_Counter
=
0
;
Write_Size
=
0
;
// ESP_LOGI("MSI", " %.2f%%", 100.00);
// ESP_LOGI("MSI", " %.2f%%", 100.00);
ESP_LOGI
(
"MSI"
,
"
\n
UpgradeStep : %d download finished
\n
"
,
UpgradeStep
);
ESP_LOGI
(
"MSI"
,
"
\n
UpgradeStep : %d download finished
\n
"
,
UpgradeStep
);
}
}
...
@@ -586,6 +601,7 @@ void BAT32A239_MCU_Update(void)
...
@@ -586,6 +601,7 @@ void BAT32A239_MCU_Update(void)
{
{
// percent = 100.0 - (double)(Write_Counter * 100) / (double)Flash_Size;
// percent = 100.0 - (double)(Write_Counter * 100) / (double)Flash_Size;
// ESP_LOGI("MSI", " %.2f%%", percent);
// ESP_LOGI("MSI", " %.2f%%", percent);
SendCmd_WriteBAT32A239_Flash
();
//下载进度
SendCmd_WriteBAT32A239_Flash
();
//下载进度
}
}
}
}
...
@@ -601,7 +617,7 @@ void BAT32A239_MCU_Update(void)
...
@@ -601,7 +617,7 @@ void BAT32A239_MCU_Update(void)
}
}
if
(
BAT32A239_ACK
.
dat
.
verification
.
CR1
==
0x00
)
if
(
BAT32A239_ACK
.
dat
.
verification
.
CR1
==
0x00
)
{
{
UpgradeStep
=
4
;
UpgradeStep
=
5
;
ESP_LOGI
(
"MSI"
,
"UpgradeStep : %d verification OK !
\n
"
,
UpgradeStep
);
ESP_LOGI
(
"MSI"
,
"UpgradeStep : %d verification OK !
\n
"
,
UpgradeStep
);
}
}
}
}
...
@@ -612,9 +628,41 @@ void BAT32A239_MCU_Update(void)
...
@@ -612,9 +628,41 @@ void BAT32A239_MCU_Update(void)
//UpgradeStep=9;
//UpgradeStep=9;
break
;
break
;
case
4
:
if
(
BackupDataTotalLen
!=
0
)
{
if
(
DataTotalLen
==
BackupDataTotalLen
)
{
UpgradeStep
=
0
;
}
else
{
UpgradeStep
=
1
;
}
if
(
DataTotalLen
>
MAX_OTA_BUFF
)
{
ESP_LOGI
(
"MSI"
,
"~~~~~~~~~~~~~~~~~~~~~~
\n
"
);
Flash_Size
=
MAX_OTA_BUFF
;
esp_partition_read
(
assert_update_partition
,
StartAddr
-
BackupStartAddr
+
16
,
buf
,
Flash_Size
);
DataTotalLen
-=
Flash_Size
;
}
else
if
(
DataTotalLen
!=
0
)
{
ESP_LOGI
(
"MSI"
,
"!!!!!!!!!!!!!!!!!!!!!!!!!!
\n
"
);
Flash_Size
=
DataTotalLen
;
esp_partition_read
(
assert_update_partition
,
StartAddr
-
BackupStartAddr
+
16
,
buf
,
Flash_Size
);
DataTotalLen
=
0
;
}
else
{
UpgradeStep
=
3
;
}
}
break
;
default:
default:
UpgradeStep
=
4
;
UpgradeStep
=
5
;
break
;
break
;
}
}
...
...
RT200T_2_ESP32/main/main_user.c
View file @
a85cf15e
...
@@ -160,7 +160,7 @@ void app_main(void)
...
@@ -160,7 +160,7 @@ void app_main(void)
printf
(
"KL30 INIT OVER~~~~~~
\r\n
"
);
printf
(
"KL30 INIT OVER~~~~~~
\r\n
"
);
xTaskCreatePinnedToCore
(
Sys_Run_Tasks
,
"Sys_Run_Tasks"
,
4096
,
NULL
,
3
,
Sys_Run_Taskshdl
,
1
);
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
);
xTaskCreatePinnedToCore
(
Upgrade_BAT32A239_Task
,
"Upgrade_BAT32A239_Task"
,
1024
*
4
,
NULL
,
5
,
NULL
,
1
);
}
}
...
...
RT200T_2_ESP32/main/mcudata.c
View file @
a85cf15e
#if 0
const unsigned char _acBAT32A239dat[88016] = {
const unsigned char _acBAT32A239dat[88016] = {
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x70, 0x00, 0x00, 0x01, 0x57, 0xC0,
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,
0xCB, 0x35, 0xDE, 0x23, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x47, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF,
...
@@ -5501,3 +5502,4 @@
...
@@ -5501,3 +5502,4 @@
0x1B, 0x28, 0x23, 0x1C, 0x25, 0x80, 0x3E, 0x74, 0x40, 0x44, 0x48, 0x38, 0x4A, 0xFF, 0x70, 0x09,
0x1B, 0x28, 0x23, 0x1C, 0x25, 0x80, 0x3E, 0x74, 0x40, 0x44, 0x48, 0x38, 0x4A, 0xFF, 0x70, 0x09,
0x12, 0x14, 0x01, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
0x12, 0x14, 0x01, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
};
#endif
\ No newline at end of file
RT200T_2_ESP32/source/wifi/CMakeLists.txt
View file @
a85cf15e
idf_component_register
(
SRCS
"
wifi_service.c"
"softap.c"
"http_server
.c"
idf_component_register
(
SRCS
"
http_server.c"
"wifi_service.c"
"softap
.c"
INCLUDE_DIRS
"."
"../../main"
INCLUDE_DIRS
"."
"../../main"
PRIV_REQUIRES nvs_flash esp_netif esp_wifi esp_http_server app_update driver
PRIV_REQUIRES nvs_flash esp_netif esp_wifi esp_http_server app_update driver
EMBED_FILES
"favicon.ico"
"ota_page.html"
)
EMBED_FILES
"favicon.ico"
"ota_page.html"
)
RT200T_2_ESP32/source/wifi/http_server.c
View file @
a85cf15e
...
@@ -15,7 +15,7 @@ static const char *TAG = "http_server";
...
@@ -15,7 +15,7 @@ static const char *TAG = "http_server";
char
buf
[
MAX_OTA_BUFF
];
// 接收服务端传来的文件缓存, 必须使用全局变量, 否则会触发看门狗复位, 原理未知
char
buf
[
MAX_OTA_BUFF
];
// 接收服务端传来的文件缓存, 必须使用全局变量, 否则会触发看门狗复位, 原理未知
extern
void
Cache_data
(
unsigned
char
*
p
,
uint32_t
len
);
extern
void
Cache_data
(
unsigned
char
*
p
,
uint32_t
len
);
extern
void
SetUpgradeFlashSize
(
uint32_t
size
);
extern
void
SetUpgradeFlashSize
(
uint32_t
size
,
uint32_t
len
);
extern
void
SetUpgradeStart
(
void
);
//初始状态
extern
void
SetUpgradeStart
(
void
);
//初始状态
static
unsigned
char
softap_ota_start
=
0
;
static
unsigned
char
softap_ota_start
=
0
;
...
@@ -204,11 +204,35 @@ static esp_err_t app_post_handler(httpd_req_t *req)
...
@@ -204,11 +204,35 @@ static esp_err_t app_post_handler(httpd_req_t *req)
// httpd_resp_send_chunk(req, NULL, 0);
// httpd_resp_send_chunk(req, NULL, 0);
// return ESP_OK;
// return ESP_OK;
// }
// }
static
void
MSI_Print_mem16
(
size_t
len
,
char
*
buf
)
{
for
(
size_t
i
=
0
;
i
<
len
;
)
{
ESP_LOGI
(
"MSI"
,
"%02xh: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x"
,
i
,
\
buf
[
i
+
0
],
buf
[
i
+
1
],
buf
[
i
+
2
],
buf
[
i
+
3
],
buf
[
i
+
4
],
buf
[
i
+
5
],
buf
[
i
+
6
],
buf
[
i
+
7
],
buf
[
i
+
8
],
buf
[
i
+
9
],
buf
[
i
+
10
],
buf
[
i
+
11
],
buf
[
i
+
12
],
buf
[
i
+
13
],
buf
[
i
+
14
],
buf
[
i
+
15
]);
i
+=
16
;
}
}
/*上传文件名是BAT32A239dat.bin的处理函数*/
/*上传文件名是BAT32A239dat.bin的处理函数*/
static
esp_err_t
nation_post_handler
(
httpd_req_t
*
req
)
static
esp_err_t
nation_post_handler
(
httpd_req_t
*
req
)
{
{
int
recv_block
=
0
;
double
percent
=
0
.
0
;
int
ret
,
remaining
=
req
->
content_len
;
int
ret
,
remaining
=
req
->
content_len
;
int
total
=
remaining
;
int
err_timeout_retry_cnt
=
0
;
size_t
erase_size
=
0
;
size_t
erase_offset
=
0
;
size_t
write_offset
=
0
;
int
Addr
=
0
;
esp_err_t
err
=
ESP_OK
;
const
char
*
partition_label
=
"assert"
;
const
esp_partition_t
*
assert_update_partition
=
esp_partition_find_first
(
ESP_PARTITION_TYPE_DATA
,
ESP_PARTITION_SUBTYPE_ANY
,
partition_label
);
// if (Sys_Run_hdl != NULL)
// if (Sys_Run_hdl != NULL)
// {
// {
...
@@ -217,7 +241,8 @@ static esp_err_t nation_post_handler(httpd_req_t *req)
...
@@ -217,7 +241,8 @@ static esp_err_t nation_post_handler(httpd_req_t *req)
// vTaskDelay(pdMS_TO_TICKS(100));
// vTaskDelay(pdMS_TO_TICKS(100));
// }
// }
SetUpgradeFlashSize
(
remaining
);
// 设定文件大小
//SetUpgradeFlashSize(remaining); // 设定文件大小
ESP_LOGI
(
TAG
,
"---- 国民技术程序文件: 需要接收的数据(byte) = %d"
,
remaining
);
ESP_LOGI
(
TAG
,
"---- 国民技术程序文件: 需要接收的数据(byte) = %d"
,
remaining
);
while
(
remaining
>
0
)
while
(
remaining
>
0
)
{
{
...
@@ -226,25 +251,98 @@ static esp_err_t nation_post_handler(httpd_req_t *req)
...
@@ -226,25 +251,98 @@ static esp_err_t nation_post_handler(httpd_req_t *req)
{
{
if
(
ret
==
HTTPD_SOCK_ERR_TIMEOUT
)
if
(
ret
==
HTTPD_SOCK_ERR_TIMEOUT
)
{
{
/* Retry receiving if timeout occurred */
err_timeout_retry_cnt
++
;
if
(
err_timeout_retry_cnt
>=
MAX_RETRY_COUNT
)
{
httpd_resp_send_408
(
req
);
httpd_resp_send_chunk
(
req
,
NULL
,
0
);
ESP_LOGE
(
TAG
,
"---- 接收数据超时, 退出升级流程, 请保持无线连接稳定后再试."
);
return
ESP_FAIL
;
}
/* else
{
Retry receiving if timeout occurred
continue;
continue;
}*/
}
else
{
ESP_LOGI
(
"MSI"
,
"total : %d
\n
"
,
total
);
ESP_LOGI
(
"MSI"
,
"remaining : %d
\n
"
,
remaining
);
err_timeout_retry_cnt
=
0
;
}
}
}
if
(
total
==
remaining
)
//下载长度+地址
{
Addr
=
0
;
Addr
|=
buf
[
8
];
Addr
<<=
8
;
Addr
|=
buf
[
9
];
Addr
<<=
8
;
Addr
|=
buf
[
10
];
Addr
<<=
8
;
Addr
|=
buf
[
11
];
SetUpgradeFlashSize
(
remaining
,
Addr
);
}
while
(
erase_offset
<
write_offset
+
ret
)
{
err
=
esp_partition_erase_range
(
assert_update_partition
,
erase_offset
,
assert_update_partition
->
erase_size
);
if
(
err
==
ESP_OK
)
{
erase_offset
+=
assert_update_partition
->
erase_size
;
}
else
{
httpd_resp_send_chunk
(
req
,
NULL
,
0
);
//ESP_LOGE(TAG, "---- assert 分区擦除失败(%s), 分区容量 = 0x%x, 偏移地址 = 0x%x, 擦除长度 = 0x%x", esp_err_to_name(err), assert_update_partition->size, erase_offset, assert_update_partition->erase_size);
return
ESP_FAIL
;
return
ESP_FAIL
;
}
}
}
err
=
esp_partition_write
(
assert_update_partition
,
write_offset
,
buf
,
ret
);
if
(
err
==
ESP_OK
)
{
remaining
-=
ret
;
remaining
-=
ret
;
Cache_data
(
&
buf
,
ret
);
write_offset
+=
ret
;
// ESP_LOGI(TAG, "=========== RECEIVED DATA ==========");
recv_block
++
;
// 数据处理代码
if
((
recv_block
%
32
)
==
0
)
// ESP_LOGI(TAG, "====================================");
{
percent
=
100
.
0
-
(
double
)(
remaining
*
100
)
/
(
double
)
total
;
ESP_LOGI
(
TAG
,
"---- 写入数据(%.2f%%), recv_block = %d"
,
percent
,
recv_block
);
}
}
//SetUpgradeStart(); // 启动升级
}
ESP_LOGI
(
TAG
,
"---- 国民技术程序文件: 接收完成"
);
else
// End response
{
httpd_resp_send_chunk
(
req
,
NULL
,
0
);
httpd_resp_send_chunk
(
req
,
NULL
,
0
);
ESP_LOGE
(
TAG
,
"---- assert 分区写数据失败(%s)"
,
esp_err_to_name
(
err
));
return
ESP_FAIL
;
}
// 增加20ms延时, 解决CPU0看门狗超时的问题
vTaskDelay
(
pdMS_TO_TICKS
(
20
));
}
ESP_LOGI
(
TAG
,
"---- write_offset = %d"
,
write_offset
);
if
(
write_offset
==
total
)
{
ESP_LOGI
(
TAG
,
"---- assert 分区更新完成, 1秒后自动重启."
);
vTaskDelay
(
pdMS_TO_TICKS
(
1000
));
}
else
{
httpd_resp_send_chunk
(
req
,
NULL
,
0
);
ESP_LOGE
(
TAG
,
"---- assert 分区更新数据部分丢失"
);
return
ESP_FAIL
;
}
SetUpgradeStart
();
// 启动升级
ESP_LOGI
(
TAG
,
"---- 国民技术程序文件: 接收完成"
);
return
ESP_OK
;
return
ESP_OK
;
}
}
void
Nat32G031_ReqReset
(
void
)
void
Nat32G031_ReqReset
(
void
)
{
{
ESP_LOGI
(
TAG
,
"---- NAT32G031程序更新完成, 3秒后自动重启."
);
ESP_LOGI
(
TAG
,
"---- NAT32G031程序更新完成, 3秒后自动重启."
);
...
...
RT200T_2_ESP32/source/wifi/http_server.h
View file @
a85cf15e
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
#define MAX_OTA_BUFF 4096u
#define MAX_OTA_BUFF 4096u
#define MAX_RETRY_COUNT 5
extern
char
buf
[
MAX_OTA_BUFF
];
extern
char
buf
[
MAX_OTA_BUFF
];
extern
httpd_handle_t
http_server
;
extern
httpd_handle_t
http_server
;
...
@@ -23,8 +25,8 @@ httpd_handle_t http_service(void);
...
@@ -23,8 +25,8 @@ httpd_handle_t http_service(void);
extern
void
delele_tasks
(
void
);
extern
void
delele_tasks
(
void
);
extern
void
Catch_data
(
unsigned
char
*
p
,
uint32_t
len
);
extern
void
Catch_data
(
unsigned
char
*
p
,
uint32_t
len
);
extern
void
SetUpgradeFlashSize
(
uint32_t
size
);
extern
void
SetUpgradeFlashSize
(
uint32_t
size
,
uint32_t
len
);
extern
void
SetUpgradeStart
(
void
);
// ʼ״̬
extern
void
SetUpgradeStart
(
void
);
//
��
ʼ״̬
void
Nat32G031_ReqReset
(
void
);
void
Nat32G031_ReqReset
(
void
);
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment