espressif / esptool

Espressif SoC serial bootloader utility
https://docs.espressif.com/projects/esptool
GNU General Public License v2.0
5.58k stars 1.38k forks source link

Issues writing external flash chip with esptool. (ESPTOOL-962) #1034

Open jackgassett opened 2 hours ago

jackgassett commented 2 hours ago

Operating System

Windows 10

Esptool Version

esptool.py v4.8.1

Python Version

Python 3.12.6

Chip Description

ESP32S3

Device Description

Esp32S3 Supermini attached to a Tang Primer 20K dev board with the SPI Flash pins routed to external pins, via verilog, which are connected to gpio pins on esp32s3 board.

Hardware Configuration

Only ground and the 4 spi pins MOSI, MISO, SCLK, and CS are connected from the FPGA to the Esp32S3.

How is Esptool Run

VSCODE IDE

Full Esptool Command Line that Was Run

esptool --port COM10 --baud 9600 write_flash 0x0000 write.bin --spi-connection 5,4,6,26,7 --flash_mode dout --flash_freq 12m

Esptool Output

$ esptool --port COM10 --baud 9600 write_flash 0x0000 write.bin --spi-connection 5,4,6,26,7 --flash_mode dout --flash_freq 12m
esptool.py v4.8.1
Serial port COM10
Connecting...
Detecting chip type... ESP32-S3
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded Flash 4MB (XMC), Embedded PSRAM 2MB (AP_3v3)
Crystal is 40MHz
MAC: 64:e8:33:72:3a:d0
Uploading stub...
Running stub...
Stub running...
Configuring SPI flash mode (CLK:5, Q:4, D:6, HD:26, CS:7)...
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00000fff...
Warning: Image file at 0x0 doesn't look like an image file, so not changing any flash settings.
Compressed 8 bytes to 16...
Wrote 8 bytes (16 compressed) at 0x00000000 in 0.0 seconds (effective 6.4 kbit/s)...
File  md5: 9c2cbeb2501b5d68f30adb5197a91e3a
Flash md5: dcd01c291740a2b2942d565da15c9b04
MD5 of 0xFF is c2cb56f4c5bf656faca0986e7eba0308

A fatal error occurred: MD5 of file does not match data in flash!

More Information

We are currently exploring the option of using an esp32s3 to replace the traditional FT2232 devices used with FPGAs to program a bitstream to the SPI Flash of the FPGA.

We noticed the option in esptool to change the SPI pins to external SPI pins. This seems like a very elegant way to be able to program both the ESP32 and the FPGA using the same tool.

We have routed the SPI Flash pins of the FPGA to GPIO pins which are connected to the GPIO pins of the ESP32. We are getting reliable reads and erases with this configuration, but unfortunately writes are not working. Every attempt to write gets the first couple of bytes correct but then there will be sections of incorrect data with sections of correct data...

We have tried to lower the frequency and use both dio and dout modes. I'm beginning to suspect that maybe the flash mode is not actually changing to dio or dout when gpio pins are specified with --spi-connection 5,4,6,26,7.

We have also tried multiple different pin locations with the same results.

Any ideas or help is greatly appreciated.

Other Steps to Reproduce

No response

I Have Read the Troubleshooting Guide

jackgassett commented 2 hours ago

Update: Have also tried it with --no-compress with the same results:

$ esptool --port COM10 --baud 9600 write_flash 0x0000 write.bin --no-compress --spi-connection 5,4,6,26,7 --flash_mode dout --flash_freq 12m esptool.py v4.8.1 Serial port COM10 Connecting... Detecting chip type... ESP32-S3 Chip is ESP32-S3 (QFN56) (revision v0.2) Features: WiFi, BLE, Embedded Flash 4MB (XMC), Embedded PSRAM 2MB (AP_3v3) Crystal is 40MHz MAC: 64:e8:33:72:3a:d0 Uploading stub... Running stub... Stub running... Configuring SPI flash mode (CLK:5, Q:4, D:6, HD:26, CS:7)... Configuring flash size... Flash will be erased from 0x00000000 to 0x00000fff... Warning: Image file at 0x0 doesn't look like an image file, so not changing any flash settings. Wrote 16384 bytes at 0x00000000 in 0.1 seconds (1053.6 kbit/s)... File md5: 9c2cbeb2501b5d68f30adb5197a91e3a Flash md5: dcd01c291740a2b2942d565da15c9b04 MD5 of 0xFF is c2cb56f4c5bf656faca0986e7eba0308

A fatal error occurred: MD5 of file does not match data in flash!

jackgassett commented 2 hours ago

With a little more testing it looks like maybe flash_mode and flash_freq are not taking affect. The amount of time and the kbits/s with and without the options are too close. I would expect the run with --flash_mode dout --flash_freq 12m to take much more time, but both are taking around 4.3 seconds. Here are the results:

Without flash_mode and flash_freq: `$ esptool --port COM10 write_flash 0x0000 bitfile.bin --no-compress --spi-connection 10,11,9,26,8 esptool.py v4.8.1 Serial port COM10 Connecting... Detecting chip type... ESP32-S3 Chip is ESP32-S3 (QFN56) (revision v0.2) Features: WiFi, BLE, Embedded Flash 4MB (XMC), Embedded PSRAM 2MB (AP_3v3) Crystal is 40MHz MAC: 64:e8:33:72:3a:d0 Uploading stub... Running stub... Stub running... Configuring SPI flash mode (CLK:10, Q:11, D:9, HD:26, CS:8)... Configuring flash size... Flash will be erased from 0x00000000 to 0x0008cfff... Wrote 589824 bytes at 0x00000000 in 4.3 seconds (1086.3 kbit/s)... File md5: 9492a3d37da4b9cef57bc109602104eb Flash md5: cbfb29229cd7bb6fd4ffedab0e288490 MD5 of 0xFF is 2645bf14d83cd5d7af79e7aa8aa44225

A fatal error occurred: MD5 of file does not match data in flash!`

With flash_mode and flash_freq: `$ esptool --port COM10 --baud 115200 write_flash 0x0000 bitfile.bin --no-compress --spi-connection 10,11,9,26,8 --flash_mode dout --flash_freq 12m esptool.py v4.8.1 Serial port COM10 Connecting... Detecting chip type... ESP32-S3 Chip is ESP32-S3 (QFN56) (revision v0.2) Features: WiFi, BLE, Embedded Flash 4MB (XMC), Embedded PSRAM 2MB (AP_3v3) Crystal is 40MHz MAC: 64:e8:33:72:3a:d0 Uploading stub... Running stub... Stub running... Configuring SPI flash mode (CLK:10, Q:11, D:9, HD:26, CS:8)... Configuring flash size... Flash will be erased from 0x00000000 to 0x0008cfff... Warning: Image file at 0x0 doesn't look like an image file, so not changing any flash settings. Wrote 589824 bytes at 0x00000000 in 4.3 seconds (1106.6 kbit/s)... File md5: 9492a3d37da4b9cef57bc109602104eb Flash md5: a33baa47802dff3c72e879d03f136ee6 MD5 of 0xFF is 2645bf14d83cd5d7af79e7aa8aa44225

A fatal error occurred: MD5 of file does not match data in flash!`