Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

官方c源码实现烧录功能未能成功 (ESF-104) #91

Closed
Qfeng116 opened this issue Dec 13, 2023 · 28 comments
Closed

官方c源码实现烧录功能未能成功 (ESF-104) #91

Qfeng116 opened this issue Dec 13, 2023 · 28 comments

Comments

@Qfeng116
Copy link

在使用官方https://github.com/espressif/esp-serial-flasher的C源码时,实现不了烧录功能。
以下为esp32c3模块串口抓到C源码对其发送的数据流:
数据流对比描述1
数据流对比描述2
数据流对比描述3
数据流对比描述4
上面的图片可以看出pc端的烧录工具和C源码烧录功能串口发出的数据流是有一定差距的。
以下为C源码的使用过程:

传入的filepath为"../binaries/bin_1027/bootloader.bin"
int espmcu_loader(const char* filepath)
{
int ret = 0;
ret = upload_file(filepath, 0x0);
return ret;
}
----------------------------------------------------------->
static int upload_file(const char *path, size_t address)
{
char *buffer = NULL;
FILE *image = fopen(path, "rb");

if (image == NULL) {

    return -1;
}

fseek(image, 0L, SEEK_END);
size_t size = ftell(image);
rewind(image);

buffer = (char *)malloc(size);

if (buffer == NULL) {
    printf("Error: Failed allocate memory\n");
    goto cleanup;
}

// copy file content to buffer
size_t bytes_read = fread(buffer, 1, size, image);

if (bytes_read != size) {
    printf("Error occurred while reading file");
    goto cleanup;
}

flash_binary((const uint8_t *)buffer, size, address);

cleanup:
fclose(image);
free(buffer);

return 0;

}
----------------------------------------------------------->
#ifdef SERIAL_FLASHER_INTERFACE_UART
esp_loader_error_t flash_binary(const uint8_t *bin, size_t size, size_t address)
{
esp_loader_error_t err;
static uint8_t payload[1024]; //2048->1024
const uint8_t *bin_addr = bin;

err = esp_loader_flash_start(address, size, sizeof(payload));

if (err != ESP_LOADER_SUCCESS) {
    printf("Erasing flash failed with error %d.\n", err);
    return err;
}
    printf("Start programming\n");
size_t binary_size = size;
size_t written = 0;

while (size > 0) {
    size_t to_read = MIN(size, sizeof(payload));
    memcpy(payload, bin_addr, to_read);
  err = esp_loader_flash_write(payload, to_read);
    if (err != ESP_LOADER_SUCCESS) {
        printf("\nPacket could not be written! Error %d.\n", err);
        return err;
    }
    size -= to_read;
    bin_addr += to_read;
    written += to_read;
    int progress = (int)(((float)written / binary_size) * 100);
    printf("\rProgress: %d %%\n", progress);
    fflush(stdout);
};

printf("\nFinished programming\n");

#ifdef MD5_ENABLED
err = esp_loader_flash_verify();
if (err == ESP_LOADER_ERROR_UNSUPPORTED_FUNC) {
printf("ESP8266 does not support flash verify command.");
return err;
} else if (err != ESP_LOADER_SUCCESS) {
printf("MD5 does not match. err: %d\n", err);
return err;
}
printf("Flash verified\n");
#endif

return ESP_LOADER_SUCCESS;

}
#endif /* SERIAL_FLASHER_INTERFACE_UART */

其中flash_binary的esp_loader_flash_start:
esp_loader_error_t esp_loader_flash_start(uint32_t offset, uint32_t image_size, uint32_t block_size)
{
s_flash_write_size = block_size;
size_t flash_size = 0;

if (detect_flash_size(&flash_size) == ESP_LOADER_SUCCESS) {

    if (image_size > flash_size) {
        return ESP_LOADER_ERROR_IMAGE_SIZE;
    }
    loader_port_start_timer(DEFAULT_TIMEOUT);

  RETURN_ON_ERROR( loader_spi_parameters(flash_size) );

} else {
    loader_port_debug_print("Flash size detection failed, falling back to default");
}

init_md5(offset, image_size);

bool encryption_in_cmd = encryption_in_begin_flash_cmd(s_target);

const uint32_t erase_size = calc_erase_size(esp_loader_get_target(), offset, image_size);

const uint32_t blocks_to_write = (image_size + block_size - 1) / block_size;

const uint32_t erase_region_timeout_per_mb = 10000;
loader_port_start_timer(timeout_per_mb(erase_size, erase_region_timeout_per_mb));

return loader_flash_begin_cmd(offset, erase_size, block_size, blocks_to_write, encryption_in_cmd);
}

其中esp_loader_flash_start的detect_flash_size:
static esp_loader_error_t detect_flash_size(size_t *flash_size)
{
uint32_t flash_id = 0;
RETURN_ON_ERROR( spi_flash_command(SPI_FLASH_READ_ID, NULL, 0, &flash_id, 24) );
uint32_t size_id = flash_id >> 16;

if (size_id < 0x12 || size_id > 0x18) {
    return ESP_LOADER_ERROR_UNSUPPORTED_CHIP;
}
*flash_size = 1 << size_id;

return ESP_LOADER_SUCCESS;

}

其中detect_flash_size的spi_flash_command:
static esp_loader_error_t spi_flash_command(spi_flash_cmd_t cmd, void *data_tx, size_t tx_size, void *data_rx, size_t rx_size)
{
assert(rx_size <= 32); // Reading more than 32 bits back from a SPI flash operation is unsupported
assert(tx_size <= 64); // Writing more than 64 bytes of data with one SPI command is unsupported

uint32_t SPI_USR_CMD  = (1 << 31);
uint32_t SPI_USR_MISO = (1 << 28);
uint32_t SPI_USR_MOSI = (1 << 27);
uint32_t SPI_CMD_USR  = (1 << 18);

uint32_t CMD_LEN_SHIFT = 28;//28
uint32_t CMD_LEN_SHIFTb = 28;//28

// Save SPI configuration
uint32_t old_spi_usr;
uint32_t old_spi_usr2;
RETURN_ON_ERROR( esp_loader_read_register(s_reg->usr, &old_spi_usr) );

RETURN_ON_ERROR( esp_loader_read_register(s_reg->usr2, &old_spi_usr2) );

if (s_target == ESP8266_CHIP) {
    RETURN_ON_ERROR( spi_set_data_lengths_8266(tx_size, rx_size) );
} else {
    RETURN_ON_ERROR( spi_set_data_lengths(tx_size, rx_size) );
}

uint32_t usr_reg_2 = (7 << CMD_LEN_SHIFT) | cmd;
uint32_t usr_reg = SPI_USR_CMD;

if (rx_size > 0) {
    usr_reg |= SPI_USR_MISO;
}
if (tx_size > 0) {
    usr_reg |= SPI_USR_MOSI;
}

RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr, usr_reg) );
RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr2, usr_reg_2 ) );

if (tx_size == 0) {
    // clear data register before we read it
    RETURN_ON_ERROR( esp_loader_write_register(s_reg->w0, 0) );
} else {
    uint32_t *data = (uint32_t *)data_tx;
    uint32_t words_to_write = (tx_size + 31) / (8 * 4);
    uint32_t data_reg_addr = s_reg->w0;
    while (words_to_write--) {
        uint32_t word = *data++;
        RETURN_ON_ERROR( esp_loader_write_register(data_reg_addr, word) );
        data_reg_addr += 4;
    }
}

RETURN_ON_ERROR( esp_loader_write_register(s_reg->cmd, SPI_CMD_USR) );

uint32_t trials = 10;
while (trials--) {
    uint32_t cmd_reg;
    RETURN_ON_ERROR( esp_loader_read_register(s_reg->cmd, &cmd_reg) );
    if ((cmd_reg & SPI_CMD_USR) == 0) {
        break;
    }
}

if (trials == 0) {
    return ESP_LOADER_ERROR_TIMEOUT;
}

RETURN_ON_ERROR( esp_loader_read_register(s_reg->w0, data_rx) );

// Restore SPI configuration
RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr, old_spi_usr) );
RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr2, old_spi_usr2) );

return ESP_LOADER_SUCCESS;

}

!此处是C源码与pc端烧录工具发送串口数据流的差异点,C源码走完该函数后直接发


其中esp_loader_flash_start的loader_spi_parameters:
esp_loader_error_t loader_spi_parameters(uint32_t total_size)
{
write_spi_command_t spi_cmd = {
.common = {
.direction = WRITE_DIRECTION,
.command = SPI_SET_PARAMS,
.size = 24,
.checksum = 0
},
.id = 0,
.total_size = total_size,
.block_size = 64 * 1024,
.sector_size = 4 * 1024,
.page_size = 0x100,
.status_mask = 0xFFFF,
};

return send_cmd(&spi_cmd, sizeof(spi_cmd), NULL);

}

其中esp_loader_flash_start的init_md5:
static inline void init_md5(uint32_t address, uint32_t size)
{
s_start_address = address;
s_image_size = size;
MD5Init(&s_md5_context);
}

其中init_md5的MD5Init:
void MD5Init(struct MD5Context *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476;

ctx->bits[0] = 0;
ctx->bits[1] = 0;

}

其中esp_loader_flash_start的encryption_in_begin_flash_cmd:
bool encryption_in_begin_flash_cmd(const target_chip_t target)
{
return esp_target[target].encryption_in_begin_flash_cmd;
}

其中esp_loader_flash_start的calc_erase_size:
static uint32_t calc_erase_size(const target_chip_t target, const uint32_t offset,const uint32_t image_size)
{
if (target != ESP8266_CHIP) {
return image_size;
} else {
/* Needed to fix a bug in the ESP8266 ROM */
const uint32_t sectors_per_block = 16U;
const uint32_t sector_size = 4096U;

    const uint32_t num_sectors = (image_size + sector_size - 1) / sector_size;
    const uint32_t start_sector = offset / sector_size;

    uint32_t head_sectors = sectors_per_block - (start_sector % sectors_per_block);

    /* The ROM bug deletes extra num_sectors if we don't cross the block boundary
       and extra head_sectors if we do */
    if (num_sectors <= head_sectors) {
        return ((num_sectors + 1) / 2) * sector_size;
    } else {
        return (num_sectors - head_sectors) * sector_size;
    }
}

}

其中esp_loader_flash_start的loader_flash_begin_cmd:
esp_loader_error_t loader_flash_begin_cmd(uint32_t offset,uint32_t erase_size,uint32_t block_size,uint32_t blocks_to_write,bool encryption)
{
flash_begin_command_t flash_begin_cmd = {
.common = {
.direction = WRITE_DIRECTION,
.command = FLASH_BEGIN,
.size = CMD_SIZE(flash_begin_cmd) - (encryption ? 0 : sizeof(uint32_t)),
.checksum = 0
},
.erase_size = erase_size,
.packet_count = blocks_to_write,
.packet_size = block_size,
.offset = offset,
.encrypted = 0
};

s_sequence_number = 0;
return send_cmd(&flash_begin_cmd,sizeof(flash_begin_cmd) - (encryption ? 0 : sizeof(uint32_t)),NULL);

}
----------------------------------------------------------->
其中flash_binary的esp_loader_flash_write:
esp_loader_error_t esp_loader_flash_write(void *payload, uint32_t size)
{
uint32_t padding_bytes = s_flash_write_size - size;
uint8_t *data = (uint8_t *)payload;
uint32_t padding_index = size;

if (size > s_flash_write_size) {
    return ESP_LOADER_ERROR_INVALID_PARAM;
}
const uint8_t padding_pattern = 0xFF;
while (padding_bytes--) {
    data[padding_index++] = padding_pattern;
}
md5_update(payload, (size + 3) & ~3);

/*loader_port_start_timer(DEFAULT_TIMEOUT);
return loader_flash_data_cmd(data, s_flash_write_size);*/

unsigned int attempt = 0;
    esp_loader_error_t result = ESP_LOADER_ERROR_FAIL;
    do {
        loader_port_start_timer(DEFAULT_TIMEOUT);
        result = loader_flash_data_cmd(data, s_flash_write_size);
        attempt++;
    } while (result != ESP_LOADER_SUCCESS && attempt < SERIAL_FLASHER_WRITE_BLOCK_RETRIES);

    return result;

}

其中esp_loader_flash_write的md5_update:
static inline void md5_update(const uint8_t *data, uint32_t size)
{
MD5Update(&s_md5_context, data, size);
}

其中esp_loader_flash_write的loader_flash_data_cmd:
esp_loader_error_t loader_flash_data_cmd(const uint8_t *data, uint32_t size)
{
data_command_t data_cmd = {
.common = {
.direction = WRITE_DIRECTION,
.command = FLASH_DATA,
.size = CMD_SIZE(data_cmd) + size,
.checksum = compute_checksum(data, size)
},
.data_size = size,
.sequence_number = s_sequence_number++,
};

return send_cmd_with_data(&data_cmd, sizeof(data_cmd), data, size);

}
----------------------------------------------------------->
其中flash_binary的esp_loader_flash_verify:
esp_loader_error_t esp_loader_flash_verify(void)
{
if (s_target == ESP8266_CHIP) {
return ESP_LOADER_ERROR_UNSUPPORTED_FUNC;
}

uint8_t raw_md5[16] = {0};

/* Zero termination and new line character require 2 bytes */
uint8_t hex_md5[MD5_SIZE + 2] = {0};
uint8_t received_md5[MD5_SIZE + 2] = {0};

md5_final(raw_md5);
hexify(raw_md5, hex_md5);

loader_port_start_timer(timeout_per_mb(s_image_size, MD5_TIMEOUT_PER_MB));

RETURN_ON_ERROR( loader_md5_cmd(s_start_address, s_image_size, received_md5) );

bool md5_match = memcmp(hex_md5, received_md5, MD5_SIZE) == 0;

if (!md5_match) {
    hex_md5[MD5_SIZE] = '\n';
    received_md5[MD5_SIZE] = '\n';

    loader_port_debug_print("Error: MD5 checksum does not match:\n");
    loader_port_debug_print("Expected:\n");
    loader_port_debug_print((char *)received_md5);
    loader_port_debug_print("Actual:\n");
    loader_port_debug_print((char *)hex_md5);

    return ESP_LOADER_ERROR_INVALID_MD5;
}

return ESP_LOADER_SUCCESS;

}

以上代码中的send_cmd:
esp_loader_error_t send_cmd(const void *cmd_data, uint32_t size, uint32_t *reg_value)
{
response_t response;
command_t command = ((const command_common_t *)cmd_data)->command;
RETURN_ON_ERROR( SLIP_send_delimiter() );
RETURN_ON_ERROR( SLIP_send((const uint8_t *)cmd_data, size));
RETURN_ON_ERROR( SLIP_send_delimiter() );

//return check_response(command, reg_value, &response, sizeof(response));

const uint8_t response_cnt = command == SYNC ? 8 : 1;

    for (uint8_t recv_cnt = 0; recv_cnt < response_cnt; recv_cnt++) {
        RETURN_ON_ERROR(check_response(command, reg_value, &response, sizeof(response)));
    }

    return ESP_LOADER_SUCCESS;

}

附代码:
Uploading esp32-app.zip…

@igrr igrr transferred this issue from espressif/esptool-js Dec 13, 2023
@github-actions github-actions bot changed the title 官方c源码实现烧录功能未能成功 官方c源码实现烧录功能未能成功 (ESF-104) Dec 13, 2023
@dobairoland
Copy link
Collaborator

@Qfeng116 Can you please help to translate the issue report to English? I'm sorry for the inconvenience but we cannot put into a translator software the screenshots. Thank you for understanding!

@Qfeng116
Copy link
Author

@dobairoland ok,my friend, thank you for your reply. The following is the translation corresponding to the screenshot, and the blue small character near the Chinese character on the screenshot is the corresponding translation.1.
C源代码发送串行数据流C source code sent serial data flow
PC刻录工具发送串行数据流PC burning toolSend serial data flow
C源代码没发,PC有发C source code did not send, PC has sent
源代码后发送的刻录命令命令是错误的C source code sent the burning command after the command is wrong
这部分命令试图转换代码中的数据以模仿pc发送的数据,但不确定这种转换数据的方式本身是否不适用于其他芯片或bin升级固件This section of the command attempts to convert data in the code to imitate the data sent by the pc, but it is not sure whether this way of converting data by itself will not be applicable to another chip or bin upgrade firmware
2.
C源码发的串口数据流C source code sent serial data flow
PC烧录工具发的串口数据流PC burning tool sent serial data flow
发命令读写完寄存器后,PC烧录工具还发了一段READ REG命令,不确定其作用After the command is finished reading and writing the register, the PC burning tool also sends a READ REG command, unsure of its role
3.
C源码发的串口数据流C source code sent serial data flow
PC烧录工具发的串口数据流PC burning tool sent serial data flow
C源码后续没有发与PC端相类似的命令了C source code did not send a similar command with the PC terminal
发完上图提到的一段后,发的命令应该是解析bin文件包After sending the paragraph mentioned above, the command sent should be parsing binDocument case
发SPI_FLASH_MD5命令Send the SPI_FLASH_MD5 command
继续解析Continue to analyze
4.
C源码发的串口数据流C source code sent serial data flow
PC烧录工具发的串口数据流PC burning tool sent serial data flow
最后发烧录命令Finally send the burn command
Translated graph.zip

@DNedic
Copy link
Contributor

DNedic commented Dec 14, 2023

Hello @Qfeng116 , after taking a look at the issue it is not clear to me what problem you are facing and what you're comparing the data stream with. I presume you are comparing it to esptool flashing, and in that case keep in mind esptool at the moment works quite differently, namely:

  1. It uses the GET_SECURITY_INFO command whereas we do not yet
  2. It uploads the flasher stub to RAM, after which flashing is usually done with the binary being compressed while we do not support compressed binaries
  3. The flasher stub has it's own commands which the boot rom does not support
  4. esptool handles SPI attach and parameter setting differently
  5. Probably more things I didn't think of

You can run esptool with the --no-stub argument to get a more similar flashing procedure that only talks to the Boot ROM, but regardless, it would be useful to get both RX and TX logs of the failing flashing process, so we can get to the bottom of the issue.

@Qfeng116
Copy link
Author

Hello @DNedic ,thank u for the response.Let me add a further description of the problem I face.The data stream of the pc burning tool is to burn the esp32c3 module using the PC burning tool flash_download_tool_3.9.5. After connecting the burning line to be connected, pull out two lines to observe and record the data stream received by the rx and tx serial ports. C source code burning function after the release of the data flow is also obtained through the two lines of rx, tx observation.
52153ce54d502b341958a44e702b04b
afe175c5d42b60d65402019f529fb16
30820192a2a5d9a487a37d7d663f506
242ed04dd7b8f2565271cf8eadf432b

22ccd0bc632d2b168b7ae60003a7696

@Qfeng116
Copy link
Author

