您的位置:首页 > 其它

TX1安装usbserial及cp210x驱动

2017-10-20 16:02 627 查看
http://blog.csdn.net/handsome_for_kill/article/details/52780737


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.sh
sudo ./installFTDIModule.sh
1
2
3


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

依然在刚才那个目录,找到prepareModule.sh文件,打开并编辑这个文件。
#!/bin/sh
# Prepare to build the FTDI module for LT4 21.4 on the NVIDIA Jetson TK1
if [ $(id -u) != 0 ]; then
echo "This script requires root permissions"
echo "$ sudo "$0""
exit
fi
# Get the kernel source for LT4 21.4
cd /usr/src/
wget http://developer.download.nvidia.com/embedded/L4T/r23_Release_v1.0/source/kernel_src.tbz2 # Decompress
tar -xvf kernel_src.tbz2
cd kernel
# Get the kernel configuration file
zcat /proc/config.gz > .config
# Enable FTDI compilation
sudo 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 set
LOCALVERSION=$(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 removed
release="${LOCALVERSION##*-}"
CONFIGVERSION="CONFIG_LOCALVERSION=\"-$release\""
# Replace the empty local version with the local version of this kernel
sudo sed -i 's/CONFIG_LOCALVERSION=""/'$CONFIGVERSION'/' .config
# Prepare the module for compilation
make prepare
make modules_prepare
# Compile the module
make M=drivers/usb/serial/
# After compilation, copy the compiled module to the system area
cp drivers/usb/serial/ftdi_sio.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial
depmod -a
/bin/echo -e "\e[1;32mFTDI Driver Module Installed.\e[0m"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

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

可以看到这一行语句:
wget http://developer.download.nvidia.com/embedded/L4T/r23_Release_v1.0/source/kernel_src.tbz2[/code]1 
这一句话的含义即下载内核源文件,内核源文件要根据自己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[/code]1 2

至于如何查看自己现在系统所用的内核版本,我的方法比较蠢,就是打开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
1

这句话的含义是修改当前目录下的.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
1

有的版本的.config文件没有# CONFIG_USB_SERIAL_FTDI_SIO is not set这句话,这是可以改成如下:
sudo sed -i 's/CONFIG_USB_SERIAL_CP210X=y/CONFIG_USB_SERIAL_CP210X=m/' .config
1

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

看到下面语句:
cp drivers/usb/serial/ftdi_sio.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial
1

由于我们是cp210x模块,所以很明显这句话应该改成:
cp drivers/usb/serial/cp210x.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial
1

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


Step 4:导入cp210x模块

tx1内部自带了cp210x模块,位置是/usr/src/kernel/drivers/usb/serial/下

使用以下命令:
sudo insmod cp210x.ko
1
2

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

如果输出中有cp210x模块,说明成功了,现在插上USB转串口的设备就可以看到ttyUSB0了。这里同样有一个可以参考的网址如下: 
http://blog.csdn.net/qingfengtsing/article/details/51783337
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: