linux使用dwc串口,linux自带usb gadget设备驱动应用

新项目中要用到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设备驱动。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值