RK3288 固定USB接口接串口线时的ttyUSB节点

当 RK3288 主板接 USB 转串口线时,USB 转串口已经调试 OK,生成的 ttyUSBx 理论上是递增的,但可能拔插一次就会变一次。

如果 ttyUSBx 是变化,会给上层读写数据造成很大麻烦。

此贴实现固定主板上某个 USB 接口为 ttyUSBx,此 USB 接口无论插什么 IC 的 USB转串口线(调试OK),或者任意插拔,生成的节点是不变的。

 

1、在主板上固定的 USB 插两根 USB 转串口线,生成的节点为 ttyUSB0 和 ttyUSB1。

root@RK3288:/ # ls /dev/ttyUSB*
ls /dev/ttyUSB*
/dev/ttyUSB0
/dev/ttyUSB1

 

2、通过指令查看这两个 USB 接口的详细信息,第一个 USB 为 3-1.2,第二个 USB 为 3-1.1.2

root@RK3288:/sys/bus/usb-serial/devices # ls -l ttyUSB0
ls -l ttyUSB0
lrwxrwxrwx root     root              2011-01-01 20:33 ttyUSB0 -> ../../../devices/ff540000.usb/usb3/3-1/3-1.2/3-1.2:1.0/ttyUSB0
root@RK3288:/sys/bus/usb-serial/devices # ls -l ttyUSB1
ls -l ttyUSB1
lrwxrwxrwx root     root              2011-01-01 20:35 ttyUSB1 -> ../../../devices/ff540000.usb/usb3/3-1/3-1.1/3-1.1.2/3-1.1.2:1.0/ttyUSB1

 

3、根据上一步记录的信息增加判断代码,固定第一个 USB 为 ttyUSB5,固定第二个 USB 为 ttyUSB6

diff --git a/kernel/drivers/usb/serial/usb-serial.c b/kernel/drivers/usb/serial/usb-serial.c
index 80d689f..a779f9f 100755
--- a/kernel/drivers/usb/serial/usb-serial.c
+++ b/kernel/drivers/usb/serial/usb-serial.c
@@ -89,6 +89,15 @@ static struct usb_serial *get_free_serial(struct usb_serial *serial,
        *minor = 0;
        mutex_lock(&table_lock);
        for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
+               if(strcmp((char*)serial->port[0]->serial->dev->devpath, "1.2") == 0){
+                       i = 5; 
+               }else if(strcmp((char*)serial->port[0]->serial->dev->devpath, "1.1.2") == 0){
+                       i = 6; 
    
                if (serial_table[i])
                        continue;

 

此时 USB 已经固定,在第一个 USB 接其中任意一条串口线,生成的节点都是 ttyUSB5,第二个 USB 接其中任意一条串口线,生成的节点都是 ttyUSB6。

posted @ 2021-01-28 11:14  LeeAaron  阅读(1544)  评论(1编辑  收藏  举报