MIDI device stops working when connected through hub (using USBHost_t36 library)

Status
Not open for further replies.

sixeight

Well-known member
My MG-300 guitar processor works fine when connected directly to the USB host port of a Teensy 3.6. But stops responding after a couple of messages when it is connected through a hub.

This hub works fine when I connect the MG-300 to a mac or PC. Also this hub works fine with the USB host port when I connect other devices.

Here is my test sketch:
Code:
#include <USBHost_t36.h>

#define NUMBER_OF_USB_HOST_MIDI_PORTS 8
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
MIDIDevice_BigBuffer usbhMIDI01(myusb); // With bigbuffer, newer Roland devices are working properly!
MIDIDevice_BigBuffer usbhMIDI02(myusb);
MIDIDevice_BigBuffer usbhMIDI03(myusb);
MIDIDevice_BigBuffer usbhMIDI04(myusb);
MIDIDevice_BigBuffer usbhMIDI05(myusb);
MIDIDevice_BigBuffer usbhMIDI06(myusb);
MIDIDevice_BigBuffer usbhMIDI07(myusb);
MIDIDevice_BigBuffer usbhMIDI08(myusb);
MIDIDevice_BigBuffer * usbhMIDI[NUMBER_OF_USB_HOST_MIDI_PORTS] = {
  &usbhMIDI01, &usbhMIDI02, &usbhMIDI03, &usbhMIDI04, &usbhMIDI05, &usbhMIDI06, &usbhMIDI07, &usbhMIDI08
};
const uint32_t TIME = 500; // time between identity request messages
uint32_t timer = millis() + TIME;
uint8_t PC = 0;

void setup() {
  Serial.begin(115200);
  delay(1000);
  myusb.begin();
}

void loop() {
  myusb.Task();
  
  if (millis() > timer) {
    send_alternative_PC_message(PC);
    if (PC++ > 9) PC = 0;
    timer = millis() + TIME;
  }
}

void send_alternative_PC_message(uint8_t program) {
  for (uint8_t p = 0; p < NUMBER_OF_USB_HOST_MIDI_PORTS; p++) {
    usbhMIDI[p]->sendControlChange(60, program, 0);
  }
  Serial.println("Sending CC#60 " + String(program));
}

So this code sends MIDI CC messages to which the MG-300 changes patch.

When the MG-300 is connected through a hub, the program will hang and the serial monitor will stop showing data:

Code:
Sending CC#60 0
Sending CC#60 1
Sending CC#60 2
Sending CC#60 3
Sending CC#60 4

This is what the debugging in the USBHost_library shows by uncommenting #define USBHOST_PRINT_DEBUG:

Code:
sizeof Device = 36

sizeof Pipe = 96

sizeof Transfer = 64

power up USBHS PHY

 reset waited 5

USBHS_ASYNCLISTADDR = 0

USBHS_PERIODICLISTBASE = 1FFFC000

periodictable = 1FFFC000

Sending CC#60 0

port change: 10001803

    connect

  begin reset

port change: 18001205

  port enabled

  end recovery

new_Device: 480 Mbit/sec

new_Pipe

enumeration:

enumeration:

enumeration:

Device Descriptor:

  12 01 00 02 09 00 01 40 E3 05 08 06 98 32 00 01 00 01 

    VendorID = 05E3, ProductID = 0608, Version = 3298

    Class/Subclass/Protocol = 9(Hub) / 0 / 1(Single-TT)

    Number of Configurations = 1

enumeration:

enumeration:

Product: USB2.0 Hub

enumeration:

Config data length = 25

enumeration:

Configuration Descriptor:

  09 02 19 00 01 01 00 E0 32 

    NumInterfaces = 1

    ConfigurationValue = 1

  09 04 00 00 01 09 00 00 00 

    Interface = 0

    Number of endpoints = 1

    Class/Subclass/Protocol = 9(Hub) / 0 / 0

  07 05 81 03 01 00 0C 

    Endpoint = 1 IN

    Type = Interrupt

    Max Size = 1

    Polling Interval = 12

