A couple of dumb questions on USBHost and USBFileSystem

aka_ptt

Member
Hi,

I have a working application on a Teensy that uses FsFile and SD.sdfs for storage. I want to move to USBHost, USBDrive, and USBFileSystem for packaging purposes.

First, I started with the ListFiles examples from USBHost_t36/Storage. Relevant code:

Code:
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);

// Setup MSC for the number of USB Drives you are using. (Two for this example)
// Mutiple  USB drives can be used. Hot plugging is supported. There is a slight
// delay after a USB MSC device is plugged in. This is waiting for initialization
// but after it is initialized ther should be no delay.
USBDrive myDrive(myusb);
USBFilesystem firstPartition(myusb);

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect.
  }

  // Start USBHost_t36, HUB(s) and USB devices.
  myusb.begin();

  Serial.print("\nInitializing USB MSC drive...");

  // future USBFilesystem will begin automatically
  // begin(USBDrive) is a temporary feature
  if (!firstPartition.begin(&myDrive)) {
    Serial.println("initialization failed!");
    return;
  }

When I run the application, a USB drive is already connected to the USB pins on the Teensy. When I run the application, the drive "flashes" indicating that it is connected properly. But the "firstPartion.begin" always fails.

Full disclosure. I am testing it with a USB SD card reader with the 128GB SD card I was using in the SD.sdfs version of the code. That reader looks just like a Thumb drive to my PC. I believe it is a FAT or ExtFAT (forgot the exact fs name).

So questions:

1. Am I missing something obvious here? Like specific formatting that is required by USBFileSystem? Or size limitations?

2. Assuming I get past 1, can I assume that the API for FsFile creation and use will work the same for my USBFileSystem instance as it did for SD.sdfs?

Thank you for any help you can provide.

Paul
 
@aka_ptt - Let's see if I can help you with your 2 questions. But first we need some more information starting with which version of Arduino and Teensyduino are you using? The latest stable versions: arduino 1.8.19 and Teensyduino 1.57.

Second, what is is the failure you are seeing on the serial monitor? Something like the following:
Code:
initialization failed with code:

I have a Targus SD card reader that I test with that was also failing to read a SD card formatted with FAT32 or EXTFAT. Turns out
that I had to change the following timeouts from:

Code:
// These two defines are timeouts for detecting a connected drive
// and waiting for it to be operational.
#define MEDIA_READY_TIMEOUT   1000
#define MSC_CONNECT_TIMEOUT 4000

to:
Code:
// These two defines are timeouts for detecting a connected drive
// and waiting for it to be operational.
#define MEDIA_READY_TIMEOUT   5000
#define MSC_CONNECT_TIMEOUT 5000

They can be found in "USBHost_t36/utility/msc.h" starting at line #73. You might want to try that and see if it helps. I have a PR in for this problem.

Edit:
To answer the second question, instead of SD.sdfs you would use something like:
Code:
USBFilesystem firstPartition(myusb);
firstPartition.mscfs.something();

Hope this helps...
 
Last edited:
Hi WWatson

Thank you for the response. First, I am using the latest versions of both.

As far as the message, nothing comes out at the console except the printfs in the program. I have to assume that there is a setting or compiler define that will enable error messages.

I suspect it is the timing issue so I'll check that. The failure is occurring in a setup in a non internet connected lab so I can't post anything from there, but since my original post, I tried it with a Teensy at my desktop and it worked just fine. The SD reader at my desk is an older USB 2.0 product while the one in the lab is a USB 3.0. I'll try tweaking the timing when I get back in the lab.

Finally, thanks for the input on "...mscfs...". I was trying to search the prj and/or arduino websites for online documentation and couldn't find any and simply searching the source is a bit of a challenge because of all the conditional compiles. I suppose I could have downloaded the git repo.zip file and pulled it from there.

Your reply was very helpful. Thank you again.

Paul
 
Back
Top