System.IO.IOException and File.Delete SD/MMC card access

I’m encountering a number of problems with SD/MMC memory card and the EMX platform:

  1. at random times triggering IOException on file write and all file writes thereafter
  2. File.Delete sometimes working, sometimes not working, sometimes locks up the EMX target entirely without generating an exception

These problems occur on a small percentage of units in production, about 10%, but are a major concern when they do occur.

When I’ve worked with SD/MMC cards before for other applications and other platforms, there is usually a check implemented that the memory card is not busy. Is there anything like that available?

Are there any caveats, cautions, or known issues when using the SD/MMC persistent storage on the EMX platform? Maximum file size?

Hi,
I was experiencing a similar problem. But it only occurred when I went down a certain route through the code. What is the IO error you are experiencing?

For me it was access denied. It was down to a small bug in my code where I had forgot to close a file after trying to check it existed.

Jas

This is usually related to your power source.

Thanks for the suggestion Jas.

Concerning error #1: IOException on write, this is for a logging application to a single file so the file is open all the time. As I wrote before, however, the error only develops on about 10% of identical production units.

Concerning error #2 lock up on File.Delete. The error occurs on the 3rd sequential call to File.Delete with no other open files. The first 2 calls to delete files seemingly go OK, but then on cycling power the files are still there. Time delay between delete calls don’t impact behavior. Again: this doesn’t happen on all units.

I am suspecting the SD/MMC card is bad on some units, but it had worked fine on them for a time, and continues to work fine on others, so I’m trying to rule out any software/firmware errors.

I replaced the memory card and the problems above went away. Same board, same power supply.

I have another open question in the general forum concerning Volume.Format not working. Replacing the memory card didn’t solve the problem calling format.

We noticed that some cards caused some noise on the power and adding 22uF+ capacitor solved this problem. This will be improved on our end in future but it is something you can try.

Gus, This is a major issue particularly as it effects system reliability. I recommend GHI placing it as an notice with the product documentation downloads rather than an informal recommendation inside the forum.

Can I tie the SD power to the 3.3V power supply as a fix, or does the GHI SD/MMC driver need to cycle power to the card via pin 68?

In general, all works just fine. Just recently we noticed this on certain cards. We are of course working on improving this.

If you tie SD to power directly then you need to disconnect the power pin from EMX module.

Is there a software fix? That would be HUGE. When my system gets in this state the only remedy to get memory card access back online is to cycle power to the whole system and that isn’t acceptable. Mount/unmount doesn’t fix it. Can I cycle power to the card via pin 68 (SD_PWR) directly via a GHI library call ?

Does GHI Electronics recommend any particular brand of memory cards they’ve tested to work with their EMX pin 68 power source that don’t need the capacitor?

Power is cycled automatically when mount/unmount.

Sandisk seem to work fine but we do not recommend a specific brand/card. It is best to test the card of your choice and us in future. Any card should work as far as the design is implemented but there is always this one card that messes everything up.

Adding a 47uF capacitor on that pin seems to have remedied these bizarre problems (that can’t be remedied with mount/unmount or other software means).

What’s the class / speed rating on the SD cards GHI has tested successfully? Can you share the exact SanDisk model number you tested previously that worked?

Sorry, we do not share exact part numbers as this may cause many problems. We rather you try a card, like it, and use it :slight_smile:

We are experiencing the same troubles. Still building prototypes, the first ones was running well while the last are SD unstable. We supply the SD card with EMX IO68. IO68 is also connected to a capacitor of 4.7µF. We will change this capacitor into a bigger one (probably 22 or 47 µF) to check if it is better or not.

We tried with capacitor of 20µF without success.

Here is the sample code:

public void SDC_open_device()
        {
            while(!PersistentStorage.DetectSDCard())
            {
                Debug.Print("Please Insert SD card!");
                Thread.Sleep(1000);
            }

            SdPS = new PersistentStorage("SD");
            SdPS.MountFileSystem();
            root_sdc = VolumeInfo.GetVolumes()[0].RootDirectory + @ "\";

        }

Here’s the debug logscreen:

[quote]Please Insert SD card!
Please Insert SD card!
#### Exception System.Exception - 0xffffffff (1) ####
#### Message:
#### GHIElectronics.NETMF.IO.PersistentStorage::.ctor [IP: 0000] ####
#### ProjetNDR.SDC::SDC_open_device [IP: 001c] ####
#### ProjetNDR.SDC::.ctor [IP: 000e] ####
#### ProjetNDR.ProjetNDR::Main [IP: 0026] ####
Une exception de première chance de type ‘System.Exception’ s’est produite dans GHIElectronics.NETMF.IO.dll
Une exception non gérée du type ‘System.Exception’ s’est produite dans GHIElectronics.NETMF.IO.dll[/quote]

Try this, do not use detect SD method ten try to remount up to 3 times and see if it works the second time. You need to put the SD card in before hand and then step in code

mount()//first one, does it work?
mount()//second one, does it work?
mount()//third one, does it work?

Hi Gus

The problem is that it crashes while creating the new persistentstorage(“SD”);
I just put the detect method to ensure that SD is inserted.

leforban,

I was having trouble using a microSD card from a manufacturer that wasn’t SanDisk. I added the 47 uF cap (because that’s all I had) as Gus suggested and that fixed my problem with the intermittent memory card exceptions. Also, the format command started working also, whereas before it would get part-way through the format operation and then throw an exception.

I also switched some systems over to using SanDisk cards without the capacitor and that also worked perfectly.

it doesn’t “Crash”, it throws an exception

try
{
mount();
}catch{}

try
{
mount();
}
...etc.

Ok it throws an exception and as exceptions are not caught, my application stops. From my point of view my code crashes. Anyway…

The board that were not working properly yesterday seems to worke better today… :’( I just have only one that goes on to throw the exception while executing SdPs= new PersistentStorage(“SD”);

Here’s the code:

 public void SDC_open_device()
        {

           SdPS = new PersistentStorage("SD");

            try
            {
                SdPS.MountFileSystem();
            }
            catch { }
            try
            {
                SdPS.MountFileSystem();
            }
            catch { }

            try
            {
                SdPS.MountFileSystem();
            }
            catch { }

            root_sdc = VolumeInfo.GetVolumes()[0].RootDirectory + @ "\";


        }

Obviously application exits before running the mount statement so the several try catch statement are unusefull in this case. Should I try put the try catch such that the persistent storage being encapsulated?