enumeration:

USBHub memory usage = 960

USBHub claim_device this=1FFF6860

found possible interface, altsetting=0

number of interfaces found = 1

USBHub control callback

09 29 04 E0 00 32 64 00 FF 00 00 00 00 00 00 00 

Hub ports = 4

USBHub control callback

USBHub control callback

USBHub control callback

USBHub control callback

power turned on to all ports

device addr = 1

new_Pipe

allocate_interrupt_pipe_bandwidth

  ep interval = 12

  interval = 256

 best_bandwidth = 2, at offset = 0

pipe cap1 = F0012101

HUB Callback (member)

status = 4

getstatus, port = 2

USBHub control callback

01 01 01 00 

New Port Status

  status=10101  port=2

  state=0

  Device is present: 

  Has Power

USBHub control callback

Port Status Cleared, port=2

timer event (19999 us): Debounce Timer, this = 1FFF6860, timer = 1FFF6B78

ports in use bitmask = 4

getstatus, port = 2

USBHub control callback

01 01 00 00 

New Port Status

  status=101  port=2

  state=2

  Device is present: 

  Has Power

timer event (19999 us): Debounce Timer, this = 1FFF6860, timer = 1FFF6B78

ports in use bitmask = 4

getstatus, port = 2

USBHub control callback

01 01 00 00 

New Port Status

  status=101  port=2

  state=3

  Device is present: 

  Has Power

timer event (20000 us): Debounce Timer, this = 1FFF6860, timer = 1FFF6B78

ports in use bitmask = 4

getstatus, port = 2

USBHub control callback

01 01 00 00 

New Port Status

  status=101  port=2

  state=4

  Device is present: 

  Has Power

timer event (20000 us): Debounce Timer, this = 1FFF6860, timer = 1FFF6B78

ports in use bitmask = 4

getstatus, port = 2

USBHub control callback

01 01 00 00 

New Port Status

  status=101  port=2

  state=5

  Device is present: 

  Has Power

timer event (20000 us): Debounce Timer, this = 1FFF6860, timer = 1FFF6B78

ports in use bitmask = 4

getstatus, port = 2

USBHub control callback

01 01 00 00 

New Port Status

  status=101  port=2

  state=6

  Device is present: 

  Has Power

sending reset

send_setreset

USBHub control callback

unhandled setup, message = 40323

timer event (19999 us): Debounce Timer, this = 1FFF6860, timer = 1FFF6B78

ports in use bitmask = 0

HUB Callback (member)

status = 4

getstatus, port = 2

USBHub control callback

03 05 10 00 

New Port Status

  status=100503  port=2

  state=7

  Device is present: 

  Enabled, speed = 480 Mbit/sec

  Has Power

USBHub control callback

unhandled setup, message = 140123

timer event (25000 us): Hello, I'm resettimer, this = 1FFF6860, timer = 1FFF6B94

port_doing_reset = 2

PORT_RECOVERY

new_Device: 480 Mbit/sec

new_Pipe

enumeration:

enumeration:

enumeration:

Device Descriptor:

  12 01 00 02 EF 02 01 40 C9 1F 60 82 00 01 01 02 03 01 

    VendorID = 1FC9, ProductID = 8260, Version = 0100

    Class/Subclass/Protocol = 239 / 2 / 1

    Number of Configurations = 1

enumeration:

enumeration:

Manufacturer: NUX

enumeration:

Product: NUX MG-300 AUDIO

enumeration:

Serial Number: 2008101346

enumeration:

Config data length = 318

enumeration:

Configuration Descriptor:

  09 02 3E 01 04 01 00 C0 01 

    NumInterfaces = 4

    ConfigurationValue = 1

  08 0B 00 03 01 00 20 00 

    Interface Association = 0 through 2

    Class / Subclass / Protocol = 1 / 0 / 0

  09 04 00 00 00 01 01 20 00 

    Interface = 0

    Number of endpoints = 0

    Class/Subclass/Protocol = 1 / 1 / 32

  09 24 01 00 02 08 65 00 00 

  08 24 0A 29 03 07 00 00 

  08 24 0B 28 01 29 03 00 

  11 24 02 02 01 01 00 28 02 00 00 00 00 00 00 00 00 

  12 24 06 0A 02 0F 00 00 00 0F 00 00 00 0F 00 00 00 00 

  0C 24 03 14 01 03 00 0A 28 00 00 00 

  11 24 02 01 01 02 00 28 02 00 00 00 00 00 00 00 00 

  0C 24 03 16 01 01 00 02 28 00 00 00 

  09 04 01 00 00 01 02 20 00 

    Interface = 1

    Number of endpoints = 0

    Class/Subclass/Protocol = 1 / 2 / 32

  09 04 01 01 02 01 02 20 00 

    Interface = 1

    Number of endpoints = 2

    Class/Subclass/Protocol = 1 / 2 / 32

  10 24 01 02 00 01 01 00 00 00 02 00 00 00 00 00 

  06 24 02 01 04 18 

  07 05 01 05 58 02 04 

    Endpoint = 1 OUT

    Type = Isochronous

    Max Size = 600

    Polling Interval = 4

  08 25 01 00 00 00 00 00 

  07 05 81 11 04 00 04 

    Endpoint = 1 IN

    Type = Isochronous

    Max Size = 4

    Polling Interval = 4

  09 04 02 00 00 01 02 20 00 

    Interface = 2

    Number of endpoints = 0

    Class/Subclass/Protocol = 1 / 2 / 32

  09 04 02 01 01 01 02 20 00 

    Interface = 2

    Number of endpoints = 1

    Class/Subclass/Protocol = 1 / 2 / 32

  10 24 01 16 00 01 01 00 00 00 02 00 00 00 00 00 

  06 24 02 01 04 18 

  07 05 82 05 58 02 04 

    Endpoint = 2 IN

    Type = Isochronous

    Max Size = 600

    Polling Interval = 4

  08 25 01 00 00 00 00 00 

  09 04 03 00 02 01 03 00 04 

    Interface = 3

    Number of endpoints = 2

    Class/Subclass/Protocol = 1 / 3 / 0

  07 24 01 00 01 41 00 

  06 24 02 01 01 00 

  06 24 02 02 02 00 

  09 24 03 01 03 01 02 01 00 

  09 24 03 02 04 01 01 01 00 

  09 05 04 02 00 01 00 00 00 

    Endpoint = 4 OUT

    Type = Bulk

    Max Size = 256

    Polling Interval = 0

  05 25 01 01 01 

  09 05 83 02 00 01 00 00 00 

    Endpoint = 3 IN

    Type = Bulk

    Max Size = 256

    Polling Interval = 0

  05 25 01 01 03 

enumeration:

USBHub memory usage = 960

USBHub claim_device this=1FFF6C20

USBHub memory usage = 960

USBHub claim_device this=1FFF6FE0

USBHub memory usage = 960

USBHub claim_device this=1FFF5380

Descriptor 11 = IAD

Descriptor 4 = INTERFACE

MIDIDevice claim this=1FFF73C0

len = 301

  Interface is unknown (might be Yahama)

type: 36, len: 9

    MIDI Header (ignored)

type: 36, len: 8

    Unknown MIDI CS_INTERFACE descriptor!

MIDIDevice claim this=1FFF84E0

len = 301

  Interface is unknown (might be Yahama)

type: 36, len: 9

    MIDI Header (ignored)

type: 36, len: 8

    Unknown MIDI CS_INTERFACE descriptor!

MIDIDevice claim this=1FFF9600

