2018-03-05 08:23 AM
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
2018-03-05 11:13 AM
Consider the 'HID class' code as example only. Copy it into your project and modify as needed.
- pa
2018-03-06 01:28 AM
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
2018-03-06 08:49 AM
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
andhttps://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
2018-03-08 12:59 AM
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
2018-05-21 02:18 PM
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;
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?