USB host mass storage exception

Doing some USB host mass storage testing with our USB stick for production on the SCM20260D. The example code: USB Host throws a exception when attempting to init the USB stick.


I have tried other USB sticks form different manufactur and succeeded so the code works but is picky about the USB stick used.

Is there other requirements for the USB stick then FAT16 or FAT32 for it to be compatible?

FAT16 and FAT32 are supported.

Does sitcore detect it as a storage device? Looked like it but then it fails to mount!

If you want to ship that memory stick we can investigate.

Yes the sitecore detect our USB stick as storage device(case BaseDevice.DeviceType.MassStorage )

Where should i ship it to?

Send us simple code that you can reproduce the issue, and show us what kind of USB you are using.

USBController sc = new USBController();
class USBController
    {
        IDriveProvider _driver;
        StorageController _storageController;

        public USBController()
        {
            var usbHostController = UsbHostController.GetDefault();

            usbHostController.OnConnectionChangedEvent +=
                UsbHostController_OnConnectionChangedEvent;

            usbHostController.Enable();
        }

        public IDriveProvider Driver
        {
            get { return _driver; }
        }

        public StorageController Controller
        {
            get { return _storageController; }
        }

        private void UsbHostController_OnConnectionChangedEvent
        (UsbHostController sender, DeviceConnectionEventArgs e)
        {

            
            Debug.WriteLine("e.Id = " + e.Id + " \n");
            Debug.WriteLine("e.InterfaceIndex = " + e.InterfaceIndex + " \n");
            Debug.WriteLine("e.PortNumber = " + e.PortNumber);
            Debug.WriteLine("e.Type = " + ((object)(e.Type)).
                ToString() + " \n");

            Debug.WriteLine("e.VendorId = " + e.VendorId + " \n");
            Debug.WriteLine("e.ProductId = " + e.ProductId + " \n");

            switch (e.DeviceStatus)
            {
                case DeviceConnectionStatus.Connected:
                    switch (e.Type)
                    {
                        case BaseDevice.DeviceType.Keyboard:
                            var keyboard = new Keyboard(e.Id, e.InterfaceIndex);
                            keyboard.KeyUp += Keyboard_KeyUp;
                            keyboard.KeyDown += Keyboard_KeyDown;
                            break;

                        case BaseDevice.DeviceType.Mouse:
                            var mouse = new Mouse(e.Id, e.InterfaceIndex);
                            mouse.ButtonChanged += Mouse_ButtonChanged;
                            mouse.CursorMoved += Mouse_CursorMoved;
                            break;

                        case BaseDevice.DeviceType.Joystick:
                            var joystick = new Joystick(e.Id, e.InterfaceIndex);
                            joystick.CursorMoved += Joystick_CursorMoved;
                            joystick.HatSwitchPressed += Joystick_HatSwitchPressed;
                            joystick.ButtonChanged += Joystick_ButtonChanged;
                            break;

                        case BaseDevice.DeviceType.MassStorage:
                            _storageController = StorageController.FromName
                                (SC20260.StorageController.UsbHostMassStorage);
                            _driver = FileSystem.Mount(_storageController.Hdc);
                            var driveInfo = new DriveInfo(_driver.Name);

                            Debug.WriteLine("Free: " + driveInfo.TotalFreeSpace);
                            Debug.WriteLine("TotalSize: " + driveInfo.TotalSize);
                            Debug.WriteLine("VolumeLabel:" + driveInfo.VolumeLabel);
                            Debug.WriteLine("RootDirectory: " + driveInfo.RootDirectory);
                            Debug.WriteLine("DriveFormat: " + driveInfo.DriveFormat);

                            break;

                        default:
                            var rawDevice = new RawDevice(e.Id, e.InterfaceIndex, e.Type);
                            var devDesc = rawDevice.GetDeviceDescriptor();
                            var cfgDesc = rawDevice.GetConfigurationDescriptor(0);
                            var endpointData = new byte[7];

                            endpointData[0] = 7;        //Length in bytes of this descriptor.
                            endpointData[1] = 5;        //Descriptor type (endpoint).
                            endpointData[2] = 0x81;     //Input endpoint address.
                            endpointData[3] = 3;        //Transfer type is interrupt endpoint.
                            endpointData[4] = 8;        //Max packet size LSB.
                            endpointData[5] = 0;        //Max packet size MSB.
                            endpointData[6] = 10;       //Polling interval.

                            var endpoint = new Endpoint(endpointData, 0);

                            var pipe = rawDevice.OpenPipe(endpoint);
                            pipe.TransferTimeout = 10;

                            var data = new byte[8];
                            var read = pipe.Transfer(data);

                            if (read > 0)
                            {
                                Debug.WriteLine("Raw Device has new data "
                                    + data[0] + ", " + data[1] + ", " + data[2] + ", " + data[3]);
                            }

                            else if (read == 0)
                            {
                                Debug.WriteLine("No new data");
                            }

                            Thread.Sleep(500);
                            break;
                    }
                    break;

                case DeviceConnectionStatus.Disconnected:
                    Debug.WriteLine("Device Disconnected");
                    //Unmount filesystem if it was mounted.
                    break;

                case DeviceConnectionStatus.Bad:
                    Debug.WriteLine("Bad Device");
                    break;
            }
        }
        private static void Keyboard_KeyDown(Keyboard sender, Keyboard.KeyboardEventArgs args)
        {
            Debug.WriteLine("Key pressed: " + ((object)args.Which).ToString());
            Debug.WriteLine("Key pressed ASCII: " +
                ((object)args.ASCII).ToString());
        }
        private static void Keyboard_KeyUp(Keyboard sender, Keyboard.KeyboardEventArgs args)
        {
            Debug.WriteLine("Key released: " + ((object)args.Which).ToString());
            Debug.WriteLine("Key released ASCII: " + ((object)args.ASCII).ToString());
        }
        private static void Mouse_CursorMoved(Mouse sender, Mouse.CursorMovedEventArgs e)
        {
            Debug.WriteLine("Mouse moved to: " + e.NewPosition.X + ", " + e.NewPosition.Y);
        }
        private static void Mouse_ButtonChanged(Mouse sender, Mouse.ButtonChangedEventArgs args)
        {
            Debug.WriteLine("Mouse button changed: " + ((object)args.Which).ToString());
        }
        private static void Joystick_ButtonChanged(Joystick sender, Joystick.ButtonChangedEventArgs e)
        {
            Debug.WriteLine("Joystick button changed  = " + ((object)(e.Which)).ToString());
        }
        private static void Joystick_HatSwitchPressed(Joystick sender, Joystick.HatSwitchPressedEventArgs e)
        {
            Debug.WriteLine("Joystick direction  = " + ((object)(e.Direction)).ToString());
        }
        private static void Joystick_CursorMoved(Joystick sender, Joystick.CursorMovedEventArgs e)
        {
            Debug.WriteLine("Joystick.move  = " + e.NewPosition.X + ", " + e.NewPosition.Y);
        }
    }

