Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 35

Thread: USB Host polling rate issues

  1. #1

    USB Host polling rate issues

    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 ?

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,453
    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...

  3. #3
    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.

  4. #4
    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.

  5. #5
    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 by mcrc; 06-07-2021 at 10:05 PM.

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,453
    Quote Originally Posted by mcrc View Post
    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.
    Might help to know exactly which mouse this is. Something like: https://www.amazon.com/Glorious-Gami.../dp/B07MCRPSP3 ?

    Might also help if you try running the example sketch HIDDeviceInfo for the USBHost_t36 library. And see what information that prints out.

  7. #7

  8. #8

  9. #9
    Yes, I think we posted in the same second.

  10. #10
    Directly connected to my PC: https://i.imgur.com/x72wo9C.png
    Via teensy 4.1 proxy (using Teensy USB Host Cable & USB Cable): https://i.imgur.com/9NXrx31.png

  11. #11
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,453
    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.

  12. #12
    Alright sounds good

  13. #13
    Any updates on the matter?

  14. #14
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,453
    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.

  15. #15
    Okay, lets see what Paul says

  16. #16
    any updates yet?

  17. #17
    bump

    10 chars

  18. #18
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,453
    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!

  19. #19
    bump

    10 chars

  20. #20
    Well any help is welcome, been stuck on it for a while now.

  21. #21
    My issue was fixed a long time ago, you should open a new thread with your exact issue to make it more clear :-)

  22. #22
    Do you mind telling me what fixed it for you?

  23. #23
    Junior Member
    Join Date
    Jul 2021
    Posts
    2
    Bump 10 char

  24. #24
    Quote Originally Posted by dota2bot View Post
    Bump 10 char
    bump 10 char

  25. #25
    bump 10 char

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •