Teensy 4.0 + audio shield: show SD card as mass storage when connected as USB device?

even_rats

Member
I'm designing a project that records audio (WAV files) to the SD card on the audio shield, inside a waterproof enclosure.

I'm hoping to be able to connect to my laptop via USB, and see the files on the SD card as though it was a flash drive. Read/write would be great, but even read-only would be adequate.

Is this possible with the SD slot on the audio shield? If not, is it possible if I get a Teensy 4.1 and use the built-in SD slot?

Regards,
 
Either "SD" can work, and that interface is 'under development'

That ongoing thread is: forum.pjrc.com/threads/68139-Teensyduino-File-System-Integration-including-MTP-and-MSC

At this point TeensyDuino 1.57 Beta (2 just released) has improvements for usage - but actual code takes libraries from github as noted reading that thread from the end up to find the current items needed.

Post there if you get stuck after reading as needed to get it working. Having another user/tester would be helpful.
 
There is work going on, but I haven't kept track of it. I think two of the repositories are here, but it would be helpful if the people working on it could post a link to a howto:
...

'crosspost' :)

The first post on the thread: forum.pjrc.com/threads/68139-Teensyduino-File-System-Integration-including-MTP-and-MSC?p=287992&viewfull=1#post287992

On occasion has been updated with links needed to join in the fun. Last edit 5/11/22 shows this now waiting for update:
EDIT: warning the MTP_Teensy code currently requires the new Teensybuino beta 1.57
Will soon update this page again with more details
 
As others have said, this is still a work in progress, though it does work pretty well if you use 1.57-beta2 and MTP_Teensy library.

https://forum.pjrc.com/threads/70409-Teensyduino-1-57-Beta-2

https://github.com/KurtE/MTP_Teensy

Many of the MTP_Teensy library examples are overly complex. At this early stage of development, they're meant more as test cases than the usual Arduino-style examples to serve as simple learning tools to get started. Just keep opening the other MTP_Teensy examples until you find one that's short and simple.

The main caveat with this early beta stuff is we might change the names of functions or other stuff in ways that don't preserve compatibility with programs written today. But most of the planned changes are expected with supporting USB drives. The SD card stuff is less likely to change in ways that break existing programs.

But changes definitely are coming on SD cards too, just less likely to break existing programs. The main work unfinished on SD cards involves automatically detecting media removal and handling it as gracefully as possible.

With all media types, we still have much to do regarding notifying your PC of changes which Teensy makes on the card, and handling cases where the PC wants to change files Teensy is actively using. If you never imagined those things could be handled well, and you don't hot-plug SD cards while Teensy is running, then you probably be pretty happy with the code that exists today. But so much better is (or should be) possible, which is the reason we're using MTP rather than regular USB MSC.... so eventually we can support some (probably not all) cases where both PC and Teensy actually use the storage media.
 
Note: As both @defragster and @MichaelMeissner, mentioned, we are working on integrating in MTP into Teensyduino.

As for being able to access files stored on an SD card (either built in or over SPI), can be reasonably simply:
One of the example sketches looks like:
Code:
#include <SD.h>
#include <MTP_Teensy.h>

#define CS_SD BUILTIN_SDCARD  // Works on T_3.6 and T_4.1
//#define CS_SD 10  // Works on SPI with this CS pin
void setup()
{
  Serial.begin(9600);
  while (!Serial && millis() < 5000) {
    // wait for serial port to connect.
  }

  // mandatory to begin the MTP session.
  MTP.begin();

  // Add SD Card
  if (SD.begin(CS_SD)) {
    MTP.addFilesystem(SD, "SD Card");
    Serial.println("Added SD card using built in SDIO, or given SPI CS");
  } else {
    Serial.println("No SD Card");
  }
  Serial.println("\nSetup done");
}


void loop() {
  MTP.loop();  //This is mandatory to be placed in the loop code.
}

Which when run (Built with USB Type= MTP Disk...
screenshot.jpg

And from this window you can use the MTP integration (in this case file explorer), to walk the directory structure and do things like copy files from your Teensy to your host, or host to teensy, delete files, ...

However This is not File System like a Mass Storage Device. That is there is no drive letter in PC for the storage(s) contained in the Teensy object here. (You can have more than one).
So for example you can not open a file up that is contained on your Teensy and the PC application manipulate the actual file.

But sometimes it feels like you can, as for example double clicking on a file, like a JPG or .WAV or the like the system downloads a copy of the file (probably to temp?) and then passes that off to the associated app that can show/play that file...

Sorry If I did not explain the differences very well. Just wanted to mention there are limits to things that you can do.
 
This all looks really cool! MTP is useful indeed, and I'm excited you're adding support. I'll certainly try it out and report back.

For my current project, MTP isn't ideal because it's being used in a lab full of Macs, which don't support MTP natively. I don't have easy access to install software on them, and even if I did, SyncMate (the package to add MTP support) is a bit expensive.

I see that MSC integration was on the list of desired features in @KurtE's original post in the relevant thread. I searched that thread for MSC, and found UsbMscFat and USBHost_t36 branch "FS_Integration_MSC" on Github. Took a look at the examples for those, but from what I can tell these deal with accessing MSC volumes on external disks connected via the USB host port, which is not what I'm trying to do.

Am I missing something, or is exposing the SD card as a MSC volume not supported?
 
MTP to MAC - As you mentioned, the MAC does not have support for it built in. There are packages that one can install to do this. For example support to copy files from an Android device.
I can not remember for example if: https://www.android.com/filetransfer/
Works for this or not.

MSC integration - is for the other side of it. That is on T3.6 and T4.x if you plug in some device, like an SSD drive, memory stick, etc that supports MSC, then we now have code built in (Beta build) that can talk to devices that
communicate over USB using MSC. And we can talk to them using the stuff in FS.h (FS and File). And with this you have the option then of exposing those volumes using MTP.

We do not support a USB type of MSC on the Teensy.

However if you are a Python person... There is MicroPython support on the Teensy boards (4, 4.1, MicroMod), and they expose a drive to the PC as MSC. But this drive is stored in the remaining storage space in the Program Flash.
Not sure yet if you can expose an SD card in this way on MPY. I keep meaning to get back to playing with it. SO far they don't have SDIO support on the Teensy boards (Built in SD card).

But, there are issues with the MSC support. That is with MSC, the host computer is in control of your file system... They simply request or write blocks of data. So if they screw up, you FS is screwed up... Like if you unplug at the
wrong time. Also as they are in control, if for example you wish to have sketch create a new file or the like, they can not do this while the MSC code is running, so they need to stop the MSC support, and then they do normal file stuff to the drive
and then they can restart the drive.... I have never tried this so no idea how well that might work.
 
Back
Top