Hello@DNedic, so this C source code(https://github.com/espressif/esp-serial-flasher) can achieve burning function?

@Qfeng116
Copy link
Author

Hello@DNedic ,Can you provide the c source code that can realize the burn function, so that I can directly merge the burn function? I want to explore the efficiency of implementing this function is too low, and the uncertainty is too high, which is not conducive to the later maintenance of the function.

@DNedic
Copy link
Contributor

DNedic commented Dec 14, 2023

I see that the response to FLASH_START is an unknown error, failed is set to 1 but the error code is not set. Perhaps you could provide the binary so we can try to reproduce the issue?

Addiitonally, you could try disconnecting everything except the connection to the PC you are using to flash with esp-serial-flasher, just in case. And if you have a logic analyzer trace, it might help us as well.

@Qfeng116
Copy link
Author

bootloader.zip
Ok, the above is the burned bin file, the pc side of the esp-serial-flasher can be burned normally regardless of whether there is an additional set of rx, tx wiring.

@DNedic
Copy link
Contributor

DNedic commented Dec 14, 2023

@Qfeng116 I have successfully flashed the file you attached with the ESP port, there seems to be nothing wrong with it, it looks like the issue is most likely in your port (Qt on Windows I assume from your provided screenshots).

If you can, please provide a logic analyzer trace of the data transferred, it could give us more clues.

@Qfeng116
Copy link
Author

Logic analyzer record.zip
@DNedic Above is my code click burn function after the logic analyzer to grab the transmission data record.The port I used was preset. I also tried to copy the serial port data stream directly and send it to the module for simulation and verification at the same time, and compared whether the returned serial port data stream was consistent with strcmp before sending the next data stream. Through the above method, I successfully simulated the erasure function, because the serial port data stream received and received by the erasure function was roughly unchanged. And there's not a lot of data flow. However, if the same way on the burning function will not work, the burning function of the data stream is huge, and change the bin file to burn the data stream will also change.

@DNedic
Copy link
Contributor

DNedic commented Dec 15, 2023

@Qfeng116 I can't really conclude anything from this logic analyzer trace, there is no response after FLASH_BEGIN and the previous commands did not error out.

@Qfeng116
Copy link
Author

a60a8cbec88a6f9551edd4a09d3bb25
@DNedic Yes, this is strange, and after sending FLASH_BEGIN, the module returns a data stream with error codes.

@Qfeng116
Copy link
Author

Hello@DNedic ,May I ask if there is something wrong with the process of my C source code, I use the example of Raspberry PI in the following linkhttps://github.com/espressif/esp-serial-flasher

@DNedic
Copy link
Contributor

DNedic commented Dec 18, 2023

There should be nothing wrong with the raspberry port, what hardware setup are you using?

@Qfeng116
Copy link
Author

I use linux system, mcu is ssd212.

@Qfeng116
Copy link
Author

Hello@DNedic ,maybe you are not very clear about my problem now, is this, I want to do a burn function: you can upgrade the esp32c3 through the MCU, just like on Windows QT screenshot click burn button, will start to perform the burn function (module will enter burn mode in advance). However, I failed to implement the functionality with the sample code and wondered if there was something wrong with my program flow. At present, I want to implement the function in the QT simulation on Windows first, if it is realized, the function will be moved to the overall code call, and after triggering the burn buttom, the software will pull the module to enter the upgrade mode required pins, and then execute the burn function.

@Qfeng116
Copy link
Author

Hello@DNedic, perhaps I have not described enough, if you need to provide more information, please let me know, I will do my best to provide.

@dobairoland
Copy link
Collaborator

@Qfeng116 We struggle to understand exactly what is your problem and what are you trying to accomplish.

Lets clarify a couple of things:

  1. What kind of burn function do you want to implement? This might be just a misunderstanding in terminology but we usually refer to burning of eFuses. Please correct me if I'm wrong but you want to flash regular flash chip. Nothing more fancy.
  2. Please don't try to reproduce by your code the communication of the Serial Flasher Tool. As it was pointed out by @DNedic, the communication is quite different in comparison with esp-serial-flasher. If you take the https://github.com/espressif/esp-serial-flasher/tree/master/examples/raspberry_example project then it will use the esp-serial-flasher library which implements all the necessary communication. You don't have to implement it by yourself.
  3. If you try to do something which is not supported by esp-serial-flasher then please describe it clearly, i.e. what should that "burning function" do?
  4. If esp-serial-flasher is not behaving as it should then please describe the situation clearly. We need in this case what you are trying to accomplish and how does esp-serial-flasher behaving instead. We will need in this case the complete communication trace of the esp-serial-flasher project (not that of the Serial Flasher Tool).

@Qfeng116
Copy link
Author

@dobairoland The feature I want to implement is a c code interface to upgrade the new firmware for the esp32c3. I can give this code the address of the bin file I want to upgrade, and this code burns the bin file into the esp32c3.

@dobairoland
Copy link
Collaborator

The feature I want to implement is a c code interface to upgrade the new firmware for the esp32c3. I can give this code the address of the bin file I want to upgrade, and this code burns the bin file into the esp32c3.

You don't have to implement that by yourself. Everything is shown in this example how to do it: https://github.com/espressif/esp-serial-flasher/tree/master/examples/raspberry_example

Moreover, @DNedic have confirmed earlier that he could flash the BIN file you provided earlier.

So where is the issue? Does the RPI example liked above updated with your binary fail at any steps? If yes then please provide the full console output and the trace capturing this communication.

@Qfeng116
Copy link
Author

@dobairoland I used this example, but since I was using qt read and write instead of Raspberry PI read and write, I also preset the baud rate and port, as shown in the image below, click Connect and then click Close to enter the Erase Burn button interface.
1703234492862
There is no loader_port_enter_bootloader() on the overall code process because my external hardware is already in burn mode.
The serial read and write functions SendData(), ReadData() and wait_read () are defined below:
void SerialTool::SendData(const char* data,int length)
{
QByteArray send_data;
for(int i=0; i<length; i++)
{
send_data.append(data[i]);
}

qDebug() << "Send Data:" << send_data.toHex() << "-Length:" << send_data.size();
emit serial_send(send_data);

}
//=========================line between==========================
int SerialTool::ReadData(char* data,qint64 maxlen)
{
return m_serial->ReadPort(data,maxlen);
}
int SerialPortQt::ReadPort(char* data,qint64 maxlen)
{
int length = -1;

if(RecvCall != NULL)
{
   return -1;
}

length = recdata.size();

if((length < maxlen)||(length <=0 ))
{
    endflag=1;
    return -1;
}

for(int i = 0; i<maxlen; i++)
{
   data[i] = recdata[i];
   cnt++;
}
cnt=0;
length = maxlen;
recdata.remove(0,length);

return length;

}
//=========================line between==========================
int SerialTool::wait_read(int delay)
{
m_serial->waitms(delay);
return 0;
}
void SerialPortQt::waitms(int delay)
{
port->waitForReadyRead(delay);
}
bool waitForReadyRead(int msecs = 30000) override;
//=========================line between==========================

In short, the code is similar to the example code, but I can only compare the errors in the code steps through serial data stream. As can be seen from the following figure, after my code completes loader_flash_begin_cmd(), check_response() returns an error code, and it is an unknown error. So I'm not sure what went wrong with the steps, because the steps are the same as in the sample code.
a60a8cbec88a6f9551edd4a09d3bb25

@dobairoland
Copy link
Collaborator

Ok, I think I understand the situation now. The confusion was caused because we assumed that something is wrong with esp-serial-flasher. But instead you have trouble with your own Qt-based application.

I'm regret to tell you that we cannot help with that. We have limited resources and we have to use them to fix issues and implement new features in esp-serial-flasher. As I stated before, if you demonstrate an issue with it then we are happy to return to. But until then I'm closing this issue. I'm sorry.

@Qfeng116
Copy link
Author

@dobairoland But my qt send and receive data is no problem, otherwise it can not use the direct data stream to achieve the erasure function.

@Qfeng116
Copy link
Author

@dobairoland I want to know whether my rewrite the https://github.com/espressif/esp-serial-flasher code is wrong, because I there is no question of qt on serial port to send and receive data.

@Qfeng116
Copy link
Author

@dobairoland Maybe you didn't get the message,my qt send and receive data is no problem, otherwise it can not use the direct data stream to achieve the erasure function.I want to know whether my rewrite the https://github.com/espressif/esp-serial-flasher code is wrong, because I there is no question of qt on serial port to send and receive data.

1 similar comment
@Qfeng116
Copy link
Author

@dobairoland Maybe you didn't get the message,my qt send and receive data is no problem, otherwise it can not use the direct data stream to achieve the erasure function.I want to know whether my rewrite the https://github.com/espressif/esp-serial-flasher code is wrong, because I there is no question of qt on serial port to send and receive data.

@zrb2002
Copy link

zrb2002 commented Jan 23, 2024

@dobairoland hi,Excuse me, how is the problem going now

@dobairoland
Copy link
Collaborator

I've left a comment earlier - #91 (comment). We are not working on this anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants