USB Flash Drive Disconnect after 20 Seconds

The main loop of USBHOSTMBED5 example FileRead indicates msd.connect as not connected after 20-30 seconds and never reconnects even though there is an attempt to reconnect.

void loop() {
delay(1000);
// handle disconnection and reconnection
if (!msd.connected()) {
msd.connect();
}
}

The file read performed in the setup does work but the issue is how to keep the FileSystem connected.

Thanks

Jim

Not sure what you mean by:

First, hopefully you are using USBHostMbed5 version 3.1. Use the library manager to check/upgrade. Next change:

void loop() {
    delay(1000);
    // handle disconnection and reconnection
    if (!msd.connected()) {
        msd.connect();
    }
}

To:

void loop() {
    delay(1000);
    // handle disconnection and reconnection
Serial.print("msd.connected() is returning");
Serial.println(msd.connected());
    if (!msd.connected()) {
        msd.connect();
    }
}
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 0
msd.connected() is returning 0
msd.connected() is returning 0
msd.connected() is returning 0
msd.connected() is returning 0
msd.connected() is returning 0
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1

The above was me unplugging and replugging the USB stick. As you can see it is reconnecting :wink:
I let the sketch run for several minutes and it never showed any disconnection. How did you determine that it was disconnecting after 20-30 seconds?

Here is what I get for your code.....
Mounting USB device...

read done Open /usb/numbers.txt

Writing numbers (0/10)

Writing numbers (1/10)

Writing numbers (2/10)

Writing numbers (3/10)

Writing numbers (4/10)

Writing numbers (5/10)

Writing numbers (6/10)

Writing numbers (7/10)

Writing numbers (8/10)

Writing numbers (9/10)

File closing

File closed

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning1

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

msd.connected() is returning0

Your original post said you were using "FileRead". That is what I tested. I will have to check the FileWrite.ino sketch...

Back with results:

Mounting USB device...                                                                                         
read done Open /usb/numbers.txt                                                                                
Writing numbers (0/10)
Writing numbers (1/10)
Writing numbers (2/10)
Writing numbers (3/10)
Writing numbers (4/10)
Writing numbers (5/10)
Writing numbers (6/10)
Writing numbers (7/10)
Writing numbers (8/10)
Writing numbers (9/10)
File closing
File closed
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1
msd.connected() is returning 1

And it stays connected until I unplug the USB stick. You might want to try another Fat32 formatted USB stick or maybe reformat the one you are using. Right now I have one that has two partitions on it. If I access partition #1 it works fine, but if I try to access partition #2 the whole thing disconnects. I am trying to recover it but I am not having much success :slightly_frowning_face:
Probably no good...

EDIT: Try the USB stick on a regular PC and see if it disconnects.

You are correct in that I selected File Write instead File Read example...Sorry.

I did find that two out of 4 USB flash drives worked and the other two did not.

All 4 USB flash drives work flawlessly on a Windows PC.

Note... All 4 USB Flash drives were under 32gb, formatted MRB.

Hi @tyrrellaz,

Please try reformatting again your USB in FAT32 as suggested by @wwatson. I have tried to replicate it but it is working fine for me without disconnecting.

Thank you for your contribution!

I have tested four USB Flash Drives all FAT32 MBR configured and only 2 of the drives work and remain connected. Appears that some other criteria is required beyond FAT32 MBR.

I have 3 different types of SanDisk and one Verbatim.

Jim

Solution: The USB-A power switch had failed causing power to the USB flash drive to drop after 20 seconds of on time.

1 Like