支持从文件系统中取文件用于烧录其它设备
This commit is contained in:
parent
6bc617180c
commit
6bc162fc44
@ -3,7 +3,7 @@ file(GLOB PORT_SRCS "wifi/*.c" )
|
|||||||
|
|
||||||
file(GLOB FILE_SYS_SRCS "file_system/spiffs.c" "file_system/file_encryptor.c" )
|
file(GLOB FILE_SYS_SRCS "file_system/spiffs.c" "file_system/file_encryptor.c" )
|
||||||
|
|
||||||
idf_component_register(SRCS "main.c" "usb_serial_task" "Receiver.c"
|
idf_component_register(SRCS "main.c" "usb_serial_task" "Receiver.c" "flasher_tool.c"
|
||||||
${PORT_SRCS}
|
${PORT_SRCS}
|
||||||
${FILE_SYS_SRCS}
|
${FILE_SYS_SRCS}
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
|
|||||||
124
main/flasher_tool.c
Normal file
124
main/flasher_tool.c
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
#include "public.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "spiffs.h"
|
||||||
|
|
||||||
|
static const char *TAG = "main";
|
||||||
|
|
||||||
|
#define WRITE_BLOCK 64
|
||||||
|
|
||||||
|
void Flasher_tool_task(void *pvParameter)
|
||||||
|
{
|
||||||
|
#if 1
|
||||||
|
FILE* f;
|
||||||
|
uint8_t* load_buff = NULL;
|
||||||
|
const loader_esp32_config_t esp32c3_config = {
|
||||||
|
.baud_rate = 1152000,
|
||||||
|
.uart_port = UART_NUM_1,
|
||||||
|
.uart_rx_pin = GPIO_NUM_20,
|
||||||
|
.uart_tx_pin = GPIO_NUM_21,
|
||||||
|
.reset_trigger_pin = GPIO_NUM_9,
|
||||||
|
.gpio0_trigger_pin = GPIO_NUM_2,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (loader_port_esp32_init(&esp32c3_config) != ESP_LOADER_SUCCESS) {
|
||||||
|
ESP_LOGE(TAG, "serial initialization failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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...");
|
||||||
|
// flash_binary()
|
||||||
|
#if 0
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
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);
|
||||||
|
#endif
|
||||||
|
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();
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
106
main/main.c
106
main/main.c
@ -40,7 +40,6 @@
|
|||||||
#include "public.h"
|
#include "public.h"
|
||||||
#include "esp_flash.h"
|
#include "esp_flash.h"
|
||||||
|
|
||||||
#define WRITE_BLOCK 64
|
|
||||||
|
|
||||||
static const char *TAG = "main";
|
static const char *TAG = "main";
|
||||||
|
|
||||||
@ -94,8 +93,18 @@ void app_main(void)
|
|||||||
gpio_config(&config);
|
gpio_config(&config);
|
||||||
gpio_set_level(8,0);
|
gpio_set_level(8,0);
|
||||||
// gpio_set_level(18,1);
|
// gpio_set_level(18,1);
|
||||||
|
|
||||||
|
// gpio_config_t input_config = {
|
||||||
|
// .mode = GPIO_MODE_INPUT,
|
||||||
|
// .pin_bit_mask = 1ULL << 9 | 1ULL << 2,
|
||||||
|
// .pull_up_en = 1
|
||||||
|
// };
|
||||||
|
// gpio_config(&input_config);
|
||||||
|
|
||||||
|
|
||||||
usb_serial2Uart(NULL);
|
usb_serial2Uart(NULL);
|
||||||
xTaskCreate(&Read_CMD_task, "Read_CMD_task", 1024*20, NULL, 14, NULL);
|
xTaskCreate(&Read_CMD_task, "Read_CMD_task", 1024*20, NULL, 14, NULL);
|
||||||
|
xTaskCreate(&Flasher_tool_task, "Flasher_tool_task", 1024*20, NULL, 10, NULL);
|
||||||
#if 0
|
#if 0
|
||||||
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);
|
||||||
@ -115,19 +124,6 @@ void app_main(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// FILE* f = fopen("/spiffs/hello.txt", "w");
|
|
||||||
// if (f == NULL) {
|
|
||||||
// printf("Failed to open file for writing\n");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// fprintf(f, "Hello World!\n");
|
|
||||||
// fclose(f);
|
|
||||||
|
|
||||||
// f = fopen("/spiffs/hello.txt", "r");
|
|
||||||
// char line[64];
|
|
||||||
// fgets(line, sizeof(line), f);
|
|
||||||
// fclose(f);
|
|
||||||
// printf("Read from file: '%s'\n", line);
|
|
||||||
|
|
||||||
esp_flash_t *chip = esp_flash_default_chip;
|
esp_flash_t *chip = esp_flash_default_chip;
|
||||||
esp_err_t ret = esp_flash_read_id(chip, &off_line_tool.flash_id);
|
esp_err_t ret = esp_flash_read_id(chip, &off_line_tool.flash_id);
|
||||||
@ -158,82 +154,16 @@ void app_main(void)
|
|||||||
// 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 0
|
|
||||||
|
|
||||||
uint8_t* load_buff = NULL;
|
while (1)
|
||||||
const loader_esp32_config_t esp32c3_config = {
|
{
|
||||||
.baud_rate = 1152000,
|
// if(gpio_get_level(GPIO_NUM_9) == 0 || gpio_get_level(GPIO_NUM_2) == 0)
|
||||||
.uart_port = UART_NUM_0,
|
// {
|
||||||
.uart_rx_pin = GPIO_NUM_20,
|
// ESP_LOGI(TAG,"BOOT Down");
|
||||||
.uart_tx_pin = GPIO_NUM_21,
|
// }
|
||||||
.reset_trigger_pin = GPIO_NUM_9,
|
// ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
||||||
.gpio0_trigger_pin = GPIO_NUM_2,
|
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
||||||
};
|
|
||||||
|
|
||||||
if (loader_port_esp32_init(&esp32c3_config) != ESP_LOADER_SUCCESS) {
|
|
||||||
ESP_LOGE(TAG, "serial initialization failed.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connect_to_target(1152000) == ESP_LOADER_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{
|
|
||||||
ESP_LOGE(TAG, "connect_to_target initialization failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
loader_port_esp32_deinit();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -53,4 +53,6 @@ extern stream_data_t uart_interface_data;
|
|||||||
|
|
||||||
extern void usb_serial2Uart(void *pvParameters);
|
extern void usb_serial2Uart(void *pvParameters);
|
||||||
extern void Read_CMD_task(void *pvParameter);
|
extern void Read_CMD_task(void *pvParameter);
|
||||||
|
extern void Flasher_tool_task(void *pvParameter);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -43,7 +43,7 @@ static void echo_task(void *arg)
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
vTaskDelay(10/ portTICK_PERIOD_MS);
|
vTaskDelay(10/ portTICK_PERIOD_MS);
|
||||||
len = usb_serial_jtag_read_bytes(data, 0, 200 / portTICK_PERIOD_MS);//刷新流控
|
len = usb_serial_jtag_read_bytes(data, 0, 200 / portTICK_PERIOD_MS);//刷新流控
|
||||||
if(frameStreamRecEmptyLen(&uart_interface_data) > 1024*6)
|
if(frameStreamRecEmptyLen(&uart_interface_data) > 1024*6)
|
||||||
{
|
{
|
||||||
// ESP_LOGE(TAG,"frameStream: %ld",frameStreamRecEmptyLen(&uart_interface_data));
|
// ESP_LOGE(TAG,"frameStream: %ld",frameStreamRecEmptyLen(&uart_interface_data));
|
||||||
@ -157,9 +157,11 @@ static void uart_event_task(void *pvParameters)
|
|||||||
stream_data_t usb_interface_data;
|
stream_data_t usb_interface_data;
|
||||||
void usb_serial2Uart(void *pvParameters)
|
void usb_serial2Uart(void *pvParameters)
|
||||||
{
|
{
|
||||||
stream_init(&usb_interface_data,1024*20);
|
// stream_init(&usb_interface_data,1024*20);
|
||||||
/* Configure parameters of an UART driver,
|
/* Configure parameters of an UART driver,
|
||||||
* communication pins and install the driver */
|
* communication pins and install the driver */
|
||||||
|
|
||||||
|
#if 0
|
||||||
uart_config_t uart_config = {
|
uart_config_t uart_config = {
|
||||||
.baud_rate = 115200,
|
.baud_rate = 115200,
|
||||||
.data_bits = UART_DATA_8_BITS,
|
.data_bits = UART_DATA_8_BITS,
|
||||||
@ -172,8 +174,9 @@ void usb_serial2Uart(void *pvParameters)
|
|||||||
//Install UART driver, and get the queue.
|
//Install UART driver, and get the queue.
|
||||||
uart_driver_install(UART_NUM_1, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
|
uart_driver_install(UART_NUM_1, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
|
||||||
uart_param_config(UART_NUM_1, &uart_config);
|
uart_param_config(UART_NUM_1, &uart_config);
|
||||||
xTaskCreate(echo_task, "USB SERIAL JTAG_echo_task", ECHO_TASK_STACK_SIZE, NULL, 20, NULL);
|
|
||||||
//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);
|
||||||
|
#endif
|
||||||
|
xTaskCreate(echo_task, "USB SERIAL JTAG_echo_task", ECHO_TASK_STACK_SIZE, NULL, 20, NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user