2019-07-01 03:39 AM
I am trying to implement a USB Host for keyboard and mouse. I have successfully implemented the demo that is shown here:
https://www.youtube.com/watch?v=MlhUG4GsOT0
Key presses are all being received successfully by the host.
I am struggling with how and where to implement the LED controls of a keyboard. As far as I understand it this is accomplished through a USBH_HID_SetReport(phost, 0x02, 0x00, rep, 0x01).
Using the function above will never send the report through and will always return a busy status.
If anyone could advise when and where this should be implemented it would be greatly appreciated.
If you have any questions please let me know.
Solved! Go to Solution.
2019-07-03 07:34 AM
Hi h.p.barden1.5619771485320828E12 ,
The HID example provided by ST has examples of other requests from host to device in USBH_HID_ClassRequest() function.
This function contains a state machine called repeatedly.
In its turn it calls each get or set request (USBH_HID_GetHIDReportDescriptor, USBH_HID_SetIdle, USBH_HID_SetProtocol...) repeatedly.
It does not have example of using USBH_HID_SetReport but it can be used in similar way,
Maybe, modify the HID class module and add your requests into its "class request" state machine.
All these are control requests and do thru USBH_CtlReq() which has a similar state machine around the control EP.
> Also, is the USB interrupt blocking that you refer to on the Host side
By blocking the interrupt I meant that the interrupt should not be disabled for long time, wait for anything in user callbacks and so on.
The ST library is designed to work without a RTOS so may look a bit backward...
Regards,
-- pa
2019-07-01 05:55 AM
Of course, a single call to USBH_HID_SetReport is not enough. As you could see from the rest of "HID" example code, these functions are kind of state machines, you have to call them in loop to make progress. And ensure that USB controller interrupts are not blocked. It's not a rocket science, but indeed complicated.
-- pa
2019-07-01 07:33 AM
First, thank you very much for taking the time to respond. Could you elaborate any further.
Do you mean that I would need to have this SetReport in a loop (perhaps that checks the status returned), or that I would need to send the setReport request at a specific point within the function state machine of the code? Would you also be able to provide more detail on where I would need to implement this SetReport function call for it to be successful?
Also, is the USB interrupt blocking that you refer to on the Host side and therefore controlled within my code or something I would need to extract from the endpoint descriptor of the device?
Many thanks again.
2019-07-03 07:34 AM
Hi h.p.barden1.5619771485320828E12 ,
The HID example provided by ST has examples of other requests from host to device in USBH_HID_ClassRequest() function.
This function contains a state machine called repeatedly.
In its turn it calls each get or set request (USBH_HID_GetHIDReportDescriptor, USBH_HID_SetIdle, USBH_HID_SetProtocol...) repeatedly.
It does not have example of using USBH_HID_SetReport but it can be used in similar way,
Maybe, modify the HID class module and add your requests into its "class request" state machine.
All these are control requests and do thru USBH_CtlReq() which has a similar state machine around the control EP.
> Also, is the USB interrupt blocking that you refer to on the Host side
By blocking the interrupt I meant that the interrupt should not be disabled for long time, wait for anything in user callbacks and so on.
The ST library is designed to work without a RTOS so may look a bit backward...
Regards,
-- pa
2019-07-06 09:02 AM
Hi anyone looking at this thread, the USBH_HID_SetReport can be used to control the LED status of a keyboard from a host device. Unfortunately there must have been some issues with the compatibility between STM Cube and IAR as when I have tried the same code I was trying with IAR on True Studio the function works. I have asked ST if this is a bug.