How to use a FAT filesystem with MassStorageDriver in USBHost_t36

Status
Not open for further replies.

lukexyz

Active member
What are the right steps needed to be able to read FAT drives on Teensy 4.1, using USBHost_t36?

I found this 2019 thread on USB mass storage driver experiments:

https://forum.pjrc.com/threads/55821-USBHost_t36-USB-Mass-Storage-Driver-Experiments

As far as I can tell, this is the work that became the MassStorageDriver.cpp code in the USBHost_t36 library. Is that correct?

https://github.com/PaulStoffregen/USBHost_t36/blob/master/MassStorageDriver.cpp

That code does not include a FAT filesystem. From the above thread, it sounds like I need the ELM-Chan FatFS library for that.

http://elm-chan.org/fsw/ff/00index_e.html

However, I'm not sure how to get that library working with MassStorageDriver, without reinventing the wheel.

The code in the uSDFS GitHub repo seems to be targeted at reading an SD card, and I assume it's based on a version of the mass storage code from before MassStorageDriver.cpp was incorporated into USBHost_t36.

https://github.com/WMXZ-EU/uSDFS

Any help would be greatly appreciated!
 
What are the right steps needed to be able to read FAT drives on Teensy 4.1, using USBHost_t36?

I found this 2019 thread on USB mass storage driver experiments:

https://forum.pjrc.com/threads/55821-USBHost_t36-USB-Mass-Storage-Driver-Experiments

As far as I can tell, this is the work that became the MassStorageDriver.cpp code in the USBHost_t36 library. Is that correct?

https://github.com/PaulStoffregen/USBHost_t36/blob/master/MassStorageDriver.cpp

That code does not include a FAT filesystem. From the above thread, it sounds like I need the ELM-Chan FatFS library for that.

http://elm-chan.org/fsw/ff/00index_e.html

However, I'm not sure how to get that library working with MassStorageDriver, without reinventing the wheel.

The code in the uSDFS GitHub repo seems to be targeted at reading an SD card, and I assume it's based on a version of the mass storage code from before MassStorageDriver.cpp was incorporated into USBHost_t36.

https://github.com/WMXZ-EU/uSDFS

Any help would be greatly appreciated!

For the record, uSDFS is ELM-CHaN's FatFs file system that together with MSC from @wwatson can be used with USBHost.
 
FYI - Several of us have been playing with integrating some of the MSC stuff as well as the MTP stuff and hopefully bring more/all of it into a Teensyduino build.
Some of the most recent work and discussions are up in the thread: https://forum.pjrc.com/threads/6633...o-work-with-each-other-8)?p=275073#post275073

With the latest Beta Releases of Teensyduino, There is new/newer addition of the FS.h file in the cores, which define a very simple interface For files and File systems. With this there is a new release of the SD library as well as a new SDFat which is based off of the Bill Greiman SDFat beta (forever) code.

The latest USBHost_t36 changes are in a Pull Request: The fork/branch of that PR: https://github.com/KurtE/USBHost_t36/tree/MSC_read_sectors_cb

MSC code, the most current up to date version is at: https://github.com/wwatson4506/UsbMscFat
This latest one (changes integrated in yesterday) includes stuff like, formatting partitions, ability to create/delete partitions... Currently works with Fat16, Fat32 and ExFat
Been testing with the sketch MSCFormatter.ino

MTP stuff - again integration with the rest. A few of us have been working on extending and integrating with system more. We have been working in my fork/branch:
https://github.com/KurtE/MTP_t4/tree/test_msc_parts
This branch has test sketch that allows us to have: SD cards (both SDIO and SPI), LittleFS drives (RAM, Flash, T4.1 added memory...) and USB MSC drives. Still lots of testing, extending, fixing needs/wants to be done here as MTP can be real fragile. (We are playing with the mtp-test arduino sketch in this project)
 
Hi KurtE, thanks for all the helpful links. I have not had any luck getting a complete working system based on any combination of these repos.

I removed the USBHost_t36 from the Teensyduino 1.54 beta 6 distribution, and replaced it with a project-local checkout of the latest version at https://github.com/KurtE/USBHost_t36/tree/MSC_read_sectors_cb . I then also checked out https://github.com/wwatson4506/UsbMscFat into the project libraries folder. I don't need MTP, so I didn't clone that repo.

The compile error I get right now is:

Code:
/home/luke/Arduino/libraries/UsbMscFat/src/USBmscDevice.cpp: In member function 'virtual bool USBMSCDevice::readSectorsWithCB(uint32_t, size_t, void (*)(uint32_t, uint8_t*), uint32_t)':
/home/luke/Arduino/libraries/UsbMscFat/src/USBmscDevice.cpp:172:28: error: 'class msController' has no member named 'msReadSectorsWithCB'
   m_errorCode = thisDrive->msReadSectorsWithCB(sector, ns, callback, token);

I understand a new beta is not far from release. Should I wait for that, or do you have a recommendation on how to fix the above issue? Thanks!
 
Ah, I see what the problem is. I forgot to include the branch name with a "-b" switch when I tried cloning that repo. Thanks, it compiles now!

I tried uncommenting this code in CardInfoUSB.ino:

Code:
  //Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root1.openRoot(volume1);
  
  // list all files in the card with date and size
  root1.ls(LS_R | LS_DATE | LS_SIZE);

and I get this error:

Code:
/opt/arduino-1.8.13/hardware/teensy/avr/libraries/SdFat/src/FsLib/FsFile.h:458:8: note: candidate: bool FsBaseFile::openRoot(FsVolume*)
   bool openRoot(FsVolume* vol);
        ^
/opt/arduino-1.8.13/hardware/teensy/avr/libraries/SdFat/src/FsLib/FsFile.h:458:8: note:   no known conversion for argument 1 from 'MSCVolume' to 'FsVolume*'
no matching function for call to 'MscFile::openRoot(MSCVolume&)'

So FsVolume is the new Teeny standard way to access volumes? Changing
Code:
MSCVolume volume1;
into
Code:
FsVolume volume1;
does not work.
 
@Kurte - I think that my old MSC branch is confusing everybody with all of the recent changes. Maybe I should remove everything that does not work anymore and keep just what will work with SdFat and uSDFS. What do you think?
 
Is there a small subset of changes that would support just USB flash drives (I don't need SD / MTP etc.), would allow basic operations like listing / copying / deleting of FAT files, and (ideally also) formatting partitions to FAT? That might be a good place to start as far as integrating changes back into the main Teensyduino tree.
 
Status
Not open for further replies.
Back
Top