USB Memory stick troubles

Hello Everyone

I am experiencing some troubles while reading content of a USB memory stick. It has been formatted as FAT32 using guiformat with 4k allocation unit. It used to work pretty well untill we add some big files on the stick.

I fact my code load a 100kB xml file that has not moved on the stick. EMX can list all files and return its size but as soon as I start to do FileCopy or try to see the content of that file, I am receiving CLR_E_FILE_IO exception.

Any idea?

@ leforban - How big are the large files that cause issues?

I am trying to read a 200kB file. Th problem is if there’s only this file it’s ok. But then as soon as I fill up the stick with big files (1x700MB and 3x 1.5GB) the 200kB file can’t be read anymore… it generates the exception. If I remove the big files it still does not work. I need to reformat and replace the 200kB file on the stick…

@ leforban - Are the large files being generated by the NETMF board or are they being loaded externally?

@ leforban - Using both the NETMF and Gadgeteer versions of interfacing USB Mass Storage, I was unable to reproduce this issue. The thumbdrive used was a 4GB drive filled 90% with multi gigabyte files, and the one small file test

NETMF USB Device Connected Event Code:

void USBHostController_DeviceConnectedEvent(GHI.Premium.System.USBH_Device device)
        {
            if (device.TYPE == GHI.Premium.System.USBH_DeviceType.MassStorage)
            {
                Debug.Print("Found mass storage on USB Host...");
                Debug.Print("Connecting to device...");
                Thread.Sleep(1000);
                try
                {
                    _usb_ms = new PersistentStorage(device);
                    Debug.Print("Device ctor...");
                    _usb_ms.MountFileSystem();
                    Debug.Print("Device mounted...");

                    FileStream file = new FileStream("USB\\small file.txt", FileMode.Open);

                    byte[] small_file_buffer = new byte[file.Length];
                    file.Read(small_file_buffer, 0, small_file_buffer.Length);

                    file.Close();

                    Debug.Print("Read Okay");
                }
                catch (Exception error)
                {
                    Debug.Print("Error mounting device");
                }
            }
        }

Gadgeteer USBHostModule USBDriveConnected Event:

        void usbHost_USBDriveConnected(UsbHost sender, GT.StorageDevice storageDevice)
        {

            Debug.Print("Found mass storage on USB Host...");
            Debug.Print("Connecting to device...");
            Thread.Sleep(1000);
            try
            {
                FileStream file = new FileStream(storageDevice.Volume.RootDirectory + "\\small file.txt", FileMode.Open);

                byte[] small_file_buffer = new byte[file.Length];
                file.Read(small_file_buffer, 0, small_file_buffer.Length);

                file.Close();

                Debug.Print("Read Okay");
            }
            catch (Exception error)
            {
                Debug.Print("Error reading file");
            }
        }

Both output:

[quote]Found mass storage on USB Host…
Connecting to device…
Device ctor…
Device mounted…
Read Okay[/quote]

and

[quote]Found mass storage on USB Host…
Connecting to device…
Read Okay[/quote]

Respectively. I tested this on EMX with Spider and G120 with Cobra II

Hi James

I also have no pb with small memory size (256MB to 1GB) but only when I use a 8GB or 64 GB. As I said if there’s only few files on memory stick it is perfect but problems occurs when large file are added. I will try to see if it happens again with other stick and file size to try to isolate the problem.