USB Host polling rate issues

False

Active member
Hello,

I posted about a year ago about an issue with my mice being stuck at 500 Hz using USBHost_t36. Back then I though it could be a hardware problem.
I unfortunatly reproduce the same issue on a teensy 4.0.

I looked into it again and I found some very strange results. I noticed switching usb type got the usbhost to pull at 1000 hz.

For test purposes I use a teensy 3.6 to emulate a mouse (simple mouse moves in the loop)
Code:
  Mouse.move(5, 0, 0);
  delay(1);
  Mouse.move(0, 5, 0);
  delay(1);
  Mouse.move(-5, 0, 0);
  delay(1);
  Mouse.move(0, -5, 0);
  delay(1);

and the teensy 4.0 USBHost_t36 sample app with an extra
Code:
     static elapsedMillis pollingRateElapsedMillis;
    static int32_t pollingRateCounter;
    pollingRateCounter++;      
    if (pollingRateElapsedMillis > 999) {
          Serial.printf("Hertz=%d\n", pollingRateCounter);
          pollingRateElapsedMillis = 0;
          pollingRateCounter = 0;
    }
in the mouse1.available() condition to measure the polling rate.

I made a custom usb type which consists of 1 to 2 interfaces - it depends on the tests - , Mouse and Keyboard (on the teensy 3.6).
Code:
  #define VENDOR_ID		0x16C0
  #define PRODUCT_ID		0x0482
  #define MANUFACTURER_NAME	{'T','e','e','n','s','y','d','u','i','n','o'}
  #define MANUFACTURER_NAME_LEN	11
  #define PRODUCT_NAME		{'K','e','y','b','o','a','r','d','/','M','o','u','s','e','/','J','o','y','s','t','i','c','k'}
  #define PRODUCT_NAME_LEN	23
  #define EP0_SIZE		64
  #define NUM_ENDPOINTS         1 // 2 when enabling keyboard
  #define NUM_USB_BUFFERS	2
  #define NUM_INTERFACE		1 // 2 when enabling keyboard
  
  #define MOUSE_INTERFACE       0	// Mouse
  #define MOUSE_ENDPOINT        1
  #define MOUSE_SIZE            8
  #define MOUSE_INTERVAL        1
  
  /*#define KEYBOARD_INTERFACE    1	// Keyboard
  #define KEYBOARD_ENDPOINT     2
  #define KEYBOARD_SIZE         8
  #define KEYBOARD_INTERVAL     1*/

  #define ENDPOINT1_CONFIG	ENDPOINT_TRANSMIT_ONLY
  //#define ENDPOINT2_CONFIG	ENDPOINT_TRANSMIT_ONLY

The results are :
Mouse only : stuck to 500 hz
Mouse + keyboard (KEYBOARD_INTERVAL 1) : 1000 hz !! (So it can actually work at 1000 Hz!)
Mouse + keyboard (KEYBOARD_INTERVAL 2) : 500 hz (unexpected, but this made me think the issue could actually be linked to the periodic table)

So I checked the periodic tables for each case :

Code:
500 hz mouse only
Periodic Schedule:
 0: 20006200
 1: 20006200
 2: 20006200
 3: 20006200
... (until 31)

Code:
1000 hz Mouse + keyboard
Periodic Schedule:
 0: 20006200 -> 200061A0
 1: 20006200 -> 200061A0
 2: 20006200 -> 200061A0
 3: 20006200 -> 200061A0
... (until 31)

Code:
500 hz Mouse + keyboard interval 2
Periodic Schedule:
 0: 20006200 -> 200061A0
 1: 200061A0
 2: 20006200 -> 200061A0
 3: 200061A0
... (until 31)
: I am not sure it works like that but 200061A0 seems to represent the keyboard, so why would it appear every line when it should be 20006200 everyline and a node with 200061A0 every 2 lines

Any idea ? Or am I on the wrong track and the issue is somewhere else in the code ?
 
It has been a long time since I played in this library.

But the first thing I would do is to turn on DEBUG stuff. Go into USBHost_tt36.h and uncomment the line:
Code:
//#define USBHOST_PRINT_DEBUG

I would plug in your mouse and see what is printed. Example USBHIDParser::claim prints out some information like:
endpoint information including interval.... You might see what those values are...
 
Yes I am using debug on to try to find the issue.
If you simply comment (or delete)
Code:
KeyboardController keyboard1(myusb);
the driver won't load, is not claimed by t36, the periodic table looks like a mouse only one,
and I get the 500 hz anomaly.
All the polling intervals, stime, ctime etc are exactly the same the only difference I see so far is the periodic table.
I have tried a few things, like fake pipe, also checked every values around the drivers, but I can't find why usb host polls at 500 hz if no keyboard.
I am currently thinking of creating 32 different pipes instead of an unique reference.
 
