Teensy 4.0 USB-MIDI host issue

Status
Not open for further replies.

trigger

Member
I've been using a Teensy 4.0 as a USB-Midi "hub" (broadcasting MIDI messages to all connected devices over USB) for a few months, and it's been working great.

However, I purchased a new synth recently, and for some reason the teensy crashes/freezes when this synth is connected.

This new synth (Behringer Crave) has a small integrated keyboard, and can send messages just fine.
As soon as another device (Arturia Keystep for example) sends a couple of messages, the teensy hangs.

Attached are a stripped-down version of the sketch I cobbled together, as well as 2 serial traces (with USBHost_t36 debug activated).
On the short trace, I just played a couple of notes from the keystep, and teensy hanged shortly after.
On the long trace, I first hit a few notes on the crave (no issue), then hit notes from the keystep. Teensy kept logging very slowly for some time (10-20 secondes for the whole trace, maybe ?), then froze.

The Crave is supposed to be usb-midi class compliant, and works fine when plugged in my computer.

Any help appreciated :)
 

Attachments

  • midi_hub_no_oled.ino
    4.4 KB · Views: 124
  • trace_short.txt
    17.2 KB · Views: 104
  • trace_long.txt
    27 KB · Views: 90
Thank you for you help.

In my case, Teensy is only a USB MIDI Host (using its second USB port through a breakout shield). Its first port (micro USB) is just a serial port.
Using USBHost_t36, I read all events from the connected MIDIDevices on the host port.

It's still highly possible there's something wrong with my sketch (although it's been working fine with a keyboard, a sequencer/sampler and a previous synth at the same time).
Or there's something funky going on with this new synth (although it's working fine when plugged into a compiter...).

I'll try experimenting a bit at lunch time, see if handling or discarding incoming messages faster solves the issues (and see if its a buffer filling up).
 
After fiddling around, I found out that sending exactly 3 MIDI messages (simple NoteOn) to this synth is enough for the sketch to hang up.
As long as I don't send anything to it, it continues to work fine.

After I send MIDI messages to this problematic device, teensy sometimes keeps on receving packets ("queue another receive packet") until the queue fills up ("wait to receive more packets").

If I run on a loop :
Code:
  Serial.println("sending");
  problematic_midi_device->sendNoteOn(40, 200, 1);
  Serial.println("sent!");
I get :
Code:
sending
sent!
sending
sent!
sending
and then it stops there, but I never get a "MIDIDevice transmit complete" message from USBHost_t36...
 
So, I've worked around the issue for the moment, using a USB to MIDI cable (as the DIN input of the Crave is working fine), but I have run out of DIN MIDI plugs, so I would prefer to use the Crave over USB...

If someone has any idea, I'd appreciate it.
Would it be worthwhile to look at the USB packets, in order to compare a PC host (working) to the Teensy host (not working) ?
 
Did you finally manage to use the usb midi with your behringer crave? I have similar issue with behringer neutron and behringer td3. It's a bit different in my case, I have behringer xtouch mini and akai MPK mini plugged to the teensy and work very well together. When I plug the behringer Neutron, I can send some midi message to it, but only work if I plug the behringer after teensy started...
 
Did you finally manage to use the usb midi with your behringer crave? I have similar issue with behringer neutron and behringer td3. It's a bit different in my case, I have behringer xtouch mini and akai MPK mini plugged to the teensy and work very well together. When I plug the behringer Neutron, I can send some midi message to it, but only work if I plug the behringer after teensy started...

No, sorry. I gave up and used a Raspberry Pi (I had laying around) as my USB-MIDI host.

I still have the Teensy 4.0 with the USB host port (and the troublesome synth), so I can try things if someone knowledgable has any idea, but I'm done looking on my own (I do not have the skills to solve this by myself).
 
My best guess is that you need to increase the size of the buffer that the USB host uses to enumerate connected devices. It uses a single buffer for an entire descriptor, and it's simply not large enough for modern USB MIDI devices. I think it's at 255 bytes, but I recommend 1k at least.
 
Hello yeahtuna, thanks for your suggestion. I tried to increase NUM_USB_BUFFERS in teensy4/usb_desc.h but didn't have any impact. How can increase the midi buffer?
Also since plugin one device after the other work, woulnd't it possible to connect device on after the other programmatically?
 
Which version of Teensyduino did you use? In Arduino, click Help > About to check.

I recently rewrote the USB Host MIDI transmit code for much better performance. Maybe it will help, or maybe the same problem will happen (perhaps sooner, perhaps later as more buffering is used).

If you used 1.53, please give 1.54-beta7 a try. Does it make a difference?

https://forum.pjrc.com/threads/66357-Teensyduino-1-54-Beta-7


And to answer the question about buffers, you can create instances of either "MIDIDevice" or "MIDIDevice_BigBuffer" in your program. The BigBuffer class is required for 480 speed devices to work. Both use exactly 2 transmit buffers in a ping-pong style, where the size is 64 bytes for the normal and 512 for the BigBuffer version.
 
Amazing PaulStoffregen, with the beta version it is working properly.
By the way while compiling, I got a warning:
Code:
/home/alex/dev/arduino/app/beta/arduino-1.8.13/hardware/teensy/avr/libraries/Audio/output_i2s.cpp:340:55: warning: default argument given for parameter 1 of 'static void AudioOutputI2S::config_i2s(bool)' [-fpermissive]
 void AudioOutputI2S::config_i2s(bool only_bclk = false)
                                                       ^
In file included from /home/alex/dev/arduino/app/beta/arduino-1.8.13/hardware/teensy/avr/libraries/Audio/output_i2s.cpp:28:0:
/home/alex/dev/arduino/app/beta/arduino-1.8.13/hardware/teensy/avr/libraries/Audio/output_i2s.h:55:14: note: previous specification in 'static void AudioOutputI2S::config_i2s(bool)' here
  static void config_i2s(bool only_bclk = false);
              ^

Else everything went well, thank you.
 
I recently rewrote the USB Host MIDI transmit code for much better performance. Maybe it will help, or maybe the same problem will happen (perhaps sooner, perhaps later as more buffering is used).

Hi Paul,

Are these changes specific for T4? If I'm using the host port with a T36, am I advised to update as well?
 
Oh lord am I happy Google found this post. I upgraded to Teensy 1.52 on MacOs and after recompiling and pushing to a customer's Teensy based device that I have for repair, the Teensy would freeze after sending a few dozen MIDI messages. I tore my hair out all afternoon trying to figure out what might be wrong. Now using beta 1.54 it is not freezing.
 
Status
Not open for further replies.
Back
Top