MTP Responder Contribution

This is an operation from within the Teensy. IMO, what is needed an operation on PC to reset session.
I have good results with using the device manager, but as I said, I hear that others have problems.
using Serial (via some sort of menu) to kill itself seems a weird approach. then I can also restart the whole program and have a better defined entry program.
I agree that sending a command via serial to cause the MTP responder to update its database seems weird. There are some cases where it can be useful:

1. If the Teensy is in the middle of a data logging session session and running on external power, disconnecting the USB or having a menu command to do so allows you to upload newly created files on the SD card without interrupting a logging session.

2. If the Teensy is running on USB5V, physically disconnecting USB will end the program--and any continuing operation is terminated. (See #1).

Using the device manager takes more mouse work than clicking the "UPDATE MTP" button on my host program interface---or sending the "rb" command if using a text interface.

Unplugging the USB from the back of my desktop is easy. Plugging it back in without being able to see the USB port is hard. I'm reluctant to plug and unplug the USB micro-b connector on the Teensy more often than necessary. If I've packaged the Teensy system, it can be impossible.
 
Let me summarize the discussion as I see it.

Starting point:
MTP was developed to retrieve files from portable devices and at the same time to store files on such devices.
It was never designed to replace a file system.
OK.
Now, we are misusing the MTP by integrating it with a data logger.
For this it would be convenient if there were a refresh option

sequence of operation:
- using MTP to check data on disk
- starting logging
- after some time checking data on disk

desired effect:
- File explorer to show newly added files

reality:
- MTP is controlled by PC and has no obligation to refresh
- in fact, MTP responder is required not to change properties of files reported to PC
- MTP allows for this the use of events, but PC is not required to implement all events

observation:
- So far, we failed (AFAIK) to implement any event that provoked the desired response from PC, we only are able to send events.

Alternative solution:
a) dismount/mount MTP disk from PC (two commands on linux, a lot of clicks on Windows, but I did a powershell script, which however needs Admin privileges)
b) restart USB from Teensy

There are two options to restart USB:
- using serial line and send a command
- copying a 'reboot.txt' file to teensy via MTP and Teensy reacts to the presence of this file, deletes it and reboots once file is deleted.

Now, all these solutions are to be implemented in the the main program and have nothing to do with MTP.

Only MTP relevant development is getting events running and when performing logging to invalidate the storage

There are a variety of events that may be possible
so far tested without success
-DEVICE_RESET
-OBJECT_ADDED
-STORE_ADDED
-OBJECT_REMOVED
-STORE_REMOVED

Task:
For this, we need first demonstrate that this is indeed possible, i.e. we need first to find a system where these types of events are working.
- e.g. connecting a camera to PC, take a picture and see if this new picture shows up in the file explorer, say after pressing refresh. (did not work with my Android phone on Win10 PC)
- then we only have to figure out how it is done and implement it on Teensy.

Note, the different Responder implementations that have events, do not show that events are working (e.g. via example) and were of little help.
So far, I found discussions on this but no solution.
 
re: "- copying a 'reboot.txt' file to teensy via MTP and Teensy reacts to the presence of this file, deletes it and reboots once file is deleted."
Indeed for "#defined" files - that would be programmed USER code response after MTP does its work.
Based 'name' on file and programmed Teensy response it could do anything, once MTP processes the USB side and the Teensy knows it happened?

'reboot', 'preFormat', USBinit, "Open file 'RunScript.txt' "

Maybe the 'RunScript.txt' or "Teensy.CMD" :: is the single file type of answer for any general response?
> parse it and act like it was SerMon typed commands - or whatever the sketch chooses. Does MTP have a way to let the sketch detect/know of a file change without a hack? - whether SD card or other?
 
@WMXZ - Yep - That is why I am experimenting. Hopefully today I will code again to send events to the PC and who knows maybe get lucky.

I was curious if the PC might try to send us any events, so far either a) I have not set it up right, or b) it has not.

The a) part T4.x I extended the device descriptor:
usb_desc.h file: #define ENDPOINT4_CONFIG ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT
usb_desc.c:
Code:
#define MTP_INTERFACE_DESC_SIZE		9+7+7+7+7
...
#ifdef MTP_INTERFACE
	// configuration for 480 Mbit/sec speed
        // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
        9,                                      // bLength
        4,                                      // bDescriptorType
        MTP_INTERFACE,                          // bInterfaceNumber
        0,                                      // bAlternateSetting
        4,                                      // bNumEndpoints
        0x06,                                   // bInterfaceClass (0x06 = still image)
        0x01,                                   // bInterfaceSubClass
        0x01,                                   // bInterfaceProtocol
        0,                                      // iInterface
        // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
        7,                                      // bLength
        5,                                      // bDescriptorType
        MTP_TX_ENDPOINT | 0x80,                 // bEndpointAddress
        0x02,                                   // bmAttributes (0x02=bulk)
        LSB(MTP_TX_SIZE_480),MSB(MTP_TX_SIZE_480), // wMaxPacketSize
        0,                                      // bInterval
        // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
        7,                                      // bLength
        5,                                      // bDescriptorType
        MTP_RX_ENDPOINT,                        // bEndpointAddress
        0x02,                                   // bmAttributes (0x02=bulk)
        LSB(MTP_RX_SIZE_480),MSB(MTP_RX_SIZE_480), // wMaxPacketSize
        0,                                      // bInterval
        // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
        7,                                      // bLength
        5,                                      // bDescriptorType
        MTP_EVENT_ENDPOINT | 0x80,              // bEndpointAddress
        0x03,                                   // bmAttributes (0x03=intr)
        MTP_EVENT_SIZE, 0,                      // wMaxPacketSize
        MTP_EVENT_INTERVAL_480,                 // bInterval
        // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
        7,                                      // bLength
        5,                                      // bDescriptorType
        MTP_EVENT_ENDPOINT,                     // bEndpointAddress
        0x03,                                   // bmAttributes (0x03=intr)
        MTP_EVENT_SIZE, 0,                      // wMaxPacketSize
        MTP_EVENT_INTERVAL_480,                 // bInterval
#endif // MTP_INTERFACE

in the usb_mtp.h and .c
I started to put in the sendEvent/recvEvent
in the configure added in the tx and rx event transfers and to try to configure both rx and tx end points.
Also pushed a transfer onto the RX one...

This is also where I then updated the cores/teensy4 printf stuff to allow debug printf to show up on USB Serial or SEREMU.
Verified it worked by uncomment the rx_event printf statement which I am receiving.


Also put in an rxEvent_event callback... And here is where I have not received anything (yet). Will probably not try a PR on those parts unless I get something of interest come back. I was curious if it might tell us something if a file copy fails with some form of timeout.

But back to experimenting.
 
Let me summarize the discussion as I see it.

Starting point:
MTP was developed to retrieve files from portable devices and at the same time to store files on such devices.
It was never designed to replace a file system.
OK..

Using MTP to fetch files written by a data logger seems to fit within the MTP usage scheme. The data logger firmware is responsible for handling the file system and the Storage portion of the MTP responder handles the interface between MTP and the file system. It seems that the unsolved part is how to generate events that will notify the PC on the other end that things have changed on the Teensy end. In a long-term logging system, just reconnecting the USB at the end of a month or more of logging is a viable option that avoids having to open up the logger to extract the SD card. Until I was able to integrate MTP into loggers, I had to write special PC host programs that could link with the logger and tell it to send the logged data files in packet format with handshaking to allow for PC timing issues. MTP avoids having to write the custom PC Host and gets about the same performance as the packet uploads (about 18MB/second on a T4.1).
 
I would have some use for a teensy version of OpenLog that uses MTP over usb. But would have to have similarly low power consumption.
 
Using MTP to fetch files written by a data logger seems to fit within the MTP usage scheme. The data logger firmware is responsible for handling the file system and the Storage portion of the MTP responder handles the interface between MTP and the file system. It seems that the unsolved part is how to generate events that will notify the PC on the other end that things have changed on the Teensy end.
Correct, If PC initiated a session, and you open a directory in file explorer MTP responder tells MTP initiator (PC), how many files are in this directory. If Teensy the writes additional files, PC will never know about them. We are hoping that we can tell PC to rescan directory for new files. This may be done with events.
 
After commenting to @mborgerson, here a first success
I succeeded to provoke a PC response using an event.
Using a device reset event PC reopened a new session. I updated the MTP github.
in MTP.h there is a define USE_EVENTS. if set to 1 on mtp-test.ini one can rend a 'r' character to Teensy that sends a reset event.
The USB event code works with cores T4. that is NO USB2.

Edit: now debugging can start
 
@WMXZ - Good news...

I thought I might try a different experiment and see about hacking up a partial USBHost_t36 implementation and then try to plug in an MTP device and see what I might see.

My main Android device is an Kindle Fire HD... So I plugged it in. So far just playing with the claim code, and if I claim it try to send of the first message (MTP_OPERATION_GET_DEVICE_INFO)

So far not claiming. When I plug it into the USBHost with debug turned on I see:
Code:
usb_cdc_line_coding, baud=134
usb_cdc_line_coding, baud=134
usb_cdc_line_coding, baud=115200
usb_cdc_line_coding, baud=115200
usb_cdc_line_coding, baud=115200
usb_cdc_line_coding, baud=115200
usb_cdc_line_coding, baud=115200
usb_cdc_line_coding, baud=115200


USB MTP Device Test Program
USB2 PLL running
 reset waited 6
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 20004000
periodictable = 20004000
port change: 10001803
    connect
  begin reset
port change: 18001205
  port enabled
  end recovery
new_Device: 480 Mbit/sec
new_Pipe
enumeration:
enumeration:
enumeration:
Device Descriptor:
  12 01 10 02 00 00 00 40 49 19 0C 00 32 02 01 02 03 01 
    VendorID = 1949, ProductID = 000C, Version = 0232
    Class/Subclass/Protocol = 0 / 0 / 0
    Number of Configurations = 1
enumeration:
enumeration:
Manufacturer: Android
enumeration:
Product: Android
enumeration:
Serial Number: D0FCA0A0342600M6
enumeration:
Config data length = 39
enumeration:
Configuration Descriptor:
  09 02 27 00 01 01 00 C0 01 
    NumInterfaces = 1
    ConfigurationValue = 1
  09 04 00 00 03 FF FF 00 04 
    Interface = 0
    Number of endpoints = 3
    Class/Subclass/Protocol = 255 / 255 / 0
  07 05 81 02 00 02 00 
    Endpoint = 1 IN
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  07 05 01 02 00 02 00 
    Endpoint = 1 OUT
    Type = Bulk
    Max Size = 512
    Polling Interval = 0
  07 05 82 03 1C 00 06 
    Endpoint = 2 IN
    Type = Interrupt
    Max Size = 28
    Polling Interval = 6
enumeration:
USBHub memory usage = 960
USBHub claim_device this=20002840
MTPDevice claim this=20002C20
09 04 00 00 03 FF FF 00 04 07 05 81 02 00 02 00 07 05 01 02 00 02 00 07 05 82 03 1C 00 06 
vid=1949, pid=C, bDeviceClass = 0, bDeviceSubClass = 0, bDeviceProtocol = 0
Descriptor 4 = INTERFACE
MTPDevice claim this=20002C20
09 04 00 00 03 [COLOR="#FF0000"]FF FF 00[/COLOR] 04 07 05 81 02 00 02 00 07 05 01 02 00 02 00 07 05 82 03 1C 00 06 
vid=1949, pid=C, bDeviceClass = 0, bDeviceSubClass = 0, bDeviceProtocol = 0
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
Descriptor 5 = ENDPOINT
I have the code setup to try to do:
if (descriptors[5] != 6) return false; // bInterfaceClass, 6 still image
if (descriptors[6] != 1) return false; // bInterfaceSubClass, 1
if (descriptors[7] != 1) return false; // bInterfaceProtocol, 1

But I am seeing Interface 0 ... So it fails.

Then did another search on MTP USB Device... and found: https://elinux.org/images/8/85/Media_Transfer_Protocol.pdf
In here under OS Descriptor is:
- According to the spec, MTP should be use the PTP device class (0x06) with Interface subclass 0x01
- Yet nobody does, let me guess: Windows does not support this
- Instead you must:
(1) attempt to get device descriptor 0xEE, if this contains the magic letters “MSFT” you send
(2) a special control message which then returns another set of magic bytes containing the string “MTP” and then
(3) a second control message which usually return the same thing again
- If any of these mismatch, the device is not MTP

Will see how far I will go.

But wonder if there are portions that are only triggered when it detects this stuff...
 
@defragster - Thanks

Sort of fun playing in USBHost code... My attempt to get the Kindle to talk MTP to it is not responding yet. I believe it talks it using the method mentioned above. I did try plugging into my Ubuntu machine and it did bring up a dialog and then window as an FS so I know that it talks the talk.

But for the fun of it, thought I would plug in a T4.1 configured as MTP Disk into my T4.1 with USBHost code, and see if it talks at all or not... But then ran into issue of wanting to see all of the Debug information that the MTP teensy was outputting. Earlier had a hack for the RAWHID code that you give it the top level USAGE of the RAWHID and see some of the stuff... Did not work at first as the RAWHID code is tied only support the VID:pID of the Teensy RAWHID... Updated that to allow other...

But was not good enough... So started yet another diversion and started creating a SEREMU USBHost HID device that is also a subclass of Stream... And it is starting to work... So for example my test sketch now has:
Code:
void loop()
{
  if (emBlink > 500) {
    emBlink = 0;
    digitalToggleFast(13);
  }
  myusb.Task();
  CheckHostDevicesChanged();

  if (Serial.available()) {
    int ch = Serial.read(); // get the first char.
    Serial.print(ch);
    while (Serial.read() != -1) ;
  }
#if  defined(USB_TRIPLE_SERIAL) || defined(USB_DUAL_SERIAL)
  uint16_t avail;
  uint16_t avail_for_write;
  if ((avail = seremu.available())) {
    avail_for_write = SerialUSB1.availableForWrite();
    if (avail > avail_for_write) avail = avail_for_write;
    if (avail > sizeof(buffer)) avail = sizeof(buffer);
    seremu.readBytes(buffer, avail);
    SerialUSB1.write(buffer, avail);
  }

  if ((avail = SerialUSB1.available())) {
    avail_for_write = seremu.availableForWrite();
    if (avail > avail_for_write) avail = avail_for_write;
    if (avail > sizeof(buffer)) avail = sizeof(buffer);
    SerialUSB1.readBytes(buffer, avail);
    seremu.write(buffer, avail);
  }
#endif  
}
And I am now starting to work, I am seeing some of the debug data in TyCommander. Although looks like I may be missing a first characters of buffer and maybe something slightly off as can not cut/paste multiple lines from TyCommander to paste here...
screenshot.jpg
But progress on that diversion :D
 
@WMXZ and all... As I mentioned before I am playing around with an MTP Host code for the USBHost_t36

And as I mentioned I have it limping along. Not able to do much although it will connect up to some MTP devices including your library and I have forwarding of the SEREMU over to SerialUSB1
In another thread I showed a session where it shows all of the top level objects for each of the top Storage IDS.

Also now I have a Kindle (Android Tablet plugged in) and right now I have all of the debug data turned on. So I see things like:
Code:
    STD Version:64
    Vendor extesion ID:6
    MTP Version:64
    Extensions:microsoft.com: 1.0; android.com: 1.0;
    Mode:0
    Operations: 1001 1002 1003 1004 1005 1006 1007 1008 1009 100A 100B 100C 100D 1014 1015 1016 1017 101B 9801 9802 9803 9804 9805 9810 9811 95C1 95C2 95C3 95C4 95C5
    Events: 4002 4003 4004 4005 C801 400C
    Device Properties: D401 D402 5003
    Capture formats:
    Playback formats: 3000 3001 3004 3005 3008 3009 300B 3801 3802 3804 3807 3808 380B 380D B901 B902 B903 B982 B983 B984 BA05 BA10 BA11 BA14 BA82 B906
    Manufacturer:Amazon
    Model:Fire
    Serial:1.0
...
*** MPT connected ***
Connected to:
Count of Storages: 1
0(10001): Internal storage() type:3 2 max:27571462144, free: 22541115392 access:0
...
========== Internal storage ===========
Music(1) FMT:3001 Size:0
Podcasts(2) FMT:3001 Size:0
Ringtones(3) FMT:3001 Size:0
Alarms(4) FMT:3001 Size:0
Notifications(5) FMT:3001 Size:0
Pictures(6) FMT:3001 Size:0
Movies(7) FMT:3001 Size:0
Download(8) FMT:3001 Size:0
DCIM(9) FMT:3001 Size:0
Android(10) FMT:3001 Size:4096
kindle(58) FMT:3001 Size:4096
Books(59) FMT:3001 Size:4096
Documents(62) FMT:3001 Size:0
.imagecache(64) FMT:3001 Size:0
Audible(68) FMT:3001 Size:0
Contacts(176) FMT:3001 Size:0
.bugsense(626) FMT:3000 Size:33
mapquest(630) FMT:3001 Size:0
sirius(1057) FMT:3001 Size:4096
TuneIn Radio(1510) FMT:3001 Size:4096
amazonmp3(2341) FMT:3001 Size:0
AccuWeather(4220) FMT:3001 Size:0
.backups(4444) FMT:3001 Size:0
.chartboost(4448) FMT:3001 Size:0

Now an interesting point:
I then went onto the Kindle and asked it to create a new file (a workbook).

I then saw some new debug information:
Code:
event token: 800C8100 transfer length: 28 len:16 - 10 0
rx: 10 00 00 00 04 00 02 40 01 01 00 00 F9 14 00 00 
event token: C8100 transfer length: 28 len:16 - 10 0
rx: 10 00 00 00 04 00 0C 40 01 01 00 00 01 00 01 00
Code:
void MTPDevice::event_data(const Transfer_t *transfer)
{
  uint32_t len = transfer->length - ((transfer->qtd.token >> 16) & 0x7FFF);

  if (len > 0) {
    const uint8_t *p = (const uint8_t *)transfer->buffer;
    print("event token: ", transfer->qtd.token, HEX);
    print(" transfer length: ", transfer->length, DEC);
    print(" len:", len, DEC);
    print(" - ", *p, HEX);
    println(" ", *(p + 1), HEX);
    print("rx: ");
    print_hexbytes(p, len);
  }
  // TODO: can be this more efficient?  We know from above which
  // buffer is no longer queued, so possible skip most of this work?
  queue_Data_Transfer(eventpipe_, rxevent, event_size_, this);
}
So this is the raw data I received on the Event Pipe: So:
Code:
10 00 00 00:04 00:02 40:01 01 00 00:F9 14 00 00
So length: (10 00 00 00) 16
So container type event 0x4: #define MTP_CONTAINER_TYPE_EVENT 4
Event Code: 0x4002 : #define MTP_EVENT_OBJECT_ADDED 0x4002
Transaction ID 0x0101
P1: Object Handle: 0x14F9

Second Event:
Code:
 10 00 00 00:04 00:0C 40:01 01 00 00:01 00 01 00
We have event 0x400c : #define MTP_EVENT_STORAGE_INFO_CHANGED 0x400C
P1: (Storage ID) 0x 010001

Which matched the Storage ID I mentioned above:
Code:
0(10001): Internal storage() type:3 2 max:27571462144, free: 22541115392 access:0

Now I notice that they are using the two bytes for Storage ID where ares are 1, 2, 3, 4
I am wondering if this may be messing up Windows with events ? Why I ask, the MTP document
talking about Storage ID... Sorry here is picture as it won't let me cut and paste out of it.
screenshot.jpg
Also sorry for sloppy red marking of the two interesting paragraphs.
 
@KurtE
Re storageID, I knew this and have thought to separate physical and logical storage, but in the end I let everything as 1 physical storage (0<<16) and consider all storage as logical. I know this not entirely correct, but... Now if this may help it can be done, but it may require a redesign of index files.
Re addObject, I seems that a single addObject is not sufficient to provoke response, but it must be followed by sending storageInfoChanged. Have to test that.
 
I'm trying to use the latest WMXZ MTP library with Teensy 3.6 and Teensy 1.54 Beta5 (with Arduino 1.8.13). The included example sketch mtp-test.ino won't compile. After a whole bunch of repeated warnings about Time.h vs TimeLib.h, I get what appears to be the actual error:

Code:
C:\Users\T410\AppData\Local\Temp\arduino_build_492362\sketch\mtp-test.ino.cpp.o: In function `setup':
C:\Users\T410\Desktop\mtp-test/mtp-test.ino:222: undefined reference to `usb_init_events'
C:\Users\T410\AppData\Local\Temp\arduino_build_492362\sketch\mtp-test.ino.cpp.o: In function `loop':
C:\Users\T410\Desktop\mtp-test/mtp-test.ino:294: undefined reference to `MTPD::send_DeviceResetEvent()'
collect2.exe: error: ld returned 1 exit status

I see that usb_init_events is in MTP.cpp, but it's unclear to me if it actually gets included when compling for T3.6.

Is the WMXZ MTP library compatible with T3.6? Do you have any suggestions on how to get it to compile?

Thanks,

Chip

Example sketch from MTP_t4 library as of 2020-12-14

Code:
#include "Arduino.h"

#include "SD.h"
#include "MTP.h"

#define USE_SD  1         // SDFAT based SDIO and SPI
#define USE_LFS_RAM 1     // T4.1 PSRAM (or RAM)
#define USE_LFS_QSPI 1    // T4.1 QSPI
#define USE_LFS_PROGM 1   // T4.4 Progam Flash
#define USE_LFS_SPI 1     // SPI Flash

#if USE_EVENTS==1
  extern "C" int usb_init_events(void);
#else
  int usb_init_events(void) {}
#endif

#if USE_LFS_RAM==1 ||  USE_LFS_PROGM==1 || USE_LFS_QSPI==1 || USE_LFS_SPI==1
  #include "LittleFS.h"
#endif

#if defined(__IMXRT1062__)
  // following only as long usb_mtp is not included in cores
  #if !__has_include("usb_mtp.h")
    #include "usb1_mtp.h"
  #endif
#else
  #ifndef BUILTIN_SCCARD 
    #define BUILTIN_SDCARD 254
  #endif
  void usb_mtp_configure(void) {}
#endif


/****  Start device specific change area  ****/
// SDClasses 
#if USE_SD==1
  // edit SPI to reflect your configuration (following is for T4.1)
  #define SD_MOSI 11
  #define SD_MISO 12
  #define SD_SCK  13

  #define SPI_SPEED SD_SCK_MHZ(33)  // adjust to sd card 

  #if defined (BUILTIN_SDCARD)
    const char *sd_str[]={"sdio","sd1"}; // edit to reflect your configuration
    const int cs[] = {BUILTIN_SDCARD,10}; // edit to reflect your configuration
  #else
    const char *sd_str[]={"sd1"}; // edit to reflect your configuration
    const int cs[] = {10}; // edit to reflect your configuration
  #endif
  const int nsd = sizeof(sd_str)/sizeof(const char *);

