igrr / esptool-ck

ESP8266 build/flash helper tool by Christian Klippel
GNU General Public License v2.0
360 stars 123 forks source link

Can't erase or reflash: FLASH_DOWNLOAD_BEGIN failed #41

Closed OrganicIrradiation closed 7 years ago

OrganicIrradiation commented 7 years ago

I've been having lots of issues trying to reflash a Wemos D1 mini (ESP-12F, CH340G USB<->Serial, 4M bytes flash). I was previously able to flash it with the Arduino IDE, but after trying to reflash it with the micropython distribution, it seems as though I've soft-bricked it.

I get the following error with esptool when trying to erase the flash:

$ ./esptool -vv -cp /dev/tty.wchusbserial1410 -cd nodemcu -ce
esptool v0.4.11 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
    setting port from /dev/tty.usbserial to /dev/tty.wchusbserial1410
    setting board to nodemcu
    espcomm_erase_flash
opening port /dev/tty.wchusbserial1410 at 115200
    tcgetattr
    tcsetattr
    serial open
opening bootloader
resetting board
trying to connect
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
trying to connect
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    setting timeout 1000
    setting timeout 100
warning: espcomm_send_command: didn't receive command response
error: espcomm_erase_flash: FLASH_DOWNLOAD_BEGIN failed
error: Invalid argument or value after -ce (argument #7)

If I try to write the flash, I get the same error:

$ ./esptool -vv -cp /dev/tty.wchusbserial1410 -bz 32M -cd nodemcu -cb 115200 -cf esp8266-20160823-v1.8.3-41-g253e1a6.bin
esptool v0.4.11 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
    setting port from /dev/tty.usbserial to /dev/tty.wchusbserial1410
setting flash size from 512K to 32M
    setting board to nodemcu
    setting baudrate from 115200 to 115200
    espcomm_upload_file
    espcomm_upload_mem
opening port /dev/tty.wchusbserial1410 at 115200
    tcgetattr
    tcsetattr
    serial open
opening bootloader
resetting board
trying to connect
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
trying to connect
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
Uploading 530708 bytes from esp8266-20160823-v1.8.3-41-g253e1a6.bin to flash at 0x00000000
    erasing flash
    size: 081914 address: 000000
    first_sector_index: 0
    total_sector_count: 130
    head_sector_count: 16
    adjusted_sector_count: 114
    erase_size: 072000
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    setting timeout 15000
    setting timeout 100
warning: espcomm_send_command: didn't receive command response
warning: espcomm_send_command(FLASH_DOWNLOAD_BEGIN) failed
closing bootloader
error: espcomm_upload_mem failed
error: Invalid argument or value after -cf (argument #11)

I'm able to read the chip_id and MAC with esptool.py:

$ esptool.py --port /dev/tty.wchusbserial1410 chip_id
esptool.py v1.1
Connecting...
Chip ID: 0x00------
$ esptool.py --port /dev/tty.wchusbserial1410 read_mac
esptool.py v1.1
Connecting...
MAC: 5c:cf:7f:--:--:--

If I connect with a serial terminal at 74880 baud I can see the module communicates from the bootloader when I press the restart button:

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

I've tried on Mac OS X 10.11.6 (with the signed driver) and on a Windows 10 machine (with automatically installed driver), both with the same results. I've also tried with virtual machines and a multitude of cables. Nothing seems to reflash it (I've tried esptool.py, esptool-ck, NodeMCU Flasher, and the espressif flash tool).

Any suggestions??

OrganicIrradiation commented 7 years ago

Fixed by putting a 10 Ohm resistor between pins D3 (DIO 0) and GND! Seems as though the reset & programming circuit's pull-down timing is off (see right side of USB to UART section of the Wemos D1 mini schematic)

$ ./esptool -vv -cp /dev/tty.wchusbserial1410 -bz 32M -cd nodemcu -cb 115200 -cf esp8266-20160823-v1.8.3-41-g253e1a6.bin
esptool v0.4.11 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
    setting port from /dev/tty.usbserial to /dev/tty.wchusbserial1410
setting flash size from 512K to 32M
    setting board to nodemcu
    setting baudrate from 115200 to 115200
    espcomm_upload_file
    espcomm_upload_mem
opening port /dev/tty.wchusbserial1410 at 115200
    tcgetattr
    tcsetattr
    serial open
opening bootloader
resetting board
trying to connect
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
trying to connect
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
    espcomm_send_command: receiving 2 bytes of data
Uploading 530708 bytes from esp8266-20160823-v1.8.3-41-g253e1a6.bin to flash at 0x00000000
    erasing flash
    size: 081914 address: 000000
    first_sector_index: 0
    total_sector_count: 130
    head_sector_count: 16
    adjusted_sector_count: 114
    erase_size: 072000
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    setting timeout 15000
    setting timeout 100
    espcomm_send_command: receiving 2 bytes of data
    writing flash
................................................................................ [ 15% ]
................................................................................ [ 30% ]
................................................................................ [ 46% ]
................................................................................ [ 61% ]
................................................................................ [ 77% ]
................................................................................ [ 92% ]
.......................................                                          [ 100% ]
starting app without reboot
    espcomm_send_command: sending command header
    espcomm_send_command: sending command payload
    espcomm_send_command: receiving 2 bytes of data
closing bootloader