cancel
Showing results for 
Search instead for 
Did you mean: 

HID non-boot protocol

martin wijk
Associate II
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

5 REPLIES 5
Pavel A.
Evangelist III
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

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

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

Posted on March 08, 2018 at 08:59

Segger (

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

) as alternative for Keil is expensive indeed (do not know the prices of Keil yet).... However, Segger seems to be more compact without RTOS. Please, keep me informed about your findings. 

Thanks again.

Martin

Richard Lowe
Senior III
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;
 }
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?