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

Cannot flash before flashing with Arduino #651

Closed
victorbnl opened this issue Jul 12, 2024 · 1 comment
Closed

Cannot flash before flashing with Arduino #651

victorbnl opened this issue Jul 12, 2024 · 1 comment

Comments

@victorbnl
Copy link

victorbnl commented Jul 12, 2024

Issue

I can flash a program onto my ESP32 once or twice with espflash, but after that, even if the chip is in download mode, it fails with the following message.

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

Then, without changing anything, when I try flashing the BareMinimum example with the Arduino IDE (esptool.py), it succeeds flashing. After that, if I restart the ESP32 in download mode, espflash successfully flashes the chip again.

Edit: It seems to happen that espflash still does not work after flashing with esptool.py. Though more often than not, after flashing with esptool.py, it works.

Reproduce

  1. Flash any program onto the ESP32
  2. Reboot to flash mode
  3. Try to flash again. If that works, go to step 1. After a second try, it shouldn’t work anymore.

Context

  • Device: Ai Thinker ESP32 CAM
  • Target: xtensa-esp32-espidf
  • Flash command: espflash flash --monitor
  • Template: esp-idf-template

Logs

Cargo fail debug output
    Finished `dev` profile [optimized + debuginfo] target(s) in 0.08s
     Running `espflash flash --monitor target/cargo/xtensa-esp32-espidf/debug/laser-server`
[2024-07-12T06:52:39Z DEBUG] Flash(
        FlashArgs {
            connect_args: ConnectArgs {
                after: HardReset,
                baud: None,
                before: DefaultReset,
                chip: None,
                confirm_port: false,
                list_all_ports: false,
                no_stub: false,
                port: None,
            },
            flash_config_args: FlashConfigArgs {
                flash_freq: None,
                flash_mode: None,
                flash_size: None,
            },
            flash_args: FlashArgs {
                erase_parts: None,
                erase_data_parts: None,
                log_format: Serial,
                monitor: true,
                monitor_baud: None,
                ram: false,
                no_verify: false,
                no_skip: false,
                image: ImageArgs {
                    bootloader: None,
                    partition_table: None,
                    partition_table_offset: None,
                    target_app_partition: None,
                    min_chip_rev: 0,
                },
            },
            image: "target/cargo/xtensa-esp32-espidf/debug/laser-server",
        },
    )
[2024-07-12T06:52:39Z DEBUG] connecting to crates.io:443 at 18.164.52.114:443
[2024-07-12T06:52:39Z DEBUG] No cached session for DnsName("crates.io")
[2024-07-12T06:52:39Z DEBUG] Not resuming any session
[2024-07-12T06:52:39Z DEBUG] Using ciphersuite TLS13_AES_128_GCM_SHA256
[2024-07-12T06:52:39Z DEBUG] Not resuming
[2024-07-12T06:52:39Z DEBUG] TLS1.3 encrypted extensions: [ServerNameAck]
[2024-07-12T06:52:39Z DEBUG] ALPN protocol is None
[2024-07-12T06:52:39Z DEBUG] created stream: Stream(RustlsStream)
[2024-07-12T06:52:39Z DEBUG] sending request GET https://crates.io/api/v1/crates/espflash/versions
[2024-07-12T06:52:39Z DEBUG] writing prelude: GET /api/v1/crates/espflash/versions HTTP/1.1
    Host: crates.io
    User-Agent: ureq/2.9.6
    Accept: */*
    accept-encoding: gzip
[2024-07-12T06:52:39Z DEBUG] Chunked body in response
[2024-07-12T06:52:39Z DEBUG] response 200 to GET https://crates.io/api/v1/crates/espflash/versions
[2024-07-12T06:52:40Z DEBUG] dropping stream: Stream(RustlsStream)
[2024-07-12T06:52:40Z DEBUG] Config: Config {
        baudrate: None,
        bootloader: None,
        connection: Connection {
            serial: None,
        },
        partition_table: None,
        usb_device: [
            UsbDevice {
                vid: 1027,
                pid: 24577,
            },
        ],
        flash: FlashSettings {
            mode: None,
            size: None,
            freq: None,
        },
        save_path: "/home/victor/.config/espflash/espflash.toml",
    }
[2024-07-12T06:52:40Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-07-12T06:52:40Z INFO ] Connecting...
[2024-07-12T06:52:40Z DEBUG] Using UnixTight reset strategy with delay of 50ms
[2024-07-12T06:52:40Z DEBUG] Failed to reset, error Connection(
        Timeout(
            TimedOutCommand {
                command: None,
            },
        ),
    ), retrying
[2024-07-12T06:52:40Z DEBUG] Using UnixTight reset strategy with delay of 500ms
[2024-07-12T06:52:40Z DEBUG] Failed to reset, error Connection(
        Timeout(
            TimedOutCommand {
                command: None,
            },
        ),
    ), retrying
[2024-07-12T06:52:40Z DEBUG] Using Classic reset strategy with delay of 50ms
[2024-07-12T06:52:40Z DEBUG] Failed to reset, error Connection(
        Timeout(
            TimedOutCommand {
                command: None,
            },
        ),
    ), retrying
[2024-07-12T06:52:40Z DEBUG] Using Classic reset strategy with delay of 500ms
[2024-07-12T06:52:41Z DEBUG] Failed to reset, error Connection(
        Timeout(
            TimedOutCommand {
                command: None,
            },
        ),
    ), retrying
[2024-07-12T06:52:41Z DEBUG] Using UnixTight reset strategy with delay of 50ms
[2024-07-12T06:52:41Z DEBUG] Failed to reset, error Connection(
        Timeout(
            TimedOutCommand {
                command: None,
            },
        ),
    ), retrying
[2024-07-12T06:52:41Z DEBUG] Using UnixTight reset strategy with delay of 500ms
[2024-07-12T06:52:42Z DEBUG] Failed to reset, error Connection(
        Timeout(
            TimedOutCommand {
                command: None,
            },
        ),
    ), retrying
[2024-07-12T06:52:42Z DEBUG] Using Classic reset strategy with delay of 50ms
[2024-07-12T06:52:42Z DEBUG] Failed to reset, error Connection(
        Timeout(
            TimedOutCommand {
                command: None,
            },
        ),
    ), retrying
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
Cargo success output
    Finished `dev` profile [optimized + debuginfo] target(s) in 0.08s
     Running `espflash flash --monitor target/cargo/xtensa-esp32-espidf/debug/laser-server`
[2024-07-12T07:11:52Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-07-12T07:11:52Z INFO ] Connecting...
[2024-07-12T07:11:52Z INFO ] Using flash stub
Chip type:         esp32 (revision v3.1)
Crystal frequency: 40 MHz
Flash size:        4MB
Features:          WiFi, BT, Dual Core, 240MHz, Coding Scheme None
MAC address:       d8:13:2a:c2:0c:f0
App/part. size:    1,081,952/4,128,768 bytes, 26.21%
[00:00:01] [========================================]      17/17      0x1000                                            
[00:00:00] [========================================]       1/1       0x8000                                            
[00:01:07] [========================================]     641/641     0x10000                                           [2024-07-12T07:13:05Z INFO ] Flashing has completed!
Commands:
    CTRL+R    Reset chip
    CTRL+C    Exit
Cargo success debug output
   Compiling laser-server v0.1.0 (/home/victor/dev/emballages-maquet/laser-server)
    Finished `dev` profile [optimized + debuginfo] target(s) in 3.15s
     Running `espflash flash --monitor target/cargo/xtensa-esp32-espidf/debug/laser-server`
[2024-07-12T07:15:31Z DEBUG] Flash(
        FlashArgs {
            connect_args: ConnectArgs {
                after: HardReset,
                baud: None,
                before: DefaultReset,
                chip: None,
                confirm_port: false,
                list_all_ports: false,
                no_stub: false,
                port: None,
            },
            flash_config_args: FlashConfigArgs {
                flash_freq: None,
                flash_mode: None,
                flash_size: None,
            },
            flash_args: FlashArgs {
                erase_parts: None,
                erase_data_parts: None,
                log_format: Serial,
                monitor: true,
                monitor_baud: None,
                ram: false,
                no_verify: false,
                no_skip: false,
                image: ImageArgs {
                    bootloader: None,
                    partition_table: None,
                    partition_table_offset: None,
                    target_app_partition: None,
                    min_chip_rev: 0,
                },
            },
            image: "target/cargo/xtensa-esp32-espidf/debug/laser-server",
        },
    )
[2024-07-12T07:15:31Z DEBUG] connecting to crates.io:443 at 18.164.52.58:443
[2024-07-12T07:15:31Z DEBUG] No cached session for DnsName("crates.io")
[2024-07-12T07:15:31Z DEBUG] Not resuming any session
[2024-07-12T07:15:31Z DEBUG] Using ciphersuite TLS13_AES_128_GCM_SHA256
[2024-07-12T07:15:31Z DEBUG] Not resuming
[2024-07-12T07:15:31Z DEBUG] TLS1.3 encrypted extensions: [ServerNameAck]
[2024-07-12T07:15:31Z DEBUG] ALPN protocol is None
[2024-07-12T07:15:31Z DEBUG] created stream: Stream(RustlsStream)
[2024-07-12T07:15:31Z DEBUG] sending request GET https://crates.io/api/v1/crates/espflash/versions
[2024-07-12T07:15:31Z DEBUG] writing prelude: GET /api/v1/crates/espflash/versions HTTP/1.1
    Host: crates.io
    User-Agent: ureq/2.9.6
    Accept: */*
    accept-encoding: gzip
[2024-07-12T07:15:32Z DEBUG] Chunked body in response
[2024-07-12T07:15:32Z DEBUG] response 200 to GET https://crates.io/api/v1/crates/espflash/versions
[2024-07-12T07:15:32Z DEBUG] dropping stream: Stream(RustlsStream)
[2024-07-12T07:15:32Z DEBUG] Config: Config {
        baudrate: None,
        bootloader: None,
        connection: Connection {
            serial: None,
        },
        partition_table: None,
        usb_device: [
            UsbDevice {
                vid: 1027,
                pid: 24577,
            },
        ],
        flash: FlashSettings {
            mode: None,
            size: None,
            freq: None,
        },
        save_path: "/home/victor/.config/espflash/espflash.toml",
    }
[2024-07-12T07:15:32Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-07-12T07:15:32Z INFO ] Connecting...
[2024-07-12T07:15:32Z DEBUG] Using UnixTight reset strategy with delay of 50ms
[2024-07-12T07:15:32Z DEBUG] Writing command: Sync
[2024-07-12T07:15:32Z DEBUG] Writing command: Sync
[2024-07-12T07:15:32Z DEBUG] Writing command: Sync
[2024-07-12T07:15:32Z DEBUG] Writing command: ReadReg { address: 1073745920 }
[2024-07-12T07:15:32Z INFO ] Using flash stub
[2024-07-12T07:15:32Z DEBUG] Loading flash stub for chip: Esp32
[2024-07-12T07:15:32Z DEBUG] Write 12884 byte stub text
[2024-07-12T07:15:32Z DEBUG] Writing command: MemBegin { size: 12884, blocks: 3, block_size: 6144, offset: 1074266112, supports_encryption: false }
...
[2024-07-12T07:15:33Z DEBUG] Write 468 byte stub data
[2024-07-12T07:15:33Z DEBUG] Writing command: MemBegin { size: 468, blocks: 1, block_size: 6144, offset: 1073414144, supports_encryption: false }
...
[2024-07-12T07:15:33Z DEBUG] Finish stub write
[2024-07-12T07:15:33Z DEBUG] Writing command: MemEnd { no_entry: false, entry: 1074274996 }
[2024-07-12T07:15:33Z DEBUG] Stub written!
[2024-07-12T07:15:33Z DEBUG] Writing command: ReadReg { address: 1073745920 }
[2024-07-12T07:15:33Z DEBUG] Re-detected chip: Esp32
[2024-07-12T07:15:33Z DEBUG] Attempting flash enable with: SpiAttachParams { clk: 0, q: 0, d: 0, hd: 0, cs: 0 }
[2024-07-12T07:15:33Z DEBUG] Writing command: SpiAttachStub { spi_params: SpiAttachParams { clk: 0, q: 0, d: 0, hd: 0, cs: 0 } }
[2024-07-12T07:15:33Z DEBUG] Writing command: ReadReg { address: 1072963612 }
[2024-07-12T07:15:33Z DEBUG] Writing command: ReadReg { address: 1072963620 }
[2024-07-12T07:15:33Z DEBUG] Writing command: WriteReg { address: 1072963612, value: 2415919104, mask: None }
[2024-07-12T07:15:33Z DEBUG] Writing command: WriteReg { address: 1072963620, value: 1879048351, mask: None }
[2024-07-12T07:15:33Z DEBUG] Writing command: WriteReg { address: 1072963628, value: 23, mask: None }
[2024-07-12T07:15:34Z DEBUG] Writing command: WriteReg { address: 1072963712, value: 0, mask: None }
[2024-07-12T07:15:34Z DEBUG] Writing command: WriteReg { address: 1072963584, value: 262144, mask: None }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1072963612 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1072963712 }
[2024-07-12T07:15:34Z DEBUG] Writing command: WriteReg { address: 1072963612, value: 2147483712, mask: None }
[2024-07-12T07:15:34Z DEBUG] Writing command: WriteReg { address: 1072963620, value: 1879048192, mask: None }
[2024-07-12T07:15:34Z DEBUG] Flash detect OK!
[2024-07-12T07:15:34Z DEBUG] Writing command: SpiSetParams { spi_params: SpiSetParams { fl_id: 0, total_size: 4194304, block_size: 65536, sector_size: 4096, page_size: 256, status_mask: 65535 } }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073111164 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061900 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061908 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061908 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073111164 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061900 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061908 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061908 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1072955412 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061900 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061904 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061912 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061900 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061892 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061896 }
Chip type:         esp32 (revision v3.1)
Crystal frequency: 40 MHz
Flash size:        4MB
Features:          WiFi, BT, Dual Core, 240MHz, Coding Scheme None
MAC address:       d8:13:2a:c2:0c:f0
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1072955412 }
[2024-07-12T07:15:34Z DEBUG] Writing command: SpiAttachStub { spi_params: SpiAttachParams { clk: 0, q: 0, d: 0, hd: 0, cs: 0 } }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073111164 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061900 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061908 }
[2024-07-12T07:15:34Z DEBUG] Writing command: ReadReg { address: 1073061908 }
App/part. size:    1,081,952/4,128,768 bytes, 26.21%
...
[2024-07-12T07:16:45Z DEBUG] Using HardReset reset strategy
[2024-07-12T07:16:45Z INFO ] Flashing has completed!
Commands:
    CTRL+R    Reset chip
    CTRL+C    Exit
Successful esptool.py output
esptool.py v4.6
Serial port /dev/ttyUSB0
Connecting.....
Chip is ESP32-D0WD-V3 (revision v3.1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: d8:13:2a:c2:0c:f0
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00050fff...
Compressed 18304 bytes to 12742...
Writing at 0x00001000... (100 %)
Wrote 18304 bytes (12742 compressed) at 0x00001000 in 0.6 seconds (effective 261.9 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 382.0 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 683.6 kbit/s)...
Hash of data verified.
Compressed 263728 bytes to 146215...
Writing at 0x00010000... (11 %)
Writing at 0x0001ba04... (22 %)
Writing at 0x00024aaa... (33 %)
Writing at 0x00029d28... (44 %)
Writing at 0x0002f090... (55 %)
Writing at 0x0003536c... (66 %)
Writing at 0x0003f91f... (77 %)
Writing at 0x00045c53... (88 %)
Writing at 0x0004b322... (100 %)
Wrote 263728 bytes (146215 compressed) at 0x00010000 in 3.5 seconds (effective 608.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
@victorbnl
Copy link
Author

Adding --before no-reset fixes the issue so it seems to be a duplicate of #616.

@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

1 participant