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

Thread: Disable USB specific interface?

  1. #1
    Junior Member
    Join Date
    Apr 2017
    Posts
    7

    Disable USB specific interface?

    Hello, I'm experimenting with a Teensy 3.6 in MTP+Serial mode, which required a bit of tinkering with the usb_desc.h. I just followed instructions in https://forum.pjrc.com/threads/43050...r-Contribution.

    I can get it to work and access files from my computer, or send and receive serial data if I don't go in the mtpd.loop(). However, I would like to disable the teensy MTP mode while a certain serial command is not received, implying that the computer does not detect it as an MTP device. The usb_desc.h file describes the CDC and MTP interfaces, and I have been trying to disable the MTP interface, but whatever I do the computer always detects an MTP device.

    The enabled case in usb_desc.h:
    #define VENDOR_ID 0x16C0
    #define PRODUCT_ID 0x04E0
    #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',' ','S','E','R','I','A','L'}
    #define PRODUCT_NAME_LEN 17
    #define EP0_SIZE 64
    #define NUM_ENDPOINTS 7
    #define NUM_USB_BUFFERS 40
    #define NUM_INTERFACE 3
    #define CDC_IAD_DESCRIPTOR 1
    #define CDC_STATUS_INTERFACE 0
    #define CDC_DATA_INTERFACE 1 // Serial
    #define CDC_ACM_ENDPOINT 1
    #define CDC_RX_ENDPOINT 2
    #define CDC_TX_ENDPOINT 3
    #define CDC_ACM_SIZE 16
    #define CDC_RX_SIZE 64
    #define CDC_TX_SIZE 64
    #define MTP_INTERFACE 2 // MTP Disk
    #define MTP_TX_ENDPOINT 6
    #define MTP_TX_SIZE 64
    #define MTP_RX_ENDPOINT 6
    #define MTP_RX_SIZE 64
    #define MTP_EVENT_ENDPOINT 7
    #define MTP_EVENT_SIZE 16
    #define MTP_EVENT_INTERVAL 10
    #define ENDPOINT1_CONFIG ENDPOINT_TRANSIMIT_ONLY
    #define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_ONLY
    #define ENDPOINT3_CONFIG ENDPOINT_TRANSIMIT_ONLY
    #define ENDPOINT4_CONFIG ENDPOINT_TRANSIMIT_ONLY
    #define ENDPOINT5_CONFIG ENDPOINT_RECEIVE_ONLY
    #define ENDPOINT6_CONFIG ENDPOINT_TRANSMIT_AND_RECEIVE
    #define ENDPOINT7_CONFIG ENDPOINT_RECEIVE_ONLY



    Any advice?

    Thank you in advance

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,304
    Quote Originally Posted by posse View Post
    However, I would like to disable the teensy MTP mode while a certain serial command is not received, implying that the computer does not detect it as an MTP device.
    That's not how USB works. The PC's operating system reads all the USB descriptors when your device is plugged in. It loads drivers based on that descriptor info.

    There isn't any USB message or PC-side feature to tell the operating system your device is now different. It is possible (though requires custom programming) to shut off the USB port on Teensy, which to your PC looks as if the cable was unplugged. Then you could turn it back on and the PC will re-detect everything, because from its perspective you plugged the cable back in.

    If you try this, you'll need to modify the Teensy-side code quite a bit. It's all designed to have a single fixed response to each read descriptor query from the PC. With enough programming work, you could edit the code to send 2 different sets of descriptors.

  3. #3
    Junior Member
    Join Date
    Apr 2017
    Posts
    7
    Quote Originally Posted by PaulStoffregen View Post
    That's not how USB works. The PC's operating system reads all the USB descriptors when your device is plugged in. It loads drivers based on that descriptor info.

    There isn't any USB message or PC-side feature to tell the operating system your device is now different. It is possible (though requires custom programming) to shut off the USB port on Teensy, which to your PC looks as if the cable was unplugged. Then you could turn it back on and the PC will re-detect everything, because from its perspective you plugged the cable back in.

    If you try this, you'll need to modify the Teensy-side code quite a bit. It's all designed to have a single fixed response to each read descriptor query from the PC. With enough programming work, you could edit the code to send 2 different sets of descriptors.
    Thanks for the quick answer.

    Yes my idea was to restart the USB port upon receiving a custom command (through the usual Serial.read). I have two different descriptor lists, one that includes the MTP interface, and one that doesn't, and I can change them through software. It's the restarting the USB port that I'm having trouble with, because changing the registers isn't making a difference.

  4. #4
    Senior Member
    Join Date
    Sep 2015
    Location
    Taiwan, Asai. (Traditional Chinese)
    Posts
    154
    Quote Originally Posted by posse View Post
    ....
    Any advice?

    Thank you in advance

    I did try something that goes to mtpd.loop() forever if USB connection is detected, or else do other main codes and never do mtpd.loop().
    but not yet sure if it can shut down after connected?
    maybe like
    Code:
    while (millis()<10,000)  mtpd.loop();
    could work?

Tags for this Thread

Posting Permissions

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