snifer

【原创】基于嵌入式系统的USB设备驱动实现

0
阅读(2078)

USB在嵌入式系统中的重要性不言而喻,今天就写写如何实现嵌入式系统的USB设备驱动。


【实验平台】

    主机:Ubantu10.10

目标板:fsc100

目标内核版本:2.6.35

【实验步骤】

1、实验代码拷贝到ubuntu主机目录下,编译且加载

2、目标板与pcUSB接口线连接,目标板上电后,进到u-boot控制台,并运行dnw

3、启用虚拟机的的USB设备

ubutn命令终端下可以看到如下信息

# lsusb -v

Bus 001 Device 002: ID 04e8:1234 Samsung Electronics Co., Ltd

Device Descriptor:

  bLength                18

  bDescriptorType         1

  bcdUSB               2.00

  bDeviceClass          255 Vendor Specific Class

  bDeviceSubClass         0

  bDeviceProtocol         0

  bMaxPacketSize0        64

  idVendor           0x04e8 Samsung Electronics Co., Ltd

  idProduct          0x1234

  bcdDevice            1.00

  iManufacturer           1 System MCU

  iProduct                2 SEC S3C6400X Test B/D

  iSerial                 0

  bNumConfigurations      1

  Configuration Descriptor:

    bLength                 9

    bDescriptorType         2

    wTotalLength           32

    bNumInterfaces          1

    bConfigurationValue     1

    iConfiguration          0

    bmAttributes         0xc0

      Self Powered

    MaxPower               50mA

    Interface Descriptor:

      bLength                 9

      bDescriptorType         4

      bInterfaceNumber        0

      bAlternateSetting       0

      bNumEndpoints           2

      bInterfaceClass       255 Vendor Specific Class

      bInterfaceSubClass      0

      bInterfaceProtocol      0

      iInterface              0

      Endpoint Descriptor:

        bLength                 7

        bDescriptorType         5

        bEndpointAddress     0x81  EP 1 IN

        bmAttributes            2

          Transfer Type            Bulk

          Synch Type               None

          Usage Type               Data

        wMaxPacketSize     0x0200  1x 512 bytes

        bInterval               0

      Endpoint Descriptor:

        bLength                 7

        bDescriptorType         5

        bEndpointAddress     0x02  EP 2 OUT

        bmAttributes            2

          Transfer Type            Bulk

          Synch Type               None

          Usage Type               Data

        wMaxPacketSize     0x0200  1x 512 bytes

        bInterval               0

4、在pc主机下编译应用程序并运行

# gcc -o test usb_app.c

# ./test zImage

5、在目标板u-boot控制台下运行

U-boot版本为:1.3.4

# bootm 20008000

U-boot版本为:2010.09

# go 20008000

是不是非常棒,很喜欢的一个应用。