Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By kalauffenburger
#51642 Ok, I tried esptool-ck. That tool acts as if it is programming the flash, but in reality does not, or it programs garbage into it. I have tried all combinations of flash mode, clock rate, baud rate, etc. Here is an example:

saturn:~/work> make flash
# esptool --port /dev/ttyUSB0 --baud 115200 write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin
# esptool -bz 8M -cp /dev/ttyUSB0 -cd none -cb 115200 -ca 0x00000 -cf firmware/0x00000.bin -ca 0x40000 -cf firmware/0x40000.bin
esptool -cp /dev/ttyUSB0 -cd none -cb 115200 -bz 4M -bf 26 -ca 0x00000 -cf firmware/0x00000.bin -ca 0x40000 -cf firmware/0x40000.bin
Uploading 29360 bytes from firmware/0x00000.bin to flash at 0x00000000
............................. [ 100% ]
Uploading 186068 bytes from firmware/0x40000.bin to flash at 0x00040000
................................................................................ [ 43% ]
................................................................................ [ 87% ]
...................... [ 100% ]
saturn:~/work> esptool.py --port /dev/ttyUSB0 --baud 38400 verify_flash 0x00000 firmware/0x00000.bin
Connecting...
Verifying 0x72b0 (29360) bytes @ 0x00000000 in flash against firmware/0x00000.bin...
-- verify FAILED: 28230 differences, first @ 0x00000000

A fatal error occurred: Verify failed.
saturn:~/work> esptool.py --port /dev/ttyUSB0 --baud 38400 flash_id
Connecting...
Manufacturer: e0
Device: 4016

Recall, if I use the esptool.py to flash the device, I get this error:
saturn:~/work> esptool.py --port /dev/ttyUSB0 --baud 38400 write_flash --flash_freq 20m --flash_mode dio --flash_size 4m --verify 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin
Connecting...
Erasing flash...
Took 0.01s to erase flash block
Writing at 0x00000000... (3 %)
A fatal error occurred: Failed to write to target Flash after seq 0 (got result 0x1, 0x8)

I have used my scope to look at the SPI protocol between the processor and flash, and it looks good:

scope_106.png

scope_107.png


...so I don't think that there is anything wrong with the SPI timing.

One thing I noticed however, is that the different flash frequency parameters do not seem to change the SPI clock timing; it is consistently about 12.5 MHz.


Are there any other tools besides esptool.py and esptool-ck that you can suggest?

The power supply is stable at 3.07 VDC, the 26 MHz clock seems very stable, and the SPI protocol seems right. Is there something else I should be looking at?

Thanks.

--ken

--ken
You do not have the required permissions to view the files attached to this post.
User avatar
By kalauffenburger
#51678 Ok, I tried an alternate programming program called esptool-ck.

It behaves as if it is programming the flash but in reality it doesn't. I believe that it is ignoring the error status that causes the other tool (esptool.py) to terminate with an error.

I have tried all combinations of SPI clock rate (40 MHz, 26 MHz, 20 MHz, 80 MHz), all SPI flash modes (qio, qout, dio, dout), nearly all baud rates, and several different flash sizes. By the way, looking at the SPI bus waveforms with my scope, it seems that the flash clock frequency is always 12.5 MHz no matter what the SPI clock rate setting is.

Here is some sample output of the programming sessions:

saturn:~/work> esptool.py --port /dev/ttyUSB0 --baud 115200 flash_id
Connecting...
Manufacturer: e0
Device: 4016


(My device is being read properly and appears to be a 4MBit flash.)

saturn:~/work> esptool -cp /dev/ttyUSB0 -cd none -cb 115200 -bz 4M -bf 26 -ca 0x00000 -cf firmware/0x00000.bin -ca 0x40000 -cf firmware/0x40000.bin
Uploading 29360 bytes from firmware/0x00000.bin to flash at 0x00000000
............................. [ 100% ]
Uploading 186068 bytes from firmware/0x40000.bin to flash at 0x00040000
................................................................................ [ 43% ]
................................................................................ [ 87% ]
...................... [ 100% ]


(Hey, it seemed to program! But...)

saturn:~/work> esptool.py --port /dev/ttyUSB0 --baud 115200 verify_flash 0x00000 firmware/0x00000.bin
Connecting...
Verifying 0x72b0 (29360) bytes @ 0x00000000 in flash against firmware/0x00000.bin...
-- verify FAILED: 28184 differences, first @ 0x00000000


