Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: How to use a FAT filesystem with MassStorageDriver in USBHost_t36

  1. #1

    How to use a FAT filesystem with MassStorageDriver in USBHost_t36

    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...er-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/US...rageDriver.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!

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,156
    Quote Originally Posted by lukexyz View Post
    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...er-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/US...rageDriver.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.

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,024
    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/66338...073#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...ead_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)

  4. #4
    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...ead_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!

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,024
    That branch relies on my USBHost_t36 library updates. Which is still in waiting on a Pull Request back to the main one.
    It is off of my Fork/Branch: https://github.com/KurtE/USBHost_t36...ead_sectors_cb

  6. #6
    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.

  7. #7
    Senior Member wwatson's Avatar
    Join Date
    Aug 2017
    Posts
    427
    @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?

  8. #8
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •