Giter VIP home page Giter VIP logo

mtp_t4's Introduction

MTP_t4

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)

Features

  • 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

Limitations

  • 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

Comments on Logging

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:

  1. Only start MTP after logging
  2. Reset MTP connection from PC (unmount/mount MTP disk on PC; disconnect/reconnect PC) after logging
  3. Reset MPT from Teensy (using reset event)

Note, these work arounds are experimental, so feedback would be appreciated.

Reset of Session

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

Examples

  • 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

Installation:

  • As of TeensyDuino 1.57 beta 3, the following steps are not required
  • If you wanted to use USB_MTP_SERIAL
  • T4.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

Known Issues

  • 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

Scripts

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)

ToBeDone

  • show creation and modification timestamps

mtp_t4's People

Contributors

frankboesing avatar james-portman avatar jaredreabow avatar smittyhalibut avatar wmxz-eu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mtp_t4's Issues

MTP device not in windows explorer, serial port not available

I installed MTP_T4 on the Teensy 3.5 and made the modifications to the usb_desc.h.
I am using arduino IDE with Teensyduino version 1.54-beta 9

  1. The device shows up in the device manager as MTP USB Device not Teensy MTP device.
  2. It is not showing up in Windows explorer.
  3. After making the changes to USB_DESC should there be a Serial device in device manager for the Teensy 3.5?

I am going to also post this to the pjrc forum when it is up but it is currently down, though you may like a note here.

Teensy 4.1 not showing as MTP storage device

Teensy 4.1 is used as data logger ,however after doing the changes in files as mentioned in MTP_t4 there is no Teensy as storage device
although the data is updated in sdcard (32 GB). the same changes done in other computer shows it as storage but when i upload program from my computer it fails as storage .system specifications are Teensy 4.1,windows 10,Teensyduino, Version 1.5,arduino-1.8.19

powershell script

I can't seem to get the powershell script to run from the scripts folder.

Message -
Command is ./MTPdiir -Path Teensy
You cannot call a method on a null-valued expression.
At D:\ChuckW\Arduino\MTP_t4-master\MTP_t4-master\scripts\MTPdir.ps1:28 char:1

  • echo @($C1.GetFolder.Items()).name
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull
    
    

PS D:\ChuckW\Arduino\MTP_t4-master\MTP_t4-master\scripts>

I really don't know anything about powershell...

#include <MTP.h>

if i use #include "mtp.h" the ide does not find the library file.
#include <MTP.h> works.

Warning Wmisleading-indentation

C:\Users\Frank\Documents\Arduino\libraries\MTP_t4-master\src\MTP.cpp:875:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation] 875 | if(!write_length_) dst=tx_data_buffer; write_length_ += len; | ^~ C:\Users\Frank\Documents\Arduino\libraries\MTP_t4-master\src\MTP.cpp:875:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if' 875 | if(!write_length_) dst=tx_data_buffer; write_length_ += len; | ^~~~~~~~~~~~~ Compiling library "USB2-master"

Can MTP access be "started" and "stopped" from the teensy?

Desired scenario: My teensy code runs in different modes. When first connected, the mode is set to mtpMode and the SD card should be accessible from the PC. When the device is switched into a different program mode, the USB drive should no longer be accessible from the PC.

I attempted to do this by calling mtpd.loop() only when mode == mtpMode. Unfortunately, when I switch to another mode this causes Windows Explorer/ ThisPC (and other things) to hang forever. Presumably Explorer is blocked waiting for a response from mtpd.

Is there a way to accomplish this? Switching off the teensy causes Windows Explorer to close, which is the ideal desired behavior, but seems to be tied to USB teardown. I'd be satisfied with showing a drive that reported "access denied," or something else along those lines.

Does this work on MacOS?

Using Teensy 4.1, Arduino 1.8.13, Teensy Loader 1.54-beta7.

map-test.ino prints contents of installed SDIO to terminal ok but nothing shows on on Mac file system.

Link error: `undefined reference to 'vtable for MTPStorageInterface'`

Not sure why this just started popping up, but I'm getting a link error:

.pio/build/teensy41/src/main.cpp.o: In function `MTPStorageInterface::MTPStorageInterface()':
/home/mark/src/SOAR/SOAR-Code/SOAR-v2-Code/lib/MTP_t4/src/Storage.h:87: undefined reference to `vtable for MTPStorageInterface'
collect2: error: ld returned 1 exit status
*** [.pio/build/teensy41/firmware.elf] Error 1

