USB requests_hook_cb: how to rcv data from host?

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times

USB requests_hook_cb: how to rcv data from host?

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: USB requests_hook_cb: how to rcv data from host?

Post by Giovanni »

Hi,

From the callback start a receive operation: usbPrepareReceive(), usbStartReceiveI().

Look in usb.c, function_usb_ep0setup(), it does the same.

Giovanni
User avatar
kreyl
Posts: 59
Joined: Sun Jan 13, 2013 11:46 pm
Been thanked: 4 times

Re: USB requests_hook_cb: how to rcv data from host?

Post by kreyl »

Thanks a lot!
flabbergast
Posts: 71
Joined: Sat Aug 22, 2015 1:22 pm

Re: USB requests_hook_cb: how to rcv data from host?

Post 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.
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: USB requests_hook_cb: how to rcv data from host?

Post 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 :)
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: USB requests_hook_cb: how to rcv data from host?

Post by DeusExMachina »

Maybe it is worth to keep usb queued api for slow devices like HID?
flabbergast
Posts: 71
Joined: Sat Aug 22, 2015 1:22 pm

Re: USB requests_hook_cb: how to rcv data from host?

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: USB requests_hook_cb: how to rcv data from host?

Post 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
User avatar
DeusExMachina
Posts: 223
Joined: Tue Apr 03, 2012 5:08 am
Has thanked: 3 times
Been thanked: 3 times

Re: USB requests_hook_cb: how to rcv data from host?

Post by DeusExMachina »

Thanks everybody for help :)
Post Reply