20240919在ubuntu20.04下适配宸芯的数传模块CX6602N
2024/9/19 19:59


2. 上位机配置
2.1 添加 rndis 和 gserial 主机驱动
进入 kernel 目录 make menuconfig,1.添加配置 CONFIG_USB_NET_RNDIS_HOST=m:

2.添加配置 CONFIG_USB_SERIAL=m:
2.添加配置 CONFIG_USB_SERIAL_GENERIC=y:
编译模块:make modules && make modules_install


2.2 加载驱动

1. 加载 rndis 主机驱动:modprobe rndis_host
2. 连接下位机,确认 rndis 驱动绑定 rndis 接口
3. 查看下位机的 usb 设备 ID:
     # lsusb
     Bus 001 Device 006: ID 18d1:181f Google Inc.

4. # lsusb -t
     /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M

           |__ Port 1: Dev 15, If 0, Class=Wireless, Driver=rndis_host, 480M
      |__ Port 1: Dev 15, If 1, Class=CDC Data, Driver=rndis_host, 480M
      |__ Port 1: Dev 15, If 2, Class=Vendor Specific Class, Driver=, 480M
      |__ Port 1: Dev 15, If 3, Class=Vendor Specific Class, Driver=, 480M
      |__ Port 1: Dev 15, If 4, Class=Vendor Specific Class, Driver=, 480M
      |__ Port 1: Dev 15, If 5, Class=Vendor Specific Class, Driver=, 480M

5. 加载 gserial 主机驱动:modprobe usbserial vendor=0x18d1 product=0x181f
     其中,0x18d1 是从机的 VID,0x181f 是从机的 PID

6. 确认 gserial 驱动绑定 gserial 接口:
     # lsusb -t
     /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
           |__ Port 1: Dev 15, If 0, Class=Wireless, Driver=rndis_host, 480M
           |__ Port 1: Dev 15, If 1, Class=CDC Data, Driver=rndis_host, 480M
           |__ Port 1: Dev 15, If 2, Class=Vendor Specific Class,
     Driver=usbserial_generic, 480M
           |__ Port 1: Dev 15, If 3, Class=Vendor Specific Class,
     Driver=usbserial_generic, 480M
           |__ Port 1: Dev 15, If 4, Class=Vendor Specific Class,
     Driver=usbserial_generic, 480M
           |__ Port 1: Dev 15, If 5, Class=Vendor Specific Class,
     Driver=usbserial_generic, 480M


3. 设备调试
3.1 端口识别

查看串口设备:
# ls /dev/ttyUSB*
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3

查看网卡设备:
ls /sys/class/net/ -l
total 0
lrwxrwxrwx 1 root root 0 Oct 23 07:33 usb0
-> ../../devices/pci0000:00/0000:00:11.0/0000:02:02.0/usb1/1-1/1-1:1.0/net/usb0
lrwxrwxrwx 1 root root 0 Oct 23 07:33 lo -> ../../devices/virtual/net/lo

# ifconfig usb0 192.168.1.15
usb0     Link encap:Ethernet HWaddr 1e:62:45:10:50:41
         inet addr:192.168.1.15 Bcast:192.168.1.255 Mask:255.255.255.0
         UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
         RX packets:6 errors:0 dropped:0 overruns:0 frame:0
         TX packets:640 errors:0 dropped:0 overruns:0 carrier:0
                    collisions:0 txqueuelen:1000
                    RX bytes:384 (384.0 B) TX bytes:51178 (51.1 KB)

3.2 AT 及灌包测试

     1.通过 USB 连接上位机后,使用 minicom 工具发送 AT 命令:
     minicom -D /dev/ttyUSB0

     2.利用 iperf 测试网络性能:
     上位机配置 ipv4 地址:
     ifconfig usb0 192.168.42.130
     上位机作为 udp 服务端接收数据:
     iperf -u -s -i 1
     下位机作为 udp 客户端发送数据:
     iperf -u -c 192.168.42.130 -i 1 -p 5001 -t 30 -b 200m
上位机作为 udp 服务端接收数据:


Xshell 7 (Build 0164)
Copyright (c) 2020 NetSarang Computer, Inc. All rights reserved.