SDClass sdx[nsd];
#endif

//LittleFS classes
#if USE_LFS_RAM==1
  const char *lfs_ram_str[]={"RAM1","RAM2"};     // edit to reflect your configuration
  const int lfs_ram_size[] = {2'000'000,4'000'000}; // edit to reflect your configuration
  const int nfs_ram = sizeof(lfs_ram_str)/sizeof(const char *);

  LittleFS_RAM ramfs[nfs_ram]; 
#endif

#if USE_LFS_QSPI==1
  const char *lfs_qspi_str[]={"QSPI"};     // edit to reflect your configuration
  const int nfs_qspi = sizeof(lfs_qspi_str)/sizeof(const char *);

  LittleFS_QSPIFlash qspifs[nfs_qspi]; 
#endif

#if USE_LFS_PROGM==1
  const char *lfs_progm_str[]={"PROGM"};     // edit to reflect your configuration
  const int lfs_progm_size[] = {1'000'000}; // edit to reflect your configuration
  const int nfs_progm = sizeof(lfs_progm_str)/sizeof(const char *);

  LittleFS_Program progmfs[nfs_progm]; 
#endif

#if USE_LFS_SPI==1
  const char *lfs_spi_str[]={"nand1","nand2","nand3","nand4"}; // edit to reflect your configuration
  const int lfs_cs[] = {3,4,5,6}; // edit to reflect your configuration
  const int nfs_spi = sizeof(lfs_spi_str)/sizeof(const char *);

LittleFS_SPIFlash spifs[nfs_spi];
#endif


MTPStorage_SD storage;
MTPD    mtpd(&storage);

