world leader in high performance signal processing
Trace: » fs


Since not every developer wants to program in the kernel, or rely specifically on the Linux kernel APIs, a user mode API is available. An example user mode driver is userspace-example. (It also needs usbstring.c and usbstring.h.) Notice how the device is initialized by writing its configuration and device descriptors to a file (such as /dev/gadget/$CHIP), and how the endpoints are initialized in similar ways (writing descriptors to /dev/gadget/$ENDPOINT). After initializing them, just read or write to the files to transfer data; or to handle events including control requests to retrieve string descriptors, configure alternate settings, and implement class or vendor requests. On Linux 2.6 AIO (Async I/O) support is available, helping user mode drivers avoid i/o latencies and letting them stream data as quickly as in-kernel drivers can stream it. Note that user mode gadget drivers do not necesarily need to be licensed according to the GPL.

Source file drivers/usb/gadget/inode.c

Kernel config for GadgetFS

[Linux Kernel Configuration] -→ [Device Drivers] -→ [USB support] -→ [USB Gadget Support]

<M>   USB Gadget Drivers
<M>     Gadget Filesystem

Using GadgetFS

  • Buildroot configuration
Package Selection for the target  --->
    Hardware handling  --->
        [*] gadgetfs-test
  • On EZKIT-BF548 board install GadgetFS
root:/dev> modprobe gadgetfs
root:/dev> mkdir /dev/gadget  
root:/dev> mount -t gadgetfs gadgetfs /dev/gadget  
root:/dev> ls /dev/gadget/ -l
-rw-------    1 root     root            0 Jan  1 04:29 musb_hdrc
  • Running gadgetfs-test on the EZKIT-BF548
root:~> gadgetfs-test -r "1.3" -v     
gadgetfs: bound to musb_hdrc driver
/dev/gadget/musb_hdrc ep0 configured
gadgetfs: connected

** Thu Jan  1 05:19:27 gadgetfs: disconnected
CONNECT high speed
gadgetfs: connected
read 2 ep0 evegadgetfs: configuration #3
CONNECT high speed
SETUP 80.06 v0300 i0000 255
SETUP 80.06 v0302 i0409 255
SETUP 80.06 v0301 i0409 255
SETUP 80.06 v0303 i0409 255
SETUP 00.09 v0003 i0000 0
simple_source_thread start 1026 fd 6
simple_sink_thread start 2051 fd 7
SETUP 80.06 v0304 i0409 255
SETUP 80.06 v0305 i0409 255
  • On Linux PC USB host, run command
cat /sys/kernel/debug/usb/devices

got following similar message.

T:  Bus=01 Lev=01 Prnt=01 Port=07 Cnt=01 Dev#= 28 Spd=480  MxCh= 0
D:  Ver= 2.00 Cls=ff(vend.) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0525 ProdID=a4a4 Rev= 1.07
S:  Manufacturer=Licensed to Code, LLC
S:  Product=My Source/Sink Product
S:  SerialNumber=1.3
C:* #Ifs= 1 Cfg#= 3 Atr=c0 MxPwr=  2mA
I:* If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=usbtest
E:  Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=125us
E:  Ad=83(I) Atr=03(Int.) MxPS=   8 Ivl=4ms
modprobe /lib/modules/2.6.32-37-generic/kernel/drivers/usb/misc/usbtest.ko
testusb -D /dev/bus/usb/001/028 -t 1