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

Exception when writing to ESP8266; flash size unknown, unable to set explicitly (ESPTOOL-981) #1045

Open
1 task done
isobit opened this issue Dec 24, 2024 · 1 comment
Open
1 task done

Comments

@isobit
Copy link

isobit commented Dec 24, 2024

Operating System

NixOS 24.11

Esptool Version

4.8.1

Python Version

3.12.7

Chip Description

ESP8266

Device Description

Sparkfun ESP8266 Thing, using a separate Sparkfun FTDI programming board.

Hardware Configuration

No response

How is Esptool Run

No IDE, PlatformIO and manually invoked CLI

Full Esptool Command Line that Was Run

esptool.py --before default_reset --after hard_reset --baud 115200 --port /dev/ttyUSB0 --chip esp8266 write_flash -z --flash_size detect 0x0 .esphome/build/thing/.pioenvs/thing-oven/firmware.bin

Esptool Output

esptool.py v4.8.1
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 18:fe:34:ef:20:e5
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
WARNING: Could not auto-detect Flash size (FlashID=0x1841f, SizeID=0x1), defaulting to 4MB
Traceback (most recent call last):
  File "/nix/store/cczavcnzjxdihxzaibhlab2zaag79bsk-esptool-4.8.1/bin/.esptool.py-wrapped", line 38, in <module>
    esptool._main()
  File "/nix/store/cczavcnzjxdihxzaibhlab2zaag79bsk-esptool-4.8.1/lib/python3.12/site-packages/esptool/__init__.py", line 1314, in _main
    main()
  File "/nix/store/cczavcnzjxdihxzaibhlab2zaag79bsk-esptool-4.8.1/lib/python3.12/site-packages/esptool/__init__.py", line 1036, in main
    operation_func(esp, args)
  File "/nix/store/cczavcnzjxdihxzaibhlab2zaag79bsk-esptool-4.8.1/lib/python3.12/site-packages/esptool/cmds.py", line 491, in write_flash
    if set_flash_size and set_flash_size > flash_end:
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>' not supported between instances of 'int' and 'NoneType'

More Information

The same error occurs even when passing an explicit flash size with --flash_size 512KB. I also noticed that flash_id shows the detected flash size as Unknown:

esptool.py -p /dev/ttyUSB0 flash_id
esptool.py v4.8.1
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 18:fe:34:ef:20:e5
Uploading stub...
Running stub...
Stub running...
Manufacturer: 1f
Device: 8401
Detected flash size: Unknown
Hard resetting via RTS pin...

Other Steps to Reproduce

No response

I Have Read the Troubleshooting Guide

  • I confirm I have read the troubleshooting guide.
@github-actions github-actions bot changed the title Exception when writing to ESP8266; flash size unknown, unable to set explicitly Exception when writing to ESP8266; flash size unknown, unable to set explicitly (ESPTOOL-981) Dec 24, 2024
@radimkarnis
Copy link
Collaborator

Hi @isobit,
thanks for the report.

This is caused by the flash memory chip of the Sparkfun Thing. I looked into this, the chip is Adesto AT25SF041. Esptool correctly reads the ID of the chip as Manufacturer: 1f (Adesto) Device: 8401.

image

Esptool detects the flash size from the Device field. Virtually all common flash memory chips manufacturers follow a common convention of storing the chip density information in the same format:

DETECTED_FLASH_SIZES = {
    0x12: "256KB",
    0x13: "512KB",
    0x14: "1MB",
    0x15: "2MB",
    0x16: "4MB",
    0x17: "8MB",
    0x18: "16MB",
    0x19: "32MB",
    0x1A: "64MB",
    0x1B: "128MB",
    0x1C: "256MB",
    0x20: "64MB",
    0x21: "128MB",
    0x22: "256MB",
    0x32: "256KB",
    0x33: "512KB",
    0x34: "1MB",
    0x35: "2MB",
    0x36: "4MB",
    0x37: "8MB",
    0x38: "16MB",
    0x39: "32MB",
    0x3A: "64MB",
}

For some reason, this manufacturer reports the density code as 0x04 (see in the screenshot above) instead of the expected 0x13 for 512KB.

Nevertheless, esptool should be able to continue even if flash size is not detected correctly. The error message TypeError: '>' not supported between instances of 'int' and 'NoneType' can be patched, we will fix this.

We will also look at the possibility of adding Adesto-flavored chip memory density codes to esptool.

As a temporary solution for you, I can recommend installing esptool in development mode and disabling the failing check in the cmds.py source file (if set_flash_size and set_flash_size > flash_end).

Sorry for the inconvenience, let me know if I can help you with adding the temporary patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants