Main Site Documentation

SD Card Problem


#1

Hello,

I got my FEZ Cerberus Tinker Kit few weeks ago and I am starting to test the modules… I am having a problem with the SD Card.

I checked the forums and documentation, but they make reference to Net 4.2 (I have 4.3) and libraries that no longer exists… but the basic idea was there… so I added the module to the designer and tried the following code… but I am getting errors and I have no idea why.

    public partial class Program
    {
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            characterDisplay.Clear();
            characterDisplay.Print("Program Started");

            sdCard.DebugPrintEnabled = true;

            sdCard.Mounted += sdCard_Mounted;
            sdCard.Unmounted += sdCard_Unmounted;

            if (!sdCard.IsCardMounted)
                sdCard.Mount();
        }

        void sdCard_Unmounted(SDCard sender, EventArgs e)
        {
            Debug.Print("sdCard_Unmounted");
            characterDisplay.Clear();
            characterDisplay.Print("sdCard_Unmounted");
        }

        void sdCard_Mounted(SDCard sender, GT.StorageDevice device)
        {
            Debug.Print("sdCard_Mounted");
            characterDisplay.Clear();
            characterDisplay.Print("sdCard_Mounted");
        }
    }

And I am getting this exception when I debug the program and the SD Card has already been inserted:

[quote]Using mainboard GHI Electronics FEZ Cerberus version 1.2
A first chance exception of type ‘System.Exception’ occurred in GHI.Hardware.dll
Program Started
A first chance exception of type ‘System.Exception’ occurred in GHI.Hardware.dll
The thread ‘’ (0x3) has exited with code 0 (0x0).[/quote]

If I cancel the Debug session and manually press the RESET button in the board I get this exception (I got it from MS Deploy)

[quote]ERROR : The SD card does not have a valid filesystem.
SDCard ERROR : The SD card does not have a valid filesystem.
sdCard_Unmounted
SDCard ERROR : The SD card does not have a valid filesystem.
sdCard_Unmounted
SDCard ERROR : The SD card does not have a valid filesystem.[/quote]

Then I disconnect the USB Cable, wait 2 seconds, connect the power back on and it works!

The Mount event gets called, if I take the SD card out, the Unmount event gets called, etc…

[quote]sdCard_Mounted
sdCard_Unmounted
sdCard_Mounted
sdCard_Unmounted
sdCard_Mounted[/quote]

At this point, if I try to debug it with Visual Studio or press RESET (without removing the power) I get the first error again.

[quote]Using mainboard GHI Electronics FEZ Cerberus version 1.2
A first chance exception of type ‘System.Exception’ occurred in GHI.Hardware.dll
Program Started
A first chance exception of type ‘System.Exception’ occurred in GHI.Hardware.dll
The thread ‘’ (0x3) has exited with code 0 (0x0).[/quote]

Any ideas why?..

I tried creating the SD Card module manually instead of the designer, I tried Mainboard.MountStorageDevice, I even tried using the class GHI.IO.Storage.SDCard instead of the Gadgeteer Module and I get the same results.

I formatted the SD Card (128mb supplied in the tinker kit) with FAT16 and I made sure it works fine in Windows.

Any help would be appreciate it.

Thanks.


#2

@ dulfe -

Please try with another SDCard, 1G or bigger.

If you don’t have any different one, try to set the SD clock slower. 4.3 supports this feature.


#3

I will try and buy a new card today… in the meantime… How do I change the SD Clock? (I would like to test that)

Thank you!


#4

@ dulfe -
Gageteer code does not support to change SD speed, if you want to change the speed, you have to use code non-gageteer for SD. But I recommend for a large size one.

SDCard sdPS = new SDCard();
            
            // Mount the file system
            sdPS.Mount(8000); // 8MHz
            //sdPS.Mount(4000); // 4MHz
            VolumeInfo vol = VolumeInfo.GetVolumes()[0];
            if (vol.IsFormatted == false )
            {
                Debug.Print("Formating...!");
                vol.Format("FAT", 0);
                Debug.Print("Formatted!");
                _led.Write(true);
                Thread.Sleep(-1);
            }
            else
            {
                Debug.Print("Initialize OK....");
                Debug.Print("Label = " + vol.VolumeLabel);
                Debug.Print("Size = " + vol.TotalSize);
            }

#5

sdCard.Mount(Clock in Khz)

@ Dat Do you have information about the default clock speed and limitations for each available board?


#6

@ RobvanSchelven -

As I know:

default:
EMX: 9MHz
G120: 10Mhz
G400: 2Mhz
Cerberus: 10MHz
Hydra: 2.5MHz

Min is 1Mhz
Max for all board is 25MHz, but some board use divide so if you call Mount(25000) it can be 30MHz when you measure (Cerberus).
Or when you try 10Mhz it can be 9Mhz on EMX (72/2/2/2 = 9MHz). I mean the speed can be not exactly as you wanted, but it will be as close as possible.


#7

@ Dat

Changing the speed to 8Mhz worked!.. the SD Card gets detected on boot without a problem…

BUT, that class does not have events… so I cannot check if the memory card has been inserted or not.

And the property “GHI.IO.Storage.SDCard.IsCardPresent” is always TRUE? (It says 36 -see image-)

Thank you!


#8

@ dulfe -

I see. It may a bug detect SD card on Cerberus.
But, you can check the SD Card is inserted or not by check the status of SD detect pin. It is not difficult.

Yes, you are using non-gageteer code, there will be no event provided. you can build by self. It is also not difficult.

:smiley:


#9

I tested with a new SD card (well… a micro SD in a SD adapter)… and it works fine without changing the clock speed.

And detecting the card was easier than I thought!..


var socket = Socket.GetSocket(7, true, null, null);
var detect = new InterruptPort(socket.CpuPins[3], true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
detect.OnInterrupt += (data1,data2,time)=> {
    Debug.Print((data2 == 0) ? "Card Detected" : "No Card Detected");
};

THANK YOU for your help!


#10

Interesting to see that the G400 is the fastest processor here but the slowest SD card access.

Is there a reason for this?