fread fails very often

dmitryga
Posts: 29
Joined: Sat Jan 14, 2017 8:36 pm

fread fails very often

Postby dmitryga » Fri Jan 18, 2019 11:19 am

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?

ESP_Sprite
Posts: 9772
Joined: Thu Nov 26, 2015 4:08 am

Re: fread fails very often

Postby ESP_Sprite » Sat Jan 19, 2019 3:12 am

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?

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 69 guests