-
• #2
Can you try calling
E.unmountSD()
before you remove the card? The last time this happened, that's what the problem was.I'm pretty surprised appendFile gives you trouble though - that should have written everything to the SD card and closed the file.
-
• #3
This happened with an SD after formatting (long run) under windows.
Inserted SD in Espruino and started the application.
For testing I did the same now on 3 Espruinos.
With or without E.unmountSD(), its alway the same problem.
See attached image.
1 Attachment
-
• #4
What is the filesystem type you are formatting to? It should be fat32, not exfat.
And this is on a normal Espruino board, via the micro SD slot? Sure seems strange - plenty of people have been using this without issues.
-
• #5
Filesystem is fat32 on a normal Espruino board with micro SD slot.
Tested with 3 boards and 3 SDcards now, always the same.
Next went back some versions, problem started in 1V73.I'm working on a simple datalogger, reading values from several sensors over days and writing to file in JSON format. Will be used first to collect environmental data from mq-sensors, temperature, humidity, ....There is no big problem doing this with older version.
-
• #6
Thanks for narrowing it down - 1v73 was the version with:
Allow filesystem to work on user-defined pins (fix #427)
With this commit
Looks to me like one thing that has changed is the SPI bit rate - it usually defaults to 100000, but it had been running the SD card at 1000000... Maybe you could try:
SPI2.setup({mosi:B15,miso:B14,sck:B13,baud:1000000}); E.connectSDCard(SPI2,D2); console.log(require("fs").readdirSync());
-
• #7
Sorry same problem, my testing is this:
- unmount
- setup SPI according to your code
- connectSDCard
- E.openFile(fileName,"w+")
- read directory (with or without sync) and mostly everything is fine
- write to file
- read Directory (with or without sync) and mostly get those strange characters
- read file and get strange characters too
- read Directory one more time and get nice list (mostly)
- read file and get strange characters
BTW, called E.unmountSD and readdir/readFile still returns data.
Unplugged from power and plugged to power, readFile still returns strange characters.I will go back to 1v72 to get my small project running. Promised to my friends, to get it running this week.
- unmount
-
• #8
Thanks... I wonder whether it's having a file open and reading the directory at the same time? If you use repeated
appendFile
calls rather thanE.openFile
do you still have the same problem?I'm kind of surprised 1v72 works and 1v73 doesn't in that case though.
called E.unmountSD and readdir/readFile still returns data.
Yes, calling any filesystem function will cause the SD card to be re-mounted...
I'll file a bug for this and will see what I can do when I get a moment.
-
• #9
Yes, same problem with appendFile. This is where I started having problems. Instead of appending, it created new files with same name.
To be honest, was it a file create or "only" create entry in directory.
With appendFile, this happens ramdom, I could'nt find special case to happen. -
• #10
Just checked with 1v79 and an external sdcard (catalex SPI MicroSD Card Adapter V1.0) on Espruino V1.3. Connected like this:
SPI1.setup({mosi:B5, miso:B4, sck:B3}); E.connectSDCard(SPI1, B6 /*CS*/); var fs = require("fs"); var i = 0; fs.appendFile("Juergen.json","hugo\n"); setInterval(function(){ digitalWrite(LED1,true); fs.appendFile("Juergen.json","emilio"); setTimeout(function(){digitalWrite(LED1,false);},200); i++; },2000);
Got same problems as mentioned above, lot of strange characters.
-
• #11
What if you set the baud rate as suggested above:
SPI1.setup({mosi:B5, miso:B4, sck:B3,baud:1000000});
-
• #12
Same problem with high baudrate, see images in entry 1 / 3
-
• #13
Tested with DrAzzys bigram, because I need some more memory.
SD card works fine with 1v72
Does not work anymore from 1v73
Same problem as official firmware from Espruino server. -
• #14
Thanks for checking - I'll see what I can do about this today.
-
• #15
Fixed! Sorry about that - it was a bit of a mess :( It'll be in the latest Git build, or 1v80 when it comes out.
Looks like it was probably the append, and I think it was less likely you hit the problem when just reading and writing - why I never spotted anything when I initially made the change.
-
• #16
...it looks like that it is time to build a test farm: a farm of connected Espruinos, each of them paired with key sensor/add-on boards to help to execute the regression tests... virtual testing just does not cut it anymore...
-
• #17
@allObjects & @Gordon I'm happy to set-up a rig as proposed and test releases.
-
• #18
I've actually already got two Espruino boards in my loft that I use for tests/benchmarking. In this case the SD code actually worked, for reading directories, and reading/writing files. AFAIK it was just appending them that was a problem - so hardly surprising it didn't pass the test.
Benchmark code is here
Perhaps we could come up with some simple design that we could share - like one board on top of the other, or perhaps even just one board with certain IO lines shorted. You just need to connect up Reset/BOOT0 pins so that one device can be reliably be put into bootloader mode.
Then, we could all come up with a whole bunch of different tests to run.
PS. the build with it fixes is here
-
• #19
Just finished testing and everything works fine with latest build.
Tested with SDcard from v1.3 board and with external SD-adapter.Thanks for fixing
-
• #20
Great! Thanks for letting me know!
Writing to SD card creates strange results.
Sometimes file is created several times.
Sometimes file holds strange characters.
Sometimes readdir returns strange characters.
Please see attached screenshot.
1 Attachment