Type `help' to learn how to use Xshell prompt.
[C:\~]$ 

Connecting to 192.168.3.71:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-107-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Expanded Security Maintenance for Applications is not enabled.

153 updates can be applied immediately.
126 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

39 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

New release '22.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Your Hardware Enablement Stack (HWE) is supported until April 2025.
Last login: Thu Sep 19 19:26:24 2024 from 192.168.3.90
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 174f:181e Syntek Integrated Camera
Bus 003 Device 004: ID 8087:0033 Intel Corp. 
Bus 003 Device 002: ID 413c:301a Dell Computer Corp. Dell MS116 USB Optical Mouse
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 174f:181e Syntek Integrated Camera
Bus 003 Device 006: ID 18d1:181f Google Inc. Android
Bus 003 Device 004: ID 8087:0033 Intel Corp. 
Bus 003 Device 002: ID 413c:301a Dell Computer Corp. Dell MS116 USB Optical Mouse
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 


crw-rw---- 1 root    dialout 4, 94 9月  19 19:51 ttyS30
crw-rw---- 1 root    dialout 4, 95 9月  19 19:51 ttyS31
crw-rw---- 1 root    dialout 4, 68 9月  19 19:51 ttyS4
crw-rw---- 1 root    dialout 4, 69 9月  19 19:51 ttyS5
crw-rw---- 1 root    dialout 4, 70 9月  19 19:51 ttyS6
crw-rw---- 1 root    dialout 4, 71 9月  19 19:51 ttyS7
crw-rw---- 1 root    dialout 4, 72 9月  19 19:51 ttyS8
crw-rw---- 1 root    dialout 4, 73 9月  19 19:51 ttyS9
viewpro@viewpro-ThinkBook-16-G5-IRH:/dev$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:/dev$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:/dev$ ll ttyUSB*
ls: cannot access 'ttyUSB*': No such file or directory
viewpro@viewpro-ThinkBook-16-G5-IRH:/dev$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:/dev$ cd /sys/class/net/
viewpro@viewpro-ThinkBook-16-G5-IRH:/sys/class/net$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:/sys/class/net$ ll
total 0
drwxr-xr-x  2 root root 0 9月  19 19:51 ./
drwxr-xr-x 84 root root 0 9月  19 19:51 ../
lrwxrwxrwx  1 root root 0 9月  19 19:51 enp0s31f6 -> ../../devices/pci0000:00/0000:00:1f.6/net/enp0s31f6/
lrwxrwxrwx  1 root root 0 9月  19 19:51 lo -> ../../devices/virtual/net/lo/
lrwxrwxrwx  1 root root 0 9月  19 19:58 usb0 -> ../../devices/pci0000:00/0000:00:14.0/usb3/3-2/3-2:1.0/net/usb0/
viewpro@viewpro-ThinkBook-16-G5-IRH:/sys/class/net$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:/sys/class/net$ ifconfig

enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.71  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::552b:e38d:6e43:e673  prefixlen 64  scopeid 0x20<link>
        ether 74:d7:13:a8:ed:24  txqueuelen 1000  (Ethernet)
        RX packets 200110  bytes 34261574 (34.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1591810  bytes 2389010911 (2.3 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0x5e480000-5e4a0000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 507  bytes 60383 (60.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 507  bytes 60383 (60.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether ba:1c:4c:05:ee:5d  txqueuelen 1000  (Ethernet)
        RX packets 6  bytes 384 (384.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 97  bytes 22411 (22.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

viewpro@viewpro-ThinkBook-16-G5-IRH:/sys/class/net$ 


viewpro@viewpro-ThinkBook-16-G5-IRH:/sys/class/net$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:/sys/class/net$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:/sys/class/net$ cd ~
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ ifconfig usb0 192.168.42.130
SIOCSIFADDR: Operation not permitted
SIOCSIFFLAGS: Operation not permitted
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ sudo ifconfig usb0 192.168.42.130
[sudo] password for viewpro: 
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ ifconfig

enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.71  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::552b:e38d:6e43:e673  prefixlen 64  scopeid 0x20<link>
        ether 74:d7:13:a8:ed:24  txqueuelen 1000  (Ethernet)
        RX packets 288521  bytes 41453847 (41.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2382729  bytes 3584688093 (3.5 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0x5e480000-5e4a0000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 533  bytes 63837 (63.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 533  bytes 63837 (63.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.42.130  netmask 255.255.255.0  broadcast 192.168.42.255

        ether ba:1c:4c:05:ee:5d  txqueuelen 1000  (Ethernet)
        RX packets 12  bytes 552 (552.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 107  bytes 24975 (24.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 


【服务器端】
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ iperf -u -s -i 1
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size:  208 KByte (default)
------------------------------------------------------------
[  3] local 192.168.42.130 port 5001 connected with 192.168.42.130 port 46128
[ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams
[  3]  0.0- 1.0 sec  23.9 MBytes   200 Mbits/sec   0.000 ms    0/17018 (0%)
[  3]  1.0- 2.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)
[  3]  2.0- 3.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)
[  3]  3.0- 4.0 sec  23.8 MBytes   200 Mbits/sec   0.001 ms    0/17007 (0%)
[  3]  4.0- 5.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)

[  3]  5.0- 6.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17006 (0%)
[  3]  6.0- 7.0 sec  23.8 MBytes   200 Mbits/sec   0.001 ms    0/17007 (0%)
[  3]  7.0- 8.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)
[  3]  8.0- 9.0 sec  23.8 MBytes   200 Mbits/sec   0.001 ms    0/17007 (0%)
[  3]  9.0-10.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)
[  3] 10.0-11.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17006 (0%)
[  3] 11.0-12.0 sec  23.8 MBytes   200 Mbits/sec   0.001 ms    0/17007 (0%)
[  3] 12.0-13.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)
[  3] 13.0-14.0 sec  23.8 MBytes   200 Mbits/sec   0.001 ms    0/17007 (0%)
[  3] 14.0-15.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)
[  3] 15.0-16.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17006 (0%)
[  3] 16.0-17.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)
[  3] 17.0-18.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)
[  3] 18.0-19.0 sec  23.8 MBytes   200 Mbits/sec   0.000 ms    0/17007 (0%)
[  3]  0.0-20.0 sec   477 MBytes   200 Mbits/sec   0.002 ms    0/340136 (0%)
^Cviewpro@viewpro-ThinkBook-16-G5-IRH:~$ 


【客户端】
Xshell 7 (Build 0164)
Copyright (c) 2020 NetSarang Computer, Inc. All rights reserved.

Type `help' to learn how to use Xshell prompt.
[C:\~]$ 

