MTP Responder for Teensy 3.x and 4.x
Uses SD interface, which interfaces to Bill Greiman's SdFat_V2 as distributed via Teenyduino supporting exFAT and SDIO.
code is based on https://github.com/yoonghm/MTP with modification by WMXZ
see also https://forum.pjrc.com/threads/43050-MTP-Responder-Contribution for discussions
files in different copy-to directories contain modifications of cores and need to be copied to cores/teensy4, cores/teensy3 and hardware/avr, respectively. These files are only necessary until Teensyduino has integrated full MTP into cores functionality
as of TD 1.57/beta-4 these copy-to directories can be ignored
(before TD 1.54 final) needs USB2 https://github.com/WMXZ-EU/USB2 for T4.x. (uses here usb1.h and usb1.c)
- Supports multiple MTP-disks (SDIO, multiple SPI disks, LittleFS_xxx disks)
- copying files from Teensy to PC and from PC to Teensy is working
- disk I/O to/from PC is buffered to get some speed-up overcoming uSD latency issues
- both Serialemu and true Serial may be used- True Serial port is, however, showing up as Everything in Com port. This is a workaround to get Serial working.
- deletion of files
- recursive deletion of directories
- creation of directories
- moving files and directories within and cross MTP-disk disks
- copying files and directories within and cross MTP-disk disks
- Maximal filename length is 256 but can be changed in Storage.h by changing the MAX_FILENAME_LEN definition
- within-MTP copy not yet implemented (i.e no within-disk and cross-disk copy)
- creation of files using file explorer is not supported, but directories can be created
- No creation and modification timestamps are shown
Assume following sequence of operation:
- you start MTP
- you start Logger
- You stop Logger
- You do not see files added by Logger.
This is how MTP works.
The PC has under normal circumstances complete control over the actions. The Teensy only responds to commands by PC.
As the PC does not know what you are doing with Teensy, it will not act an inquire.
Solutions:
- Only start MTP after logging
- Reset MTP connection from PC (unmount/mount MTP disk on PC; disconnect/reconnect PC) after logging
- Reset MPT from Teensy (using reset event)
Note, these work arounds are experimental, so feedback would be appreciated.
Modification of disk content (directories and Files) by Teensy is only be visible on PC when done before mounting the MTP device. To refresh disk content it is necessary to unmount and remount Teensy MTP device. AFAIK: On Windows this can be done by using device manager and disable and reanable Teensy (found under portable Device). On Linux this is done with standard muount/unmount commands.
Session may be reset from Teensy by sending a reset event. This is shown in mtp-test example where sending the character 'r' from PC to Teensy generates a reset event. It is suggested to close file explorer before reseting mtp
In scipts directory is a powershell script that unmounts/mounts the Teensy portable device
- mtp-basic: basic MTP program
- mtp-test: basic MTP test program
- mtp-logger: basic data logger with MTP access
- mtp-audioRecorder: example about using mtp-logger as sgtl5000 audioRecorder
- As of TeensyDuino 1.57 beta 3, the following steps are not required
If you wanted to use USB_MTP_SERIALT4.x edit teensy/avr/cores/teensy4/usb_desc.h with content of 'modifications_for_cores_teensy4' (insert after USB_MTPDISK)T3.x edit teensy/avr/cores/teensy3/usb_desc.h with content of 'modifications_for_cores_teensy3' (insert after USB_MTPDISK)edit teensy/avr/boards.txt with content of 'modifications_for_teensy_avr' (copy to end of file)- As of TeensyDuino 1.54 the following step is not required
install also USB2 from WMXZ github if cores does not have "usb_mtp.h"- install LittleFS from https://github.com/PaulStoffregen/LittleFS for use of LittleFS basd filesystems
- remove "Time.h" in "libraries/Time" to eliminate compiler warnings
- copying of files and directories work but are not displayed in file explorer, manual unmount/mount sequence required
- deleting large nested directories may generate a time-out error and brick MTP. No work around known, only restart Teensy
There are some useful scripts for Windows PowerShell in scrips directory. open them with right-click "Run with PowerShell"
- MTPdir list the files in Teensy
- MTPreset to reset MTP (disable/enable)
- show creation and modification timestamps