Exception on creating instance of PersistentStorage Class

I’m testing sample code for SD Cards shown in Chapter 21.1 of “Beginners guide to NETMF”.
I got the following exception on creating instance of PersistentStorage Class.

Exception System.Exception - 0xffffffff (1)

GHIElectronics.NETMF.IO.PersistentStorage::.ctor [IP: 0000]

FezSD_Card2.Program::Main [IP: 0007]

Exception caught at the line;
PersistentStorage sdPS = new PersistentStorage(“SD”);

My firmware is R4.0.3.0 and I’m using latest SDK Ver.1.0.5.
--------- MFDeploy log ---------
ClrInfo.targetFrameworkVersion: 4.0.1681.0
SolutionReleaseInfo.solutionVersion: 4.0.3.0
SolutionReleaseInfo.solutionVendorInfo: GHI Electronics, LLC
SoftwareVersion.BuildDate: May 21 2010

Attaching deployed file.
Assembly: GHIElectronics.NETMF.IO (4.0.3.0) (212 RAM - 664 ROM - 289 METADATA)

AssemblyRef = 8 bytes ( 2 elements)
TypeRef = 12 bytes ( 3 elements)
FieldRef = 8 bytes ( 2 elements)
MethodRef = 4 bytes ( 1 elements)
TypeDef = 8 bytes ( 1 elements)
FieldDef = 4 bytes ( 2 elements)
MethodDef = 20 bytes ( 9 elements)

Attributes = 0 bytes ( 0 elements)
TypeSpec = 0 bytes ( 0 elements)
Resources = 0 bytes ( 0 elements)
Resources Files = 0 bytes ( 0 elements)
Resources Data = 0 bytes
Strings = 212 bytes
Signatures = 33 bytes
ByteCode = 36 bytes

I ran the program with SD card (2GB/FAT32) inserted and removed, and resulted same exception. Please advice cause and workaround for this issue.

Did you try a different card?
Is there about 2 seconds delay from the time you call the constructor till you see the exception?

I tried two different cards (both 2GB, FAT16 and FAT32) and got same exceptions.

Yes, after I step over constructor call, exception occurred about 2 seconds of delay.

I tried to test PersistentStorage constructor call using USB memory, however Domino dose not detect my 4GB USB memory (could detect USB mouse and keyboard). I’m thinking to get other one for further test. Could this test be helpful for you?

It is unlikely that domino is having with multiple cards and USB memory! Maybe the power source is not okay. Try a power pack maybe

Thank you for your advice.

I did the following test with external power (9V DC) connected.

I got other USB memory (2GB) and sample code shown in section 22.2 of “Beginners guide to NETMF” worked fine! That’s say instance creation of PersistentStorage Class with USB mass storage is OK.

However, SD card sample caught exception as same as I reported at the first post. Exception caused after 2 seconds of constructor call. Please note that I’m not connecting multiple SD card and USB device, but connecting SD card ONLY.

I understood that constructor call of PersistentStorage Class kicks some access to the SD card via SPI. As USB memory access is possible using same class library, is there any hardware problem with my FEZ Domino?

FEZ use a standard 4-bit SD interface for SD cards…not SPI :slight_smile:

I doubt the problem is in FEZ. What brand if card are you using? I am near positive the problem is SD card. If you like to send us the SD card then we can test it for you. Can you try different SD cards?

Actually I had tested with three different SD cards;

  • Kingston SDC/2G
  • KINGMAX 2G
  • No brand 2G
    All resulted same exception on constructor call.

Even the above 3 SD cards are working fine with my PC, they are bit cheap ones. So, I’ll try to test with new SD card. SD card with Class 4 compliant is OK for testing? (I mean Class 6 compliant is not necessary).

In general, all cards should work. If out have cards that do not work, you can mail them to us to test out if you like.

I wouldn’t trust or use the cheap cards you buy on internet, especially the ones with no brand

Thank you for your quick response.

I bought new TOSHIBA SD card (2GB, Class4), and test resulted NG (exception on constructor call). At this moment, SD card support is not must have feature for me, so I’m not thinking to send my SD cards for your test.

However, I have one question. In case SD card is not present, I always got same exception on constructor call of PersistentStorage class. That say, exception occurred after few seconds of constructor call and exception code is same if SD card is present or not.
What is the expected behavior in case constructor call without presence of SD card?

=== Exception on PersistentStorage sdPS = new PersistentStorage(“SD”) w/o SD card ===
#### Exception System.Exception - 0xffffffff (1) ####
#### GHIElectronics.NETMF.IO.PersistentStorage::.ctor [IP: 0000] ####
#### FezSD_Card2.Program::Main [IP: 0007] ####

There is a method in the library to detect SD cards, try it before mounting.

If we can buy the card that doesn’t work then we would buy it and test it. Did you buy these cards online in USA?
All cards we have here work just fine…and we have many cards!

I had tested with minimum code as follows with SD card and external power present,


using GHIElectronics.NETMF.IO;

namespace FezSD_Minimum
{
    public class Program
    {
        public static void Main()
        {
            PersistentStorage sdPS = new PersistentStorage("SD");
        }

    }
}

I measured Drain voltage of T2 (P-ch FET to provide power for SD card slot), and found that voltage rose to 3.2V on constructor call. However, this code caused exception on constructor call.
========= exception =======
#### Exception System.Exception - 0xffffffff (1) ####
#### GHIElectronics.NETMF.IO.PersistentStorage::.ctor [IP: 0000] ####
#### FezSD_Minimum.Program::Main [IP: 0007] ####

Actually I bought my SD cards at retail store in Japan.
I found Kingston SD card (that dose not work with my FEZ Domino) in US Amazon site.

Kingston 2 GB microSD Flash Memory Card SDC/2GB:

I couldn’t find TOSHIBA card at Amazon.

regards.

I have ordered the card from amazon. I will test once I have it and let you know

I also verified this issue with two different cards on EM-TFT board

I used the code from the beginner ebook and with one card I get an execption

Source code from chapter 22.1 (page 111 and 112)

With a Transcend 8GB micro-sd with adapter I got following execption

[quote]Getting files and folders:
Files available on \SD:
\SD\CC-Zwei-225.mp3
\SD\Lost in Space 320.mp3
\SD\Lost in Space 192.mp3
\SD\Lost in Space 256.mp3
Folders available on \SD:
The thread 0x1 has exited with code 0 (0x0).
#### Exception System.IO.IOException - CLR_E_FILE_IO (4) ####
#### Microsoft.SPOT.IO.VolumeInfo::.ctor [IP: 0000] ####
#### Microsoft.SPOT.IO.RemovableMedia::MessageHandler [IP: 0017] ####
An unhandled exception of type ‘System.IO.IOException’ occurred in Microsoft.SPOT.IO.dll

Uncaught exception
#### Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4) ####
#### Microsoft.SPOT.IO.RemovableMedia::MessageHandler [IP: 004a] ####
An unhandled exception of type ‘System.NullReferenceException’ occurred in Microsoft.SPOT.IO.dll

Uncaught exception
Done.
Waiting for debug commands…
The program ‘[0x6] Micro Framework application: Managed’ has exited with code 0 (0x0).
[/quote]

With a normal 16GB Transcend SD-Card it works fine.

My first idea was to give some extra time after this line of code


PersistentStorage sdPS = new PersistentStorage("SD");

I add a settle time up to 2 sec with no luck.

When I use the debugger , step for step it works also with the 8Gb card.

I have been having trouble with Persistent storage, too. Interestingly enough, I am using the same card linked above.

same card…what if the problem is in the card.

Did someone try a USB drive or a different card?

Please try this , it works with my 8Gb card now


using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
namespace Test
{
class Program
{
public static void Main()
{
// ...
// SD Card is inserted
// Create a new storage device
PersistentStorage sdPS = new PersistentStorage("SD");
Thread.Sleep(2000);
// Mount the file system
try
{
    sdPS.MountFileSystem();
    // Assume one storage device is available, access it through Micro Framework and displayavailable files and folders:
    Debug.Print("Getting files and folders:");
    if (VolumeInfo.GetVolumes()[0].IsFormatted)
    {
        string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
        string[] files = Directory.GetFiles(rootDirectory);
        string[] folders = Directory.GetDirectories(rootDirectory);
        Debug.Print("Files available on " + rootDirectory + ":");
        for (int i = 0; i < files.Length; i++)
            Debug.Print(files[i]);
        Debug.Print("Folders available on " + rootDirectory + ":");
        for (int i = 0; i < folders.Length; i++)
            Debug.Print(folders[i]);
    }
    else
    {
        Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
    }
    // Unmount
    sdPS.UnmountFileSystem();
}
catch (IOException ex)
{

    Debug.Print(ex.ToString());
}
}
}
}

[quote]The thread 0x1 has exited with code 0 (0x0).

Exception System.IO.IOException - CLR_E_FILE_IO (4)

Microsoft.SPOT.IO.VolumeInfo::.ctor [IP: 0000]

Microsoft.SPOT.IO.RemovableMedia::MessageHandler [IP: 0017]

An unhandled exception of type ‘System.IO.IOException’ occurred in Microsoft.SPOT.IO.dll

Uncaught exception

Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (4)

Microsoft.SPOT.IO.RemovableMedia::MessageHandler [IP: 004a]

An unhandled exception of type ‘System.NullReferenceException’ occurred in Microsoft.SPOT.IO.dll[/quote]

This happens when you Umount() too fast which shouldn’t normally be the case. For example:
-Insert SD and Mount.
-Microsoft.SPOT.IO.RemovableMedia::MessageHandler will try to send an Insert Event
-before the event is sent, you called Unmount.
-Microsoft.SPOT.IO.RemovableMedia::MessageHandler will send an exception because there is no SD card anymore!

Our examples in documentation do not have these issues because they process SD cards in Insert events not sooner…

As I said before , this piece of code is copied directly from the beginner’s ebook.

With the 8GB Transcend card it didn’t work.

When I extend the code with


....

Thread.Sleep(2000);
....
try {

....

}

catch (IOExecption ex)

{
...
}



it works

But I think it depends which SD-Card is used.

Well, my CLR_E_FILE_IO occurred when I was reading the file, not when I mounted it. I think I have a similar, but different bug.

I have encountered the same exceptions as cypher with a no-brand name 1gb SD card.

Initially I had one file (a .txt named “Test” with some random strings in it for testing) and both cypher’s code and the booklet code threw exceptions. The Documentation code did not.

But, I found that if I put a lot of random files on the card (about 100mb worth) all the code examples worked without throwing exceptions!!!

I also have a Kingston marked 2gb SD card and the example code in the documentation, booklet, and cypher’s all worked with that card (no exceptions) regardless of how much space on it is used.

Edited for clarity

Edit2:

I’ve been experimenting further and I must have been mistaken before as my Kingston SD cards are now having the same problem. If I just have the test text file (~1kb) on the card, exceptions are thrown. But if I add a few random pdf’s (~7mb) no exceptions are thrown.