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

Thread: Teensy to imitate a USB bulk data transfer

  1. #1
    Banned
    Join Date
    Jun 2019
    Posts
    2

    Teensy to imitate a USB bulk data transfer

    I've purchased a teensy 3.0 in the hope I can use it to imitate the USB bulk transfer from another piece of hardware.

    I am developing some software to read and process the data coming over USB in a bulk transfer

    But I am trying to do this prior to actually having the USB device to test against

    Hence I thought I could imitate the actual device by having a teensy send a few representative packets over the USB instead.

    I know the USB packet format so can knock up a few char arrays with the expected binary format. I'd then have write a program (hopefully in C as thats what I know) that encapsulates those char buffers and then tries to send them as a bulk transfer over USB, probably using libusb I think. I'd have to build and load this on to the teensy using the correct build tool (avr-gcc and halfkay?) and then plug in the teensy and hope it behaves like the device i am trying to simulate

    does this sound feasible/possible?

    can anyone suggest what the code might look like or any good tutorials? I'm so new to this I don't even know what to search for.

    Might it be the case that I have to learn 'arduino' as opposed to being able to write the program in C?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,095
    When & where did you purchase a Teensy 3.0? PJRC discontinued 3.0 several years ago.

    On USB, here's a copy of the USB 2.0 spec. You can also get it from www.usb.org, but it's inside a big collection of other stuff. Here's just the PDF:

    https://www.pjrc.com/teensy/beta/usb20.pdf

    You really must read chapter 4 and maybe the first part of chapter 5 to become familiar with the essential USB terminology and most important concepts. The PDF is 600 pages, but chapter 4 is very short and easy to read. Please, read it. Then ask these sorts of USB questions.

  3. #3
    Banned
    Join Date
    Jun 2019
    Posts
    2
    Quote Originally Posted by PaulStoffregen View Post
    When & where did you purchase a Teensy 3.0? PJRC discontinued 3.0 several years ago.

    On USB, here's a copy of the USB 2.0 spec. You can also get it from www.usb.org, but it's inside a big collection of other stuff. Here's just the PDF:

    https://www.pjrc.com/teensy/beta/usb20.pdf

    You really must read chapter 4 and maybe the first part of chapter 5 to become familiar with the essential USB terminology and most important concepts. The PDF is 600 pages, but chapter 4 is very short and easy to read. Please, read it. mcdvoice Then ask these sorts of USB questions.
    Thanks so much for your suggestion.

  4. #4
    Quote Originally Posted by Laura974 View Post
    But I am trying to do this prior to actually having the USB device to test against
    I have used Teensies for exactly this purpose.

    I had a friend who had captured the USB transfers to a device (that uses USB serial), with known reason/action behind each transfer, on a Windows machine. This allowed reverse-engineering of the control protocol. I then wrote a very simple "driver" program to do those same actions as needed on non-Windows machines. Because I did not have the real device myself, I used a Teensy to simulate it, accepting messages and responding per the USB capture, when writing the "driver" program.

    In my case, since the device used USB serial transfers, I knew the communications were a character stream (as opposed to packets, as for example with USB HID devices). Delimiter characters were easy to spot, so this was not at all difficult. The Teensy program was a simple loop reading from and writing to the Serial object provided by Teensyduino libraries in the Arduino programming environment.

    In another case, I had the comms specs of a high-voltage power supply, and wanted to test the responsiveness of Python code to asynchronous/full duplex communications (ie. when sending and receiving occurs concurrently). It turns out that device only does strict question-response protocol, but nevertheless, implementing a dummy device using a Teensy made everything easier, because I controlled both sides, and didn't need to worry about accidentally causing a 100 kilovolt, kilowatt zap anywhere.

    So yes, this is definitely doable.

    However, you also want to make sure you have genuine parts, to minimize the number of possible problem sources. You do not want to fight the oddness of a counterfeit, when writing such code; it is way too frustrating. Main reasons I like to use Teensies for this as opposed to other microcontrollers, is their robustness, knowing they've been designed by Paul (the quality of his published work is why), the native USB interface, and the forum here in case of unexpected behaviour or other weirdness. I personally even use a short USB wire hub (with micro and mini connectors on the other end) bought from a reputable source for 2x the price similar ones have at ebay/amazon, just to minimize the number of things I need to worry about.

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,605
    Sorry to say, but this thread is an attempt to spam, maybe later. The question is copied from here: https://stackoverflow.com/questions/...nsfer/27443813

    You can find these fakes by copying the question to Google. Usually, the first hit is it. Most of these attempts were copied from Stackoverflow.

    I'll leave it here, but will ban "Laura"
    Last edited by Frank B; 06-12-2019 at 12:23 PM.

Posting Permissions

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