SD Card File System Corruption

It sounds like you needed some of the data off those card’s. I’m lucky that in my situation. I’m OK with just kissing it good bye. But it’s got to be a smooth transition. I’m really hoping that I can achieve that or my project could be in tatters’.

@ John -

I’ve tried all sorts of ways at using new Microsoft.SPOT.IO.VolumeInfo(@ “\SD”).Format(???)


new Microsoft.SPOT.IO.VolumeInfo(@ "\SD").Format(???)

It does erase the card, but does not install the new file system. Can I get an example please.

Thanks

Thanks for adding the extra info. I did try that and a few other uses but I can’t get it to work.

This is what I tried.


new Microsoft.SPOT.IO.VolumeInfo(@ "\SD").Format("FAT", 0, true);

This is what is thrown.


nothing mounted yet?
SD Card Mounted!
    #### Exception System.IO.IOException - CLR_E_FILE_IO (1) ####
    #### Message: 
    #### Microsoft.SPOT.IO.NativeIO::Format [IP: 0000] ####
    #### Microsoft.SPOT.IO.VolumeInfo::Format [IP: 003c] ####
    #### Microsoft.SPOT.IO.VolumeInfo::Format [IP: 000b] ####
    #### G120.Tools.FileManagement.FileManager::Format [IP: 0013] ####
    #### G120.Program::Main [IP: 0034] ####
A first chance exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll
An unhandled exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll

Am I supposed to mount it first? I can’t get it to work no matter what I try.

Thanks

I’ve been playing with that this morning and can’t get it to work.

This;

VolumeInfo.GetVolumes()[0].Format(“FAT”, 0, true);

Throws This;


    #### Exception System.IO.IOException - CLR_E_FILE_IO (1) ####
    #### Message: 
    #### Microsoft.SPOT.IO.NativeIO::Format [IP: 0000] ####
    #### Microsoft.SPOT.IO.VolumeInfo::Format [IP: 003c] ####
    #### Microsoft.SPOT.IO.VolumeInfo::Format [IP: 000b] ####
    #### G120.Tools.FileManagement.FileManager::Format [IP: 0012] ####
    #### G120.Program::Main [IP: 0034] ####
A first chance exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll
An unhandled exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll

And This;


public static void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            //sdCardVolume = e.Volume;
            Debug.Print("Card Inserted.");

            if (!e.Volume.IsFormatted)
            {
                e.Volume.Format("FAT", 0);
            }
        }

Throws This;


Card Inserted.
    #### Exception System.IO.IOException - CLR_E_UNAUTHORIZED_ACCESS (4) ####
    #### Message: 
    #### System.IO.FileSystemManager::LockDirectory [IP: 0037] ####
    #### Microsoft.SPOT.IO.VolumeInfo::Format [IP: 0031] ####
    #### Microsoft.SPOT.IO.VolumeInfo::Format [IP: 000b] ####
    #### G120.Program::RemovableMedia_Insert [IP: 001f] ####
    #### Microsoft.SPOT.IO.RemovableMedia::MessageHandler [IP: 0041] ####
A first chance exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll
An unhandled exception of type 'System.IO.IOException' occurred in Microsoft.SPOT.IO.dll

I’m beginning to wonder if it is possible to format the card at all without a PC. But @ John- pointed me to this class. So I’m pursuing it. Could someone from GHI chime in here. I’d hate to waste @ andre.m- 's time if it can’t be done.

Thanks

@ stotech -
Try a different SD if the code below still doesn’t work for you!
This test is done on FEZ Cobra II

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;
using GHI.IO;
using GHI.IO.Storage;
namespace Format
{
    public class Program
    {
        private static OutputPort led = new OutputPort((Cpu.Pin)(47), true); // LED
        private static InputPort ldr1 = new InputPort((Cpu.Pin)(22), false, Port.ResistorMode.PullUp); // LDR1
        public static void Main()
        {
            while (ldr1.Read())
            {
                Thread.Sleep(50);
                led.Write(!led.Read());
            }
            SDCard sdPS = new SDCard();
            sdPS.Mount();
            VolumeInfo vol = VolumeInfo.GetVolumes()[0];
            try
            {
                Debug.Print("Formating...!");
                vol.Format("FAT", 0);
                Debug.Print("Formatted");
            }
            catch (Exception)
            {
                Debug.Print("Can not format this SD.");
            }            
            Thread.Sleep(Timeout.Infinite);
        }
    }
}

Thankyou so much!

I ran it on my cobra 2 and it failed. I went and got a new SD Card this morning and it worked.

Do you guys have a specific size and brand that you recommend. If I want to put these in factory’s everywhere. I better nail it.

The SD Card I was using worked fine for every operation but formatting???

Thanks Again!

@ stotech - A few years back we had problems with some Kingston cards, and there were several reports by others of this.
It was suspected to be a power supply issue, with the card supply from the EMX being insufficient for some write operations, and we changed our board design so that the uSD card is powered directly from the 3.3V rail.
We have been using Transcend and SanDisk 8GB cards without any problems.

I was totally thrown because the card seemed fine for everything else but formatting. Thought I’d mention it for anyone else who is browsing the forums that this can happen.

This is probably a really dumb question. But I’m just trying to be as thorough as possible. Can the file system become corrupt during a read operation. I’m using a 1F cap, diode and interrupt pin, to protect against the power failure thing. So far so good. But just to be sure I thought I’d ask the question.

Thanks

:-[

if you only do read opperations the file system can’t get corrupt. Only if you do writes and files are not closed before power down or reset.