实现脱机烧录器功能
This commit is contained in:
parent
98dfc91e52
commit
663827d6a2
118
main/main.c
118
main/main.c
@ -72,7 +72,7 @@ static void echo_task(void *arg)
|
|||||||
|
|
||||||
// Write data back to the USB SERIAL JTAG
|
// Write data back to the USB SERIAL JTAG
|
||||||
if (len) {
|
if (len) {
|
||||||
// usb_serial_jtag_write_bytes((const char *) data, len, 20 / portTICK_PERIOD_MS);
|
usb_serial_jtag_write_bytes((const char *) data, len, 20 / portTICK_PERIOD_MS);
|
||||||
// uart_write_bytes(EX_UART_NUM, (const char *) data, len);
|
// uart_write_bytes(EX_UART_NUM, (const char *) data, len);
|
||||||
data[len] = '\0';
|
data[len] = '\0';
|
||||||
ESP_LOG_BUFFER_HEXDUMP("Recv str: ", data, len, ESP_LOG_INFO);
|
ESP_LOG_BUFFER_HEXDUMP("Recv str: ", data, len, ESP_LOG_INFO);
|
||||||
@ -196,10 +196,10 @@ void app_main(void)
|
|||||||
err = nvs_flash_init(); // 重新初始化
|
err = nvs_flash_init(); // 重新初始化
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(err);
|
ESP_ERROR_CHECK(err);
|
||||||
ESP_ERROR_CHECK(esp_netif_init());
|
// ESP_ERROR_CHECK(esp_netif_init());
|
||||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
|
|
||||||
init_spiffs();
|
// init_spiffs();
|
||||||
ESPFlash_Init();
|
ESPFlash_Init();
|
||||||
ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
||||||
gpio_config_t config = {
|
gpio_config_t config = {
|
||||||
@ -209,7 +209,7 @@ void app_main(void)
|
|||||||
};
|
};
|
||||||
gpio_config(&config);
|
gpio_config(&config);
|
||||||
gpio_set_level(8,0);
|
gpio_set_level(8,0);
|
||||||
gpio_set_level(7,1);
|
// gpio_set_level(18,1);
|
||||||
/* Configure parameters of an UART driver,
|
/* Configure parameters of an UART driver,
|
||||||
* communication pins and install the driver */
|
* communication pins and install the driver */
|
||||||
uart_config_t uart_config = {
|
uart_config_t uart_config = {
|
||||||
@ -228,47 +228,103 @@ void app_main(void)
|
|||||||
//Create a task to handler UART event from ISR
|
//Create a task to handler UART event from ISR
|
||||||
// xTaskCreate(uart_event_task, "uart_event_task", 2048*10, NULL, 12, NULL);
|
// xTaskCreate(uart_event_task, "uart_event_task", 2048*10, NULL, 12, NULL);
|
||||||
|
|
||||||
home_html.html_data = load_html2Ram(home_html);
|
// home_html.html_data = load_html2Ram(home_html);
|
||||||
wifi_config_html.html_data = load_html2Ram(wifi_config_html);
|
// wifi_config_html.html_data = load_html2Ram(wifi_config_html);
|
||||||
upload_ota_html.html_data = load_html2Ram(upload_ota_html);
|
// upload_ota_html.html_data = load_html2Ram(upload_ota_html);
|
||||||
// favicon_ico.html_data = load_html2Ram(favicon_ico);
|
// // favicon_ico.html_data = load_html2Ram(favicon_ico);
|
||||||
// ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
// // ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
||||||
// ESP_LOGI(TAG,"def_name:%s",Sys_wifi_config.def_AP_Name);
|
// // ESP_LOGI(TAG,"def_name:%s",Sys_wifi_config.def_AP_Name);
|
||||||
ESP_LOGI(TAG,"sizeof--Sys_wifi_config:%d",sizeof(wifi_Save_info_t));
|
// ESP_LOGI(TAG,"sizeof--Sys_wifi_config:%d",sizeof(wifi_Save_info_t));
|
||||||
Read_ESPFlash(0x40,0,&Sys_wifi_config,sizeof(wifi_Save_info_t));
|
// Read_ESPFlash(0x40,0,&Sys_wifi_config,sizeof(wifi_Save_info_t));
|
||||||
ESP_LOGI(TAG,"wifi_ssid:%s",Sys_wifi_config.wifi_ssid);
|
// ESP_LOGI(TAG,"wifi_ssid:%s",Sys_wifi_config.wifi_ssid);
|
||||||
ESP_LOGI(TAG,"wifi_password:%s",Sys_wifi_config.wifi_password);
|
// ESP_LOGI(TAG,"wifi_password:%s",Sys_wifi_config.wifi_password);
|
||||||
if(Sys_wifi_config.wifi_mode != 0x55)
|
// // if(Sys_wifi_config.wifi_mode != 0x55)
|
||||||
{
|
// {
|
||||||
wifi_init_softap();
|
// wifi_init_softap();
|
||||||
}else{
|
// }else{
|
||||||
wifi_init_station();
|
// wifi_init_station();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// while (1)
|
||||||
|
// {
|
||||||
|
// vTaskDelay(1000/ portTICK_PERIOD_MS);
|
||||||
|
// }
|
||||||
|
|
||||||
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
||||||
start_web_server();
|
// start_web_server();
|
||||||
// xTaskCreate(tcp_server_task, "tcp_server", 4096, (void*)AF_INET, 5, NULL);
|
// xTaskCreate(tcp_server_task, "tcp_server", 4096, (void*)AF_INET, 5, NULL);
|
||||||
ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
||||||
|
// Document_feeder_test();
|
||||||
|
#if 1
|
||||||
|
|
||||||
#if 0
|
uint8_t* load_buff = NULL;
|
||||||
const loader_esp32_config_t config = {
|
const loader_esp32_config_t esp32c3_config = {
|
||||||
.baud_rate = 115200,
|
.baud_rate = 1152000,
|
||||||
.uart_port = UART_NUM_1,
|
.uart_port = UART_NUM_0,
|
||||||
.uart_rx_pin = GPIO_NUM_5,
|
.uart_rx_pin = GPIO_NUM_20,
|
||||||
.uart_tx_pin = GPIO_NUM_4,
|
.uart_tx_pin = GPIO_NUM_21,
|
||||||
.reset_trigger_pin = GPIO_NUM_2,
|
.reset_trigger_pin = GPIO_NUM_9,
|
||||||
.gpio0_trigger_pin = GPIO_NUM_1,
|
.gpio0_trigger_pin = GPIO_NUM_2,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (loader_port_esp32_init(&config) != ESP_LOADER_SUCCESS) {
|
if (loader_port_esp32_init(&esp32c3_config) != ESP_LOADER_SUCCESS) {
|
||||||
ESP_LOGE(TAG, "serial initialization failed.");
|
ESP_LOGE(TAG, "serial initialization failed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connect_to_target(230400) == ESP_LOADER_SUCCESS) {
|
if (connect_to_target(1152000) == ESP_LOADER_SUCCESS) {
|
||||||
|
|
||||||
ESP_LOGI(TAG, "connect_to_target initialization success.");
|
ESP_LOGI(TAG, "connect_to_target initialization success.");
|
||||||
|
if(esp_get_free_heap_size() >200*1024)
|
||||||
|
{
|
||||||
|
load_buff = malloc(WRITE_BLOCK*1024+24);
|
||||||
|
if(load_buff == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(esp_loader_get_target() == ESP32S3_CHIP)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG,"Find ESP32S3");
|
||||||
|
ESP_LOGI(TAG, "Loading bin...");
|
||||||
|
// flash_binary()
|
||||||
|
uint32_t bin_size = 749504;
|
||||||
|
uint32_t write_addr = 0;
|
||||||
|
while (bin_size)
|
||||||
|
{
|
||||||
|
if(bin_size > WRITE_BLOCK*1024)
|
||||||
|
{
|
||||||
|
if(Read_ESPFlash(0x45,write_addr,&load_buff[0],WRITE_BLOCK*1024) == WRITE_BLOCK*1024)
|
||||||
|
{
|
||||||
|
flash_binary(&load_buff[0],WRITE_BLOCK*1024,write_addr);
|
||||||
|
write_addr+=WRITE_BLOCK*1024;
|
||||||
|
bin_size -= WRITE_BLOCK*1024;
|
||||||
|
ESP_LOGI(TAG,"Load : %ld --- %ld",write_addr,bin_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
Read_ESPFlash(0x45,write_addr,&load_buff[0],bin_size);
|
||||||
|
flash_binary(&load_buff[0],bin_size,write_addr);
|
||||||
|
write_addr += bin_size;
|
||||||
|
bin_size = 0;
|
||||||
|
ESP_LOGI(TAG,"Load : %ld --- %ld",write_addr,bin_size);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ESP_LOGI(TAG, "Loading bin success");
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Done!");
|
||||||
|
esp_loader_reset_target();
|
||||||
|
|
||||||
|
// Delay for skipping the boot message of the targets
|
||||||
|
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
// Forward slave's serial output
|
||||||
|
ESP_LOGI(TAG, "********************************************");
|
||||||
|
ESP_LOGI(TAG, "*** Logs below are print from slave .... ***");
|
||||||
|
ESP_LOGI(TAG, "********************************************");
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
ESP_LOGE(TAG, "connect_to_target initialization failed.");
|
ESP_LOGE(TAG, "connect_to_target initialization failed.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,6 +55,30 @@ def write_flash(directory, base_address=0x2D1000, port="COM11", baud=460800):
|
|||||||
print("Flashing command:", flash_cmd)
|
print("Flashing command:", flash_cmd)
|
||||||
esptool.main(flash_cmd)
|
esptool.main(flash_cmd)
|
||||||
|
|
||||||
|
def flash_file(chip, port, baud, address, file_path):
|
||||||
|
"""使用 esptool.main 烧录指定文件到 ESP32"""
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
print(f"文件未找到: {file_path}")
|
||||||
|
return
|
||||||
|
|
||||||
|
flash_cmd = [
|
||||||
|
"--chip", "esp32c3",
|
||||||
|
"--port", port,
|
||||||
|
"--baud", str(baud),
|
||||||
|
"write_flash", "--force", "-z", hex(address), file_path
|
||||||
|
]
|
||||||
|
|
||||||
|
print("正在烧录,命令:", flash_cmd)
|
||||||
|
esptool.main(flash_cmd)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
directory = r"D:\\esp\\WorkSpace\\esp32c3-usb_serial\\main\\wifi\\www"
|
# directory = r"D:\\esp\\WorkSpace\\esp32c3-usb_serial\\main\\wifi\\www"
|
||||||
write_flash(directory)
|
# write_flash(directory)
|
||||||
|
|
||||||
|
chip = "esp32c3"
|
||||||
|
port = "COM11"
|
||||||
|
baud = 460800
|
||||||
|
address = 0x2e1000 # 修改为你的烧录地址
|
||||||
|
file_path = r"D:\esp\WorkSpace\esp32c3-usb_serial\tools\target_esp32s3.bin" # 修改为你的文件路径
|
||||||
|
|
||||||
|
flash_file(chip, port, baud, address, file_path)
|
||||||
Loading…
Reference in New Issue
Block a user