len = 301

  Interface is unknown (might be Yahama)

type: 36, len: 9

    MIDI Header (ignored)

type: 36, len: 8

    Unknown MIDI CS_INTERFACE descriptor!

MIDIDevice claim this=1FFFA720

len = 301

  Interface is unknown (might be Yahama)

type: 36, len: 9

    MIDI Header (ignored)

type: 36, len: 8

    Unknown MIDI CS_INTERFACE descriptor!

MIDIDevice claim this=1FFF5740

len = 301

  Interface is unknown (might be Yahama)

type: 36, len: 9

    MIDI Header (ignored)

type: 36, len: 8

    Unknown MIDI CS_INTERFACE descriptor!

MIDIDevice claim this=1FFF2020

len = 301

  Interface is unknown (might be Yahama)

type: 36, len: 9

    MIDI Header (ignored)

type: 36, len: 8

    Unknown MIDI CS_INTERFACE descriptor!

MIDIDevice claim this=1FFF3140

len = 301

  Interface is unknown (might be Yahama)

type: 36, len: 9

    MIDI Header (ignored)

type: 36, len: 8

    Unknown MIDI CS_INTERFACE descriptor!

MIDIDevice claim this=1FFF4260

len = 301

  Interface is unknown (might be Yahama)

type: 36, len: 9

    MIDI Header (ignored)

type: 36, len: 8

    Unknown MIDI CS_INTERFACE descriptor!

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 4 = INTERFACE

MIDIDevice claim this=1FFF73C0

len = 191

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF84E0

len = 191

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF9600

len = 191

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFFA720

len = 191

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF5740

len = 191

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF2020

len = 191

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF3140

len = 191

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF4260

len = 191

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

Descriptor 4 = INTERFACE

MIDIDevice claim this=1FFF73C0

len = 182

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF84E0

len = 182

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF9600

len = 182

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFFA720

len = 182

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF5740

len = 182

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF2020

len = 182

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF3140

len = 182

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF4260

len = 182

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 5 = ENDPOINT

Descriptor 37 =  ???

Descriptor 5 = ENDPOINT

Descriptor 4 = INTERFACE

MIDIDevice claim this=1FFF73C0

len = 129

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF84E0

len = 129

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF9600

len = 129

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFFA720

len = 129

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF5740

len = 129

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF2020

len = 129

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF3140

len = 129

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

MIDIDevice claim this=1FFF4260

len = 129

  Interface is unknown (might be Yahama)

type: 4, len: 9

This interface is not MIDI

Descriptor 4 = INTERFACE

MIDIDevice claim this=1FFF73C0

len = 120

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF84E0

len = 120

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF9600

len = 120

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFFA720

len = 120

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF5740

len = 120

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF2020

len = 120

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF3140

len = 120

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

MIDIDevice claim this=1FFF4260

len = 120

  Interface is unknown (might be Yahama)

type: 36, len: 16

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 5, len: 7

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 5 = ENDPOINT

Descriptor 37 =  ???

Descriptor 4 = INTERFACE

MIDIDevice claim this=1FFF73C0

len = 74

  Interface is MIDI

type: 36, len: 7

    MIDI Header (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 36, len: 6

    MIDI IN Jack (ignored)

type: 36, len: 9

    MIDI OUT Jack (ignored)

type: 36, len: 9

    MIDI OUT Jack (ignored)

type: 5, len: 9

    MIDI Endpoint: 4

      tx_size = 256

type: 37, len: 5

    MIDI Endpoint Jack Association (ignored)

type: 5, len: 9

    MIDI Endpoint: 83

      rx_size = 256

type: 37, len: 5

    MIDI Endpoint Jack Association (ignored)

new_Pipe

new_Pipe

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 36 =  ???

Descriptor 5 = ENDPOINT

Descriptor 37 =  ???

Descriptor 5 = ENDPOINT

Descriptor 37 =  ???

Sending CC#60 1

MIDIDevice transmit complete

  MIDI Data: 0B BF 3C 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

MIDIDevice Receive

  MIDI Data: 0B B0 49 00 

avail = 398

queue another receive packet

Sending CC#60 2

MIDIDevice transmit complete

  MIDI Data: 0B BF 3C 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

Sending CC#60 3

Sending CC#60 4

Who can help me?
 
I added the following lines to the top of void MIDIDeviceBase::write_packed(uint32_t data) in midi.cpp of the USBHost_t36 library:

Code:
println"("tx1_count: ", tx1_count);
println"("tx2_count: ", tx2_count);(

When the library send data succesfull, both tx1_count and tx2_count are 0. After that first one and then the other go to a value of 64. After that the code hangs here, as none of the buffers are made available.

What should cause the buffers to be cleared? It looks like MIDIDeviceBase::tx_data() should be called. But where from? The search brought me to ehci.cpp, but there are too many pointers there. My guess is that USBHost::followup_Transfer() should be called, but where is this called?

My guess is it has to do with void USBHost::isr(). As all data stops in the monitor, it looks like the interrupt somehow no longer is called. Now what could cause this?
 
I have been trying to decipher the USBHost library for days. But it is very complicated. What would be a good strategy to find out where the data gets stuck? It looks like it is starting to send a message, but it is never actually being sent. Who can explain how this actually works? i am completely in the dark here...
 
What would be a good strategy to find out where the data gets stuck?

Uncomment this line in USBHost_t36.h

Code:
//#define USBHOST_PRINT_DEBUG


Who can explain how this actually works?

I guess that would be me.

Last time a particular hub didn't work, I wrote this detailed blog article about the troubleshooting process and ultimately discovering the bug deep within the EHCI pipe configuration code.

https://www.pjrc.com/usb-hub-bug-hunting-lessons-learned/


Before we discuss details, I'd like to ask you to give us photos and whatever info you have about this hub, especially where to buy the exact same model (if it's still for sale). The idea is to help me or anyone else who might try to reproduce the problem to find this particular hub, so please try to get photos which capture the model number or any unique markings or other info if the hub is a "generic no-name" style. The debug info using USBHOST_PRINT_DEBUG will also give plenty of info about the hub.

Also, can you confirm whether it does indeed work with a different hub? If all hubs fail the same way, that's a very different scenario than just 1 particular hub.
 
Hi Paul,

To explain a bit more clearly: I have tried several hubs. Belkin, D-Link and some cheap thing from China. They all work fine with the USBHost_t36 library with all sorts of MIDI devices, apart from this NUX MG-300. This NUX device is giving me a trouble, even though it does work when I connect the NUX to a Mac, PC or Raspberry Pi using any of the hubs.

To sum it up:
MG-300 connected directly to Teensy 3.6 port: works.
MG-300 connected via hub to Teensy 3.6 port: does not work
Other MIDI devices connected directly to Teensy 3.6 port: work.
Other MIDI devices connected via hub to Teensy 3.6 port: work.

Already to have a working sysex connection with the MG-300, I had to change the library. I found sysex messages are sent with just three bytes in one full USB stream in the USBHost_t36 library. But MIDI allows several messages to be sent, filling up the buffer size that is in the MIDI descriptor. The NUX only started working with sysex, once I started sending bytes after one another. Here you can find my fork of the USBHost library - which is a bit messy now: https://github.com/sixeight7/USBHost_t36

But I wrote the test sketch above, which does not use sysex and went back to the original library. To make sure i was not breaking stuff through my modifications.

If you read my first post, you can see I already uncommented USB_HOST_DEBUG and included the serial monitor log. I just cannot discover any errors here.

I would be grateful if you could help me.

More information about my Teensy projects: https://www.vguitarforums.com/smf/index.php?board=277.0
 
Just to make sure I understand this...

