G_hid module error on loading


#1

Hi

Just trying to emulate the board to be recognized as a Keyboard. Everything seemed ok, just took the example of the g_hid, changed hid.c to have the descriptor, kernel compiled (Linaro OS). I noticed that I need first to load libcomposite.ko. When I start the module g_hid with insmod I get the error: g_hid ci_hdrc.0: failed to start g_hid: -2
Any help would be appreciated

Paulo Moreira


#2

I suggest you to read the documentation: https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt
USB HID gadget driver is a platform driver, requesting definition of a platform device.

You can also try using the ‘new’ hid function driver (configfs), there are some examples on the web: https://github.com/qlyoung/keyboard-gadget


#3

Hi

Thanks for the support, I have everything done before in this example, hid.c with the right code, g_hid.ko and usb_f.hid.ko on the right places, modules.dep configured and depmod to make modules.dep in .bin, but loading the g_hid driver it gives always error on the kernel :frowning:
I’ll try the configfs. Thank you Loic

Paulo Moreira


#4

Hi all once again

After further investigation on the g_hid module crashes, I arrived at the kernel/drivers/usb/gadget/udc/core.c, the concerned function is udc_bind_to_driver. After putting several printk(KERN_ALERT “DEBUG: Passed %s %d \n”,FUNCTION,LINE); I noticed that the line “ret = driver->bind(udc->gadget, driver);” is the one that crashes. With the module g_ether that uses the same function also to bind the gadget everything is ok.
Anyone has solved this problem ?

Thank you
Paulo Moreira


#5

Ok, so continuing my investigation, after several debugs I fall in the line:

status = usb_add_config(cdev, &config_driver, do_config);

This line is inside hid.c
So after several debugs inside I saw that in the function do_config the following line crashes:

status = usb_add_function(c, e->f);

I didn’t change the code of hid.c I just added the keyboard desccriptors and the register of the device as on the examples around internet.
Any help around ?

Thank you in advance
Paulo Moreira


#6

So, where in that function crash happens. usb_add_function is supposed to call back your function (hid) bind method (hid_bind).


#7

Hi Loic

Yes, the problem is that I’m just using a desccriptor to emulate a HID Keyboard, this is the example that we find in internet. I don’t understand why the driver cant be load. The g_ether works good, and it uses the same lib (libccomposite) that’s why at the beginning I thought it could be something related on hid.c. It’s strange that we couldn’t find anyone with a solution, or the example that I found it’s not suitable for this hardware, I don’t know…

Paulo Moreira


#8

Tried also the hid keyboard example using configfs. Exactly the same error I got when used as a module g_hid :frowning:


#9

I’ll try and let you know…


#10

Thank you so much Loic.
Just for info, I use Linaro 17.09 and kernel 4.9.56.
Tried before with 17.06.1 and kernel 4.9.39

Regards
Paulo Moreira


#11

Hi Loic

I solved it, in fact there is some problems in file f_hid.c :frowning:
I got to make the board to be recognizable as a keyboard.

Thank you
Paulo Moreira


#12
  • Good news, If you think this you applied a reasonable fix maybe it would be good to share or/and upstream it.

#13

Sure

Just got this patch on this page for Raspberry, it worked, no more crashes starting g_hid module.

Regards
Paulo Moreira


#14

Well, now I have other problem, my hid device only is recognized by the host if they are already connected before via USB before starting the g_hid module. If I disconnect them and connected after, the host won’t recognize the device. Anyway, in the devicce side, the module continues active and no errors are reported…


#15

It was due to have the switch between host and device, just disabling the host side solved the problem.


#16

btw, I think you should be able to force a particular mode in the Device tree (arch/arm64/boot/dts/qcom/apq8016-sbc.dtsi).

usb@78d9000 {
    ...
    dr_mode = "device";
    ...
}