esp-rs / espflash

Serial flasher utility for Espressif SoCs and modules based on esptool.py
Apache License 2.0
455 stars 110 forks source link

v3 Error while connecting to esp32 #616

Open owenthewizard opened 3 months ago

owenthewizard commented 3 months ago

Flashing a WT32-ETH01, v2 flashes fine and reports:

Chip type:         esp32 (revision v1.0)
Crystal frequency: 40MHz
Flash size:        4MB
Features:          WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None

v3 does not connect:

     Running `espflash flash --monitor --no-stub target/xtensa-esp32-espidf/debug/esp32-wifi-bridge`
[2024-03-14T21:32:46Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-03-14T21:32:46Z INFO ] Connecting...
Error: espflash::connection_failed

  × Error while connecting to device
  ╰─▶ Failed to connect to the device
  help: Ensure that the device is connected and the reset and boot pins are not being held down

Debug logs: https://dpaste.com/F4ANNZZ2S

SergioGasquez commented 3 months ago

Sorry for the inconvenience, the dpaste looks like it has expired, mind pasting the logs here? Have you tried the suggestion of pressing the buttons?

birkenfeld commented 3 months ago

I had the same problem - turns out since I don't have RTS/DTR pins connected and pulled IO0 low myself, I need -b no-reset in espflash v3.

SergioGasquez commented 3 months ago

I had the same problem - turns out since I don't have RTS/DTR pins connected and pulled IO0 low myself, I need -b no-reset in espflash v3.

I guess your scenario was different, since using espflash v2 didn't work either, right?

birkenfeld commented 3 months ago

I guess your scenario was different, since using espflash v2 didn't work either, right?

No, it worked fine. AFAICS v2 doesn't have a before-reset option, so probably it didn't try to do the reset itself?

SergioGasquez commented 3 months ago

No, it worked fine. AFAICS v2 doesn't have a before-reset option, so probably it didn't try to do the reset itself?

Thats correct, mind trying this @owenthewizard?

owenthewizard commented 3 months ago

No, it worked fine. AFAICS v2 doesn't have a before-reset option, so probably it didn't try to do the reset itself?

Thats correct, mind trying this @owenthewizard?

Confirmed, adding --before no-resetresolves the issue. My TTL doesn't have RTS/CTS pins, I'm only using TX, RX, 5V, and GND.

birkenfeld commented 3 months ago

While mine does have RTS and CTS, it doesn't have DTR which I understand would be necessary to use the auto-reset (@SergioGasquez ?) Can there be a mode added to pull IO0 down with RTS?

birkenfeld commented 3 months ago

Scratch that, there also needs to be one for actually resetting the board...

timboldt commented 1 month ago

To add to this, I have an Adafruit Feather ESP32 V2 (ESP32­ Pico ­Mini 02).

P.S. For any other Rust ESP32 newbie's having this issue, you can install 2.1.0 like this cargo install espflash@2.1.0.

hydra commented 1 month ago

note that running espflash -h doesn't show you the arguments so you may be unaware of what arguments you can specify:

$ espflash -h
A command-line tool for flashing Espressif devices

Usage: espflash.exe <COMMAND>

Commands:
  board-info       Print information about a connected target device
  completions      Generate completions for the given shell
  erase-flash      Erase Flash entirely
  erase-parts      Erase specified partitions
  erase-region     Erase specified region
  flash            Flash an application in ELF format to a connected target device
  monitor          Open the serial monitor without flashing the connected target device
  partition-table  Convert partition tables between CSV and binary format
  read-flash       Read SPI flash content
  save-image       Generate a binary application image and save it to a local disk
  write-bin        Write a binary file to a specific address in a target device's flash
  checksum-md5     Calculate the MD5 checksum of the given region
  help             Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

however, if you go espflash monitor -h you'll see more arguments applicable to the monitor command:

$ espflash monitor -h
Open the serial monitor without flashing the connected target device

Usage: espflash.exe monitor [OPTIONS]

Options:
  -a, --after <AFTER>            Reset operation to perform after connecting to the target [default:
                                 hard-reset] [possible values: hard-reset, no-reset,
                                 no-reset-no-stub]
  -B, --baud <BAUD>              Baud rate at which to communicate with target device [env:
                                 ESPFLASH_BAUD=]
  -b, --before <BEFORE>          Reset operation to perform before connecting to the target
                                 [default: default-reset] [possible values: default-reset, no-reset,
                                 no-reset-no-sync, usb-reset]
  -c, --chip <CHIP>              Target device [possible values: esp32, esp32c2, esp32c3, esp32c6,
                                 esp32h2, esp32p4, esp32s2, esp32s3]
  -C, --confirm-port             Require confirmation before auto-connecting to a recognized device
      --list-all-ports           List all available ports
      --no-stub                  Do not use the RAM stub for loading
  -p, --port <PORT>              Serial port connected to target device [env: ESPFLASH_PORT=]
  -e, --elf <FILE>               Optional file name of the ELF image to load the symbols from
      --non-interactive          Avoids asking the user for interactions like resetting the device
  -L, --log-format <LOG_FORMAT>  Logging format [default: serial] [possible values: defmt, serial]
  -h, --help                     Print help (see more with '--help')
  -V, --version                  Print version

same applies to the flash command:

$ espflash flash -h
Flash an application in ELF format to a connected target device

Usage: espflash.exe flash [OPTIONS] <IMAGE>

Arguments:
  <IMAGE>  ELF image to flash

Options:
  -a, --after <AFTER>
          Reset operation to perform after connecting to the target [default: hard-reset] [possible
          values: hard-reset, no-reset, no-reset-no-stub]
  -B, --baud <BAUD>
          Baud rate at which to communicate with target device [env: ESPFLASH_BAUD=]
  -b, --before <BEFORE>
          Reset operation to perform before connecting to the target [default: default-reset]
          [possible values: default-reset, no-reset, no-reset-no-sync, usb-reset]
  -c, --chip <CHIP>
          Target device [possible values: esp32, esp32c2, esp32c3, esp32c6, esp32h2, esp32p4,
          esp32s2, esp32s3]
  -C, --confirm-port
          Require confirmation before auto-connecting to a recognized device
      --list-all-ports
          List all available ports
      --no-stub
          Do not use the RAM stub for loading
  -p, --port <PORT>
          Serial port connected to target device [env: ESPFLASH_PORT=]
  -f, --flash-freq <FREQ>
          Flash frequency [possible values: 12mhz, 15mhz, 16mhz, 20mhz, 24mhz, 26mhz, 30mhz, 40mhz,
          48mhz, 60mhz, 80mhz]
  -m, --flash-mode <MODE>
          Flash mode to use [possible values: qio, qout, dio, dout]
  -s, --flash-size <SIZE>
          Flash size of the target [possible values: 256kb, 512kb, 1mb, 2mb, 4mb, 8mb, 16mb, 32mb,
          64mb, 128mb, 256mb]
      --bootloader <FILE>
          Path to a binary (.bin) bootloader file
      --erase-parts <LABELS>
          Erase partitions by label
      --erase-data-parts <PARTS>
          Erase specified data partitions
  -L, --log-format <LOG_FORMAT>
          Logging format [default: serial] [possible values: defmt, serial]
      --min-chip-rev <MIN_CHIP_REV>
          Minimum chip revision supported by image, in format: major.minor [default: 0.0]
  -M, --monitor
          Open a serial monitor after flashing
      --monitor-baud <BAUD>
          Baud rate at which to read console output
      --partition-table <FILE>
          Path to a CSV file containing partition table
      --target-app-partition <LABEL>
          Label of target app partition
      --partition-table-offset <OFFSET>
          Partition table offset
      --ram
          Load the application to RAM instead of Flash
      --no-verify
          Don't verify the flash contents after flashing
      --no-skip
          Don't skip flashing of parts with matching checksum
  -h, --help
          Print help (see more with '--help')
  -V, --version
          Print version

I didn't spot this in the documentation and ended up at this issue, I too have my own custom board with only IO0, TX, RX, 5V, GND and was getting:

Error: espflash::connection_failed  

  × Error while connecting to device
  ╰─▶ Failed to connect to the device
  help: Ensure that the device is connected and the reset and boot pins are not being held down

Using espflash monitor --before no-reset allowed be to connect.

Hope this helps.