(Verification fails; let's read it back and compare manually:)

saturn:~/work> esptool.py --port /dev/ttyUSB0 --baud 115200 read_flash 0 29360 boot.bin
saturn:~/work> od -t x4 boot.bin | head
0000000 00000000 00000000 00000000 00000000
*
0005040 00000000 22381248 5701d452 22490693
0005060 00c6043d 39331b00 3732b822 95370b9b
0005100 c6324904 331b0000 20c03239 30073800
0005120 a3567430 00f00dfa 3ffe8080 3ffe9914
0005140 3ffeb664 3ffeb564 3ffe8024 3ffe807c
0005160 3ffe8004 3ffe8044 3ffe8088 4c957f2d
0005200 5851f42d 7fffffff 80000000 fff00000
0005220 7fdfffff 000fffff 80100000 000000ff

saturn:~/work> od -t x4 firmware/0x00000.bin | head
0000000 000003e9 40100004 40100000 00006c1c
0000020 40100000 20ffff21 25c513e7 00000000
0000040 46007200 0000fffe 00000000 00000000
0000060 8513d300 00000007 00000000 00000000
0000100 46004100 0000fffe 00000000 00000000
0000120 00000000 00000000 00000000 00000000
0000140 8513d100 00000010 00000000 00000000
0000160 00000000 00000000 00000000 00000000
0000200 46004140 0000fffe 00000000 00000000
0000220 00000000 00000000 00000000 00000000


(Doesn't match.)


If I look at the verbose output of the programming program, I see the following:

esptool v0.4.11 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
setting port from /dev/ttyUSB0 to /dev/ttyUSB0
setting board to none
setting baudrate from 115200 to 115200
setting flash size from 512K to 4M
setting flash frequency from 40 to 26
setting address from 0x00000000 to 0x00000000
espcomm_upload_file
espcomm_upload_mem
opening port /dev/ttyUSB0 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
espcomm_send_command: didn't receive command response
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: received 2 bytes:
0x00
0x00
espcomm_send_command: response 0x20120707
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x00
0x00
espcomm_send_command: response 0x20120707
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x00
0x00
espcomm_send_command: response 0x20120707
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x00
0x00
espcomm_send_command: response 0x20120707
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x00
0x00
espcomm_send_command: response 0x20120707
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x00
0x00
espcomm_send_command: response 0x20120707
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x00
0x00
espcomm_send_command: response 0x20120707
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x00
0x00
espcomm_send_command: response 0x20120707
Uploading 29360 bytes from firmware/0x00000.bin to flash at 0x00000000
erasing flash
size: 0072b0 address: 000000
first_sector_index: 0
total_sector_count: 8
head_sector_count: 8
adjusted_sector_count: 4
erase_size: 004000
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
espcomm_send_command: received 2 bytes:
0x00
0x00
espcomm_send_command: response 0x20120707
writing flash
espcomm_send_command: sending command header
espcomm_send_command: sending command payload
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x01
0x08
espcomm_send_command: response 0x20120707
. espcomm_send_command: sending command header
espcomm_send_command: sending command payload
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x01
0x08
espcomm_send_command: response 0x20120707
. espcomm_send_command: sending command header
espcomm_send_command: sending command payload
espcomm_send_command: receiving 2 bytes of data
espcomm_send_command: received 2 bytes:
0x01
0x08
...


(Notice that the status looks quite similar to the error status from the esptool.py program:)
saturn:~/work> esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_freq 26m --flash_size 4m 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin
Connecting...
Erasing flash...
Took 0.01s to erase flash block
Writing at 0x00000000... (3 %)
A fatal error occurred: Failed to write to target Flash after seq 0 (got result 0x1, 0x8)


After programming, when I pull up GPIO0 pin and release the reset, I get a few SPI transactions on the flash bus and the following diagnostic on the UART output:

ets Jan 8 2013,rst cause:2, boot mode:(1,7)

Also, there is a very solid 26 MHz clock signal on the GPIO0 signal.


So, are there any other flash programs you can suggest aside from esptool.py and esptool-ck?

Also, is there anything else from a hardware perspective that I am overlooking? The power rail is a solid 3.07 VDC, and apparently from the nice 26 MHz output on the GPIO0 pin, I guess my oscillator circuit is working fine.

The SPI bus also looks good. See waveforms below:

scope_106.png

scope_107.png


Any suggestions?

Thanks.

--ken
You do not have the required permissions to view the files attached to this post.