Page 1 of 1

USB-HID working with IIO but now with hidraw subsystem

Posted: Thu Nov 29, 2018 8:44 am
by aicastell
Hello forum.

My uC is connected to a Linux kernel through a USB interface. It is running Chibios 16.1.0 firmware to send data collected from HID sensors to the Linux kernel. Running on a Linux kernel 4.x, the application can receive data through Industrial I/O subsystem (IIO) and consume them. That works really nice.

I have tryied to use this Chibios firmware with an older Linux kernel 3.x. The problem I found is kernel 3.x doesn't provide that IIO subsystem.

To fix this I tried enabling hidraw subsystem in that 3.x kernel to consume data. But any data is received though /dev/hidrawX.

Is there something missing on Chibios side that must be implemented to enable communications with that hidraw subsystem?

I can provide any relevant source code details you need to review this.

Thanks a lot in advance!

Re: USB-HID working with IIO but now with hidraw subsystem

Posted: Thu Nov 29, 2018 9:10 am
by Giovanni
Hi,

Are you using USB CDC? ChibiOS Serial_USB driver does not implement all CDC messages, if it gets an unsupported message it stops the communication. You need to implement the messages you need in your application code.

Anyway, 16.1.0 is way out of maintenance, you better update to new versions.

Giovanni

Re: USB-HID working with IIO but now with hidraw subsystem

Posted: Thu Nov 29, 2018 10:18 am
by aicastell
The firmware is implemented as a composite USB-device with diferent configurations, and in some configurations we use the CDC serial driver. But the active configuration we are talking about doesn't use Serial_USB driver, just HID sensors.

Using wireshark to check the traffic through the USB, we can see a single GET_REPORT request/response when we read the /sys/bus/iio/devices/X sensor. However, there is no traffic on the USB bus when reading the /dev/hidrawX device.

Re: USB-HID working with IIO but now with hidraw subsystem

Posted: Mon Dec 03, 2018 2:02 pm
by icastell
Sniffing USB traffic with tcpdump we captured an INTERRUPT SUBMIT packet from host to uC device when we execute:

# cat /dev/hidrawX

The capture was done with this command:

# tcpdump -XX -v -i 10

08:41:00.765323 INTERRUPT SUBMIT from 3:21:5
0x0000: 0071 51ee 0000 0000 5301 8515 0300 2d3c .qQ.....S.....-<
0x0010: 0cde 045c 0000 0000 8bad 0b00 8dff ffff ...\............
0x0020: 0d00 0000 0000 0000 0000 0000 0000 0000 ................
0x0030: 0800 0000 0000 0000 0402 0000 0000 0000 ................

As you can see, there is no response from the uC to the host.

To debug that I have tried to switch on a led on different RSI, USBConfig and EndPoint callbacks. But none callback seems to switch on the led when I execute the "cat" command. So I don't know what code receives that packet in order to manage the response properly.

In general it's being really hard to debug this problem...

Re: USB-HID working with IIO but now with hidraw subsystem

Posted: Mon Dec 10, 2018 8:18 pm
by sabdulqadir
Hi,
I do not have much experience with HID, but my two cents, try placing your led turn-on in:

Code: Select all

static void usb_lld_serve_interrupt(USBDriver *usbp) {
  ...
  /* IN/OUT endpoints event handling.*/
  src = otgp->DAINT;

}

in os/hal/ports/STM32/.....hal_usb_lld.c

You should be able to trace from there if you may...

Thanks,
AQ

Re: USB-HID working with IIO but now with hidraw subsystem

Posted: Mon Jan 07, 2019 8:17 pm
by skute
The difference seems to be that using /sys/bus/iio/devices/X sensor results in a GET_REPORT which is a control request and using /dev/hidrawX results in an interrupt read request. For the device to respond to the interrupt read request your software needs to send something on that endpoint (otherwise it will NAK).