122 lines
4.6 KiB
C
122 lines
4.6 KiB
C
#include "esp_log.h"
|
|
#include "spiffs.h"
|
|
#include "flasher_tool.h"
|
|
#include "lvgl.h"
|
|
|
|
|
|
static const char *TAG = "main";
|
|
|
|
#define WRITE_BLOCK 64
|
|
|
|
EventGroupHandle_t Flasher_eventGroup;
|
|
|
|
void Flasher_tool_task(void *pvParameter)
|
|
{
|
|
EventBits_t bits;
|
|
Flasher_eventGroup = xEventGroupCreate();
|
|
#if 1
|
|
FILE* f;
|
|
uint8_t* load_buff = NULL;
|
|
const loader_esp32_config_t esp32s2_config = {
|
|
.baud_rate = 1152000,
|
|
.uart_port = UART_NUM_1,
|
|
.uart_rx_pin = GPIO_NUM_5,
|
|
.uart_tx_pin = GPIO_NUM_4,
|
|
.reset_trigger_pin = GPIO_NUM_1,
|
|
.gpio0_trigger_pin = GPIO_NUM_2,
|
|
};
|
|
|
|
if (loader_port_esp32_init(&esp32s2_config) != ESP_LOADER_SUCCESS) {
|
|
ESP_LOGE(TAG, "serial initialization failed.");
|
|
return;
|
|
}
|
|
|
|
while (1)
|
|
{
|
|
bits = xEventGroupWaitBits(Flasher_eventGroup, EVENT_CONNECT | EVENT_BURN_BEGIN,pdFALSE,pdFALSE,portMAX_DELAY);
|
|
if (bits&EVENT_CONNECT) {
|
|
ESP_LOGI(TAG, "connect_to_target initialization ing.");
|
|
lv_obj_t *focused_obj = lv_group_get_focused(lv_group_get_default()); // 获取当前焦点对象
|
|
if (!focused_obj) return;
|
|
printf("发送用户数据\n");
|
|
lv_event_send(focused_obj, LV_EVENT_CUSTOM_UPDATE, (void *)LV_KEY_ESC);
|
|
xEventGroupClearBits(Flasher_eventGroup,EVENT_CONNECT);
|
|
} else if (bits&EVENT_BURN_BEGIN) {
|
|
|
|
if (connect_to_target(1152000) == ESP_LOADER_SUCCESS) {
|
|
|
|
ESP_LOGI(TAG, "connect_to_target initialization success.");
|
|
if(esp_get_free_heap_size() >(WRITE_BLOCK + 20)*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...");
|
|
|
|
f = fopen("/spiffs/target_esp32s3.bin", "rb");
|
|
if (f == NULL) {
|
|
ESP_LOGE(FILE_TAG, "Failed to open file for writing");
|
|
return;
|
|
}
|
|
uint32_t bin_size = off_line_tool.directory[0].size;
|
|
uint32_t write_addr = 0;
|
|
size_t bytesRead;
|
|
while (bin_size)
|
|
{
|
|
if(bin_size > WRITE_BLOCK*1024)
|
|
{
|
|
bytesRead = fread(&load_buff[0],1,WRITE_BLOCK*1024,f);
|
|
if(bytesRead == 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);
|
|
fread(&load_buff[0],1,bin_size,f);
|
|
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;
|
|
}
|
|
}
|
|
fclose(f);
|
|
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{
|
|
ESP_LOGE(TAG, "connect_to_target initialization failed.");
|
|
}
|
|
free(load_buff);
|
|
loader_port_esp32_deinit();
|
|
|
|
xEventGroupClearBits(Flasher_eventGroup,EVENT_BURN_BEGIN);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
vTaskDelete(NULL);
|
|
#endif
|
|
} |