June 22 4.2 Beta - USB Host with Mass Storage

I am having trouble getting a thumb drive recognized under 4.2 with a Spider mainboard.

The 4.2 SDK was already loaded on board.

I created a 4.2 Gadgeteer application which had a button, USB Host and T35 display. I added event
handlers for the button, and USB drive connect and disconnect.

The test program deploys normally. When the thumb drive is inserted into the host module, I
get the following exception:

#### Exception System.Exception - 0xffffffff (4) ####
#### Message: 
#### GHI.Premium.IO.PersistentStorage::MountFileSystem [IP: 0000] ####
#### Gadgeteer.Modules.GHIElectronics.UsbHost::USBHostController_DeviceConnectedEvent [IP: 0026] ####
#### GHI.Premium.USBHost.USBH_DeviceConnectionEventHandler::Invoke [IP: 0000] ####
#### GHI.Premium.USBHost.USBHostController::nativeEventDispatcher_OnInterrupt [IP: 0037] ####
#### GHI.Premium.System.InternalEvent::nativeEventDispatcher_OnInterrupt [IP: 0054] ####

A first chance exception of type ‘System.Exception’ occurred in GHI.Premium.IO.dll
UsbHost ERROR : Unable to identify USB Host device.

The line “UsbHost ERROR : Unable to identify USB Host device.” is misleading. I checked the USB Host module
source, and the device was recognized. The driver code is organized in a way that this error message is
displayed if the device is recognized but an exception occurs. Might be worth while to add a return in the
exception handler to avoid the identify error message.

Back to the problem at hand…

Based upon the exception, which says there is a problem mounting the file system for the thumb drive,
I tried several other thumb drives. The exception continued. I reformatted the drive(fat32) but that
did not stop the exception.

I then decided to go back to the 4.1 SDK and see if the problem could be reproduced.

I did a firmware upgrade/downgrade from 4.2 to 4.1.

I then built a new 4.1 Gadgeteer solution/project which the same hardware configuration as
the 4.2 project. I then copied the 4.2 program.cs contents from the 4.2 project to
the 4.1 project, changing only the namespace name.

I compiled and deployed the 4.1 project, and inserted the thumb drive. It worked.
Mumble mumble… :slight_smile:

I then went back to 4.2 solution, after upgrading the firmware. and tried again. I got the
same exception.

program.generated.cs


//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by the Gadgeteer Designer.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace Gadgeteer42_SSD
{
    public partial class Program : Gadgeteer.Program
    {
        // GTM.Module definitions
        Gadgeteer.Modules.GHIElectronics.UsbClientDP usbClientDP;
        Gadgeteer.Modules.GHIElectronics.Display_T35 display_T35;
        Gadgeteer.Modules.GHIElectronics.UsbHost usbHost;
        Gadgeteer.Modules.GHIElectronics.Button button;

        public static void Main()
        {
            //Important to initialize the Mainboard first
            Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();			

            Program program = new Program();
            program.InitializeModules();
            program.ProgramStarted();
            program.Run(); // Starts Dispatcher
        }

        private void InitializeModules()
        {   
            // Initialize GTM.Modules and event handlers here.		
            usbClientDP = new GTM.GHIElectronics.UsbClientDP(1);
		
            usbHost = new GTM.GHIElectronics.UsbHost(3);
		
            button = new GTM.GHIElectronics.Button(4);
		
            display_T35 = new GTM.GHIElectronics.Display_T35(14, 13, 12, 10);

        }
    }
}

program.cs

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace Gadgeteer42_SSD
{
    public partial class Program
    {
        private GT.StorageDevice storageDevice = null;
        // private String fileName = "test.txt";

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            usbHost.USBDriveConnected += new UsbHost.USBDriveConnectedEventHandler(usbHost_USBDriveConnected);
            usbHost.USBDriveDisconnected += new UsbHost.USBDriveDisconnectedEventHandler(usbHost_USBDriveDisconnected);
            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
        }


        void usbHost_USBDriveDisconnected(UsbHost sender)
        {
            Debug.Print("Drive disconnected");

        }

        void usbHost_USBDriveConnected(UsbHost sender, GT.StorageDevice storageDevice)
        {
            Debug.Print("Drive connected");
            this.storageDevice = storageDevice;
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            if (storageDevice == null)
                return;

            Debug.Print("Root Directory: " + storageDevice.RootDirectory);
            String[] ts = storageDevice.ListRootDirectoryFiles();
            String indent = new string(' ', 5);
            Debug.Print("Directories:");
            foreach (String s in ts)
                Debug.Print(indent + s);
            ts = storageDevice.ListRootDirectoryFiles();
            foreach (String s in ts)
                Debug.Print(indent + s);
        }
    }
}

Have I missed something that has changed between 4.1 and 4.2?

presistance storage is not added yet to the 4.2

I thought that might be the problem. You might want to update the release notes. :slight_smile: