MTP Responder Contribution

For Teensy3 you can use the descriptor file made by yoonghm on his GitHub site.
I´m more interested in Teeny4

Has anyone been able to get the yoonghm MTP code to work recently?

I'm on Arduino 1.8.10 and Teensyduino 1.49. I downloaded the latest Grieman SdFat (not the beta) to go with the yoonghm MTP code, per the instructions. I copied over the usb_desc.h and corrected the TRANSIMIT to TRANSMIT. I restarted the Arduino IDE. I selected USB Type -> MTP Disk (Experimental). It doesn't work for me.

It compiles but the Teensy does not appear in Windows (I'm still Win7). I also get no Teensy showing up under the Port menu, other than "(emulated serial)", which doesn't actually do anything (no serial comms).

Does the yoonghm MTP code work for any of you? Do you get both the MTP functionality *and* the serial?

Thanks,

Chip
 
Chip I´m still struggling to get on T4 Serial + MTP. MTP works but Serial does not behave on Arduino SerialMonitor but only on Putty.
I may try tomorrow on T3 (similar to Chris) and then working backwards.
 
@WMXZ, I just got Chris's usb_desc.h entries working with your MTP library with SdFat-beta (as you describe) with your example sketch on a T3.6.

I get both the SD card to appear in Windows *and* I seem to get a real serial port. So that's cool! Smiles all around!

Now, I just have to integrate the MTP functionality into a much larger project where I use an older SD library for logging. I'm not too excited about replumbing my logging code to use the newer SD library nor an I excited about trying to get both the new and the old libraries to play nice with each other.

We'll see...

Chip
 
Teensy 4.0 MTP + Native Serial port :)
EDIT:
Well I speak too soon the Serial port seems laggy :confused:

MS WIN10
Arduino-1.8.10
Teensy Loader 1.49

----\arduino-1.8.10\hardware\teensy\avr\boards.txt
Code:
teensy40.menu.usb.mtp=MTP Disk (Experimental)
teensy40.menu.usb.mtp.build.usbtype=USB_MTPDISK
teensy40.menu.usb.mtp.fake_serial=teensy_gateway
# EDIT TEENSY 4.0 MTP+Serial by Chris O.
teensy40.menu.usb.mtpserial=MTP Disk (Experimental) + Serial
teensy40.menu.usb.mtpserial.build.usbtype=USB_MTPDISK_SERIAL
edit: ---\arduino-1.8.10\hardware\teensy\avr\cores\teensy4\usb_desc.h
Code:
#elif defined(USB_MTPDISK) // \cores\teensy4 usb_desc.h
  #define VENDOR_ID             0x16C0
  #define PRODUCT_ID            0x04D1
  #define MANUFACTURER_NAME     {'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN 11
  #define PRODUCT_NAME          {'T','e','e','n','s','y',' ','M','T','P',' ','D','i','s','k'}
  #define PRODUCT_NAME_LEN      15
  #define EP0_SIZE              64
  #define NUM_INTERFACE         2
  #define NUM_ENDPOINTS         4
  #define SEREMU_INTERFACE      1 // Serial emulation
  #define SEREMU_TX_ENDPOINT    2
  #define SEREMU_RX_ENDPOINT    2
  #define SEREMU_TX_SIZE        64
  #define SEREMU_RX_SIZE        32
  #define SEREMU_TX_INTERVAL    1  // TODO: is this ok for 480 Mbit speed
  #define SEREMU_RX_INTERVAL    2  // TODO: is this ok for 480 Mbit speed
  #define MTP_INTERFACE         2 // MTP Disk
  #define MTP_TX_ENDPOINT       3
  #define MTP_RX_ENDPOINT       3
  #define MTP_EVENT_ENDPOINT    4
  #define MTP_TX_SIZE_480       512
  #define MTP_RX_SIZE_480       512
  #define MTP_TX_SIZE_12        64
  #define MTP_RX_SIZE_12        64
  #define MTP_EVENT_SIZE        16
  #define MTP_EVENT_INTERVAL    1
  #define ENDPOINT2_CONFIG  ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT // Serial emulation
  #define ENDPOINT3_CONFIG  ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
  #define ENDPOINT4_CONFIG  ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT  // ????

#elif defined(USB_MTPDISK_SERIAL) // \cores\teensy4 usb_desc.h
  #define VENDOR_ID             0x16C0
  #define PRODUCT_ID            0x04D1
  // from (USB_SERIAL_HID)
  #define DEVICE_CLASS          0xEF
  #define DEVICE_SUBCLASS       0x02
  #define DEVICE_PROTOCOL       0x01
  #define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN 11
  #define PRODUCT_NAME    {'T','e','e','n','s','y',' ','M','T','P',' ','D','i','s','k','/','S','e','r','i','a','l'}
  #define PRODUCT_NAME_LEN      22
  #define EP0_SIZE              64
  #define NUM_ENDPOINTS         5
  //#define NUM_USB_BUFFERS     22
  #define NUM_INTERFACE         3
  #define CDC_IAD_DESCRIPTOR    1
  #define CDC_STATUS_INTERFACE  0
  #define CDC_DATA_INTERFACE    1 // Native Serial port
  #define CDC_ACM_ENDPOINT      2
  #define CDC_RX_ENDPOINT       3
  #define CDC_TX_ENDPOINT       3
  #define CDC_ACM_SIZE          16
  #define CDC_RX_SIZE_480       512
  #define CDC_TX_SIZE_480       512
  #define CDC_RX_SIZE_12        64
  #define CDC_TX_SIZE_12        64
  #define MTP_INTERFACE         2 // MTP Disk
  #define MTP_TX_ENDPOINT       4
  #define MTP_RX_ENDPOINT       4
  #define MTP_EVENT_ENDPOINT    5
  #define MTP_TX_SIZE_480       512
  #define MTP_RX_SIZE_480       512
  #define MTP_TX_SIZE_12        64
  #define MTP_RX_SIZE_12        64
  #define MTP_EVENT_SIZE        16
  #define MTP_EVENT_INTERVAL    1
  #define ENDPOINT2_CONFIG  ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT    // Native Serial port
  #define ENDPOINT3_CONFIG  ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK           // Native Serial port
  #define ENDPOINT4_CONFIG  ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK           // MTP Disk
  #define ENDPOINT5_CONFIG  ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT // MTP Disk

\libraries\MTP\example
Important to have this: while (!Serial && millis() < 1000) {} // wait for Serial Monitor with 1s. timeout.
Instead of while: (!Serial); // This Will Never run if serial Port is not open.
Code:
#include "Arduino.h"

#if 1
#include "MTP.h"

MTPStorage_SD storage;
MTPD       mtpd(&storage);
#endif

void logg(uint32_t del, const char *txt)
{ static uint32_t to;
  if (millis() - to > del)
  {
    Serial.println(txt);
    to = millis();
  }
}

void setup()
{
  // while (!Serial);
  while (!Serial && millis() < 1000) {}  // wait for Serial Monitor with 1s. timeout.

  Serial.println("MTP test");  Serial.flush();
  storage.init();
  SD.ls();
}

void loop()
{
  mtpd.loop();
  logg(1000, "loop");
}
 
Last edited:
WMXZ
I just noticed your other thread Weird behavior of SerialMonitor and I am running into the same issues.

I cannot use automode for download (i.e. butto-press is required)
Also cannot upload code without button press.

TD-SerialMonitor is only showing data in blocks (every 10 seconds data are printed)
About 2.5 second on my PC if I use Teensy Ports in Arduino IDE tools menu.
No issues if I select Serial Ports COMx in tools menu.
 
I'm curious how hard would it be to add the renaming file functionality in the MTP library?
Now we can copy files from MicroSD <--> PC and delete files.
 
Media Transfer Protocol 1.1 spec:
Opcode ----- Operation --------- Name Explanation
0x1019 ----- MoveObject ------- Rename a file or directory
 
I still can't get MTP to work on Linux with the t4.

The t3.6 worked using yoongmh's library, wolfmanjm's edits and SdFat, but then I upgraded to IDE 1.8.10 and Teensyduino 1.49 and it all went belly up.

The mtp-test example with the latest mtp-t4 library (21st Jan) compiles with the following warnings now:

Code:
In file included from /home/dean/arduino-1.8.10/hardware/teensy/avr/cores/teensy4/WProgram.h:45:0,
                 from /tmp/arduino_build_409530/pch/Arduino.h:6,
                 from /home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/SdFat-beta/src/common/../SdFatConfig.h:45,
                 from /home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/SdFat-beta/src/common/SysCall.h:33,
                 from /home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/SdFat-beta/src/SdFat-beta.h:31,
                 from /home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/MTP_t4/src/MTP_config.h:8,
                 from /home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/MTP_t4/src/MTP_Storage.h:40,
                 from /home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/MTP_t4/src/MTP.h:35,
                 from /home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/MTP_t4/src/MTP.cpp:30:
/home/dean/arduino-1.8.10/hardware/teensy/avr/cores/teensy4/wiring.h: In instantiation of 'constexpr decltype (((a < b) ? forward<A>(a) : forward<B>(b))) min(A&&, B&&) 
     [with A = long unsigned int; B = int; decltype (((a < b) ? forward<A>(a) : forward<B>(b))) = long unsigned int]':
/home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/MTP_t4/src/MTP.cpp:351:55:   required from here
/home/dean/arduino-1.8.10/hardware/teensy/avr/cores/teensy4/wiring.h:73:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   return a < b ? std::forward<A>(a) : std::forward<B>(b);
            ^
/home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/MTP_t4/src/MTP.cpp: In member function 'uint32_t MTPD::SendObjectInfo(uint32_t, uint32_t)':
/home/dean/arduino-1.8.10/hardware/teensy/avr/libraries/MTP_t4/src/MTP.cpp:475:9: warning: unused variable 'size' [-Wunused-variable]
     int size = read32(); len -=4;

IDE cannot connect to the t4 and I have to press the button. The programme seems to upload (bright red LED) and then nothing. If I attempt to open Nautilus, it hangs. I then disconnect the USB from the t4, Nautilus opens as normal. Reconnect the t4 with Nautilus open and the t4 isn't there.

Thanks for the effort you are putting in, hope you can get it sorted.
 
I still can't get MTP to work on Linux with the t4.

The t3.6 worked using yoongmh's library, wolfmanjm's edits and SdFat, but then I upgraded to IDE 1.8.10 and Teensyduino 1.49 and it all went belly up.

The mtp-test example with the latest mtp-t4 library (21st Jan) compiles with the following warnings now:

....

IDE cannot connect to the t4 and I have to press the button. The programme seems to upload (bright red LED) and then nothing. If I attempt to open Nautilus, it hangs. I then disconnect the USB from the t4, Nautilus opens as normal. Reconnect the t4 with Nautilus open and the t4 isn't there.

Thanks for the effort you are putting in, hope you can get it sorted.

Warnings are OK, I have them too.

IDE issues are complicated as MTP is officially not yet supported for T4. So expect button press for download. Killing SerialMonitor before download may help.

Don't use Linux, but it was working on a Linux machine using Nautilus.
 
Media Transfer Protocol 1.1 spec:
Opcode ----- Operation --------- Name Explanation
0x1019 ----- MoveObject ------- Rename a file or directory

Seems more complicated (need to hack more the MTP_storage code), also, while I understand to move file or directory it is not clear how to rename a file or directory.
This is as the move object does not change object description and index.
So I lowered the priority of this feature.
 
Seems more complicated (need to hack more the MTP_storage code), also, while I understand to move file or directory it is not clear how to rename a file or directory.
I think you are correct, this is all thanks to >Wikipedia error<. Since now that I downloaded the specification for Media transport protocol v1.1 I don't see a way of rename a file with that Opcode 0x1019.:(
 
I hate to ask a stupid question - But suppose I was curious to try this all out.

What do I need to do to make it work?
I have SDFat-beta installed in my Arduino\libraries folder as the sdfat.
@wmxz - I cloned your version logically into my arduino\libraries folder ( I actually clone it to another disk and create symbolic link to it in the library folder...)
I copied the header file sdfat.h to sdfat-beta.h
And the other edits as mentioned in your readme, like copy files and uncomment...

So I was able to build mtp-test sketch from examples.

Now what?

If I run the sketch maybe a little garbage shows up in monitor window. Sometime Windows mentions something about an MTP disk... But I don't see anything in the

Does this require an SD adapter on the T4? If so I assume with the built-in? (i.e. bottom pads).

Should I logical drive show up on my windows 10 machine in the This PC area.

Again sorry I know I can probably dig for this information. But sometimes too many diversions.
 
Does this require an SD adapter on the T4? If so I assume with the built-in? (i.e. bottom pads).
I am using the SDIO (4 bit) Teensy 4.0 bottom pads for SD card, external micro SD card should work also but slower (1 bit SPI).
And yes you should see your device, here's a picture on Windows 10
teensy mtp.jpg
I believe Linux has some issues with Teensy 4.0 right now ?

