Page 1 of 1
USB requests_hook_cb: how to rcv data from host?
Posted: Wed Dec 30, 2015 5:09 pm
by kreyl
stm32f072 + Chibios 3.0.4 RT
I am trying to implement USB HID Keyboard.
I need to process Set_Report Request. HID Standard says: "The meaning of the request fields for the Set_Report request is the same as for the Get_Report request, however the data direction is reversed and the Report Data is sent from host to device".
In case of Get_Report Request I need to send report from device to host, this is made with usbSetupTransfer macro.
But how can I receive data from host to device? This is OUT transaction in EP0 following SETUP request.
Re: USB requests_hook_cb: how to rcv data from host?
Posted: Wed Dec 30, 2015 7:19 pm
by Giovanni
Hi,
From the callback start a receive operation: usbPrepareReceive(), usbStartReceiveI().
Look in usb.c, function_usb_ep0setup(), it does the same.
Giovanni
Re: USB requests_hook_cb: how to rcv data from host?
Posted: Wed Dec 30, 2015 7:37 pm
by kreyl
Thanks a lot!
Re: USB requests_hook_cb: how to rcv data from host?
Posted: Thu Dec 31, 2015 11:54 am
by flabbergast
Just in case you'd like to "compare notes", I've got a working keyboard (+mouse+other things) example working, on STM32F072-DISCOVERY board,
here.
Re: USB requests_hook_cb: how to rcv data from host?
Posted: Wed Jan 20, 2016 6:39 am
by DeusExMachina
flabbergast wrote:Just in case you'd like to "compare notes", I've got a working keyboard (+mouse+other things) example working, on STM32F072-DISCOVERY board,
here.
I have tried your example, but in the latest releases 16.1.1 and 3.1.1
"Removed queued API."
So this staff doesn't work any more. Could you please update some of your HID examples? Especially f072-rawhid example is interesting

Re: USB requests_hook_cb: how to rcv data from host?
Posted: Wed Jan 20, 2016 6:40 am
by DeusExMachina
Maybe it is worth to keep usb queued api for slow devices like HID?
Re: USB requests_hook_cb: how to rcv data from host?
Posted: Wed Jan 20, 2016 9:01 am
by flabbergast
I've updated the keyb example recently, it works now (the previous code worked with stable_3.0.x). I'll update the other ones (e.g. rawhid) soon-ish. For HID, removing the queued API wasn't a problem, but the other change in USB API was.
In the keyb example, the queued API was used only for the CONSOLE endpoint, and that can be disabled during compile-time by removing -DCONSOLE_ENABLE from the Makefile. Likewise you can disable other features in Makefile as well, namely MOUSE, EXTRAKEY and NKRO, they are not needed for a very basic keyboard example.
And it is not worth keeping the queued API - Giovanni has written code that can be used to replace it, in his USB_CDC examples. It now uses buffers queue, which I think is better and more efficient. Anyway, I've updated the CONSOLE endpoint in the keyb example to use this approach.
Re: USB requests_hook_cb: how to rcv data from host?
Posted: Wed Jan 20, 2016 9:06 am
by Giovanni
Hi,
Now the USB driver has blocking calls, queues are no more required. See the demo \testhal\STM32\STM32F7xx\USB_RAW, it is even easier to use.
If you still
need queues then use HAL_buffers.c/.h, serial_usb uses this new mechanism, it is a queue of buffers, closer to how USB works.
The rationale for removing queues is that those prevented any USB driver implementation to use DMAs, usually DMAs are not flexible enough to write/read a circular buffer.
Edit: flabbergast explained it already

Giovanni
Re: USB requests_hook_cb: how to rcv data from host?
Posted: Thu Jan 21, 2016 5:02 am
by DeusExMachina
Thanks everybody for help
