Linux USB Device Driver Part5 - USB Character driver

In this post, we will try to register our USB Device with the character subsystem (/dev/mydevice) allowing the user space to communicate with the USB Device

To register a USB  as character device, we need to call the below API in probe function:

int usb_register_dev(struct usb_interface *intf, struct usb_class_driver *class_driver);

To unregister, call the below API in disconnect function:

void usb_deregister_dev(struct usb_interface *intf, struct usb_class_driver *class_driver);

As we know for a device file we need to specify the major number and minor number. The major number is fixed for the character USB devices. It is 180. We need to specify the following in the members of struct usb_class_driver:
1. Name of the device node
2. File operations structure
3. Minor Number

Code:

O/P: 


You can observe from the output, after I loaded the module and connected the device, I got four entries (/dev/mydevice*), this is because the device which I am using has four interface. If your device has only one interface, you will get /dev/mydevice0.

To test the write functionality executed: echo "hello" > /dev/mydevice0

To test the read functionality executed: cat < /dev/mydevice0

Comments

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto