Main Site Documentation

Problem with SD card reader on USB


#1

Hi all,

I set up the FEZ Panda II to debug using RS232 and did the hardware mod via the cable to enable the USB host. I have managed to read files from an USB thumb drive using the examples… but I get a System.Exception when inserting an USB SD card reader (this one: http://www.kijkshop.nl/productafbeeldingen/kijkshop/zoom/KS117752z/trust%20cardreader%20cr-1350p.gif)

From the examples I have the following code. It’s an event handler that gets triggered when I insert an USB device. It works as expected with the thumb drive but not with the SD card reader. It doesn’t matter if I insert the card reader with or without a card. I tried with PersistentStorage(device) and PersistentStorage(device, 0) and also with 1,2,3 as second argument. (Windows detect the card reader as two drives).


        static void DeviceConnectedEvent(USBH_Device device)
        {
            Debug.Print("Device connected...");
            Debug.Print("ID: " + device.ID + ", Interface: " +
                        device.INTERFACE_INDEX + ", Type: " + device.TYPE);
         
            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Debug.Print("USB Mass Storage detected...");
                 ps = new PersistentStorage(device);
                 ps.MountFileSystem();
           }
        }

The debug window shows:

[italic]Device connected…
ID: 1073775012, Interface: 0, Type: 6
USB Mass Storage detected…
#### Exception System.Exception - 0xffffffff (3) ####
#### Message:
#### GHIElectronics.NETMF.IO.PersistentStorage::PersistentStorage_Helper [IP: 0000] ####
#### GHIElectronics.NETMF.IO.PersistentStorage::.ctor [IP: 0011] ####
#### SDC.Program::DeviceConnectedEvent [IP: 0060] ####
#### GHIElectronics.NETMF.USBHost.USBH_DeviceConnectionEventHandler::Invoke [IP: 0000] ####
#### GHIElectronics.NETMF.USBHost.USBHostController::nativeEventDispatcher_OnInterrupt [IP: 0037] ####
#### GHIElectronics.NETMF.System.InternalEvent::nativeEventDispatcher_OnInterrupt [IP: 0054] ####
A first chance exception of type ‘System.Exception’ occurred in GHIElectronics.NETMF.IO.dll
An unhandled exception of type ‘System.Exception’ occurred in GHIElectronics.NETMF.IO.dll

Uncaught exception [/italic]

The line that throws the exception is: ps = new PersistentStorage(device);

Am I missing something?


#2

Not sure why. Card readers and USB drives should be identical.


#3

System.Exception is very generic. Can I enable more debug features or trace into the GHI libraries to see on what it fails?

Or can I start from the USBH_RawDevice class and read/write some messages to the device to see what is going on? Are there any source snippets that I could use for that?


#4

Do you must use this one particular reader? It maybe simpler to try a different one.


#5

It’s the only one I have so I wanted to test with it. It works fine on the desktop system so it would be better if the issue can get resolved otherwise you end up creating a list of what is and isn’t supported rather than coding against specs.

I ordered the single slot SD Card reader I am planning to use in the final product. They should arrive next week. I wasn’t planning on ordering them until I was done testing with the stuff I already had to keep the costs low in case the project falls through because of things like this.


#6

If windows detects it as two drives, this may be that your SD card is formatted with two partitions. Try with an SDCard freshly formatted as FAT32. If the problem persists, this is due to the card reader that instantiates mounting points even if there’s no real filesystem (i.e. SD card) connected.

What about your SDCard reader without SD inserted on windows?


#7

The card reader without card shows up as two hidden drives in Windows (just tested). There are three slots on this device:

[ulist]T-Flash/MicroSD
SD/MMC
MS[/ulist]

I only have a SD card to test with, but I would think two of those slots share a logical drive, and then the other slot is a drive of its own. Maybe because of the cards being diff technology or something. The 60-in-1 or something card reader that is build in the desktop system shows up as a number of drives as well (hidden drives when empty).

I reformatted the card for FAT32, still the same logging.

I commented the lines:
// ps = new PersistentStorage(device, 0);
// ps.MountFileSystem();

And it gave this logging:

Device connected…
ID: 1073773092, Interface: 0, Type: 6
USB Mass Storage detected…

So it sees it as one USB Mass Storage… it does that with or without the card inserted.
Is this what you mean with mounting points? Sounds fair that it would raise an exception when the event is raised and there isn’t a card inside, but it should just work when the card is present at the moment of the event.

I’m not sure what that second argument (byte) is, that’s the logical drive? So when I get two drives in windows (J & K) and J is the SD card than that second argument would be 0 for the SD card?


#8

Update:

I received the SD card readers (single slot) that I’m planning on using and finally gotten around doing some initial tests and the readers are detected and I can read file and directory structure, and the content of a file from them. Haven’t tested writing to them yet.

A weird thing is that they are seen as a thumb drive, not as removable storage media. Is this normal? When I insert the card reader with card, events fire, and I can start using it. When I insert the card reader without a card, the same events fire, and I have to catch exceptions.

So there doesn’t seem to be a way to determine if a storage card is actually present in the card reader besides just trying to access it and catching the exception. To get notified about a card insert I would have to implement a polling. This seems like a waste of CPU to be honest.

I’m a missing something, or is this due to the SD card reader itself?


#9

Our library doesn’t check if media is installed in the reader as the main purpose was to serve thumb drives.


#10

I’ve seen many hardware implementations make choices that seem strange, but it comes down to what reference design the “designer” used when they built their module in Shenzen or wherever. Obviously some chips only present a storage device not a card reader, even though they’re physically a card reader; in a PC that isn’t usually a big deal, but it’s something you have to cater for yourself at this level, as you’ve found.


#11

Thanks for the replies. I will design the software accordingly. Plus side to this is that I can go with the cheap card readers I ordered :slight_smile: (there’s no need for a high end / more expensive reader if it doesn’t offer more functionality)