MG-300 connected via hub to Teensy 3.6 port: does not work

Seems like you're using MG-300 fails the same way when connected with any of the 3 hubs you mentioned? This is a very important point to know. If any of the hubs are different, that's a very different sort of problem than if they all do the same wrong thing.
 
The MG-300 fails with all hubs.

Two Midi messages are sent and then the USBHost library hangs in the loop that is in write_packed(). Tx1 count and tx2_count are not cleared. That is as far as I got.
 
Ok. Here's one more "easy" thing to try, before the very difficult work of diving into the details.

Uncomment this line in ehci.cpp.

Code:
        //USBHS_PORTSC1 |= USBHS_PORTSC_PFSC; // force 12 Mbit/sec

Does it also fail when the library can't run at 480 Mbit speed?
 
Tried that, but it does not make a difference. It still works without a hub and fails with the hub.
 
Here is the serial monitor after one successful and then one unsuccessful MIDI message. I uncommented all //print and //println statements I could find in ehci.h. And I added two print statements to midi.c:

Code:
void MIDIDeviceBase::write_packed(uint32_t data)
{
	if (!txpipe) return;
	uint32_t tx_max = tx_size / 4;
    while (1) {
	uint32_t tx1 = tx1_count;
	uint32_t tx2 = tx2_count;
        print("tx1_count: ", tx1_count);
        println(", tx2_count: ", tx2_count);
	if (tx1 < tx_max && (tx2 == 0 || tx2 >= tx_max)) {
		// use tx_buffer1
        ...etc

Code:
Sending CC#60 2

ISR: 4C089
 USB Interrupt
 Frame List Rollover
 SOF
 Periodic Sched En
 Async Sched En
 USB Async
Async Followup
Transfer Followup List 1FFF4A80 to 1FFFD540
    forward:
    1FFF4A80 IN 256
    1FFFD540 OUT 0
    backward:
    1FFFD540 OUT 0
    1FFF4A80 IN 256
  Followup 1FFF4A80    token=1008180
  Followup 1FFFD540    token=80008001
tx_callback
MIDIDevice transmit complete
  MIDI Data: 0B BF 3C 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    completed
Transfer Followup List 1FFF4A80 to 1FFF4A80
    forward:
    1FFF4A80 IN 256
    backward:
    1FFF4A80 IN 256
tx1_count: 0, tx2_count: 0
new_Data_Transfer
Transfer Followup List 1FFFD500 to 1FFFD500
    forward:
    1FFFD500 OUT 0
    backward:
    1FFFD500 OUT 0
Sending CC#60 3
tx1_count: 64, tx2_count: 0
new_Data_Transfer
Transfer Followup List 1FFFD540 to 1FFFD540
    forward:
    1FFFD540 OUT 0
    backward:
    1FFFD540 OUT 0
Sending CC#60 4
tx1_count: 64, tx2_count: 64
tx1_count: 64, tx2_count: 64
tx1_count: 64, tx2_count: 64
tx1_count: 64, tx2_count: 64
tx1_count: 64, tx2_count: 64
...etc. Now we are stuck in a loop in midi.h - MIDIDeviceBase::write_packed(uint32_t data)

But I cannot find the "Transfer Followup List " print statement in the code. Where is this generated?
 
It does look like some of the data is being sent and then it stops when the hub is connected. Is there anyway to do a crude jumpstart? I can set a timer inside write_packed that can detect when it is taking too long for the buffers to become available. But most of ehci.h is a complete mystery to me. I found some of the documentation on the subject, but it really is beyond me.

Paul, do you have any suggestions on how to proceed?
 
I'm way late to this party, but...
Are you compiling with Tools/USB Type: "Serial + MIDI"?
I have some pure MIDI USB devices fail with that (iConnectivity MID interface, Yamaha digital piano).
They work fine with Serial Type: MIDI (only)
Good luck!
 
Status
Not open for further replies.
Back
Top