How to show a USB Host object over USB Client?

In trying to expose a USB Thumbdrive attached to my spider board via the usb host module to a PC, I’m able to see a device hooked up to my PC.

I’m using this code:


PersistentStorage ps = new PersistentStorage(device);
ms.AttachLun(0, ps, " ", " ");
ms.EnableLun(0);

having already established the device to the PC (ms = USBClientController.StandardDevices.StartMassStorage():wink:

However, the drive that my PC creates for the new device is always empty or needs formatting. The thumbdrive I’ve hooked up to my spider/usbhost is accessible on the PC, and if I look at it internally to the Spider I can see the directories, etc.

Am I missing something in the sequence of getting the USBHost-attached thumbdrive exposed to the PC? (Let me rephrase, I’m sure I am - but haven’t figured out what)

Any tips? (FWIW, my usb host module is NOT wired to the Spider in the IDE, avoiding conflicts with the gadgeteer library)

Are you using serial debugging?

Of course, although it took me a bit to learn how that works :-). My complete configuration is Fez Spider, RS232 module connected to socket 11, USB Client DP hooked up to Socket 1, USBHost hooked up to socket 3 and T35 LCD hooked up to 10, 12, 13, and 14.

In the IDE, the USB Client module and DIsplay module are the only things “connected” to the Spider. The RS232 and USBHost modules are on the picture, but not hooked up. (see attached picture)

In the project properties, I’ve selected Serial debugging through COM5, and set the Spider switches accordingly.

I added a reference for the GHI.Premium.USBClient.dll.

I start with a good USB Flashdrive plugged into the Spider USBHost module.

Here’s the program.cs code (I’ll change the name later…)


using System;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;

using GT = Gadgeteer;

using GHI.Premium.USBHost;
using GHI.Premium.IO;
using GHI.Premium.System;
using GHI.Premium.USBClient;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp1
{
    public partial class Program
    {
        static PersistentStorage ps = null;
        static USBC_MassStorage ms = null;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {

            ms = USBClientController.StandardDevices.StartMassStorage();
            Debug.Print("USB ms started");
            RemovableMedia.Insert += RemovableMedia_Insert;
            RemovableMedia.Eject += RemovableMedia_Eject;
            // Subscribe to USB events
            USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
            Debug.Print("USB Host subscribed to events");
            
            Debug.Print("Program Started");
        }

        void DeviceConnectedEvent(USBH_Device device)
        {
            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Debug.Print("USB Mass Storage detected...");
                ps = new PersistentStorage(device);
                ms.AttachLun(0, ps, " ", " ");
                ms.EnableLun(0);
            }
        }

        void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            Debug.Print("Removable Media_Insert Triggered. Storage \"" + e.Volume.RootDirectory + "\" is inserted");
        }

        void RemovableMedia_Eject(object sender, MediaEventArgs e)
        {
            Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is ejected.");
            ps = null;
            ms.DisableLun(0);
        }
    }
}

And, here’s the output:

USB ms started
USB Host subscribed to events
Program Started
USB Mass Storage detected…
The thread ‘’ (0x3) has exited with code 0 (0x0).

I can remove the tumbrive, but not see the eject message.

I can plug it back in and go back through the …_insert code

And, I’m unable to see the thumbdrive contents (there are a few files) from the PC.

I’m trying to follow the information int he 4.2 NETMF documents, but I’m confused. Help?

@ Mike - I am. A hopefully complete description of the issue is in the previous message.

@ jzeevi - I am thinking about this and I do not recall this being tested on the new NETMF 4.2. Will test and get back to you soon.

@ Gus - Thanks, Chief! I look forward to learning what you discover…

I would mount the file system in the DeviceConnectedEvent then attach and enable the lun in the RemovableMedia_Insert event.

Just a guess…

@ Mike - Interesting idea. I moved the attachlun and enablelun calls to the media insert function, but that never gets called… I left the PersistentStorage() instantiation in the connectevent, and that gets seen when I plug in the flashdrive tot he USBHost module…