ERROR: Could not open file : DISK_ERR

Posted on
Page
of 2
/ 2
Next
  • Hello,

    I connected a SD card reader module to the Pico. I set it up the following way:

    var spi = new SPI();
    spi.setup({mosi:B14,miso:B15,sck:B13});
    E.connectSDCard(spi, A8);

    I experience in some situations that I receive "ERROR: Could not open file : DISK_ERR" errors for files that are definitely existing. After receiving the error message I have to set the above mentioned settings again to do subsequent file access.

    What can cause this error? How can I handle it, so that my software automatically sets the configuration again when it got lost? I thought it could be a problem with E.unmountSD(), so I removed all unmounts in my code, but that didn't work.

    Best,

    Tobias

  • That's a strange one. When you get DISK_ERR, can do do anything (eg. list files) or is it totally dead?

    Are you sure it's not that something is using the pin for something else, or even potentially a wiring issue? Calling E.connectSDCard would cause the card to be re-initialised, so if something had confused it (for instance dodgy power wiring?) that would fix it.

    To detect it, I think you could check for readFile returning undefined, or even catching any exceptions that get thrown. However I'd maybe check wiring first, and put a capacitor across the power lines right near the SD card just in case. It really shouldn't happen in normal use.

  • Everything is working well for the most of the time. Sometimes this error comes up and then I can't do anything with files before I set the SPI settings again. Can it be a problem with the SD card itself?

    The wiring seems to be ok for me.

  • I guess it's possible. Hard to say - I don't think anyone else has had this kind of issue.

    Is anything else connected to the 3.3v line? If the voltage on it is unstable, that could throw off your SD card I guess?

  • The reader needs 5V, so it's connected through a regulator with the battery.

  • Ahh - is it one of those with circuitry to change the voltage levels on? I've only ever really connected directly so I guess that could be a problem - after all, the Espruino is only giving out 3.3v signals so if it's expecting 5v it could be unreliable?

  • It is a little bit strange. When I upload the code and write save() in the console. Everything is working well. But when I call reset(); and load(); then I get DISK_ERR, but not directly.

    I do the following:

    function onInit() {
      var spi = new SPI();
      spi.setup({mosi:B14,miso:B15,sck:B13});
      E.connectSDCard(spi, A8);
      eval(require('fs').readFile('code.js'));­
    }
    

    In the code.js there are subsequent file access routines.

  • Ahh, ok - that could maybe be related to software SPI. You need to call spi.setup({mosi:B14,miso:B15,sck:B13}); from onInit - you can't rely on it staying set up correctly after a reset.

  • Hmm... I call it from onInit as you can see in the code above.

  • Sorted it out. But I am not happy with the solution.

    The problem was Serial1. The sim900 board was sending some bytes while the interpreter was executing some code. Unfortunately the bytes haven't been sent just to USB. It has been sent to the interpreter as well, which was confusing the code execution.

    This code piece in onInit() did it:

    setInterval(function() {
        if (process.env.CONSOLE=="Serial1") setConsole(LoopbackA);
      }, 1000);
    

    As well after some time this code piece produces the following warning:

    WARNING: Unable to create string as not enough memory
    

    Unfortunately I soldered the wires for connecting the sim900 to the Serial1 pins. Is there a way to set Serial2 to be the default fallback serial port when USB is not connected (maybe in some build parameters for the firmware)? I would be happy with disabling this feature totally as well.

    Best,

    Tobias

  • That's kind of strange - if the device boots when not connected to USB, if you set the console just once in onInit you should be fine. It'd only be if you then plug USB in and unplug it again that you'd have a problem?

    But yes, if you're building your own binary it's pretty easy to change the default serial port - the lines you need to change are here

  • If I use the device just without USB it seems to be working (I am not 100% sure because I can't see any logs) but when it is connected I get the DISK_ERR and some weird characters in the console. You told me that USB.setConsole() in onInit should do it. But this didn't help. With the lines above this problems are not coming up.

    Did you see the warning message I put in the update of my post? Why does that come up after a while?

    Best,

    Tobias

  • UPDATE: I had a question regarding the build process here. Forget about this post. I use vagrant now.

  • I created my own build now for solving the Serial1 problem. As well I experienced that the DISK_ERR is not related to this line (beside the other problem I had):

     if (process.env.CONSOLE=="Serial1") setConsole(LoopbackA);
    

    I am currently able to solve it by just setting some interval. The following line helps as well:

    setInterval(function() { /* do nothing */ }, 1000); 
    

    Do you think it could be a problem with the software SPI when the Espruino goes in sleep mode?

    UPDATE: Is there a possibility to set the SD card settings in the build settings for the Pico as well? I saw there is a DEVICES section in the script for the regular Espruino. Can I use that in the script for the pico for the SD card as well?

  • Do you think it could be a problem with the software SPI when the Espruino goes in sleep mode?

    Are you using setDeepSleep(1)? I doubt it'd be a software SPI issue, but that will stop Espruino from receiving Serial data when it's asleep. Without it, it should be ok though.

    Warning message

    Well, that's telling you you're out of memory - but you're saying you don't get that without the LoopbackA.setConsole() (I assume that's what you meant, and not setConsole(LoopbackA); that you wrote?).

    I guess the only possibility there is that LoopbackA loops characters back to LoopbackB, which then stores (up to 512) of them. Any more get dropped off the end.

    If you were very short on memory I guess those extra 512 chars could cause you problems?

  • Okay I'll make sure that it doesn't use deepSleep. Have you read my update regarding the build settings for the SD card under the post as well?

    What's the difference between setConsole(Serial) and Serial.setConsole() ?

  • What's the difference between setConsole(Serial) and Serial.setConsole() ?

    setConsole(Serial) should fail with Uncaught Error: Function "setConsole" not found!, the other will work :)

    Sorry, I missed the SD card question...

    Is there a possibility to set the SD card settings in the build settings for the Pico as well?

    Yes, then you won't need E.connectSD - however I'm pretty sure that only works for SD cards connected with hardware SPI, not software SPI...

    To use it, just copy the SD card lines you'd have seen for the original board and change them as needed.

  • Hmm.. it is not working. It states "ERROR: Unable to mount SD card : NOT_READY"

  • Not sure what to suggest - maybe check in gen/platform_config.h and check SD_SPI is set to the correct SPI number. It should be though.

    Which pins are you using?

  • I had the following config:

      'SD' :  { 'pin_cs' :  'A8',
                'pin_di' :  'B15',
                'pin_do' :  'B14',
                'pin_clk' :  'B13' }
    

    The platform_config.h defines are looking good as well:

    #define SD_CS_PIN 8/* A8 /
    #define SD_DI_PIN 30/
    B15 /
    #define SD_DO_PIN 29/
    B14 /
    #define SD_CLK_PIN 28/
    B13 */
    #define SD_SPI EV_SPI2

  • That is strange then - I really don't know what to suggest. It's not saying anything about the SD card not being configured, just that it can't find the SD?

    What if you then set up the SD card manually with the E.connectSD as you were doing before? Does it work then?

    Are you sure those pins aren't used for anything else? For instance even initialising I2C3 without any arguments could pick pin A8 and use that.

  • It just shows the message "ERROR: Unable to mount SD card : NOT_READY" nothing else. It is not saying anything about a missing configuration. When I do an E.connectSD it works as in the other build.

    I checked that I don't use the pins for something else. Is there maybe a parameter that I missed in the build settings?

  • As far as I can see it should be fine - the relevant code is here

    However I notice you're using software SPI in your connectSD example - does it still work if you use hardware with:

      SPI2.setup({mosi:B14,miso:B15,sck:B13});­
      E.connectSDCard(SPI2, A8);
    

    and what if you try:

      SPI2.setup({mosi:B14,miso:B15,sck:B13,ba­ud:1000000}); // maybe try 10x bigger/smaller values for baud rate and see what happens
      E.connectSDCard(SPI2, A8);
    

    My only guess right now is that there might be some issue with the wiring/SD card and the speed of communication. Software SPI might happen to be the right speed, but if there are pauses in it because of interrupts/etc then that might confuse the SD card and would account for your unreliability.

  • I solved the problem !!!! I didn't see that I swapped MISO and MOSI in my wiring... I saw it in the code that there must be something wrong. :)

    The strange thing is that it worked with

    var spi = new SPI();
    spi.setup({mosi:B14,miso:B15,sck:B13});
    E.connectSDCard(spi, A8);
    

    but not with

    SPI2.setup({mosi:B14,miso:B15,sck:B13});­
    E.connectSDCard(spi, A8);
    

    Thank you so much for your patience and for your help Gordon!

  • This should have thrown an error saying that the pins were not capable of that:

    SPI2.setup({mosi:B14,miso:B15,sck:B13});­

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

ERROR: Could not open file : DISK_ERR

Posted by Avatar for net-tobi @net-tobi

Actions