Sdfat-beta now ported to USB Mass Storage devices two ways

wwatson

Well-known member
I now have SdFat-beta and MSC working together two ways. One way uses a heavily modified version of the SdFat and Sd libraries. I matched or in-lined the the classes in the two libraries and added block device access for USB host storage devices to the SdFat src directory. This works well but is very invasive to the two libraries. In the second version I created a new library, mscFS that parallels SD and is less in invasive to SdFat and does not use the SD library. It uses all of the latest file system abstraction @Paul created. It only makes an entry in a couple of files in SdFat.
The SdFat src directory contains a a new directory called "USBmsController" containing the low level access to MSC. Actually it uses a modified version of the USBHost_t36 library. MSC now is not used. Instead "USBHost_t36.h" has the former contents of "msc.h" and "msc.h" located in the utiliy directory contains portions of "MassStorage.h". The latest version of "MassStorageDriver.ccp" was added to the USBHost_t36 library. @Paul - I will do a PR on the USBHost_t36 library. I forked the latest one from your Github and modified it.

I was not sure which version of SdFat would be the best one to use. Both have been tested with T3x and T4.x, builtin and external SD cards and USB host devices. So far I have not detected any conflicts but further testing of these libraries is needed:)

For what I call the inline version of SdFat you will need these libraries for my GitHub site:

https://github.com/wwatson4506/USBHost_t36

https://github.com/wwatson4506/SdFat-beta/tree/SdFat-inline

and

https://github.com/wwatson4506/SD

These will be installed in the TD1.54B5 libraries directory. Of course, make sure to backup the existing libraries.

For what I call the parallel version of SdFat you would use these libraries:

https://github.com/wwatson4506/USBHost_t36

https://github.com/wwatson4506/SdFat-beta/tree/SdFat-parrallel

and:

https://github.com/wwatson4506/mscFS

There are example sketches I added in all five of the libraries. The ones I modified for USB host devices the filename it's self end with "USB.ino".

Examples - "cardInfoUSB.ino" "listfilesUSB.ino" "benchUSB.ino" etc...

Again, the MSC library is not used. It will probably morph into a "MSHost" library where I have time to work in making MSC compatible with USBHost_t36 which right now is not completely backwards compatible. However, I do have uSDFS and FatFs working.

I know @Paul and everybody is busy as heck right now but if you have time please try these libraries. It has been a long hard road to get this working but I have learned so much by studying Sdfat-beta, SD, FS.h and littleFS:)
 
For anybody that may have tried these libraries there was a major bug in both of the SdFat-inline and SdFat-parallel branches of my USB driver for SdFat-beta. I used a global variable (thisDrive) instead of a private one. This ment that 'thisDrive' always pointed to the last USB drive initialized no matter what instance of SdFat or UsbFat was being used. any attempt to copy a file from one drive to another was actually copying to the last drive initialized which would be the same drive. As Bill Greiman stated in one of the source files this could and DID cause file system corruption. I changed both versions of my SdFat branches to use a private uses of 'thisDrive'. Now file copying works between to instance of USB drives.

I see a lot of work going on with right now with MTP_T4, USBHost_t36, LittleFS and cores. I have MSC working with SdFat now and there is a lot more work to be done error code processing and such. My brain is fried right now and I think I am going to sit back and play with other things you guy's have been working with. Everything to do with the memory board chips work as you guys have tested. I never have really gotten MTP_T4 to work properly and I think it is because I don't fully understand how to set it up properly and possibly not using the versions of libraries:)
 
THX

Excuse my novice question, but how do you install the hardware, that is, do you have a basic arrangement to test the operation of the library you have designed?
 
I think I was probably still a little vague on how to setup these libraries. My repository of Paul's SdFat-beta has three branches. I would suggest downloading the zip files instead of cloning and then rename the one you download to SdFat. The branches are Sdfat-beta-master.zip (Forked from Paul's repository), SdFat-beta-SdFat-beta-inline.zip and SdFat-beta-SdFat-parallel.zip. To avoid getting as confused as I have I would suggest using SdFat-beta-inline first to test with as both versions inline and parallel should work the same. SdFat-beta-inline is the easiest to install and use because it more closely resembles the SdFat-beta and current SD API. You will need to download my USBHost_t36.zip from my github. This is used for both the inline and parallel version of SdFat-beta. If using the inline version of SdFat-beta also download my updated version of SD-Juse_Use_SdFat.zip or if using the parallel version of SdFat-beta download mscFs-main.zip. Both SD-Juse_Use_SdFat.zip and mscFs-main.zip shoud be renamed to SD and mscFS respectively. The links to these files are shown in post #1.

All of these libraries are installed in the arduino-1.8.13/hardware/teensy/avr/libraries folder so make sure to backup any library you are replacing. mscFS probably does not exist in the folder.

Hopefully this is NOT clear as mud:)
Again I would start with installing SdFat-beta-inline and the needed files for that library.

There are examples in the examples folder of the library's. All of the existing examples for SDIO and external SD card's will still work. I have tested both with T3.2-T4.1. All examples related to USB type drives the filename ends with 'USB' like 'cardInfoUSB.ino'.

I am hoping more testing can be done. I am sure with all of the development going on there is going to be a lot of changes to these libraries.
 
Back
Top