Connecting to 192.168.3.71:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-107-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Expanded Security Maintenance for Applications is not enabled.

153 updates can be applied immediately.
126 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

39 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

New release '22.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Your Hardware Enablement Stack (HWE) is supported until April 2025.
Last login: Thu Sep 19 19:57:43 2024 from 192.168.3.90
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ iperf -u -c 192.168.42.130 -i 1 -p 5001 -t 20 -b 200m
------------------------------------------------------------
Client connecting to 192.168.42.130, UDP port 5001
Sending 1470 byte datagrams, IPG target: 58.80 us (kalman adjust)
UDP buffer size:  208 KByte (default)
------------------------------------------------------------
[  3] local 192.168.42.130 port 46128 connected with 192.168.42.130 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 1.0 sec  23.8 MBytes   200 Mbits/sec
[  3]  1.0- 2.0 sec  23.8 MBytes   200 Mbits/sec
[  3]  2.0- 3.0 sec  23.8 MBytes   200 Mbits/sec
[  3]  3.0- 4.0 sec  23.8 MBytes   200 Mbits/sec
[  3]  4.0- 5.0 sec  23.8 MBytes   200 Mbits/sec

[  3]  5.0- 6.0 sec  23.8 MBytes   200 Mbits/sec
[  3]  6.0- 7.0 sec  23.8 MBytes   200 Mbits/sec
[  3]  7.0- 8.0 sec  23.8 MBytes   200 Mbits/sec
[  3]  8.0- 9.0 sec  23.8 MBytes   200 Mbits/sec
[  3]  9.0-10.0 sec  23.8 MBytes   200 Mbits/sec
[  3] 10.0-11.0 sec  23.8 MBytes   200 Mbits/sec
[  3] 11.0-12.0 sec  23.8 MBytes   200 Mbits/sec
[  3] 12.0-13.0 sec  23.8 MBytes   200 Mbits/sec
[  3] 13.0-14.0 sec  23.8 MBytes   200 Mbits/sec
[  3] 14.0-15.0 sec  23.8 MBytes   200 Mbits/sec
[  3] 15.0-16.0 sec  23.8 MBytes   200 Mbits/sec
[  3] 16.0-17.0 sec  23.8 MBytes   200 Mbits/sec
[  3] 17.0-18.0 sec  23.8 MBytes   200 Mbits/sec
[  3] 18.0-19.0 sec  23.8 MBytes   200 Mbits/sec
[  3]  0.0-20.0 sec   477 MBytes   200 Mbits/sec
[  3] Sent 340136 datagrams
[  3] Server Report:
[  3]  0.0-20.0 sec   477 MBytes   200 Mbits/sec   0.001 ms    0/340136 (0%)
viewpro@viewpro-ThinkBook-16-G5-IRH:~$ 

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部