TX1安装usbserial及cp210x驱动

来源:互联网 发布:fd软件下载 编辑:程序博客网 时间:2024/06/06 03:58

TX1安装usbserial及cp210x驱动

为了拿TX1作为上位机,通过USB连线与底层电路通信,那么usbserial驱动必不可少。但是,当我拿到TX1以后,发现了一件非常尴尬的事情,那就是没有这个驱动。所以我把底层电路板用USB线与TX1连接起来以后,发现找不到ttyUSB0这个设备,当然也就没有办法读取他,利用他通信了。所以,这里介绍一下如何为TX1安装USB转串口的驱动——cp210x驱动,方便大家的开发。

Step 1:下载TX1FTDIModule

到github上下载这个文件,附网址如下:
https://github.com/jetsonhacks/TX1FTDIModule
下面这个网址是一个相关问题的答案,大家也可以参考一下:
https://devtalk.nvidia.com/default/topic/912219/compiling-kernel-modules-for-jetson-tx1/?offset=4

Step 2:安装编译环境

安装编译环境以便于待会儿编译linux内核模块时不会报错。具体方法可以参考TX1FTDIModule的readme文件。
方法:解压TX1FTDIModule,进入解压后的目录,之后按如下方法操作:

chmod +x installFTDIModule.shsudo ./installFTDIModule.sh

Step 3:下载内核源代码并编译cp210x模块

依然在刚才那个目录,找到prepareModule.sh文件,打开并编辑这个文件。

#!/bin/sh# Prepare to build the FTDI module for LT4 21.4 on the NVIDIA Jetson TK1if [ $(id -u) != 0 ]; then   echo "This script requires root permissions"   echo "$ sudo "$0""   exitfi# Get the kernel source for LT4 21.4cd /usr/src/wget http://developer.download.nvidia.com/embedded/L4T/r23_Release_v1.0/source/kernel_src.tbz2# Decompresstar -xvf kernel_src.tbz2cd kernel# Get the kernel configuration filezcat /proc/config.gz > .config# Enable FTDI compilationsudo sed -i 's/# CONFIG_USB_SERIAL_FTDI_SIO is not set/CONFIG_USB_SERIAL_FTDI_SIO=m/' .config# Make sure that the local kernel version is setLOCALVERSION=$(uname -r)# vodoo incantation; This removes everything from the beginning to the last occurrence of "-"# of the local version string i.e. 3.10.67 is removedrelease="${LOCALVERSION##*-}"CONFIGVERSION="CONFIG_LOCALVERSION=\"-$release\""# Replace the empty local version with the local version of this kernelsudo sed -i 's/CONFIG_LOCALVERSION=""/'$CONFIGVERSION'/' .config# Prepare the module for compilationmake preparemake modules_prepare# Compile the modulemake M=drivers/usb/serial/# After compilation, copy the compiled module to the system areacp drivers/usb/serial/ftdi_sio.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serialdepmod -a/bin/echo -e "\e[1;32mFTDI Driver Module Installed.\e[0m"

需要更改的地方比较多,由于这是较旧以前的版本,下载的内核源代码可能不是我们目前TX1内核在用的,另外这是编译FTDI模块的脚本文件,我们需要更改一下,用来编译cp210x模块。步骤如下:
1 更改下载地址
可以看到这一行语句:

wget http://developer.download.nvidia.com/embedded/L4T/r23_Release_v1.0/source/kernel_src.tbz2

这一句话的含义即下载内核源文件,内核源文件要根据自己TX1上所使用的版本来下载,这些脚本文件的原作者用的版本是L4T 23.1,而我的版本是L4T 24.1,所以我需要把这一句话改成:

wget http://developer.download.nvidia.com/embedded/L4T/r24_Release_v1.0/24.1_64bit/source/kernel_src.tbz2

至于如何查看自己现在系统所用的内核版本,我的方法比较蠢,就是打开JetPack,看看自己安装的是什么版本。具体的版本信息可以到以下网址参考:
https://developer.nvidia.com/embedded/downloads#?search=Kernel
2 选取对应模块
可以看到下面这句话:

sudo sed -i 's/# CONFIG_USB_SERIAL_FTDI_SIO is not set/CONFIG_USB_SERIAL_FTDI_SIO=m/' .config

这句话的含义是修改当前目录下的.config文件,把# CONFIG_USB_SERIAL_FTDI_SIO is not set这句话替换成CONFIG_USB_SERIAL_FTDI_SIO=m,而我们要安装的是cp210x模块,所以应该修改为如下语句:

sudo sed -i 's/# CONFIG_USB_SERIAL_CP210X is not set/CONFIG_USB_SERIAL_CP210X=m/' .config

有的版本的.config文件没有# CONFIG_USB_SERIAL_FTDI_SIO is not set这句话,这是可以改成如下:

sudo sed -i 's/CONFIG_USB_SERIAL_CP210X=y/CONFIG_USB_SERIAL_CP210X=m/' .config

想要检查是否更改成功,可以直接打开.config文件查看,如果没有成功也可以直接在文件中进行修改。.config文件的位置在/usr/src/kernel。(注意:这个文件是在你运行了prepareModule.sh这个脚本之后才会存在的)
3 复制模块
看到下面语句:

cp drivers/usb/serial/ftdi_sio.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial

由于我们是cp210x模块,所以很明显这句话应该改成:

cp drivers/usb/serial/cp210x.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial

到了这一步,我们就可以直接运行这个脚本文件了,等待编译完毕即可。

Step 4:导入cp210x模块

使用以下命令:

insmod cp210x.ko

检验是否导入成功,可以用以下命令:

lsmod

如果输出中有cp210x模块,说明成功了,现在插上USB转串口的设备就可以看到ttyUSB0了。这里同样有一个可以参考的网址如下:
http://blog.csdn.net/qingfengtsing/article/details/51783337

结语

博文中有不对的地方欢迎大家在评论中指正,有问题也可以在评论中提出,希望和大家多多交流!

1 0