Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 39 of 39

Thread: MTP Responder Contribution

  1. #26
    Quote Originally Posted by murpia View Post
    See here for how to create a composite MTP and CDC device, which sounds to me like what you need:

    https://forum.pjrc.com/threads/44569...l=1#post145192

    Regards, Ian
    No, it should be using the "emulated serial" automatically.

  2. #27
    Junior Member
    Join Date
    Jun 2017
    Posts
    8
    No, emulated serial is for program downloads only. If you look at all the other 'Serial + ...' options in usb_desc.h you'll see they implement CDC in place of SEREMU.

    Compare 'MIDI' to 'Serial + MIDI' as an example. Open the basic Arduino example sketch 'AnalogReadSerial'. The serial monitor only works if you select 'Serial + MIDI'. It doesn't for 'MIDI'. At least not on my PC with a Teensy 3.6. You can see in Windows device monitor that the com port is only there for 'Serial + MIDI'.

    Then look into 'usb_desc.h' and you'll see that 'MIDI' implements emulated serial while 'Serial + MIDI' implements CDC. More details in my other post.

    Hopefully Paul can correct any errors in my explanation...

    Regards, Ian

  3. #28
    No need to bother Paul.
    The "emulated serial" is a simpler and non-standard (I think) usb serial port implementation. It still works with the serial monitor, but will not show up as a CDC device. (Because it's not.)
    If it doesn't work on your machine, that's a bug.

  4. #29
    Junior Member
    Join Date
    Jun 2017
    Posts
    8
    Possibly 'emulated' just works in the Arduino IDE serial monitor, then?

    I needed a real COM port to communicate with a Windows program, hence adding CDC to the MTP example.

    Regards, Ian

  5. #30
    Will this only work with 3.6 or will it work with the 3.2?

  6. #31
    Quote Originally Posted by bdoan View Post
    Will this only work with 3.6 or will it work with the 3.2?
    It should work on any of the 3.x. I wrote it using a 3.2.

  7. #32
    Junior Member
    Join Date
    Jun 2015
    Posts
    4
    Quote Originally Posted by yoonghm View Post
    I have converted the file into library. The library could be downloaded from

    https://github.com/yoonghm/Teensy_3..../Libraries/MTP

    This library requires the following changes
    * SdFat libraries - https://github.com/greiman/SdFat-beta/tree/master/SdFat
    * <Arduino_path>/hardware/teensy/avr/cores/teensy3/usb_desc.c
    * <Arduino_path>/hardware/teensy/avr/cores/teensy3/usb_dev.c
    * <Arduino_path>/hardware/boards.txt
    I apologize if I missed something, but what changes exactly are required to the above files?

    I see that maybe the changes to boards.txt was made for teensy35 & 36 through the pull request mentioned, but how about usb_desc.c and usb_dev.c?

    Thanks for the help!

  8. #33
    Junior Member
    Join Date
    Aug 2017
    Posts
    3
    Great work!
    Is there a way to signal the usb host that an object on the sd card was added, deleted or renamed? I know the mtp specification mentions events to do this, but i have no idea how to implement this.

    best regards, Thorvard

  9. #34
    Junior Member
    Join Date
    Aug 2017
    Posts
    3
    After some reading and fiddling i found this solution:

    I changed in usb_desc.h following line when "MTP_EVENT_ENDPOINT" is defined as 4:

    Code:
    //  #define ENDPOINT4_CONFIG	ENDPOINT_RECEIVE_ONLY
    #define ENDPOINT4_CONFIG	ENDPOINT_TRANSMIT_AND_RECEIVE
    Code:
        uint32_t eventID = 1;
     
        void sendEvent(int event, uint32_t param)
        {
          usb_packet_t *eventBuffer;
          eventBuffer = usb_malloc();
          eventBuffer->len = 16;
          eventBuffer->index = 0;
          eventBuffer->next = NULL;
          MTPContainer eventContainer;
          eventContainer.len = 16; // maximum length for an event container
          eventContainer.type = 4; // Type: Event
          eventContainer.op = event; // event code
          /*  the event codes must be included in WriteDescriptor() 
           *  otherwise the responder just ignores the event code
           */
          eventContainer.transaction_id = eventID++;
          eventContainer.params[0] = param;
          memcpy(eventBuffer->buf, (char*)&eventContainer, 16);
          usb_tx(MTP_EVENT_ENDPOINT, eventBuffer);
          /*  the MTP_EVENT_ENDPOINT must be defined as
           *  "ENDPOINT_TRANSMIT_AND_RECEIVE" in 
           *  ...\hardware\teensy\avr\cores\teensy3\usb_desc.h
           */
          get_buffer();
          usb_tx(MTP_EVENT_ENDPOINT, data_buffer_); // send empty packet to finish transaction
          data_buffer_ = NULL;
        }
    I hope this helps others using this great library with mtp events.

    best regards, Thorvard

  10. #35
    Member
    Join Date
    Jun 2014
    Location
    Singapore
    Posts
    41
    Sorry for delay, it took time to reinstall, read the forum, update and test again.

    I have updated the MTP into https://github.com/yoonghm/MTP, with comments for Teensyduino 1.39.
    I have also created an example that call mtpd.loop() only when SD card is present. The example also demonstrate to use Serial port.
    The original systick_isr() is removed from the example as it conflicts with the non-weak systick_isr() used by thread library. I did not want to use delay(), so I made use of RTC second timer interrupt, i.e., rtc_seconds_isr().

  11. #36
    Member
    Join Date
    Sep 2015
    Location
    Taiwan
    Posts
    89
    Quote Originally Posted by yoonghm View Post
    Sorry for delay, it took time to reinstall, read the forum, update and test again.

    I have updated the MTP into https://github.com/yoonghm/MTP, with comments for Teensyduino 1.39.
    I have also created an example that call mtpd.loop() only when SD card is present. The example also demonstrate to use Serial port.
    The original systick_isr() is removed from the example as it conflicts with the non-weak systick_isr() used by thread library. I did not want to use delay(), so I made use of RTC second timer interrupt, i.e., rtc_seconds_isr().
    I also came up with the same technique, but with another idea
    repeating mtp.loop() while millis()<2000 , e.t.c.
    and if USB established, continue loop

    and I found that MTP+Serial doesn't compile with snooze library, though deep sleep and MTP is not commonly used together, and easily overcome
    with commenting out the error part in snooze library

  12. #37
    Member
    Join Date
    Jun 2014
    Location
    Singapore
    Posts
    41
    You have to check if inserting SD card would cause the K64 to wake up.

    There is a thread library, perhaps can try to run two threads, one is to serve MTG, another is to run other tasks.

    I think I will add another examples, to write data to the SD periodically. If a file is opened, the on-board LED is turned on, indicating to user not to remove the card.

  13. #38
    Member
    Join Date
    Sep 2015
    Location
    Taiwan
    Posts
    89
    Thank you,
    My SD is planned to place constantly.
    And MTP is the main access port

    And now I plan to use the second USB port on T3.6, So the USB plug can be place at preferred location
    Anyone know if the MTP library suits the
    Other port? Thanks.

  14. #39
    Junior Member
    Join Date
    Aug 2017
    Posts
    3
    There is a severe bug somewhere in the code.
    When copying a file with a filename of 24 characters length the teensy hangs. This happens with the blinky example on github, i reported this issue on github.

Posting Permissions

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