not sure how to identify what USB stick we’re using as it is a no brand device

  1. Try with FAT32.
  2. There is “USBController()” that has something behind.
    Recommend simple like this to test
 var usbReady = false;
            var usbHostController = UsbHostController.GetDefault();

            usbHostController.OnConnectionChangedEvent +=(a, b) => { usbReady = b.DeviceStatus == DeviceConnectionStatus.Connected;  };

            usbHostController.Enable();

            while (usbReady == false)
            {
                Debug.WriteLine("Waiting for connect ready!");

                Thread.Sleep(1000);

            }

            var sc = StorageController.FromName(SC20260.StorageController.UsbHostMassStorage);

            IDriveProvider drive = GHIElectronics.TinyCLR.IO.FileSystem.Mount(sc.Hdc);

Hey

I have now attempted your suggestion without any luck. when I insert the USB stick it throws the exception.

Is it failed on that one only or other ones?

Is there any way we can have that one to investigate?

I have tested 3 with same result.
please let me know the shipping info and we will send some.

Thank you for sharing the USB.

I guess the address is on our website, but you can contact to our support: support@ghielectronics.com

They take care shipping better than me.

Just tell them that you need to send your usb thumbdrives to GHI for investigating.

Thanks a lot.

Did you ship your usb yet, please?

1 Like

Yes they should be shipped yesterday or today.

1 Like

Thanks. Curious about this usb.

1 Like

Hi,

We tested your thumb drives and able to reproduce issues.

The fixed is available in next release. For now, if you don’t want to wait, you need find a way to format these usb drives with “full size”. We found and tested the first method (diskpart) from this link below and get it work:

Note: Link and instructions from the link are from third party. We are not responsible about that link.

2 Free Methods: Format USB to Full Capacity in Windows 11, 10, 8, 7 (diskpart.com)

1 Like