• I'm writing some code to do some logging of data to the SD card and am seeing occasional errors when calling appendFileSync(), 2 writes out of 160 in a recent run.

    The error is: "ERROR: Unable to write file : INT_ERR"

    The appendFileSync() doesn't return a value to tell me programatically whether the operation succeeded or not. Is there any other way to tell if appendFileSync() encountered an error?

  • There isn't a way to tell if there has been an error I'm afraid. A return value could be good though...

    Have you tried using the absolute latest from http://www.espruino.com/binaries/git/com­mit_date/?

    I recently updated to a more recent filesystem library and rewrote bits of the SPI interface, so you might find that it fixes your problems.

  • At the moment I'm using the Espruino to do some long term logging tests, using the serial port rather than the SD card.
    I'll try using the latest code when I've finished my tests, probably next weekend.
    I'm going to have to order some more of these Espruinos...

  • My second Espruino arrived on Friday, so I've had a chance to do some more testing. I see this problem on two different Espruino's and two SDcards (although both SDcards are the same make , Kingston 8GB).

    If I run the following test program which simulates the type of logging I've been doing:

    var fs = require('fs');
    var testName    = "TEST152B.LOG";
    var testDetails = "Some text";
    var logInterval = 5000;
    var logEntry    = 0;
    // Initialise log file here with header information
    fs.appendFileSync(testName, testDetails);
    // Function to log some data every so often
        // Indicate each time function is executed 
        digitalPulse(LED1, 1, 100);
        // Log some data.
        var logString = logEntry + ": 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz : Time = " + getTime() + "\r\n";
        fs.appendFileSync(testName, logString);
    }, logInterval);    

    On Espruino running v1.50, I see the occasional INT_ERR, often two in a row on average 1 in every 100 writes. The log file on the SD card is missing the line logged:

    From console log:
    383: 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz : Time = 2239.606450000000222644
    ERROR: Unable to write file : INT_ERR
    384: 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz : Time = 2244.606450000000222644
    ERROR: Unable to write file : INT_ERR

    On Espruino v1.52, the errors are still there but the error type and pattern has changed. Now I see bursts of around 10 consecutive DISK_ERR. Again, the log file on the SD card is missing the lines logged:

    From console log:
    >1749: 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz : Time = 8814.510775683593237772
    ERROR: Unable to write file : DISK_ERR
    >1750: 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz : Time = 8859.444492382812313735
    ERROR: Unable to write file : DISK_ERR
    >... More consecutive DISK_ERR
    >1760: 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz : Time = 9122.928319238280892022
    ERROR: Unable to write file : DISK_ERR
    >1761: 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz : Time = 9135.649541601562305004

    I think the problem seems to be a little worse when I run PWM outputs, onewire temperature probes and serial output. I did wonder if the problem is related to electrical noise or maybe a problem with interrupts.

  • It could be interrupts I guess (especially on Serial IO). SPI is a little frustrating in that the hardware output buffer is effectively 2 bytes but the input buffer is 0ne byte, so it's amazingly easy to lose a byte if you don't service SPI immediately.

    However that's unlikely to be the problem, as you should get an SPI timeout in that case. Could you maybe try reformatting the card on your PC as FAT32 (it could be that there is something strange with the existing formatting).

    You could also try calling SPI2.setup({sck:B13,miso:B14,mosi:B15,ba­ud:100000}) after you've first used the SD card. That should push SPI into a lower bit rate which may solve problems if they are to do with IRQs.

  • Is there a way to determine when this has failed, so, we could, for example, automatically retry writing it?

    I will run into this issue pretty soon in my project. I need to be able to make sure that the data I'm logging is being recorded.

  • I could make it return a boolean value I guess - that would be the easiest way to check...

    I'd really like to try and find the root of the problem though ;)

  • Hi Gordon,

    I've doing a full format (FAT32) to the cards between each test to ensure they start off in a known state. I just ran the test overnight, setting the SPI speed to a lower bit rate after the initial write as you suggested. The problem is still there and I have more of an idea of how often it occurs...

    The results:

    • Log entries made 6944
    • 7 bursts of DISK_ERR
    • 92 lines missing from log

    That means bursts of errors happen about every 1000 writes and on average every 72 writes.

    Although I have several SD cards, they're only one type (Kingston, 8GB, Class4).

    Is there anyone who has a different type of card that could run the test listed in post number 4?

    You will need to run the test for at least a couple of hours to be reasonably sure of encountering the problem.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Occasional SD card: ERROR: Unable to write file : INT_ERR

Posted by Avatar for dprime @dprime