-
Notifications
You must be signed in to change notification settings - Fork 118
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
Comments
@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! |
@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. |
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
You can run |
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. |
Hello@DNedic, so this C source code(https://github.com/espressif/esp-serial-flasher) can achieve burning function? |
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. |
I see that the response to Addiitonally, you could try disconnecting everything except the connection to the PC you are using to flash with |
bootloader.zip |
@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. |
Logic analyzer record.zip |
@Qfeng116 I can't really conclude anything from this logic analyzer trace, there is no response after |
|
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 |
There should be nothing wrong with the raspberry port, what hardware setup are you using? |
I use linux system, mcu is ssd212. |
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. |
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. |
@Qfeng116 We struggle to understand exactly what is your problem and what are you trying to accomplish. Lets clarify a couple of things:
|
@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. |
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. |
@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.
}
} 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. |
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. |
@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. |
@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. |
@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
@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. |
@dobairoland hi,Excuse me, how is the problem going now |
I've left a comment earlier - #91 (comment). We are not working on this anymore. |
在使用官方https://github.com/espressif/esp-serial-flasher的C源码时,实现不了烧录功能。
以下为esp32c3模块串口抓到C源码对其发送的数据流:
上面的图片可以看出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");
cleanup:
fclose(image);
free(buffer);
}
----------------------------------------------------------->
#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;
#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
}
#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;
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;
}
其中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
}
!此处是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,
};
}
其中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;
}
其中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;
}
其中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
};
}
----------------------------------------------------------->
其中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;
}
其中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++,
};
}
----------------------------------------------------------->
其中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;
}
}
以上代码中的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() );
}
附代码:
Uploading esp32-app.zip…
The text was updated successfully, but these errors were encountered: