Exception with multiple USB flash drives on G120

Hello

I just connected an USB hub to my FEZ Cobra II and put 2 USB flash drives into it. The first one is mounted correctly:


USB Mass Storage detected...
Storage "\USB" is inserted.
Total size of storage device \USB is : 3.44 GB.
Total free memory on \USB is : 2.93 GB.

The second is mounted but gets a very strage name:


USB Mass Storage detected...
Storage "\USB_1��NO NAME    " is inserted.
Total size of storage device \USB_1��NO NAME     is : 3.80 GB.
Total free memory on \USB_1��NO NAME     is : 3.59 GB.

When I remove the first one everything seems to work:


Storage "\USB" is ejected.

But I get an exception when I remove the USB flash drive that was inserted last:


    #### Exception System.Exception - CLR_E_WRONG_TYPE (4) ####
    #### Message: 
    #### System.String::ToUpper [IP: 0000] ####
    #### System.IO.FileSystemManager::ForceRemoveNameSpace [IP: 0007] ####
    #### Microsoft.SPOT.IO.RemovableMedia::MessageHandler [IP: 005c] ####
A first chance exception of type 'System.Exception' occurred in mscorlib.dll
An unhandled exception of type 'System.Exception' occurred in mscorlib.dll

It might have to do with the strange name the second drive gets assigned, since it originates in String::ToUpper.

Here is my test code:


using System.Collections;
using System.Threading;
using GHI.Premium.IO;
using GHI.Premium.System;
using GHI.Premium.USBHost;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;

namespace UsbWrite
{
    public class Program
    {
        private static readonly ArrayList Storages = new ArrayList();

        public static void Main()
        {
            USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;

            RemovableMedia.Insert += RemovableMedia_Insert;
            RemovableMedia.Eject += RemovableMedia_Eject;

            Thread.Sleep(Timeout.Infinite);
        }

        static void DeviceConnectedEvent(USBH_Device device)
        {
            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Debug.Print("USB Mass Storage detected...");
                var storage = new PersistentStorage(device);
                storage.MountFileSystem();
                Storages.Add(storage);
            }
        }

        static void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            Debug.Print("");
            Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is inserted.");
            if (e.Volume.IsFormatted)
            {
                Debug.Print("Total size of storage device " + e.Volume.RootDirectory + " is : " + (e.Volume.TotalSize / (float)(1<<30)).ToString("F2") + " GB.");
                Debug.Print("Total free memory on " + e.Volume.RootDirectory + " is : " + (e.Volume.TotalFreeSpace / (float)(1 << 30)).ToString("F2") + " GB.");
            }
            else
            {
                Debug.Print("Storage is not formatted. Format on PC with FAT32/FAT16 first.");
            }
        }

        static void RemovableMedia_Eject(object sender, MediaEventArgs e)
        {
            Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is ejected.");
        }
    }
}

Is there something I did wrong, or are 2 flash drives just not supported?

Greetings
Peter

I don’t think it’s the USB stick. I have 4 different sticks on my table and can reproduce the issue with all of them. The first one works and the second crashes the system.

[quote=“Peter B”]
I just connected an USB hub to my FEZ Cobra II and put 2 USB flash drives into it. The first one is mounted correctly:[/quote]
As a guess, I’d say that the USB Host driver does not implement the USB hub protocol. This is necessary to correctly handle insertion and removal of USB devices from a hub.

Cuno

@ andre.m - Yes :slight_smile:

Our Mountaineer Prime software also supports USB Host, but has the same restriction.

FYI: I have used a USB thumb drive and a USB GPS receiver with a USB hub on a Spider with success.

if it is just happened on usb which has larger than 4G, I think that is NETMF

Stil read/write ok?

I cut-n-pasted your code into a Gadgeteer (spider mainboard) and it worked fine:

[quote]Storage “\USB” is inserted.
Total size of storage device \USB is : 3.61 GB.
Total free memory on \USB is : 2.87 GB.
Storage “\USB_1” is inserted.
Total size of storage device \USB_1 is : 3.61 GB.
Total free memory on \USB_1 is : 3.32 GB.
[/quote]

but I am using a beta of the upcoming SDK

@ Jeff - will try Cobra now.

No I won’t – no H socket

Thanks for your attempts.

I am using the Premium libraries. The insertion of multiple USB-devices seems to work - at least I get an Inserted-event.

I think there is a problem with the names that are assigned to the devices. As I wrote the name of the second stick is always

"\USB_1��NO NAME    "

(with 4 trailing spaces). I think this is what causes

System.String::ToUpper

to throw exceptions.

Strange thing that it works with Spider, but not with Cobra II.

But anyway: That feature is not super important to me.

I have seen this same issue with the G400D v1.3. When you insert the second USB Drive you get the garbled name. I have found that if you unplug and reinsert the second USB drive a second time that it does come up with a correct name and you can use the drive, atleast with the G400D.

[em]During development last week, we as well noticed this issue. The issue is not one with using a HUB, using a HUB with 2 different USB devices (as mentioned) will work, the issue arises when using 2 devices of the same type (2 thumb drives, 2 keyboards, etc). We are working to resolve this issue, hopefully in time for the next SDK.[/em]

My apologies, this was an explanation to a similar, but unrelated issue also involving USB.

Fixed in the nex SDK.