There is definitively something strange with the t36 library.

For the teensy mouse only exemple If I manually add the pipe_t at the second node level I manage to get a refresh rate of 1000 hz, when it is 500 hz at first node level.
Unfortunately this dirty trick does not work on the 'real' mice, they are still stuck at 500 hz or not working.

Another clear issue is : If I fill only the first case of the periodic table with my hid pipe, I get 32 hz which is normal (1000hz / 32).
But If I fill 2 cases I am still stuck at 32 Hz. If I fill the 3rd one I get to 64 hz. It should be basically 32 Hz per case.
 
I'm stuck on the exact same problem, using a Model O 1000hz Gaming Mouse.
I've used 2 different teensy 4.1, still the same issues. It must be something in the code.

Code:
#include <USBHost_t36.h>

USBHost usb_host;
USBHIDParser hid1(usb_host);
USBHIDParser hid2(usb_host);
USBHub hub(usb_host);

MouseController mouse_in(usb_host);
//KeyboardController keyboard_in(usb_host);

void setup() {
  // USB IN
  usb_host.begin();
}

void loop() {
  usb_host.Task();

  // Listen to mouse updates
  if (mouse_in.available()) 
  { 
    // Proxy Mouse
    report_mouse_update_to_host();
    mouse_in.mouseDataClear();
  }
}

// Proxy mouse data to host
void report_mouse_update_to_host()
{
  // Inside teensy4/usb_mouse.h
  usb_mouse_buttons_state = mouse_in.getButtons();
  usb_mouse_move(mouse_in.getMouseX(), mouse_in.getMouseY(), mouse_in.getWheel(), mouse_in.getWheelH());
}

I'm using Serial + Keyboard + Mouse + Joystick Mode.

Please help :)

@PaulStoffregen
 
Last edited:
So it looks like it is a HID device, which is good. I did order one, but my guess it may be next week before it arrives.
 
Actually mine just arrived yesterday... (Actually day before at my PMB in town)...

But running my HID info sketch:
Code:
USB HID Device Info Program

This Sketch shows information about plugged in HID devices

*** You can control the output by simple character input to Serial ***
R - Turns on or off showing the raw data
C - Toggles showing changed data only on or off
<anything else> - toggles showing the Hid formatted breakdown of the data


USBDeviceInfo claim this=20005DE8

****************************************
** Device Level **
  vid=258A
  pid=36
  bDeviceClass = 0
  bDeviceSubClass = 0
  bDeviceProtocol = 0
09 04 00 00 01 03 01 02 00 09 21 11 01 00 01 22 47 00 07 05 81 03 08 00 01 09 04 01 00 01 03 01
01 00 09 21 11 01 00 01 22 D5 00 07 05 82 03 08 00 01 

USBDeviceInfo claim this=20005DE8

****************************************
** Interface Level **
09 04 00 00 01 03 01 02 00 09 21 11 01 00 01 22 47 00 07 05 81 03 08 00 01 09 04 01 00 01 03 01
01 00 09 21 11 01 00 01 22 D5 00 07 05 82 03 08 00 01 
 bInterfaceNumber = 0
 number end points = 1
 bInterfaceClass =    3
 bInterfaceSubClass = 1
    HID (BOOT)
 bInterfaceProtocol = 2
report descriptor size = 71
  endpoint = 81
    attributes = 3 Interrupt
    size = 8
    interval = 1

USBDeviceInfo claim this=20005DE8

****************************************
** Interface Level **
09 04 01 00 01 03 01 01 00 09 21 11 01 00 01 22 D5 00 07 05 82 03 08 00 01 
 bInterfaceNumber = 1
 number end points = 1
 bInterfaceClass =    3
 bInterfaceSubClass = 1
    HID (BOOT)
 bInterfaceProtocol = 1
report descriptor size = 213
  endpoint = 82
    attributes = 3 Interrupt
    size = 8
    interval = 1
*** Device HID1 258a: 36 - connected ***
  manufacturer: SINOWEALTH
  product: Wired Gaming Mouse
HIDDumpController Claim: 258a:36 usage: 10002 - Yes
*** HID Device hdc1 258a: 36 - connected ***
  manufacturer: SINOWEALTH
  product: Wired Gaming Mouse
Paul is probably the best to debug this part, but will look into it soon, probably something with: allocate_interrupt_pipe_bandwidth with interval=1 and see what it does.
 
Sorry, I know Paul has been up to his eyeballs with running the company short handed, plus part shortages...

Hopefully soon this next version of Teensyduino will be released soon and then he will more free to do stuff...

But as for what things he will prioritize to do next ??? We will see. And again I only just a customer. so take this with a grain of salt!
 
My issue was fixed a long time ago, you should open a new thread with your exact issue to make it more clear :)
 
Back
Top