MTP Responder for SPIFFS

mjs513

Senior Member+
Just finished the initial library for using MTP Responder with SPIFSS on the Teensy 4.1.

The library takes the core MTP implementation from @WMXZ MTP_t4 library and reworks the Storage class on the library to use SPIFFS on the external FLASH chip of the Teensy 4.1.

The library has been posted on a GitHub repository: MTPspiffs_t41. You will need to download the following libraries that MTPspiffs_t41 is dependent on:

There is one buggy thing left to fix. When you copy a file to the Flash from the PC you can not immediately delete. Appears to need a reboot for it to work consistently. So far this is the only thing I have seen that does not work 100% correctly. All other features seem to be working. There is one caveat with SPIFFS - no subdirectories.

In addition to use MTPspiffs above 450MHz it requires a change to the core file usb.c per @WMXZ:
modify usb.c:
function: usb_transfer_status
changed #if 0 to #if 1

MTPspiffs allows you to do the same as MTP Resopnder:
  • copy files to and from the PC
  • delete files
  • open files on the Flash from the PC
  • etc


Have fun testing.
 
Last edited:
Seems to be working - on Win 10 without the external driver tool {see MTPdrive below }. I can copy and read a file from there. Notepad can navigate to open a file.

No Subdirectories:: Right click new is only 'folder' - gave it a name - it doesn't show - and it isn't there on restart - that seems somewhat consistent with the earlier test of MTP.

T_4.1 at 600 Mhz with edits. The build even told me to select the right USB :)

usb.c:
Code:
uint32_t usb_transfer_status(const transfer_t *transfer)
{
[B][U]#if 1[/U][/B]

This "#elif defined(USB_MTPDISK)" precedes where "#elif defined(USB_MTPDISK_SERIAL)" was added.

The default is properly set in : ...\libraries\MTP_t4\src\Storage.h - but that may be for non-SPIFFS

Just opened "MTPdrive" - It maps the 'mtp teensy' to a drive letter.
Code:
Z:\>dir
 Volume in drive Z is Teensy [Ext FLASH] @ MTPdrive(TRIAL)
 Volume Serial Number is 600D-CAFE

 Directory of Z:\

05/27/2020  06:14 AM                48 mtpindex.dat
05/27/2020  06:14 AM            12,466 Prior sketches.txt
05/27/2020  06:14 AM               119 test
05/27/2020  06:14 AM               119 test
05/27/2020  06:14 AM               466 test2
05/27/2020  06:14 AM               466 test2
05/27/2020  06:14 AM             1,416 justOne
05/27/2020  06:14 AM             1,416 justOne
05/27/2020  06:14 AM             1,416 justOne.txt
05/27/2020  06:14 AM             1,416 justOne.txt
              10 File(s)         19,348 bytes
               0 Dir(s)      15,395,328 bytes free
Doing 'dir c:\ > z:\justOne.txt' results in two files - until the Teensy is restarted:
Code:
Z:\>dir
 Volume in drive Z is Teensy [Ext FLASH] @ MTPdrive(TRIAL)
 Volume Serial Number is 600D-CAFE

 Directory of Z:\

05/27/2020  06:22 AM                48 mtpindex.dat
05/27/2020  06:22 AM             1,416 justOne.txt
05/27/2020  06:22 AM             1,416 justOne
05/27/2020  06:22 AM               466 test2
05/27/2020  06:22 AM               119 test
05/27/2020  06:22 AM            12,466 Prior sketches.txt
               6 File(s)         15,931 bytes
               0 Dir(s)      15,395,328 bytes free
 
@defragster

Glad you tested it and it seems to be working for you. As I said the only thing changed from the @WMXZ'z MTP_t4 lib to the MTPspiffs_t41 lib was the storage class in order to support spiffs. Which was fun exercise.

The default is properly set in : ...\libraries\MTP_t4\src\Storage.h - but that may be for non-SPIFFS
Little confuse here - what default are you talking about. The defaults I see in Storage.h are for using SDFat which is for MTP_t4?

Looking at your directory listing it appears you are using a third party driver for MTP: @ MTPdrive(TRIAL). Looks like you are using this: https://mtpdrive.com/features.html. Might be a cool app to invest in if you want to connect your Apple (which I have a problem with) or other smart phone :) If you are using the windows MTP driver (comes with it) you see something like this:

Capture.PNG
Notice - no drive mapped to device.

Not sure why you are seeing double file names in you first directory listing. Haven't see that.

Have you tried dragging files to and from the Teensy yet?
 
@defragster

Glad you tested it and it seems to be working for you. As I said the only thing changed from the @WMXZ'z MTP_t4 lib to the MTPspiffs_t41 lib was the storage class in order to support spiffs. Which was fun exercise.

Little confuse here - what default are you talking about. The defaults I see in Storage.h are for using SDFat which is for MTP_t4?

Looking at your directory listing it appears you are using a third party driver for MTP: @ MTPdrive(TRIAL). Looks like you are using this: https://mtpdrive.com/features.html. Might be a cool app to invest in if you want to connect your Apple (which I have a problem with) or other smart phone :) If you are using the windows MTP driver (comes with it) you see something like this:

... Notice - no drive mapped to device.

Not sure why you are seeing double file names in you first directory listing. Haven't see that.

Have you tried dragging files to and from the Teensy yet?

YES - it worked.

:confused: ... I made note of storage.h because it was noted on 'some' github - but was not in the same library as 'edit' line above it - of course with 4 or 8 associated libs - following the install path and knwowing what did what was a bit tenuous :)

The initial test was as shown in p#5 with no drive letter. Yes, a file was dragged over and opened with notepad.

It was boring without a drive letter to CmdLine add/create files - so THEN the MTPdrive was run that exposed the Teensy as "Z:".

So the double 'dir' of files an issue with [Win ... MTPdrive ... Teensy] as a unit somewhere. I'd have to revisit the other MTP thread - seems that is the same I saw there ... 4 months back

>> Jan 2020 ... MTP-Responder-Contribution

Some dupe there - but unique sizes? Above p#3 both have the same size.
 
@defragster
Thanks for explaining got confused reading it with only one cup of coffee in me :)

Think the dups are with using MTPdrive because I haven't run into that issue with testing just with windows. It is possible that MTPdrive is looking for some other MTP id set - just guessing. As for the Serial Number that's actually a hardcoded into the MTP class for both the SPIFFS or the SDFat version. Wonder if we could use the Teensy S/N - just have to figure out how to get it - any ideas?
 
Back
Top