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.
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?
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
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).
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?
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.
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.
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());
}
}
}
}
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…
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.