Found the solution here: https://stackoverflow.com/a/57504289

It's a simple one to implement, so I submitted a pull request: #19

MTP.cpp - Debug is turn on...

Not sure if by design, but thought I would mention it;

At about line 45 we have:

#define DEBUG 1

I noticed it as I posted a data logger example on the New Teensyduino beta thread about LittleFs Datalogger, I did a quick and dirty add of MTP...

But then I was seeing debug output like:

1002 16 1 0:  1
1001 12 1 1: 
1014 16 1 2:  d402

Which I am pretty sure is from:

void MTPD::loop(void) 
  {
    usb_packet_t *receive_buffer;
    if ((receive_buffer = usb_rx(MTP_RX_ENDPOINT))) {
      printContainer();
      

The printContainer call.

Support for `SdFat` has been removed?

The original library this was based on (https://github.com/yoonghm/MTP) was written to use SdFat.

Your comments here: https://github.com/WMXZ-EU/MTP_t4/blob/master/src/Storage.h#L24-L26 are unclear on your intent with regards to library support.

But the CURRENT revision looks like it has REMOVED SdFat support. Is this intentional? Is the use of SdFat discouraged now? I thought it was the preferred library to access files on an SD card on a Teensy; am I wrong? (I'm not an expert on this, I'm still figuring out the whole SD Card On Teensy space.)

Teensy 3.2

I have tried really hard and cannot get this to work on a teensy 3.2. I have the latest version of Teensyduino, done all of the the mods as per instructions. It compiles the source files with no issues but is does not work like the original yoonghm/MTP code. It is not showing up in Windows explorer as a drive. Is there some place to set the CS pin? I am using the SPI and change made the changes for that. Can you help me out with some ideas?

Issue with Write/read in MTP

Hello,
How can i use the library SD.h with the mtp activ ?
Actually MTP work great but i can't write or read files in arduino program :

Serial.print("Initializing SD card...");

  if (!SD.begin(BUILTIN_SDCARD)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

return me initialisation fail if is after the following code

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

How can i use exemple like this :

File dataFile = SD.open(filn, FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString1);
    dataFile.close(); 

Thx for help

PS: I use teensy 3.6

Compiling mtp-test.ino for Teensy 3.6

I am trying to compile mtp-test-ino for Teensy 3.6 using Arduino IDE + Teensyduino.

I get the error: 'FS' has not been declared in storage.cpp at this line:

void sd_addFilesystem(FS &fs, const char *name) {

I am using the following libraries:
Using library SD at version 1.2.2 in folder: /home/user/arduino-1.8.13/hardware/teensy/avr/libraries/SD
Using library Time at version 1.6 in folder: /home/user/arduino-1.8.13/hardware/teensy/avr/libraries/Time
Using library SPI at version 1.0 in folder: /home/user/arduino-1.8.13/hardware/teensy/avr/libraries/SPI

If I change #include "SD.h" to #include "SdFat.h" and use the SDFat V2 library from here https://github.com/greiman/SdFat, I get the same error.

What am I missing?

Desire to use MTP on the USB1 (USBHS) port on t3.6, 4.0, and 4.1

I have seen comments indicating that in some earlier version of the MTP it was possible to connect via a high-speed port rather than the 12 Mbps main port. There was some reference to an example, but I have not been able to find such an example. This would be highly desirable functionality.

Files read through GetPartialObject return some garbage

The easiest way to replicate is using a very small text file e.g. "hello"

Some applications will only read the correct amount of data according to the file size, but some load in everything that the code sends, which might be a minimum of MTP_TX_SIZE packet

I think this might also happen with large files which are not exactly a multiple of MTP_TX_SIZE

It seems like all the code that sends out data will only do so once it hits a size that is a multiple of MTP_TX_SIZE
e.g.
https://github.com/WMXZ-EU/MTP_t4/blob/master/src/MTP.cpp#L959

This one seems like it sends too much, should probably send with size "len"?
https://github.com/WMXZ-EU/MTP_t4/blob/master/src/MTP.cpp#L1001

I am trying to unpick it all and I will send a PR if I can work it out but I'm struggling

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.