-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Writing files with SPIFFS no longer working for ESP-01 #4061
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
Comments
I found out some additional information that might be helpful. and the new ones that are not working: May the new flash chip is not supported by the arduino esp plugin yet ? |
I'm having the same problem. Out of the first batch of 20 where the problem first showed up only 7 of them worked properly. All functions except for SPIFFS seem fine. Out of the next batch of 20, 9 worked properly. I just received another 2 batches of 20. One batch from a different seller on eBay and the other batch from a seller on AliExpress. Out of the new batch from eBay only 2 work properly. All 20 of the new batch from Aliexpress are faulty. I checked the Chip ID's and I can confirm that Flash Chips with a manufacturer ID of 85 and Device ID of 6014 do not work. I can also confirm that the 2 that did work have the manufacturer ID of E0 and Chip ID of 4014. I had a look at the flash chips with a magnifying glass and found the faulty ones were all branded FUYA and the 2 that have working SPIFFS are branded BergMicro. I sure hope someone has a solution for this as it's a major problem for anyone who needs to store stuff like settings. EEPROM is an alternative but it's so clunky compared to SPIFFS and I really don't want to have to recode my sketches. |
Its definitely a problem with writing SPIFFS. Reading works because i uploaded a flash image of a functional device with SPIFFS data present. But for reading the flash as anyway only mapped to memory while for writing a correct initializiation and timing is needed. I wonder why the booter itself has no problems writing the flash but SPIFFS has. I would have expected that finally the same functions are used to write the flash but it seems that the spiffs implementation is doing something strang and chip dependend. |
So it seems like problem in SPIFFS and/or write implementation. Right? |
yes seems like |
I found that the 'Upload Sketch Data' function of the IDE works. A sketch can then read the data but a sketch can't write to SPIFFS. This will impact a lot of people, I've bought esp-01 modules witj these PUYA branded flash chips from 3 different suppliers now. Out of the 80 modules only 18 have worked as they had BergMicro flash chips onboard. |
I'm seeing a similar, but different problem. My sketch does not find any files in the fs after uploading the spiffs image. I're tried uploading with esptool and the Arduino IDE, but I get the same result. The processor is an ESP01 on a Sonoff device. I've tried both the 512k64k and 1m64k configurations and neither work. Is the issue I'm seeing related to this report? Am I possibly doing something wrong? What is the best way to diagnose this? I've added some code to the setup function that lists all files and it finds none. |
@weswitt is this a new board purchased recently? //************************************************* void setup() { SPIFFS.begin(); float fileTotalKB = (float)fs_info.totalBytes / 1024.0; float flashChipSize = (float)ESP.getFlashChipSize() / 1024.0 / 1024.0; Serial.printf("\n#####################\n"); Serial.printf("__________________________\n\n"); Serial.printf("__________________________\n\n"); Serial.println("Flash chip information: "); Serial.printf("__________________________\n\n"); Serial.println("File system (SPIFFS): "); Dir dir = SPIFFS.openDir("/"); Serial.printf("__________________________\n\n"); Serial.printf("CPU frequency: %u MHz\n\n", ESP.getCpuFreqMHz()); // open file for reading void loop() { |
Same issue as #3616 , tracking there. |
@ondabeach thanks for the assistance. below is the diagnostic output from the sketch you provided: ##################### Firmware: Flash chip information: File system (SPIFFS): SPIFFS directory {/} : CPU frequency: 80 MHz #####################file open failed |
@weswitt The last sketch was just to get the flash chip data, the printing of 1~10 at the bottom was left in by mistake. The chip ID retrieved shows that you have a flash chip that should work, it does for the OP and myself. Try the following code, it should work on your board. //********************************************************** String realSize = String(ESP.getFlashChipRealSize()); void setup() { if(flashCorrectlyConfigured){ Serial.println("\nVery basic Spiffs example, writing 10 lines to SPIFFS filesystem, and then read them back"); if (!SPIFFS.exists("/formatComplete.txt")) {
} else { void loop() { f.close(); // open file for reading } |
Thanks @ondabeach. Running that code does confirm that writing to and reading from SPIFFS work fine on my device. But this brings me back to my problem. What I'm seeing is that when I flash a SPIFFS to the device and then run a sketch the sketch sees zero files. This happens if I use the Arduino IDE or esptool. This is the esptool command line that I'm using: esptool.exe -vv -cd ck -cb 115200 -cp com3 -ca 0xEB000 -cf test-spiffs.bin Does the tool used to flash the SPIFFS need to be up todate with the SPIFFS in the core? Maybe the tool is too old and is not writing a format that the core runtime understands? |
No problem @weswitt. I'm not sure if esptool needs to.be updated. Much quicker and simpler to use the IDE as you're already in there rather than using command line methods. We know your hardware is ok and that sketch can write and read SPIFFS so to look at your uploading files to SPIFFS issue: No idea of your experience level, I'm just a hacker myself so we'll start with the basics. Use "Show Sketch Folder" under "Sketch" menu. Make sure you carriage return after the "10" or that line won't be read. Here's a tidied up version of the Get Flash Data/SPIFFS Read sketch. //************************************************************* void setup() { SPIFFS.begin(); float fileTotalKB = (float)fs_info.totalBytes / 1024.0; float flashChipSize = (float)ESP.getFlashChipSize() / 1024.0 / 1024.0; Serial.println("=========================================================="); Serial.printf("__________________________\n\n"); Serial.println("Flash chip information: "); Serial.println("File system (SPIFFS): "); Dir dir = SPIFFS.openDir("/"); } void loop() { |
Hi @igrr, here's the output with the PUYA chip: phys_addr=962560 Flash size, as set in IDE: 1048576 SPIFFS_close: fd=1 SPIFFS_close: fd=2 |
@igrr For comparison, this is the output from a BergMicro chip on one of my last 2 modules that can use SPIFFS (hint hint ;) phys_addr=962560 Flash size, as set in IDE: 1048576 SPIFFS_close: fd=1 SPIFFS_close: fd=1 |
@ondabeach thanks for these logs! What happens if you run the test on the PUYA module, setting flash configuration in IDE to, say, 512K/64K? |
@igrr pretty much the same result Ivan. Thanks for your help with this issue. Whatever you need, just let me know. phys_addr=438272 Flash size, as set in IDE: 524288 SPIFFS_close: fd=1 SPIFFS_close: fd=2 |
Hmm, that doesn't give any clue, to be honest. Okay, let's try another kind of a test: https://gist.github.com/igrr/964b0d139ce63fcee07c8c1f1facb24d Same as before, please have debug level set to CORE. No need to run on the "working" board, just on the PUYA one. |
Hi igrr, scandone connected with CAROLAN, channel 6 Flash size, as set in IDE: 1048576 connected with CAROLAN, channel 6 SPIFFS_close: fd=1 SPIFFS_close: fd=1 |
@funtastic99 Your output is what i would describe as "normal". Perhaps the issues you and @ondabeach are seeing are not the same after all... |
@igrr The strange thing is that ondebeach an me both have spiffs problems with flash id Manufacturer: 85, Device: 6014. Maybe its causing different effects. |
@igrr Ok, exact same settings as last test, same board, nothing moved or changed. phys_addr=962560 Flash size, as set in IDE: 1048576 SPIFFS_close: fd=1 SPIFFS_close: fd=2 |
Sorry, not getting any closer... Please try replacing Esp.cpp in your esp8266 core directory with the one attached here, run same test. |
@igrr esp.cpp replaced, IDE restarted and all settings the same. phys_addr=438272 Flash size, as set in IDE: 524288 SPIFFS_close: fd=1 SPIFFS_close: fd=2 |
@igrr I have a second machine as a backup. I made everything the same as far as I can see, including the new Esp.cpp. The only difference I'm aware of is that on the original machine that gave the Flash Verify errors in the output The esp8266com/esp8266 folder was updated to v2.4.0 using GitGui whereas on this machine it was done through the Boards Manager and the URL in IDE preferences. I can't write to SPIFFS via a sketch on either machine but the esp8266 Sketch Data Upload plugin can. phys_addr=438272 Flash size, as set in IDE: 524288 SPIFFS_close: fd=1 SPIFFS_close: fd=2 |
Thanks @ondabeach , these logs with "flash verify error" mean that we are indeed seeing some hardware dependent issue. I have updated the test: https://gist.github.com/igrr/964b0d139ce63fcee07c8c1f1facb24d and Esp.zip, please give it another try. If the log ends up being long, could you please paste it into gist.github.com and post a link here? |
@igrr No longer than the others I think. phys_addr=438272 Flash size, as set in IDE: 524288 SPIFFS_close: fd=1 SPIFFS_close: fd=2 |
Take this file Esp.zip from @mrlightsman's post above. Replace it with the esp.cpp file in your arduino IDE program folder. I am using the portable version so it looks like this: C:\arduino-1.8.6\portable\packages\esp8266\hardware\esp8266\2.4.2\cores\esp8266\Esp.cpp. Just look for the 'packages' folder in your install directory and follow it down. Once the esp.cpp file is replaced, restart the IDE and flash your sketch using the "Tools -> Erase Flash -> All Flash Contents" option. After it's done flashing, go to "Tools -> ESP8266 Sketch Data Upload". This will upload all the files in the "data" subfolder of your sketch folder. |
I can confirm that @uzi18 v2 patch works nicely (thanks to everyone involved in creating it!). Using Arduino IDE, on some "Sonoff Basic" modules with PUYA chips. However, I have some tips to give:
|
Edit file Esp.cpp:
|
Applied this patch made by @uzi18 esp8266/Arduino#4061 (comment) It is now included in all builds
Applied this patch made by @uzi18 esp8266/Arduino#4061 (comment) It is now included in all builds
@ALL updated puya patch v3 used now in ESPEasy project: |
The described fix (flashWrite function) worked for me as well with Sonoff S26, which also uses PUYA flash. Any plans to perform the change in mainline? |
Any plans to perform the change in mainline? |
It is not in -beta1. A variation of the patch used in ESPEasy will be used in the core, but it's not targeted to a release yet. |
@devyte Just curious, what will be different? |
Ok, so all the people that use the ESP-01 with (almost all nowadays) a PUYA chip cannot upgrade to a new version in the foreseeable future ?! |
Not only ESP-01 but many other new devices. Sonoff S26 is one of the examples |
The patch:
Given the above, the patch won't be accepted as-is into our core. There have been several internal discussions on exactly what to do, but given that the patch is available, there have been, and still are, higher priorities, e.g.: figuring out how to ease IRAM usage. There have been a lot of comments from many users in this discussion, and I see the patch is even being applied elsewhere, but I still don't see a PR here. Instead of wondering what will happen, I invite those involved to make a PR with the proposed patch, and implement at least points 1-3 above on top of it. If you come up with a good solution for point 4, even better. |
While do understand that the expected behavior in open source is to some up with a proper patch for an issue, I tend to disagree with this point: No. You've just indicated that the patch is a really basic workaround, apparently not suitable for any production use. People only use it as PoC because it makes their devices work at least somehow, comparing to not working at all So, if there's any prioritization done, pease consider this issue as not having any workaround at all, as apparently there's no candidate for a merge Current firmware literally doesn't work on recent chips. Also, comparing to other issues, at least some investigation has been done by the community, identifying the root cause and a PoC fix |
Totally agree with maxim-kukushkin |
@maxim-kukushkin and @mrWheel everyone else on the thread: you obviously care very much about the Puya patch. Please, one of you take what @devyte has suggested and wrap it into a PR so we can advance. |
@maxim-kukushkin & @devyte |
@devyte Sounds like very legitimate points. |
Given the length of this thread, I'm closing in favor of #5493 . Resolution will be handled there. |
Basic Infos
SPIFFS no longer works on a ESP-01.
Hardware
Hardware: ESP-01
Core Version: 2.3.0-rc2
also tried with stable
I reproduced this problem on several different ESP-01. So seems not to be hardware related
Description
Problem description
SPIFFS worked for a long time but all of a sudden it stoped working on a ESP-01.
Whenever i write a file its not existing or empty after next boot.
Using the same sketch on an Wemos D1 mini its works without problems. Actually im only facing this problem on a ESP-01.
Settings in IDE
Module: Generic ESP8266 Module
Flash Size: 1MB (64k SPIFFS), also tried with 512k (64k SPIFFS)
CPU Frequency: 80Mhz
Flash Mode: DIO
Flash Frequency: 40Mhz
Upload Using: SERIAL
Reset Method: ck
Sketch
#include <FS.h>
void setup()
{
Serial.begin(115200);
if (!SPIFFS.begin()) Serial.println("error while mounting filesystem!");
readFile();
writeFile();
readFile();
Serial.println("done");
}
void readFile()
{
Serial.println("reading");
File f = SPIFFS.open("/myFile.txt", "r");
if (!f) Serial.println("file not available");
else if (f.available()<=0) Serial.println("file exists but available <0");
else
{
String ssidString = f.readStringUntil('#');
Serial.print("read from file: ");
Serial.println(ssidString);
}
f.close();
}
void writeFile()
{
Serial.println("writing");
File f = SPIFFS.open("/myFile.txt", "w");
if (!f) Serial.println("File creation failed");
else
{
f.print("networkConfig");
f.print("#");
f.flush();
f.close();
}
}
void loop()
{
}
Debug Messages
messages here
Output of first run:
reading
file not available
writing
reading
read from file: <--- here we see the problem already
done
Output of second run:
eading
file not available
writing
reading
read from file:
done
Output of third run:
reading
read from file:
writing
File creation failed <---- check this!
reading
read from file:
done
Any ideas?
thank you!
The text was updated successfully, but these errors were encountered: