PDA

View Full Version : USB MIDI on Teensy 3; midi debugging



cmason
10-25-2012, 04:54 AM
I succeeded in getting MIDI transmit to work. I "borrowed" the code from teensy2 and massaged (read: hacked) it to work with the new usb mechanism. I'm honestly not sure what took so long, but I think ultimately I just needed to insert some delay before I started sending usb messages.

Code is here (https://bitbucket.org/cmason/teensy3). Apologies for the mess I made there.

I'm now trying to get the USB-debug HID RAW stuff working (aka hid_listen). I'm again in this state where the teensy is recognized by the USB host but no data is transmitted (hid_listen just prints dots).

Debugging this stuff is a bit of a pain. I'd appreciate any suggestions on debugging tips. I assume there's no real debugging tools at the teensy level (like remote gdb or something). I found USB Prober on the Mac and that's somewhat useful. I'm hoping for something that would let me see the raw USB traffic from/to my Mac for a specific device. I noticed this post (http://dangerousprototypes.com/forum/viewtopic.php?f=2&t=4606&p=45520#p44948) about debugging USB under linux, so maybe I'll just hook the teensy up to my raspberry pi and use that.

The teensy is so cool. I feel like I'm learning a ton just by hacking on it at this level. Thanks to Paul for all the effort and for providing such a great development environment with full source code.

-c

JBeale
10-25-2012, 03:25 PM
I don't know how useful it is, but on Linux, the "Wireshark" ethernet-packet monitoring program can also monitor USB traffic, with the usbmon module, I was able to see Teensy 3 USB traffic using it. See for example http://dangerousprototypes.com/forum/viewtopic.php?f=2&t=4606#p44948

RobM
10-29-2012, 10:23 PM
Hi Chris,
Much appreciate you sharing your work. This is a piece of code that I will need in the not too distant future.

Rob

Bambu
10-29-2012, 10:54 PM
When I attempt to use MIDI I'm told only Arduino leonardo supports MIDI. Attempting to compile gives header errors. I believe this is just the IDE getting in my way, but I thought I read MIDI wasn't yet supported.

Is this simply not so?

cmason
10-30-2012, 04:16 AM
I don't know how useful it is, but on Linux, the "Wireshark" ethernet-packet monitoring program can also monitor USB traffic, with the usbmon module, I was able to see Teensy 3 USB traffic using it. See for example http://dangerousprototypes.com/forum/viewtopic.php?f=2&t=4606#p44948

For posterity: there's an Apple USB development page (http://developer.apple.com/library/mac/#qa/qa1370/_index.html) that links to the downloadable debug logging versions of the USB drivers. Then there's a tool -- USB Prober, installed in the Mac Developer tools -- which can turn on and off logging. USB Prober also has the ability to display the configuration information from attached USB devices.

However, the messages these drivers give are still incredibly cryptic and huge. The dump from the 3.5 second period in which the Teensy gets configured by the Mac host is 5000 lines long (!) and has messages like:


2.097 [3] IOUSBHIDDriver(IOUSBHIDDriver)[0xf66fb00]::GetHIDDescriptor Final request failed; err = 0xe000404f
2.097 [1] IOUSBHIDDriver(IOUSBHIDDriver)[0xf66fb00]::start - super::start returned false!
2.097 [1] IOUSBHIDDriver(IOUSBHIDDriver)[0xf66fb00]::start - @ 0x6200000 aborting startup
2.097 [5] IOUSBPipe[0xd09ac80]::AbortPipe

My strategy so far has been to grep this output for the address assigned to the Teensy by the mac (which can very between pluggings) and then stare at it for along time to read the tea leaves. For instance, this one is I believe saying that the Teensy failed to send the HID raw report descriptor.

I'm going to try running Wireshark on my raspberry pi (as my primary development machine is a mac and I imagine that running Wireshark inside a virtual machine will just complicate matters). Since making USB devices is part of the reason I was interested in the Teensy, I suppose I need to figure out way to get Wireshark working. I guess a USB protocol analyzer would be easier, but they're like $400.

Just thought I'd post this in case anyone else is crazy (read: stupid) enough to try to debug teensy USB stuff on the mac.

-c

cmason
10-30-2012, 04:28 AM
When I attempt to use MIDI I'm told only Arduino leonardo supports MIDI. Attempting to compile gives header errors. I believe this is just the IDE getting in my way, but I thought I read MIDI wasn't yet supported.

Is this simply not so?

I should have noted: I'm not using the Arduino development environment. I'm just compiling using the Makefile (https://bitbucket.org/cmason/teensy3/src/28b7e32e0e0e4e223ae27cc0b7f0c0d40c33e09d/Makefile?at=default) that Paul provided and the compiler toolchain from the Arduino.app that he posted on the Teensy 3 Kickstarter (http://www.kickstarter.com/projects/paulstoffregen/teensy-30-32-bit-arm-cortex-m4-usable-in-arduino-a/posts) page. This code is standalone, and will upload to the Teensy using Paul's Teensy Loader.

I should also note that I only have MIDI transmit working so far, not receive.

I honestly haven't found that Arduino IDE very useful. It just seems to get in the way of what's really going on. I've been using AppCode (http://www.jetbrains.com/objc/)'s new C++ support and, having been spoiled by their Java IDE, I'm finding the code completion and navigation stuff to be hard to live without.

Paul
10-30-2012, 05:17 AM
I'm planning to work on MIDI soon. I use a Total Phase Beagle USB protocol analyzer....

JBeale
10-30-2012, 06:13 AM
I'd be curious to hear if Wireshark is usable on the Raspberry Pi. I booted my normally-Windows laptop into Linux for that purpose, as I assumed that the R-Pi would be too slow to run it well (plus the R-Pi has a history of USB stack issues, which last I checked are still not fully debugged.)

Bambu
10-30-2012, 03:31 PM
If I remember correctly Wireshark uses usbmon. I always found Wireshark cumbersome, so I used usbmon directly.

The IDE is written in Java, so we never really liked each other much. I just wrote a quick IDE with Python and ACE. I'll release code later.

cmason
10-30-2012, 05:02 PM
Bambu, thanks that's useful to know. I was afraid I was going to have to setup remote X, etc.

Here's a page that seems useful talking about running usbmon directly (http://aftami.wordpress.com/2010/02/01/usbmon-how-to/).

I can confirm that the usbmon.ko is indeed present on the raspberry pi. Tonight I'll try to follow the above linked instructions to capture traces and report back what I find.

-c

Nantonos
11-08-2012, 12:33 AM
When I attempt to use MIDI I'm told only Arduino leonardo supports MIDI. Attempting to compile gives header errors. I believe this is just the IDE getting in my way, but I thought I read MIDI wasn't yet supported.

Is this simply not so?

Using native USB MIDI on the Teensy is not like using serial DIN MIDI on an arduino. Specifically, you don't add the MIDI library header include to your code - because your code is not calling that library. Instead, it's all hidden away in the hardware folders. You just select USB MIDI in the IDE, and use it.

Additionally, USB MIDI on Teensy 3 is not ported yet - but you can copy across from Teensy 2 and then hack on it to make it work, as the OP is starting to do.

Ouistyty
11-10-2012, 08:06 PM
Hello,
Thanks to all of you who are sharing theyr knowledge.

Jus to let you know if you need to analyse and compare usbmon log you can help yourself with a free tool call Virtual USB Analyzer (http://vusb-analyzer.sourceforge.net/).
This program was originaly desing to analyse vmware output debug. but they say in the main page that you can use dump from usbmon.

Cheers.

/Ouistyty