Skip to content

Bizarre SPIFFS readBytes crash - only when exactly 52 bytes read #3664

Closed
@philbowles

Description

@philbowles

Basic Infos

Hardware

Hardware: Wemos D1 Mini
Core Version: 2.3.0

Description

readBytes on a SPIFFS file causes reboot (with no error messages) - but only when exactly 52 bytes are read. The file is the same in all case (a "config" file named "/conf").

Dozens of other (shorter AND longer) strings work perfectly and have done for weeks.

The only thing I can think of is that my SPIFFS memory area has become corrupted somehow and that some historic "footprint" of a bad 52-byte file is lying around and keeps getting re-used when the same length string is written again.

Settings in IDE

Module: WeMos D1 R2 & Mini
Flash Size: 4MB (1M SPIFFS)
CPU Frequency: 80Mhz
Upload Using: SERIAL

Sketch

String ICACHE_FLASH_ATTR ESPArto::readSPIFFS(const char* fn){
	String rv;
	File f=SPIFFS.open(fn, "r");
	if(f) {
		int n=f.size();
		Serial.printf("readSPIFFS size=%d\n",n);
		char* buff=(char *) malloc(n);
		f.readBytes(buff,n);
		rv=buff;
		free(buff);
	}
	f.close();
	return rv;	
}

Debug Messages

Here's a working Example:

readSPIFFS size=53
CFG data=Middle EarthX,Righthander,0,30000,30000,300000,300000

09826c6d
uptime=0d 0h 0m 2s H=27496 W=0 WiFi Connected SSID=ToiioT-Etage

Here's another:

readSPIFFS size=51
CFG data=MiddleEarth,Righthander,0,30000,30000,300000,300000

09826c6d
uptime=0d 0h 0m 1s H=27680 W=0 asyncp: event/5/4 [1]
uptime=0d 0h 0m 1s H=27856 W=0 asyncp: sound [1]
uptime=0d 0h 0m 2s H=27320 W=0 WiFi Connected SSID=ToiioT-Etage

And a 3rd:

readSPIFFS size=59
CFG data=Middle Earth,Much longer string,0,30000,30000,300000,300000

09826c6d
uptime=0d 0h 0m 2s H=27488 W=0 WiFi Connected SSID=ToiioT-Etage

But as soon as the same file containing exactly 52 bytes is read:

readSPIFFS size=52
"B΃K���⸮⸮	⸮%⸮⸮u⸮�⸮)S
!⸮o�XÈ

There are no other messages: no boot reason code, nothing but the gibberish and then my setup() routine running again.

I'm convinved it's a SPIFFS corruption as the same code running on a NodeMCU v0.9 shows:

uptime=0d 0h 0m 0s H=36832 W=0 Alive as esparto6
readSPIFFS size=52
CFG data=Middle Earth,Righthander,0,30000,30000,300000,300000

09826c6d
uptime=0d 0h 0m 2s H=27504 W=0 WiFi Connected SSID=ToiioT-Etage

How to further diagnose or fix? I have reuploaded my SPIFFS image (which does NOT include the /conf file) many times using the IDE (1.8.3) tool, as well as automatically on boot via ESPhttpUpdate. After each such re-upload, I then use my config web page to write the file, which appears to be written fine. Upon next reboot, the problem of the 52-byte read appears.

I'm going to try one more thing and that is to change the SPIFFS size and try the whole process again, unless someone has any other ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions