Skip to main content
martin wijk
Associate II
March 5, 2018
Question

HID non-boot protocol

  • March 5, 2018
  • 2 replies
  • 1721 views
Posted on March 05, 2018 at 17:23

Hi All,

I found an example for hosting a USB keyboard and works fine on my nucleo L476 board. However, my bar code reader (also a HID keyboard device) does not work because the CubeMX library expects a device which only support the boot protocol:

interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFF);

Are there some code examples available interfacing a non-boot HID device?

The documentation I found (STM32Cube USB host library, section 4.3.5) does not bring me any further:

'For custom HID devices (other than boot mouse/keyboard), the application can use the USBH_HID_SetReport or USBH_HID_GetReport to send or get HID report through the control pipe.'

Thanks! 

Martin

    This topic has been closed for replies.

    2 replies

    Pavel A.
    March 5, 2018
    Posted on March 05, 2018 at 20:13

    Consider the 'HID class' code as example only. Copy it into your project and modify as needed.

    - pa

    martin wijk
    Associate II
    March 6, 2018
    Posted on March 06, 2018 at 09:28

    Hi Pavel, 

    Thanks for quick reponse man! In fact, I was doing that already, but I am completely lost in the USB stack code. Yes, deeply digging into USB core code, debugging and spending lots of time will work. But I don't have that luxuary unfortunately. My opinion is that when you have to modify CubeMX generated code, it completely passes the concept of having a framework. 

    Martin

    Pavel A.
    March 6, 2018
    Posted on March 06, 2018 at 16:49

    Hi Martin,

    If you browse in this forum you can find few similar threads about the ST USB library and USB IP (cores).

    Unfortunately what ST provides in the Cube 'middleware' and examples is all we have.

    http://www.keil.com/support/man/docs/rlarm/rlarm_usb.htm

    and

    https://www.segger.com/products/connectivity/emusb-host/

    offer high quality, supported USB libraries... but their prices are too high compared to free.

    I've received 30-days evaluation of Keil MDK Pro and will try my board with their libraries. Expecting a steep learning ramp, as these libraries involve use of their RTOS...

    Good luck,

     -- pavel

    Richard Lowe
    Senior II
    May 21, 2018
    Posted on May 21, 2018 at 23:18

    Implemented a 'misc' class for non-bootmodeHID devices:

     interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFF);
     misc_interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_NONE_BOOT_CODE, 0xFF);
     interface = (interface == 0xFF) ? misc_interface : interface;
     
     if(interface == 0xFF) /* No Valid Interface */
     {
     status = USBH_FAIL; 
     USBH_DbgLog ('Cannot Find the interface for %s class.', phost->pActiveClass->Name); 
     }
     else
     {
     USBH_SelectInterface (phost, interface);
     phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc (sizeof(HID_HandleTypeDef));
     HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; 
     HID_Handle->state = HID_ERROR;
     
     /*Decode Bootclass Protocol: Mouse, Keyboard, or Misc*/
     if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE)
     {
     USBH_UsrLog ('KeyBoard device found!'); 
     HID_Handle->Init = USBH_HID_KeybdInit; 
     }
     else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE) 
     {
     USBH_UsrLog ('Mouse device found!'); 
     HID_Handle->Init = USBH_HID_MouseInit; 
     }
     else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_NONE_BOOT_CODE)
     {
     USBH_UsrLog('Other device found!');
     HID_Handle->Init = USBH_HID_MiscInit;
     }
     else
     {
     USBH_UsrLog ('Protocol not supported.'); 
     return USBH_FAIL;
     }
    �?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?