Page 1 of 1

fread fails very often

Posted: Fri Jan 18, 2019 11:19 am
by dmitryga
Hi everybody!

I'm using SPIFFS file system to store some intermediate data in files. So I use fopen/fread/fwrite/fclose functions to manipulate file contents. Generally everything works OK, but fread fails in about 10% of cases. When it happens ferror returns 1 and errno is equal to 5. I've tried to repeat read operations in such cases, but it does not help at all (if I try to call fread 5 times it fails all 5 times).
I expect that this happens because of some sort of conflict on SPI bus (I also use HSPI to access several peripheral devices from different threads) but I have no proofs for that.
Is where any way to make fread be successful in 100% of calls?

Re: fread fails very often

Posted: Sat Jan 19, 2019 3:12 am
by ESP_Sprite
FWIW, error 5 is EIO, which indeed indicates something has gone wrong in communicating with the device. Something SPI related is likely. Could you elaborate a bit more on your setup, as in, tell us what devices are attached where and how you communicate with them?