Chinaunix首页 | 论坛 | 博客
  • 博客访问: 549066
  • 博文数量: 105
  • 博客积分: 3274
  • 博客等级: 中校
  • 技术积分: 1161
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-21 12:14
文章分类

全部博文(105)

文章存档

2011年(1)

2010年(104)

分类: LINUX

2010-09-03 19:57:42

   新项目中要用到USB通信,所以需要弄一个usb gadget驱动。Linux内核里面本身自带了USB转串口驱动,本打算使用这个的,但是由于一些原因,被PASS掉了,总之就是不能使用串口。
   于是阅读相关文档,如下:
 
Installing the Gadget Serial Driver
-----------------------------------
To use the gadget serial driver you must configure the Linux gadget
side kernel for "Support for USB Gadgets", for a "USB Peripheral
Controller" (for example, net2280), and for the "Serial Gadget"
driver.  All this are listed under "USB Gadget Support" when
configuring the kernel.  Then rebuild and install the kernel or
modules.
 
Then you must load the gadget serial driver.  To load it as an
ACM device (recommended for interoperability), do this:
 
  modprobe g_serial use_acm=1
 
To load it as a vendor specific bulk in/out device, do this:
 
  modprobe g_serial
 
This will also automatically load the underlying gadget peripheral
controller driver.  This must be done each time you reboot the gadget
side Linux system.  You can add this to the start up scripts, if
desired.
 
   加载驱动时,如果传递参数use_acm=1,则为usb转串口驱动,如果没有传递该参数或者是之为0,则为普通的usb驱动。
   显然,不传递参数或者use_acm=0就可以满足项目中的需求。如果是直接把这个模块编译进内核,则在/driver/usb/gadget/serial.c里面把use_acm设置为0即可。
   在linux主机下面,我利用万能驱动---usb-skeleton.c,更改VID和PID后测试,一切OK
 
   于是我把板子交给写WINDOWS下USB驱动的同事,板子可以发送数据给PC,但是PC发送数据给板子时,板子显示没有收到数据。
   linux内核自带的驱动肯定是没有问题的,于是用bus hound抓取数据,证明PC机的确已经把数据发送给板子了,那问题出在哪里呢?
   百般无奈之下,只好看源代码。
   看源代码时发现,虽然没有使用USB转串口,但是还是设置了串口的相关参数,感觉似乎是参数没有设置好,源代码里采用的是终端式的串口,而我需要的是raw。之所以在Linux主机里好用,是因为我采用的是echo发送数据,而echo发送数据时会多发一个"\n",应该就是这个原因,于是在设置串口参数时增加了如下设置
// zhh add start
 gs_tty_driver->init_termios.c_lflag  &= ~(ICANON | ECHO | ECHOE | ISIG);  /*Input*/
    gs_tty_driver->init_termios.c_oflag  &= ~OPOST;   /*Output*/
 // zhh add end
然后就可以使用了。
 
不过,这里总是担心速度可能会有影响,下周有空写一个直接一点的USB设备驱动。
阅读(5907) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

niexiaogen2019-01-18 15:43:05

你好, 如果没有传递该参数或者是之为0,则为普通的usb驱动。 为啥开发板可以write 数据到PC端, 但PC发数据,开发板read 不到任何数据?  百思不得解。有什么办法啊??多谢!

root@socfpga:~# dwc2 ffb40000.usb: new device is high-speed
dwc2 ffb40000.usb: new device is high-speed
dwc2 ffb40000.usb: new address 4
dwc2 ffb40000.usb: s3c_hsotg_ep_disable(ep bfb290b8)
dwc2 ffb40000.usb: s3c_hsotg_ep_disable(ep bfb2905c)
g_serial gadget: high-speed config #1: Generic Serial&nb

chinaunix网友2010-09-07 11:22:11

Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com