teensy 3.6 USB host hangs when USB device plugged in

mykle

Well-known member
Hi all,

Is there general pointer to gotchas/tips for solving USB Host-mode problems, on Teensy 3.6, or in general?

Today I've got everything wired together, using the USB host cable from PJRC.
But at the moment the symptom is that Teensy hangs the moment I plug in a USB client device.
(Log stops printing & led stops blinking.)

I tried this with a 150ma (labeled) USB MIDI musical instrument as client, as well as with
my 64ma (measured!) Pocket Integrator board. In both cases the Teensy freezes
when I plug in, stays frozen after I unplug.

Could this be a power problem?
I am plugging Teensy straight into a powered hub, so I expect to be able to draw 500ma total.
I am using short, thick USB cables.
Also, I have the LED lit on the Teensy when I plug this in, it doesn't dim or flicker when the hang happens.
And the USB devices themselves function just fine.

Or maybe it's a software problem? Code below, it's simple. Possibly the call to myusb.Task() or MIDI.read() is hanging
when I plug in the usb MIDI device? But I don't know why they would.

Any ideas would be most welcome. Thanks!
-mykle-

------
Code:
#include <elapsedMillis.h>
#include <MIDI.h>

#define TEENSY36

#ifdef TEENSY36
#include <USBHost_t36.h>
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
MIDIDevice MIDI(myusb);
#else 
MIDI_CREATE_DEFAULT_INSTANCE();
#endif

#include "NoteList.h"
NoteList nl;


void handleNoteOn(byte channel, byte pitch, byte velocity)
{
	nl.add(channel, pitch, velocity);
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
	nl.remove(pitch);
}

// -----------------------------------------------------------------------------

void setup()
{ 
	pinMode(LED_BUILTIN, OUTPUT);

#ifdef TEENSY36
  Serial.begin(115200); 
	// Wait 1.5 seconds before turning on USB Host. 
  delay(1500);
  Serial.println("USB Host InputFunctions example");
  delay(10); // why?
  myusb.begin();
#endif

	MIDI.setHandleNoteOn(handleNoteOn); 
	MIDI.setHandleNoteOff(handleNoteOff);

#ifdef TEENSY36
	MIDI.begin();
#else
	MIDI.begin(MIDI_CHANNEL_OMNI);
#endif

#ifndef TEENSY36
	// on Pico-philtower, there were problems when (usb)Serial was started before (usb)MIDI
	Serial.begin(115200);  
	delay(200); // let USB stabilize before speaking ...
#endif
}

#define LOGTIME 1000 //ms
void loop()
{
	static elapsedMillis logTimer = 0;
	static bool ledOn = false;

#ifdef TEENSY36
	myusb.Task();
#endif
	MIDI.read();

	if (logTimer > LOGTIME){
		digitalWrite(LED_BUILTIN, ledOn ? HIGH : LOW);
		logTimer -= LOGTIME;
		ledOn = !ledOn;

		Serial.println("log:");
		nl.print(&Serial);
	}
}
 
Sorry, I don't own any MIDI equipment or have any expertise in that part of the USBHost code.

So for example I don't know anything about your device. For example, does it communicate over USB in Full Speed (12mbs) or High Seed (480mbs). If the later, you might need to try using the MIDIDevice_BigBuffer object instead of the MIDIDevice.

Not sure what the MIDI.begin();
call does here. I don't see that in a couple of examples.

You might try turning on more debug output. Go into the USBHost_t36.h header file, and uncomment the line:
//#define USBHOST_PRINT_DEBUG

Other things to try. If you are wondering if it is taking too much power. Try plugging in a powered USB Hub into the Teensy and see if that makes a difference.
 
Hi,

My test devices are full-speed, 12mbit. I turned on the debugging and got this at startup:

Code:
USB Host InputFunctions example
sizeof Device = 36
sizeof Pipe = 96
sizeof Transfer = 64
power up USBHS PHY
 reset waited 5
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 1FFF3000
periodictable = 1FFF3000
sizeof Device = 36
sizeof Pipe = 96
sizeof Transfer = 64
power up USBHS PHY
 reset waited 5
USBHS_ASYNCLISTADDR = 0
USBHS_PERIODICLISTBASE = 1FFF3000
periodictable = 1FFF3000
log:
0 notes on:
log:
0 notes on:

[...]

... and then I saw this debug output when I plugged in a device, just before Teensy hung:

Code:
[...]
log:
0 notes on:
log:
0 notes on:
port change: 10001803
    connect
  begin reset
port change: 10001805
  port enabled
  end recovery
new_Device: 12 Mbit/sec
new_Pipe
enumeration:
enumeration:

I notice it's doing a couple of things twice. Is that normal, to see enumeration: two times ?
(I tried disabling hub2, so there's only one USBHub object, but that didn't seem to make a difference.)
 
Not sure what the MIDI.begin();
call does here. I don't see that in a couple of examples.

I think that was the problem. It must be getting called automatically by the Arduino environment somewhere, and i was calling it a second time so something was getting doubled up. Without that, it's behaving better now. Thanks!
 
Back
Top