This is how I have it all set up on Win 10.
Arduino 1.8.10 and Teensyduino 1.49.
Download SdFat Version 2 BETA: https://github.com/greiman/SdFat-beta
Download MTP: https://github.com/WMXZ-EU/MTP_t4

Create MTP directory inside the teensy arduino libraries.
[example in Windows 10]--> C:\Users\ --->PC user name here<--- \Desktop\arduino-1.8.10\hardware\teensy\avr\libraries\MTP
Copy all the files from WMXZ-EU/MTP_t4 scr to MTP libraries director you just created:
MTP.CPP
MTP.H
MTP_config.h
MTP_Storage.cpp
MTP_Storage.h
You can also create examples directory inside MTP and (Rename main.cpp to mtp-test.ino) copy the mtp-test.ino here.
[example in Windows 10]--> C:\Users\--->PC user name here<---\Desktop\arduino-1.8.10\hardware\teensy\avr\libraries\MTP\examples\mtp-test\mtp-test.ino

MTP_t4/copy-of-core/ --- copy to Teensy 4.0 cores directory.
[example in Windows 10]--> C:\Users\ --->PC user name here<--- \Desktop\arduino-1.8.10\hardware\teensy\avr\cores\teensy4
usb.c
usb_desc.c
usb_desc.h
usb_mtp.c
usb_mtp.h
 
I get a valid HEX, but nothing showing on Win 10 PC - except if I connect TyCommander it shows: Teensy MTP Disk {Seremu \\.\HID#VID_16C0&PID_04D1&MI_01#7&116C8F1A&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} }

I build from SublimeTxt with TSET and then the IDE - both give a complete HEX. Plugging into a second Win 10 machine it CHIMES IN a USB device - but nothing shows up?

I do have an SD card on a FRDM4236 mounted T4. Went to ...\libraries\SdFat\examples\SdInfo\SdInfo.ino and the card is there and working with FAT32 format:
Code:
...
Volume is FAT32
sectorsPerCluster: 64
clusterCount:      973584
freeClusterCount:  959401
fatStartSector:    9362
dataStartSector:   24576
...

Post #188 is what I did - except in the ZIP it seems the folder structure is right so it was just extracted in place to my libraries
Arduino 1.8.9 and Teensyduino 1.49.
Download SdFat Version 2 BETA: https://github.com/greiman/SdFat-beta
Download MTP: https://github.com/WMXZ-EU/MTP_t4

My build shows this for libs - where MTP and SdFat is indeed SdFat-beta are fresh from github:
Code:
Using library MTP at version 1.0.0-beta.1 in folder: T:\tCode\libraries\MTP 
Using library SdFat at version 2.0.0-beta.7 in folder: T:\tCode\libraries\SdFat 
Using library SPI at version 1.0 in folder: T:\arduino-1.8.9\hardware\teensy\avr\libraries\SPI 
Using library Time at version 1.6 in folder: T:\arduino-1.8.9\hardware\teensy\avr\libraries\Time

Had to do the header file copy (rename?) as noted in p#117: SdFat.h > SdFat-beta.h and the copy of 5 files to cores, 3 were overwrites.

I had to enable by uncomment the 3 boards.txt lines for : teensy40.menu.usb.mtp=MTP Disk (Experimental)

build shows this with USB_MTPDISK as a define that matches what the code shows?:
Code:
"T:\\arduino-1.8.9\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=149 -DARDUINO=10600 -DF_CPU=600000000 [B][COLOR="#FF0000"]-DUSB_MTPDISK[/COLOR][/B] -DLAYOUT_US_ENGLISH "-IT:\\arduino-1.8.9\\hardware\\teensy\\avr\\cores\\teensy4" "T:\\TEMP\\arduino_build_mtp-test.ino\\sketch\\[B]mtp-test.ino.cpp[/B]" -o nul

This would work from github as posted using SPI SD CARD, but this T4 is using native SDIO connected SD card and requires the following:
In order to use SDIO or SPI-SD you can edit ...\libraries\MTP\src\MTP_config.h, which allows you to switch from SDIO (#define USE_SDIO 1) to SPI (#define USE_SDIO 0)

<edit>:: Posts below on function test - thanks for p#120 WMXZ comment added above
 
Last edited:
I hate to ask a stupid question - But suppose I was curious to try this all out.

What do I need to do to make it work?
….
Does this require an SD adapter on the T4? If so I assume with the built-in? (i.e. bottom pads).

Should I logical drive show up on my windows 10 machine in the This PC area.

In order to use SDIO or SPI-SD you can edit MTP_config.h, which allows you to switch from SDIO (#define USE_SDIO 1) to SPI (#define USE_SDIO 0)
At the moment I´m using T4 with an audio_card, no SDIO, so USE_SDIO is 0

On windows 10 there should be a Teensy show up as a portable device.(on left panel under This PC)

Now, I did my work on a T4, as I need it for a T4. finished desired functionality yesterday (including move and rename)
Before publishing on GitHub, I will go again through T3.6 and T4.0 tests.

One open question is Using Seremu or Serial.
Paul used Seremu for T3, but there was some desire to use Serial. (I only got Serial working with T4)
The MTP_t4 GitHub version is set for seremu
 
In order to use SDIO or SPI-SD you can edit MTP_config.h, which allows you to switch from SDIO (#define USE_SDIO 1) to SPI (#define USE_SDIO 0)
At the moment I´m using T4 with an audio_card, no SDIO, so USE_SDIO is 0
...

THAT DID IT :: #define USE_SDIO 1

I now see my disk - left pane or 'This PC' in file explorer:
MTP_T4.png

No DRIVE LETTER - but through file explorer the directory can be walked and files opened relatively well!

But files don't 'drag' - I suppose it can't pass an acceptable path.

But Windows 'Photos' opened on one image can scroll to the others in the folder.

The device is 'Teensy' and in this case the 'SD CARD' is an object on that device.
 
With current code TyCommander can connect to Serial 'Seremu' and get sketch output - Cool - except it is just a boring repeat print of : "loop"

( apologies for noob'ness - p#119 above edited for steps used to SUCCESS - I've been scanning this cool thread but not tried to run until now and like Kurt appreciate the personal tips }

> can do "New / Folder" - but no other items in the context menu. { but no choice in the name or ability to rename }

> Remove device and those 'New Folders' do show on the Teensy reconnected.

> can copy a 32 MB file quickly from Teensy to a system drive. About 16 seconds for a 190 MB file - about 12 MB/sec.

> can connect two T4's in this mode - both appear as "Teensy"

> can pretend to COPY a file and paste but that fails

> can drag a file from one Teensy to the second Teensy and it fails on release but on drag it say: Copy to root of storage

> No 'eject' on device and not showing in USB Safe Remove list.


== so Read only? - except directory creation - and fast enough - Cool. Promising new Teensy feature!


This for $40 creates a drive letter from an MTP drive :: mtpdrive.com/features.html
Trial version limitations
Limit of 30 transferred files from a device in total (until the Windows is restarted)
One MTP device mapped to a drive letter concurrently
Automatic mapping of a connected device to a drive letter is disabled
Cache size cannot be changed, it is hard-coded to unlimited
 
Updated GitHub with lastest version.
can now
- copy files from/to PC (folders not yet tested)
- delete files (folders not yet tested)
- move files (folders not yet tested)
- rename files (folders not yet tested)

MTP generates a portable device (similar to Camera, etc) No disk label, although there are products that map portable devices to drive letters.
Not a issue for me as I only use MTP for file transfer (mainly Teensy to PC)

Uses Seremu for Terminal
Serial does not work properly on T4, does not work at all on T3 (consequently on T4 usb_desc.h is given)
reprogramming may need Button press (may be an issue with TeensyMonitor on Windows10)

Limitations:
single storage device only
No session handling
No event handling (e.g. add object event)
No device reset

Session handling would benice but if windows does not send a close session command I can hardly implement a good response ( still a lot to learn)
 
Nice, will update and try soon.

Hit github and paused long enough to read and see the SDIO note there. :)

BTW: if the SDFAT.h file is renamed the sdfat-beta code won't build - if copied to SdFat-beta.h Then both worked.
 
Nice, will update and try soon.

Hit github and paused long enough to read and see the SDIO note there. :)

BTW: if the SDFAT.h file is renamed the sdfat-beta code won't build - if copied to SdFat-beta.h Then both worked.

Make sense, not sure what I did. Created now ´link´ include file SdFat-beta.h
Code:
#include "SdFat.h"
to be side-by-side with SdFat.h

Obviously, this SdFat-beta is only necessary if SdFat-beta is installed in addition to official SdFat library
 
Back
Top