esp-rs / esp-flasher-stub

Rust implementation of flasher stub located in esptool
Apache License 2.0
18 stars 10 forks source link

Flashing an S3 with baud rate higher than 115,200 causes a timeout #49

Closed AnthonyGrondin closed 5 months ago

AnthonyGrondin commented 5 months ago

I'm running the same flash command, with --baud 921600, and it used to work previously, (IE in v2.1.0) but it is now returning a timeout error.

With v2.1.0 (expected result):

     Running `espflash flash --port /dev/ttyUSB1 --baud 921600 --monitor target/xtensa-esp32s3-none-elf/release/my_app`
[2024-02-27T19:59:58Z INFO ] 🚀 A new version of espflash is available: v3.0.0-rc.1
[2024-02-27T19:59:58Z INFO ] Serial port: '/dev/ttyUSB1'
[2024-02-27T19:59:58Z INFO ] Connecting...
[2024-02-27T19:59:59Z INFO ] Using flash stub
[2024-02-27T19:59:59Z WARN ] Setting baud rate higher than 115,200 can cause issues
Chip type:         esp32s3 (revision v0.1)
Crystal frequency: 40MHz
Flash size:        8MB
Features:          WiFi, BLE
MAC address:       7c:df:a1:e2:5a:0c
App/part. size:    982,864/8,323,072 bytes, 11.81%
[00:00:00] [========================================]      14/14      0x0                                                                                                                        
[00:00:00] [========================================]       1/1       0x8000                                                                                                                     
[00:00:15] [========================================]     599/599     0x10000                                                                                                                    
[2024-02-27T20:00:16Z INFO ] Flashing has completed!
Commands:
    CTRL+R    Reset chip
    CTRL+C    Exit

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 
...

With v3.0.0-rc.1 (bug: timeout):

     Running `espflash flash --port /dev/ttyUSB1 --baud 921600 --monitor target/xtensa-esp32s3-none-elf/release/my_app`
[2024-02-27T20:01:50Z INFO ] Serial port: '/dev/ttyUSB1'
[2024-02-27T20:01:50Z INFO ] Connecting...
[2024-02-27T20:01:51Z INFO ] Using flash stub
[2024-02-27T20:01:52Z WARN ] Setting baud rate higher than 115,200 can cause issues
Error: espflash::timeout

  × Error while connecting to device
  ╰─▶ Timeout while running ChangeBaudrate command

...
SergioGasquez commented 5 months ago

Hi! Thanks for reporting this issue. I just did a quick try and I was able to reproduce it. It looks like a stub issue as using --no-stub solves the issue. Here are the debug logs using the stub:

[2024-02-27T20:25:44Z WARN ] Setting baud rate higher than 115,200 can cause issues
[2024-02-27T20:25:44Z DEBUG] Change baud to: 921600
[2024-02-27T20:25:44Z DEBUG] Writing command: ChangeBaudrate { new_baud: 921600, prior_baud: 115384 }
Error: espflash::timeout

  × Error while connecting to device
  ╰─▶ Timeout while running ChangeBaudrate command

The prio_baud looks a bit weird to me.

When trying the same command for an ESP32-C3, the command succeeds:

❯ espflash flash  --baud 921600 --monitor target/riscv32imc-unknown-none-elf/debug/esp32c3
[2024-02-27T20:30:54Z INFO ] Serial port: '/dev/ttyACM0'
[2024-02-27T20:30:54Z INFO ] Connecting...
[2024-02-27T20:30:54Z INFO ] Using flash stub
[2024-02-27T20:30:54Z WARN ] Setting baud rate higher than 115,200 can cause issues
Chip type:         esp32c3 (revision v0.3)
Crystal frequency: 40 MHz
Flash size:        4MB
Features:          WiFi, BLE
MAC address:       60:55:f9:c0:39:7c
App/part. size:    223,248/4,128,768 bytes, 5.41%
[2024-02-27T20:30:54Z INFO ] Segment at address '0x0' has not changed, skipping write
[2024-02-27T20:30:54Z INFO ] Segment at address '0x8000' has not changed, skipping write
[2024-02-27T20:30:54Z INFO ] Segment at address '0x10000' has not changed, skipping write
[2024-02-27T20:30:55Z INFO ] Flashing has completed!
SergioGasquez commented 5 months ago

A bit more of information, I've regenerated the S3 stub with current main of esp-flasher-stub, enabling dprints and the stubs receives the change baud command:

process command: ChangeBaudrate
                 Waiting for command

So, either we are not processing the ChangeBaudrate command properly in the stub or espflash is not reading the OHAI response properly

I will be on vacations for the rest of the week! Will take a look at it as soon as I come back!

SergioGasquez commented 5 months ago

Moved this issue from espflash repo. Using espflash 3.0.0-rc.1 with --no-stub or the C stub works fine.

SergioGasquez commented 5 months ago
SergioGasquez commented 5 months ago

Important update: Seems like the issue does not affect all the S3 targets. Some folks are able to flash different S3 devkits while changing the baudrate. Even the same devkit (ESP32-S3-DevKitC-1 v1.0) works for some people and does not work for others.

I've also tested using different wires/computers and the results, for me, are the same, ESP32-S3-DevKitC-1 v1.0 does not work

SergioGasquez commented 5 months ago

Hi @AnthonyGrondin, I think I found the issue, could you try the following branch and see if it solves the issue for you?

cargo install espflash --git https://github.com/SergioGasquez/espflash --branch fix/s3-stub --force
AnthonyGrondin commented 5 months ago

I've tried with the updated espflash origin/main and it fixes the issue. Thanks for taking care of this.