esptool via python code - "Failed to enter Flash download mode. Only got 2 byte status response."

nullbert
Posts: 14
Joined: Sun May 29, 2022 5:31 pm

esptool via python code - "Failed to enter Flash download mode. Only got 2 byte status response."

Postby nullbert » Wed Oct 23, 2024 9:25 pm

Hi,

I'm trying to flash an ESP32-S3 within my python program. using esptool (4.8.1) I can successfully flash using the command line version of esptool.py:

Code: Select all

esptool.py -p /dev/ttyACM0 write_flash 0x10000 firmware.bin
However, my sample code generates an error when calling esp.flash_begin():

Failed to enter Flash download mode. Only got 2 byte status response.

Code: Select all

from esptool.cmds import detect_chip

try_port = "/dev/ttyACM0"
filename = "./firmware.bin"
def progress_callback(current, total):
    percent = current / total * 100
    print(f"percent {percent}")
    
with detect_chip(try_port) as esp:
    print(str(type(esp)))
    esp.connect()
    esp.change_baud(115200)
    chip_desc = esp.get_chip_description()
    features = esp.get_chip_features()
    print(f"Detected bootloader on port {try_port} : {chip_desc}")
    print(f"Features {features}")
    port = try_port
    esp.run_stub()

    with open(filename, 'rb') as firmware:
        firmware_data = firmware.read()
        print(f"{len(firmware_data)}")
        esp.flash_begin(len(firmware_data), 0x10000)
        esp.flash_data(firmware_data, progress_callback=progress_callback)
        esp.flash_finish()
It works up until the flash_begin command:

Code: Select all

python f.py 
Connecting...
Detecting chip type... ESP32-S3
<class 'esptool.targets.esp32s3.ESP32S3ROM'>
Connecting...
Changing baud rate to 115200
Changed.
Detected bootloader on port /dev/ttyACM0 : ESP32-S3 (QFN56) (revision v0.2)
Features ['WiFi', 'BLE', 'Embedded PSRAM 2MB (AP_3v3)']
Uploading stub...
Running stub...
Stub running...
1562064
Traceback (most recent call last):
  File "/home/brent/git-projects/RC_app_private/f.py", line 19, in <module>
    esp.flash_begin(len(firmware_data), 0x10000)
  File "/home/brent/.pyenv/versions/r_c/lib/python3.11/site-packages/esptool/loader.py", line 916, in flash_begin
    self.check_command(
  File "/home/brent/.pyenv/versions/r_c/lib/python3.11/site-packages/esptool/loader.py", line 516, in check_command
    raise FatalError(
esptool.util.FatalError: Failed to enter Flash download mode. Only got 2 byte status response.
What am I missing? TIA for any help.


nullbert
Posts: 14
Joined: Sun May 29, 2022 5:31 pm

Re: esptool via python code - "Failed to enter Flash download mode. Only got 2 byte status response."

Postby nullbert » Thu Oct 24, 2024 4:16 pm

Update, I think I have a working example in the github issue linked in this post.

Who is online

Users browsing this forum: No registered users and 293 guests