void storage_configure()
{
  #if USE_SD==1
    #if defined SD_SCK
      SPI.setMOSI(SD_MOSI);
      SPI.setMISO(SD_MISO);
      SPI.setSCK(SD_SCK);
    #endif

    for(int ii=0; ii<nsd; ii++)
    { 
      #if defined(BUILTIN_SDCARD)
        if(cs[ii] == BUILTIN_SDCARD)
        {
          if(!sdx[ii].sdfs.begin(SdioConfig(FIFO_SDIO))) 
          { Serial.printf("SDIO Storage %d %d %s failed or missing",ii,cs[ii],sd_str[ii]);  Serial.println();
          }
          else
          {
            storage.addFilesystem(sdx[ii], sd_str[ii]);
            uint64_t totalSize = sdx[ii].totalSize();
            uint64_t usedSize  = sdx[ii].usedSize();
            Serial.printf("SDIO Storage %d %d %s ",ii,cs[ii],sd_str[ii]); 
            Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
          }
        }
        else if(cs[ii]<BUILTIN_SDCARD)
      #endif
      {
        pinMode(cs[ii],OUTPUT); digitalWriteFast(cs[ii],HIGH);
        if(!sdx[ii].sdfs.begin(SdSpiConfig(cs[ii], SHARED_SPI, SPI_SPEED))) 
        { Serial.printf("SD Storage %d %d %s failed or missing",ii,cs[ii],sd_str[ii]);  Serial.println();
        }
        else
        {
          storage.addFilesystem(sdx[ii], sd_str[ii]);
          uint64_t totalSize = sdx[ii].totalSize();
          uint64_t usedSize  = sdx[ii].usedSize();
          Serial.printf("SD Storage %d %d %s ",ii,cs[ii],sd_str[ii]); 
          Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
        }
      }
    }
    #endif

    #if USE_LFS_RAM==1
    for(int ii=0; ii<nfs_ram;ii++)
    {
      if(!ramfs[ii].begin(lfs_ram_size[ii])) 
      { Serial.printf("Ram Storage %d %s failed or missing",ii,lfs_ram_str[ii]); Serial.println();
      }
      else
      {
        storage.addFilesystem(ramfs[ii], lfs_ram_str[ii]);
        uint64_t totalSize = ramfs[ii].totalSize();
        uint64_t usedSize  = ramfs[ii].usedSize();
        Serial.printf("RAM Storage %d %s ",ii,lfs_ram_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
      }
    }
    #endif

    #if USE_LFS_PROGM==1
    for(int ii=0; ii<nfs_progm;ii++)
    {
      if(!progmfs[ii].begin(lfs_progm_size[ii])) 
      { Serial.printf("Program Storage %d %s failed or missing",ii,lfs_progm_str[ii]); Serial.println();
      }
      else
      {
        storage.addFilesystem(progmfs[ii], lfs_progm_str[ii]);
        uint64_t totalSize = progmfs[ii].totalSize();
        uint64_t usedSize  = progmfs[ii].usedSize();
        Serial.printf("Program Storage %d %s ",ii,lfs_progm_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
      }
    }
    #endif

    #if USE_LFS_QSPI==1
    for(int ii=0; ii<nfs_qspi;ii++)
    {
      if(!qspifs[ii].begin()) 
      { Serial.printf("QSPI Storage %d %s failed or missing",ii,lfs_qspi_str[ii]); Serial.println();
      }
      else
      {
        storage.addFilesystem(qspifs[ii], lfs_qspi_str[ii]);
        uint64_t totalSize = qspifs[ii].totalSize();
        uint64_t usedSize  = qspifs[ii].usedSize();
        Serial.printf("QSPI Storage %d %s ",ii,lfs_qspi_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
      }
    }
    #endif

    #if USE_LFS_SPI==1
    for(int ii=0; ii<nfs_spi;ii++)
    {
      if(!spifs[ii].begin(lfs_cs[ii])) 
      { Serial.printf("SPIFlash Storage %d %d %s failed or missing",ii,lfs_cs[ii],lfs_spi_str[ii]); Serial.println();
      }
      else
      {
        storage.addFilesystem(spifs[ii], lfs_spi_str[ii]);
        uint64_t totalSize = spifs[ii].totalSize();
        uint64_t usedSize  = spifs[ii].usedSize();
        Serial.printf("SPIFlash Storage %d %d %s ",ii,lfs_cs[ii],lfs_spi_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
      }
    }
    #endif
}
/****  End of device specific change area  ****/

  // Call back for file timestamps.  Only called for file create and sync(). needed by SDFat-beta
   #include "TimeLib.h"
  void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) 
  { *date = FS_DATE(year(), month(), day());
    *time = FS_TIME(hour(), minute(), second());
    *ms10 = second() & 1 ? 100 : 0;
  }

void setup()
{ 
  #if defined(USB_MTPDISK_SERIAL) 
    while(!Serial); // comment if you do not want to wait for terminal
  #else
    while(!Serial.available()); // comment if you do not want to wait for terminal (otherwise press any key to continue)
  #endif
  Serial.println("MTP_test");

  usb_init_events();

#if !__has_include("usb_mtp.h")
  usb_mtp_configure();
#endif
  storage_configure();

  #if USE_SD==1
  // Set Time callback // needed for SDFat
  FsDateTime::callback = dateTime;

  {
    const char *str = "test1.txt";
    if(sdx[0].exists(str)) sdx[0].remove(str);
    File file=sdx[0].open(str,FILE_WRITE_BEGIN);
        file.println("This is a test line");
    file.close();

    Serial.println("\n**** dir of sd[0] ****");
    sdx[0].sdfs.ls();
  }

  #endif
  #if USE_LFS_RAM==1
    for(int ii=0; ii<10;ii++)
    { char filename[80];
      sprintf(filename,"/test_%d.txt",ii);
      File file=ramfs[0].open(filename,FILE_WRITE_BEGIN);
        file.println("This is a test line");
      file.close();
    }
    ramfs[0].mkdir("Dir0");
    for(int ii=0; ii<10;ii++)
    { char filename[80];
      sprintf(filename,"/Dir0/test_%d.txt",ii);
      File file=ramfs[0].open(filename,FILE_WRITE_BEGIN);
        file.println("This is a test line");
      file.close();
    }
    ramfs[0].mkdir("Dir0/dir1");
    for(int ii=0; ii<10;ii++)
    { char filename[80];
      sprintf(filename,"/Dir0/dir1/test_%d.txt",ii);
      File file=ramfs[0].open(filename,FILE_WRITE_BEGIN);
        file.println("This is a test line");
      file.close();
    }
    uint32_t buffer[256];
    File file = ramfs[1].open("LargeFile.bin",FILE_WRITE_BEGIN);
    for(int ii=0;ii<3000;ii++)
    { memset(buffer,ii%256,1024);
      file.write(buffer,1024);
    }
    file.close();

  #endif

  Serial.println("\nSetup done");
}

void loop()
{ 
  mtpd.loop();

#if USE_EVENTS==1
  if(Serial.available())
  {
    char ch=Serial.read();
    Serial.println(ch);
    if(ch=='r') 
    {
      Serial.println("Reset");
      mtpd.send_DeviceResetEvent();
    }
  }
#endif
}

Full Error Output of Arduino IDE, including all the Time.h warnings:

Code:
Warning: Board breadboard:avr:atmega328bb doesn't define a 'build.board' preference. Auto-set to: AVR_ATMEGA328BB
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src/ExFatLib/ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src/ExFatLib/ExFatVolume.h:28,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src/ExFatLib/ExFatLib.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src/SdFat.h:33,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\src/SD.h:27,
                 from C:\Users\T410\Desktop\mtp-test\mtp-test.ino:3:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src/ExFatLib/ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src/ExFatLib/ExFatVolume.h:28,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src/ExFatLib/ExFatLib.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src/SdFat.h:33,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\src/SD.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\src\SD.cpp:24:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFilePrint.cpp:27:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatVolume.h:28,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatDbg.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFile.cpp:27:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFileWrite.cpp:27:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\upcase.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFormatter.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFormatter.cpp:27:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatVolume.h:28,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatVolume.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatVolume.h:28,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatPartition.cpp:27:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\ExFatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\upcase.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\ExFatLib\upcase.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFile.cpp:27:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatVolume.h:28,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatDbg.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFilePrint.cpp:28:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFileLFN.cpp:27:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFileSFN.cpp:28:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFormatter.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFormatter.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatFile.h:36,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatVolume.h:28,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FatLib\FatVolume.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatFile.h:36,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatVolume.h:28,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\fatlib.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FsLib\FsVolume.h:32,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FsLib\FsLib.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FsLib\FsFile.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatFile.h:36,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatVolume.h:28,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\fatlib.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FsLib\FsVolume.h:32,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FsLib\FsLib.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\FsLib\FsVolume.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatFile.h:36,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatVolume.h:28,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\fatlib.h:27,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fslib\FsVolume.h:32,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fslib\fslib.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\ios.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\ostream.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\ostream.cpp:26:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatFile.h:36,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatVolume.h:28,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\fatlib.h:27,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fslib\FsVolume.h:32,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fslib\fslib.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\ios.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\istream.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\iostream.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\fstream.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\StreamBaseClass.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatFile.h:36,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatVolume.h:28,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\fatlib.h:27,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fslib\FsVolume.h:32,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fslib\fslib.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\ios.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\istream.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\istream.cpp:27:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\stat.h:9:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\_default_fcntl.h:188,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\sys\fcntl.h:4,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\fcntl.h:1,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\common\fsapiconstants.h:30,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatFile.h:36,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\FatVolume.h:28,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fatlib\fatlib.h:27,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fslib\FsVolume.h:32,
                 from c:\program files (x86)\arduino\hardware\teensy\avr\libraries\sdfat\src\fslib\fslib.h:31,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\ios.h:27,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\StdioStream.h:32,
                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat\src\iostream\StdioStream.cpp:25:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Time/time.h:1:2: warning: #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h" [-Wcpp]
 #warning "Please include TimeLib.h, not Time.h.  Future versions will remove Time.h"
  ^
C:\Users\T410\Documents\Arduino\libraries\MTP_t4\src\MTP.cpp: In member function 'void MTPD::WriteDescriptor()':
C:\Users\T410\Documents\Arduino\libraries\MTP_t4\src\MTP.cpp:295:76: warning: array subscript is above array bounds [-Warray-bounds]
     for (size_t i=0; i<10; i++) buf[i] = usb_string_serial_number.wString[i];
                                                                            ^
C:\Users\T410\AppData\Local\Temp\arduino_build_492362\sketch\mtp-test.ino.cpp.o: In function `setup':
C:\Users\T410\Desktop\mtp-test/mtp-test.ino:222: undefined reference to `usb_init_events'
C:\Users\T410\AppData\Local\Temp\arduino_build_492362\sketch\mtp-test.ino.cpp.o: In function `loop':
C:\Users\T410\Desktop\mtp-test/mtp-test.ino:294: undefined reference to `MTPD::send_DeviceResetEvent()'
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "SD.h"
 Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
 Not used: C:\Users\T410\Documents\Arduino\libraries\SD_preTeensy
 Not used: C:\Program Files (x86)\Arduino\libraries\SD
Error compiling for board Teensy 3.6.
 
Chip,
Have not integrated yet events to T3.6.
I'm still testing with T4.1 (my real application runs on T4.1)
T3.6 needs own usb interface so it needs a mind-change to get integrated.
otherwise it should work with "#define USE_EVENTS 0" in MTP.h

To get rid of the Time warning, best delete Time.h in Time library and when necessary replace "Time.h" by "TimeLib.h" except you wanted to include system library "time.h" (not first character)
 
When I was trying to get it to work, I did try turning USE_EVENTS to zero. It didn't seem to work...but I was having multiple issues, so USE_EVENTS not solving my problem was probably my fault and not a problem with the code.

In the end, I left the library unchanged and stripped down the example sketch to suit my limited goal, which was to get basic MTP access to the built-in SD slot. From the example sketch, I removed all the event stuff and I removed all the non SD stuff. In its stripped-down form, it seems to compile and run fine.

https://github.com/Tympan/Tympan_Sandbox/tree/master/MTP-Test-Chip

With this sketch, I am now successfully getting MTP access to the SD through Windows. I'm a happy camper

Thanks for all the great work to bring MTP up-to-date...and to push it forward with new capabilities. Amazing.

Chip
 
Chip,
mtp-test.ino does work now with T3.6
to use USB_MTPDISK_SERIAL you need to copy the desc.h parts into desc.h cores files
if you prefer to use old mtpdisk (seremu) you should edit desc.h to have for USB_MTPDISK " #define ENDPOINT4_CONFIG ENDPOINT_TRANSMIT_ONLY"

have not looked yet into your test example, will do next
Walter

Edit: as you say your test example should work
 
Thanks for the extra work. No need to check my example (unless you are interested) as it worked well enough for my needs. I was sharing it in case others had similar problems.

But, now that you've provided additional guidance for T3.6, my code isn't needed!

Thanks again.

Chip
 
@KurtE
Re storageID, I knew this and have thought to separate physical and logical storage, but in the end I let everything as 1 physical storage (0<<16) and consider all storage as logical. I know this not entirely correct, but... Now if this may help it can be done, but it may require a redesign of index files.
Re addObject, I seems that a single addObject is not sufficient to provoke response, but it must be followed by sending storageInfoChanged. Have to test that.

I may start playing with some of this.

I am thinking of changing the storageID stuff to have the high word by non-zero... My quick look through I think it might get most the way there, by maybe changing:
Code:
#define Store2Storage(x) (x+1)
#define Storage2Store(x) (x-1)

To something like:
Code:
#define Store2Storage(x) (((x)+1) | 0x10000000ul)
#define Storage2Store(x) (((x) & 0xefffffff) -1)

Then try out some more of the events stuff.

Again my USB Host MTP test program is teaching me a few things. Not sure if it will ever be something released... Although not very far away from having a a version where I can enumerate all of the storage and maybe will add a FS wrapper and maybe add a few Write to a file and read from a file on the remote storage.

As I mentioned in a LittleFS thread, some of the stuff I am seeing:
Code:
*** Device MTPD 1949: c - connected ***
  manufacturer: Android
  product: Android
  Serial: D0FCA0A0342600M6
    STD Version:64
    Vendor extesion ID:6
    MTP Version:64
    Extensions:microsoft.com: 1.0; android.com: 1.0;
    Mode:0
    Operations: 1001 1002 1003 1004 1005 1006 1007 1008 1009 100A 100B 100C 100D 1014 1015 1016 1017 101B 9801 9802 9803 9804 9805 9810 9811 95C1 95C2 95C3 95C4 95C5
    Events: 4002 4003 4004 4005 C801 400C
    Device Properties: D401 D402 5003
    Capture formats:
    Playback formats: 3000 3001 3004 3005 3008 3009 300B 3801 3802 3804 3807 3808 380B 380D B901 B902 B903 B982 B983 B984 BA05 BA10 BA11 BA14 BA82 B906
    Manufacturer:Amazon
    Model:Fire
    Serial:1.0
Get Storage IDS: 10001

*** MPT connected ***
Connected to:
Count of Storages: 1
0(10001): Internal storage() type:3 2 max:27571462144, free: 22527651840 access:0

========== Internal storage ===========
Music(1) FMT:3001 Size:0
Podcasts(2) FMT:3001 Size:0
Ringtones(3) FMT:3001 Size:0
Alarms(4) FMT:3001 Size:0
Notifications(5) FMT:3001 Size:0
Pictures(6) FMT:3001 Size:0
Movies(7) FMT:3001 Size:0
Download(8) FMT:3001 Size:0
DCIM(9) FMT:3001 Size:0
Android(a) FMT:3001 Size:4096
kindle(3a) FMT:3001 Size:4096
Books(3b) FMT:3001 Size:4096
Documents(3e) FMT:3001 Size:0
.imagecache(40) FMT:3001 Size:0
Audible(44) FMT:3001 Size:0
Contacts(b0) FMT:3001 Size:0
.bugsense(272) FMT:3000 Size:33
mapquest(276) FMT:3001 Size:0
sirius(421) FMT:3001 Size:4096
TuneIn Radio(5e6) FMT:3001 Size:4096
amazonmp3(925) FMT:3001 Size:0
AccuWeather(107c) FMT:3001 Size:0
.backups(115c) FMT:3001 Size:0
.chartboost(1160) FMT:3001 Size:0
zzz(14fe) FMT:3004 Size:0
rx event, len=1, i=0
rx queue i=0

---------- Commands ----------
  s - Show storage list
  e - enum <ID>
  d - dump storage list
  R - Remove <ID> 
rx event, len=5, i=1
rx queue i=1


 ================= Start ENUM(62:Documents) =================

========== Enum completed (62:Documents ===========
Sidecars(3f) FMT:3001 Size:4096
PSNL!DigitalSupportPSNLs!bWFrZVNvZnR3YXJlVXBncmFkZUxldHRlci5odG1sLz9sb2NhbGU9QVRWUERLSUtYMERFUg_PSNL(6b4) FMT:3000 Size:88192
PSNL!DigitalSupportPSNLs!bWFrZVNvZnR3YXJlVXBncmFkZUxldHRlci5odG1sLz9sb2NhbGU9QVRWUERLSUtYMERFUg_PSNL.prc(6e4) FMT:3001 Size:0
PSNL!DigitalSupportPSNLs!bWFrZVdhUG9MZXR0ZXIuaHRtbD9iaW5hcnk9bW9iaTg_PSNL(752) FMT:3000 Size:81760
my data(14fc) FMT:3004 Size:0
Naxos.xls(14fd) FMT:ba85 Size:11776
abcdefg(1501) FMT:3000 Size:0
qwerty(1502) FMT:3000 Size:0
kkk(1504) FMT:3000 Size:0


EVENT C<- len:16 EVENT:  OP:4002(EVT:OBJECT_ADDED) TID:166 P:1505
EVENT C<- len:16 EVENT:  OP:400c(EVT:STORAGE_INFO_CHANGED) TID:169 P:10001
mtpd_event_callback 4002 1505 20206a88 : 0 0 20206320
 CALLBACK: Object added: 20206a88 ID:00001505 P:20206320 C:0000: S:00010001 F:3000 new_file
mtpd_event_callback 400c 10001 - no node
CALLBACK: Storage Changed: 10001
EVENT C<- len:16 EVENT:  OP:4003(EVT:OBJECT_REMOVED) TID:171 P:1504
mtpd_event_callback 4003 1504 202068c8 : 0 0 20206320
 CALLBACK: Object removed: ## FreeStorageListTree: 202068c8 1504 10001: kkk
EVENT C<- len:16 EVENT:  OP:400c(EVT:STORAGE_INFO_CHANGED) TID:171 P:10001
mtpd_event_callback 400c 10001 - no node
CALLBACK: Storage Changed: 10001

20006f70 ID:00010001 P:0000 C:202060e0: S:00010001 F:3001 Internal storage
202060e0   ID:00000001 P:20006f70 C:0000: S:00010001 F:3001 Music
20206110   ID:00000002 P:20006f70 C:0000: S:00010001 F:3001 Podcasts
20206140   ID:00000003 P:20006f70 C:0000: S:00010001 F:3001 Ringtones
20206170   ID:00000004 P:20006f70 C:0000: S:00010001 F:3001 Alarms
202061a0   ID:00000005 P:20006f70 C:0000: S:00010001 F:3001 Notifications
202061d0   ID:00000006 P:20006f70 C:0000: S:00010001 F:3001 Pictures
20206200   ID:00000007 P:20006f70 C:0000: S:00010001 F:3001 Movies
20206230   ID:00000008 P:20006f70 C:0000: S:00010001 F:3001 Download
20206260   ID:00000009 P:20006f70 C:0000: S:00010001 F:3001 DCIM
20206290   ID:0000000a P:20006f70 C:0000: S:00010001 F:3001 Android
202062c0   ID:0000003a P:20006f70 C:0000: S:00010001 F:3001 kindle
202062f0   ID:0000003b P:20006f70 C:0000: S:00010001 F:3001 Books
20206320   ID:0000003e P:20006f70 C:20206748: S:00010001 F:3001 Documents
20206748     ID:0000003f P:20206320 C:0000: S:00010001 F:3001 Sidecars
20206778     ID:000006b4 P:20206320 C:0000: S:00010001 F:3000 PSNL!DigitalSupportPSNLs!bWFrZVNvZnR3YXJlVXBncmFkZUxldHRlci5odG1sLz9sb2NhbGU9QVRWUERLSUtYMERFUg_PSNL
202067a8     ID:000006e4 P:20206320 C:0000: S:00010001 F:3001 PSNL!DigitalSupportPSNLs!bWFrZVNvZnR3YXJlVXBncmFkZUxldHRlci5odG1sLz9sb2NhbGU9QVRWUERLSUtYMERFUg_PSNL.prc
202067d8     ID:00000752 P:20206320 C:0000: S:00010001 F:3000 PSNL!DigitalSupportPSNLs!bWFrZVdhUG9MZXR0ZXIuaHRtbD9iaW5hcnk9bW9iaTg_PSNL
20206808     ID:000014fc P:20206320 C:0000: S:00010001 F:3004 my data
20206838     ID:000014fd P:20206320 C:0000: S:00010001 F:ba85 Naxos.xls
20206868     ID:00001501 P:20206320 C:0000: S:00010001 F:3000 abcdefg
20206898     ID:00001502 P:20206320 C:0000: S:00010001 F:3000 qwerty
20206a88     ID:00001505 P:20206320 C:0000: S:00010001 F:3000 new_file
20206350   ID:00000040 P:20006f70 C:0000: S:00010001 F:3001 .imagecache
20206380   ID:00000044 P:20006f70 C:0000: S:00010001 F:3001 Audible
202063b0   ID:000000b0 P:20006f70 C:0000: S:00010001 F:3001 Contacts
202063e0   ID:00000272 P:20006f70 C:0000: S:00010001 F:3000 .bugsense
20206410   ID:00000276 P:20006f70 C:0000: S:00010001 F:3001 mapquest
20206440   ID:00000421 P:20006f70 C:0000: S:00010001 F:3001 sirius
20206470   ID:000005e6 P:20006f70 C:0000: S:00010001 F:3001 TuneIn Radio
202064a0   ID:00000925 P:20006f70 C:0000: S:00010001 F:3001 amazonmp3
202064d0   ID:0000107c P:20006f70 C:0000: S:00010001 F:3001 AccuWeather
20206500   ID:0000115c P:20006f70 C:0000: S:00010001 F:3001 .backups
20206530   ID:00001160 P:20006f70 C:0000: S:00010001 F:3001 .chartboost
20206560   ID:000014fe P:20006f70 C:0000: S:00010001 F:3004 zzz

This is with me adding a file on Kindle and seeing the events and I went through and asked for the properties.... Plus on delete I found the item and removed it...

Now back to playing
 
@KurtE
Just back on line and downloaded the USBHost_t3.6_USB_USBSerial library to give it a try. I ran the SerialTest.ino (I think this is the right sketch) but an getting the following error several times:
Code:
D:\Users\Merli\Documents\Arduino\libraries\USBHost_t36-BT-Multi-Merge/ehci.cpp:220: undefined reference to `USBHostDebugStream'
Not sure where this is coming from or how to fix?

EDIT: Ok now using the MTP version and compiling no errors. So now what do I have to do to attach a device?
 
Last edited:
@KurtE
My bad.... Realized I should have been running MTP Disk Info sketch.

1. Attached to my old Kindle but would not recognize it (paperwhite).
2. Attached to a windows 10 tablet and not recognize (just a wild test).
3. Connected to my Samsung 5 Android. Did enumerate but did not do anything else:
Code:
USB MTP Device Test Program
*** Device MTPD 4e8: 6860 - connected ***
  manufacturer: SAMSUNG
  product: SAMSUNG_Android
  Serial: e8ce9b22
*** Device MTPD - disconnected ***
*** Device MTPD 4e8: 6865 - connected ***
  manufacturer: SAMSUNG
  product: SAMSUNG_Android
  Serial: e8ce9b22
*** Device MTPD - disconnected ***
*** Device MTPD 4e8: 6860 - connected ***
  manufacturer: SAMSUNG
  product: SAMSUNG_Android
  Serial: e8ce9b22
*** Device MTPD - disconnected ***
*** Device MTPD 4e8: 6860 - connected ***
  manufacturer: SAMSUNG
  product: SAMSUNG_Android
  Serial: e8ce9b22

---------- Commands ----------
  s - Show storage list
  e - enum <ID>
  d - dump storage list
  R - Remove <ID> 

*** MPT connected ***
Connected to:(null)
Count of Storages: 0

EDIT: Been a while since i worked on USBHost. Remembered that I had to add it to the device list so I added {0x04e8,0x6860} then it only got up basically saying ready. Now if I deleted what I just added then nothing.
 
Last edited:
Sorry took rest of day off.. will look more in morning.

But wondering if you see any files if you plug in to pc? May have to do something to enable MTP. I have seen some instructions online for different version, like when plugged in swipe down or ??? And click on charging ...
 
@KurtE
Not a problem - pretty much took most of the day off myself but couldn't help checking.

For the phone I made sure I went into developer options and turned MTP on. Also checked it on the PC and it did show the drive so I could copy files. On the Kindle I plugged it into the PC and it came right up on the PC so I could access it. What got me curious is why the phone didn't show up again?
 
Good Morning @mjs513 (and others). Sorry I was distracted with other tasks, like watch movies, drink eggnog, eat chexmix :D Hope everyone else had some fun as well!

Not sure if my last post came through OK, as I don't like "typing' on the tablets.

I don't remember if awhile ago if I had to do something with my Kindle to allow it to transfer files to and from a PC. I know I probably did. Earlier I did things to try to allow me to for example install other Android stuff. Don't remember much. I never really like this Kindle Fire as this display has a blue tinge going around the whole outside of the display.... Maybe the newer ones don't.

But looking up on web found some web pages mentioning people not seeing files on their PC when the plug it in. Some of them had instuctions like they had to slide finger down from top of screen when plugged in. And some symbol or text on screen say like USB charging. If they clicked on that there was an option to transfer files...

Again not sure if that works or not.

Yesterday before that was playing with the notification system of the MTPD. I removed the updates I did to Core (actually git stashed them) and merged in @WMXZ stuff he added later to core to my version which I left in code that I could trigger to send events. I think maybe one event got out, but the USB system never fully processed it. It left the USB state in screwy state that would time out and not try to send any other events...

Will be investigating that more this morning.

Happy Boxing day

EDIT: Looks like we cross posted.

Also you might need to reboot at program at times. I am not sure if I did fully cleanup everything when device disconnects.
 
@mjs513 and @wmxz @defragster ...

Some progress on sending an event to the PC.

Not fully working yet, but the Cores event end point is configured wrong...

In cores4\usb_desc.h

I upped the event size from 16 to 32... Not sure we need that much, Kindle configures it for 28
Code:
#define MTP_EVENT_SIZE	32
The main thing is how this end point is configured.
Code:
 // TODO: Should ENDPOINT4_CONFIG be ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT ???
  //#define ENDPOINT4_CONFIG	ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_UNUSED
  #define ENDPOINT4_CONFIG  ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
The answer to the TODO is YES...

Before the change I was not getting any response from PC, and any attempt to send 2nd one timed out...
So with my version of the mtpd-test program, I have command to create a new file and then tell MTPD about the new file, which tries to find the node by
name and storage index. If it finds parent but not it, it creates a new node and then sends an event to PC

Here is part of debug outputs:
Code:
*** List of Storages ***
    0: sdio
    1: RAM1
    2: RAM2
    3: PROGM
    4: QSPI
    5: spif-5
    6: spif-6
    7: nspif-3
    8: nspif-4

Commands
  Create File: f <storage index> pathname [size]
  Create directory: d <SI> pathname
  Remove file.dir: r <SI> pathname
  print storage index list: i
[COLOR="#FF0000"]MTPStorage_SD::MapFileNameToIndex 1 /abcdefg.txt dir:0 add:1[/COLOR]
1: 1 1 1 1 0 19
Looking for: abcdefg.txt
19: 1 0 0 1 18 21
18: 1 0 0 1 17 21
17: 1 0 0 1 16 21
16: 1 0 0 1 15 21
15: 1 0 0 1 14 21
14: 1 0 0 1 13 21
13: 1 0 0 1 12 21
12: 1 0 0 1 11 21
11: 1 0 0 1 10 21
10: 1 0 0 1 9 21
9: 1 1 0 1 0 0
Node Not found
New node created: 20
20: 1 0 0 1 19 0
[COLOR="#FF0000"]notifyFileCreated: 20002a98:2005fdd0 maps to handle: 14[/COLOR]

 >>> call usb_mtp_wait
usb_mtp_sendEvent: 2005fc50 10
  parent: 1 storage: 1 -> 10000002

 >>> call usb_mtp_wait

[COLOR="#FF0000"]>>> tx0
usb_mtp_sendEvent: 2005fc50 10
MTPD notified of file:/abcdefg.txt size:1024 on RAM1 created
<< 512: 14 00 00 00 01 00 03 98 74 00 00 00 14 00 00 00 02 DC 00 00 FF FF FF FF D0 8D 11 23 FF AD E3 7E
9803 20 1 116:  14 dc02
>> 000e:  0E 00 00 00 02 00 03 98 74 00 00 00 00 30
>> 0014:  14 00 00 00 03 00 01 20 74 00 00 00 14 00 00 00 02 DC 00 00
<< 512: 14 00 00 00 01 00 03 98 75 00 00 00 14 00 00 00 01 DC 00 00 7F 6E 9F FE 43 4B C0 4C BF A7 57 FC
9803 20 1 117:  14 dc01
>> 0010:  10 00 00 00 02 00 03 98 75 00 00 00 02 00 00 10
>> 0014:  14 00 00 00 03 00 01 20 75 00 00 00 14 00 00 00 01 DC 00 00

[/COLOR]>>> tx1
<< 512: 14 00 00 00 01 00 03 98 76 00 00 00 14 00 00 00 07 DC 00 00 BB EB 69 62 0E 0C DA CF C8 92 AF BE
9803 20 1 118:  14 dc07
>> 0025:  25 00 00 00 02 00 03 98 76 00 00 00 0C 61 00 62 00 63 00 64 00 65 00 66 00 67 00 2E 00 74 00 78
>> 0014:  14 00 00 00 03 00 01 20 76 00 00 00 14 00 00 00 07 DC 00 00
<< 512: 14 00 00 00 01 00 02 98 77 00 00 00 0B DC 00 00 00 30 00 00 FF FF FF FF BA 01 32 64 41 7A B9 AF
9802 20 1 119:  dc0b 3000
>> 001a:  1A 00 00 00 02 00 02 98 77 00 00 00 0B DC 06 00 00 00 00 00 00 00 00 00 00 00
>> 0014:  14 00 00 00 03 00 01 20 77 00 00 00 0B DC 00 00 00 30 00 00
<< 512: 14 00 00 00 01 00 03 98 78 00 00 00 14 00 00 00 0B DC 00 00 FF FF FF FF D0 8D 11 23 FF AD E3 7E
9803 20 1 120:  14 dc0b
>> 0010:  10 00 00 00 02 00 03 98 78 00 00 00 01 00 00 00
>> 0014:  14 00 00 00 03 00 01 20 78 00 00 00 14 00 00 00 0B DC 00 00
<< 512: 14 00 00 00 01 00 03 98 79 00 00 00 14 00 00 00 41 DC 00 00 7F 6E 9F FE 43 4B C0 4C BF A7 57 FC
9803 20 1 121:  14 dc41
>> 001c:  1C 00 00 00 02 00 03 98 79 00 00 00 14 00 00 00 01 00 00 00 02 00 00 10 00 00 00 00
>> 0014:  14 00 00 00 03 00 01 20 79 00 00 00 14 00 00 00 41 DC 00 00
<< 512: 14 00 00 00 01 00 03 98 7A 00 00 00 14 00 00 00 44 DC 00 00 BB EB 69 62 0E 0C DA CF C8 92 AF BE
9803 20 1 122:  14 dc44
>> 0025:  25 00 00 00 02 00 03 98 7A 00 00 00 0C 61 00 62 00 63 00 64 00 65 00 66 00 67 00 2E 00 74 00 78
>> 0014:  14 00 00 00 03 00 01 20 7A 00 00 00 14 00 00 00 44 DC 00 00
<< 512: 14 00 00 00 01 00 03 98 7B 00 00 00 01 00 00 00 02 DC 00 00 FF FF FF FF BA 01 32 64 41 7A B9 AF
9803 20 1 123:  1 dc02
>> 000e:  0E 00 00 00 02 00 03 98 7B 00 00 00 01 30
>> 0014:  14 00 00 00 03 00 01 20 7B 00 00 00 01 00 00 00 02 DC 00 00
<< 512: 14 00 00 00 01 00 03 98 7C 00 00 00 01 00 00 00 01 DC 00 00 FF FF FF FF D0 8D 11 23 FF AD E3 7E
9803 20 1 124:  1 dc01
>> 0010:  10 00 00 00 02 00 03 98 7C 00 00 00 02 00 00 10
>> 0014:  14 00 00 00 03 00 01 20 7C 00 00 00 01 00 00 00 01 DC 00 00
<< 512: 14 00 00 00 01 00 02 98 7D 00 00 00 0B DC 00 00 01 30 00 00 7F 6E 9F FE 43 4B C0 4C BF A7 57 FC
9802 20 1 125:  dc0b 3001
>> 001a:  1A 00 00 00 02 00 02 98 7D 00 00 00 0B DC 06 00 00 00 00 00 00 00 00 00 00 00
>> 0014:  14 00 00 00 03 00 01 20 7D 00 00 00 0B DC 00 00 01 30 00 00
<< 512: 14 00 00 00 01 00 03 98 7E 00 00 00 01 00 00 00 0B DC 00 00 BB EB 69 62 0E 0C DA CF C8 92 AF BE
9803 20 1 126:  1 dc0b
>> 0010:  10 00 00 00 02 00 03 98 7E 00 00 00 01 00 00 00
>> 0014:  14 00 00 00 03 00 01 20 7E 00 00 00 01 00 00 00 0B DC 00 00
<< 512: 14 00 00 00 01 00 03 98 7F 00 00 00 01 00 00 00 41 DC 00 00 FF FF FF FF BA 01 32 64 41 7A B9 AF
9803 20 1 127:  1 dc41
>> 001c:  1C 00 00 00 02 00 03 98 7F 00 00 00 01 00 00 00 01 00 00 00 02 00 00 10 00 00 00 00
>> 0014:  14 00 00 00 03 00 01 20 7F 00 00 00 01 00 00 00 41 DC 00 00

...
Dump index list
0: 0 1 0 0 0 0 /
1: 1 1 1 1 0 20 /
2: 2 1 0 2 0 0 /
3: 3 1 0 3 0 0 /
4: 4 1 0 4 0 0 /
5: 5 1 0 5 0 0 /
6: 6 1 0 6 0 0 /
7: 7 1 0 7 0 0 /
8: 8 1 0 8 0 0 /
9: 1 1 0 1 0 0 Dir0
10: 1 0 0 1 9 21 test_0.txt
11: 1 0 0 1 10 21 test_1.txt
12: 1 0 0 1 11 21 test_2.txt
13: 1 0 0 1 12 21 test_3.txt
14: 1 0 0 1 13 21 test_4.txt
15: 1 0 0 1 14 21 test_5.txt
16: 1 0 0 1 15 21 test_6.txt
17: 1 0 0 1 16 21 test_7.txt
18: 1 0 0 1 17 21 test_8.txt
19: 1 0 0 1 18 21 test_9.txt
20: 1 0 0 1 19 0 abcdefg.txt

Some of the lines in RED and below those are interesting.

It shows for example that I found where the new item should live, in the list at end it shows up with 0 size I believe

But one of the interesting lines for example right after I send the notify.
You see lines like: 9803 20 1 116: 14 dc02
That translates to:
#define MTP_OPERATION_GET_OBJECT_PROP_VALUE 0x9803
For object 0x14 -> 20
For property:
#define MTP_PROPERTY_OBJECT_FORMAT 0xDC02

And it follows on asking for ones like:
#define MTP_PROPERTY_STORAGE_ID 0xDC01
#define MTP_PROPERTY_PARENT_OBJECT 0xDC0B


It is still not showing up properly, and I am not sure if the other event is being sent.... But progress.
 
Back
Top