Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Mount Teensy both as HID and MSC?

  1. #1
    Junior Member
    Join Date
    Jul 2022
    Posts
    4

    Mount Teensy both as HID and MSC?

    Hello,

    When I tested the MSC examples in USBHost_t36, I had an idea, could THE MSC device still appear in windows explorer, when teensy reads the MSC device? So I can manage MSC on PC and teensy at the same time.

    I have tried to do some work, modifying usb_desc.h and usb_desc.c, but THE MSC device is different from mouse or keyboard, which makes me frustrated about this, do you have any good suggestions or ideas?

    I found some related information here https://forum.pjrc.com/threads/39423...and-SD-Storage, but yet not been solved.

    As a beginner, I would like to get your advice. Thank you in advance!

    Teensy 4.1
    Arduino 1.8.19
    Teensyduino 1.57 beta 3
    Windows 10

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,979
    I am not sure if I fully understand all of your questions, but will give it a shot.

    For the most part, the Teeensy code does not support connecting to the host computer as an MSC device. As I mentioned "for the most part" as, there is now support in CircuitPython to allow it to run on the Teensy 4, 4.1 and Micromod, and they have their own implementation of code and they do connect the teensy up as an MSC type device.

    However we do have code that we are working that allows the Teensy to connect up as an MTP (Media Transfer Protocol ) device. The code for this is not fully in the builds yet, but we are working on it.
    Lots more details up on the thread: https://forum.pjrc.com/threads/68139...ng-MTP-and-MSC

    As part of this, currently the MTP stuff is in the library: https://www.github.com/kurte/MTP_Teensy
    There are several examples of code that for example allow you to plug an MSC type device (USBDrive, USBFilesystem) into the USBHost port of T3.6 or T4.x and the code will enumerate the partitions on the drive and try to assign a USBFilesystem object to each partition that we understand (Fat, ExFat).

    Once this is done, your code on the Teensy can open up files on the filesystem the same way it can with an SD drive, or LittleFS.

    Again some of the examples, then add these FileSystems to the list of storage items shown by MTP. Example run right on a MicroMod.
    Click image for larger version. 

Name:	screenshot.jpg 
Views:	17 
Size:	39.0 KB 
ID:	28879
    Where I have an SSD drive plugged in using and SSD to Serial adapter...

    The MTP USB Types show up on the host computers, like I showed. However they are not normal Filesystems on the host, like an MSC device would be. Instead all of the communications is done through the MTP protocol. What does this mean. Your typical apps can not open up files on the Teensy and edit them directly.

    However MTP does allow you to do things, like copy files, delete files, enumerate the hierarchy, etc. And some operations may sort of disguise some of this. For example if you double click on a bitmap file, the underlying code will probably use the MTP transfer code to copy the file to your PC probably into the temporary directory and then launch the app on your PC for that type file passing it the file from TEMP.

    Wit this I have played around with stuff, like editing configuration file. I have two explorer windows open, one to some main folder on PC and another to the browsing into the Teensy object. I drag the file from the Teensy to the PC folder. I then edit the file on the pc and after I save the changes, I drag the file back to the Teensy object.

    This was done in example sketch that shows image files stored in on an SD card, and when plugged in to PC, allows me to copy more Images to the teensy to be shown in the slide show. It also has simple config file that allows me to experiment by changing the options, which the sketch checks to see if the file was updated.

    However with USB Types including MTP.
    Currently only in 1.57 Beta 3 so far we have:
    MTP - Only MTP plus a Serial Emulator type which talks to Terminal Monitor in Arduino.
    Serial + MTP - like the other one but instead of emulated Serial it has the normal Serial .

    What we don't have is the easy ability to add this to other USB types. That is we don't have things like: Joystick + MTP... Would be nice and one could probably hack it up by changing some stuff. As actually in previous builds we did not have Serial + MTP, but had setups to do it anyway.

    Hope this answers most of the questions.

  3. #3
    Junior Member
    Join Date
    Jul 2022
    Posts
    4
    I run some related codes, which are very useful. But when I connect different USB flash drives, they are all too slow. The speed of USB flash disk can only reach 1MB/s, and even 330KB/s. you know, this will be very frustrating, because for Teensy 4.1, the theoretical speed should reach 60MB/s. I tried to modify the cache, but it didn't seem to work. I don't know whether I didn't modify the correct code, or it can only reach this speed. I hope you can give me some suggestions.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,826
    Difficult to offer suggestions without seeing exactly how you tested, ideally with enough detail to be able to run the test and reproduce the same result. Often small details matter greatly.

  5. #5
    Junior Member
    Join Date
    Jul 2022
    Posts
    4
    I try to modify these codes to improve the transmission rate of the MSC equipment and the MTP_TX_SIZE and MTP_RX_SIZE has been modified, but the transmission rate has not been improved. For beginners, it is not clear which definitions are helpful for speed improvement. Could you give me some suggestions?

    Code:
      #elif defined(USB_MTPDISK)
      #define VENDOR_ID		0x16C0
      #define PRODUCT_ID		0x04D1
      #define MANUFACTURER_NAME	{'T','e','e','n','s','y','d','u','i','n','o'}
      #define MANUFACTURER_NAME_LEN	11
      #define PRODUCT_NAME		{'T','e','e','n','s','y',' ','M','T','P',' ','D','i','s','k'}
      #define PRODUCT_NAME_LEN	15
      #define EP0_SIZE		64
      #define NUM_ENDPOINTS         4
      #define NUM_INTERFACE		2
      #define MTP_INTERFACE		1	// MTP Disk
      #define MTP_TX_ENDPOINT	3
      #define MTP_TX_SIZE_12	64  
      #define MTP_TX_SIZE_480	512
      #define MTP_RX_ENDPOINT	3
      #define MTP_RX_SIZE_12	64
      #define MTP_RX_SIZE_480	512 
      #define MTP_EVENT_ENDPOINT	4
      #define MTP_EVENT_SIZE	32
      #define MTP_EVENT_INTERVAL_12	10	// 10 = 10 ms
      #define MTP_EVENT_INTERVAL_480 7	// 7 = 8 ms
      #define SEREMU_INTERFACE      0	// Serial emulation
      #define SEREMU_TX_ENDPOINT    2
      #define SEREMU_TX_SIZE        64
      #define SEREMU_TX_INTERVAL    1
      #define SEREMU_RX_ENDPOINT    2
      #define SEREMU_RX_SIZE        32
      #define SEREMU_RX_INTERVAL    2
      #define ENDPOINT2_CONFIG	ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_INTERRUPT
      #define ENDPOINT3_CONFIG	ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
      #define ENDPOINT4_CONFIG  ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
    At the same time, when running MTP-test-integrity sketch, I found that the SSD connected through the USB interface seems to be unrecognizable. I speculate that the reason is that the MSC device is defined as a device that “Removable Device: NO”. Could you give me some advice?

    I got the relevant codes from the following : https://www.github.com/kurte/MTP_Teensy

  6. #6
    Senior Member wwatson's Avatar
    Join Date
    Aug 2017
    Posts
    744
    @hupool - Something to keep in mind is a lot of thumb drives have small write buffers. I have a 16G Kingston DataTraveler 3.0 that can only do 1.5- 1.6 MB/s. This a fairly old thumb drive. A newer 128G Kingston drive does writes at about 6.5 MB/s. It does have a larger write buffer. And the kingston SSD drive I have is about 10.7 MB/s.

    As far as your SSD drive not being recognized did you try connecting with the 'DriveInfo.ino' sketch? It's located in the 'USBHost_t36/examples/Storage' folder. This will show you if the SSD drive is being recognized and initialized. If not then there is one other possibility. In 'USBHost_t36/utility' there is a msc.h file. Starting at line #73 you will see two timeout defines:
    Code:
    // These two defines are timeouts for detecting a connected drive
    // and waiting for it to be operational.
    #define MEDIA_READY_TIMEOUT	1000
    #define MSC_CONNECT_TIMEOUT     4000
    Change these to:
    Code:
    // These two defines are timeouts for detecting a connected drive
    // and waiting for it to be operational.
    #define MEDIA_READY_TIMEOUT	5000
    #define MSC_CONNECT_TIMEOUT     5000
    And see if the SSD is recognized. I have had other issues with these timeouts. I do have a PR in for this #62.

    Timeouts of 3000ms usually works ok.

  7. #7
    Junior Member
    Join Date
    Jul 2022
    Posts
    4
    My SSD could connect with the 'DriveInfo.ino' sketch and 'DriveInfoAll.ino' sketch. But I ran 'DriveInfoAll.ino' sketch, which Unable to display File system information in SSD. However I could get my 64G Kingston DataTraveler' File system information.

    Click image for larger version. 

Name:	03e044acdddf5d4812d503084ae349d.jpg 
Views:	5 
Size:	84.2 KB 
ID:	29133
    Click image for larger version. 

Name:	c28f8b58f03415370a047ea5fa7a4e6.jpg 
Views:	3 
Size:	92.0 KB 
ID:	29134
    I can't understand. Maybe the reason of "Removable Device: NO" ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •