jjzjj

解决Ubuntu22.04无法使用ch34x串口问题

CheeseZhangz 2024-02-10 原文

问题背景

在去年RDC2022上很幸运抽中了纪念板柿饼M7。在此感谢RT-Thread!!!本文介绍了Ubuntu22.04下开发RT Smart遇到的无法使用ch34x串口问题。


问题描述

Ubuntu22.04无法使用ch34x串口
使用lsusb命令可以看到有Bus 001 Device 005: ID 1a86:7523 QinHeng Electronics CH340 serial converter是能识别出ch34x设备


原因分析

  1. Ubuntu22.04自带的ch34x驱动版本过老
    使用ls /lib/modules/$(uname -r)/kernel/drivers/usb/serial命令查看Ubutnu自带驱动,找到ch341.ko发现是2013年的文件…(无语~)先把旧驱动删除sudo rm ch341.ko
    找到一篇相似的文章ubuntu20.4系统安装CH340驱动并使用串口调试助手看来不是我一个人遇到相同的问题…
    2.brltty进程占用了串口
    使用sudo dmesg | grep tty命令可以看到
    [ 0.223411] printk: console [tty0] enabled
    [ 44.099146] usb 1-1: ch341-uart converter now attached to ttyUSB0
    [ 44.673749] usb 1-1: usbfs: interface 0 claimed by ch34x while ‘brltty’ sets config #1
    [ 44.675063] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0

解决过程

WCH官网下载最新的驱动CH341SER_LINUX.ZIP

解压驱动

unzip CH341SER_LINUX_ZIP 得到三个文件ch34x.c Makefile readme.txt

// ChangeLog 
// 1.0 - 1.1   modified to solve transmition between ch341 and ch341
// 1.1 - 1.2   Support high Linux kernel
Instructions

Note: 1.Please run followed executable programs as root privilege
      2.Current Driver support versions of linux kernel range from 2.6.25 to 3.13.x
      3.Current Driver support 32bits and 64bits linux systems

Usage:
	(load or unload linux driver of CH34x)
	//compile 
	#make
	//load ch34x chips driver
	#make load
	//unload ch34x chips driver
	#make unload
// 1.2 - 1.3 Fix some bugs			

编译安装驱动

readme.txt里面介绍到驱动的加载方式,但注意到第7行写着支持的内核版本从2.6.25 to 3.13.x隐约感觉问题不妙
敲入make命令后,果然出现了错误(这年头官网的驱动也不靠谱哇)

make -C /lib/modules/5.15.0-58-generic/build  M=/home/$USER/Documents/CH341SER_LINUX  
make[1]: Entering directory '/usr/src/linux-headers-5.15.0-58-generic'
  CC [M]  /home/$USER/Documents/CH341SER_LINUX/ch34x.o
/home/$USER/Documents/CH341SER_LINUX/ch34x.c: In function ‘ch34x_close’:
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:591:9: error: unknown type name ‘wait_queue_t’; did you mean ‘wait_event’?
  591 |         wait_queue_t wait;
      |         ^~~~~~~~~~~~
      |         wait_event
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:591:22: warning: unused variable ‘wait’ [-Wunused-variable]
  591 |         wait_queue_t wait;
      |                      ^~~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:590:14: warning: unused variable ‘timeout’ [-Wunused-variable]
  590 |         long timeout;
      |              ^~~~~~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:589:13: warning: unused variable ‘bps’ [-Wunused-variable]
  589 |         int bps;
      |             ^~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c: At top level:
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:1297:27: error: initialization of ‘unsigned int (*)(struct tty_struct *)’ from incompatible pointer type ‘int (*)(struct tty_struct *)[-Werror=incompatible-pointer-types]
 1297 |         .write_room     = ch34x_write_room,
      |                           ^~~~~~~~~~~~~~~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:1297:27: note: (near initialization for ‘ch34x_device.write_room’)
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:1298:28: error: initialization of ‘unsigned int (*)(struct tty_struct *)’ from incompatible pointer type ‘int (*)(struct tty_struct *)[-Werror=incompatible-pointer-types]
 1298 |         .chars_in_buffer = ch34x_chars_in_buffer,
      |                            ^~~~~~~~~~~~~~~~~~~~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:1298:28: note: (near initialization for ‘ch34x_device.chars_in_buffer’)
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:297: /home/$USER/Documents/CH341SER_LINUX/ch34x.o] Error 1
make[1]: *** [Makefile:1902: /home/$USER/Documents/CH341SER_LINUX] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-58-generic'
make: *** [Makefile:5: default] Error 2

uname -r 可查看操作系统的发行版号,获得Ubuntu22.04的Linux版本是5.15.0-58-generic
Linux kernel source code v5.15查看ch341.c的源代码,直接复制到CH341SER_LINUX/ch34x.c中,重新make,此次通过。
在目录执行sudo make load命令,出现以下错误

modprobe usbserial
insmod ch34x.ko
insmod: ERROR: could not insert module ch34x.ko: File exists
make: *** [Makefile:10: load] Error 1

将目录中生成ch34x.ko文件复制到/lib/modules/$(uname -r)/kernel/drivers/usb/serial下,使用lsmod查看模块,发现已识别。

Module                  Size  Used by
ch34x                  24576  0
usbserial              57344  1 ch34x

测试

正常到达这步就可以与开发板通信了,但是配置完minicomminicom: cannot open /dev/ttyUSB0: No such file or directory
这时查看/dev/ttyUSB*发现没有此文件

zsh: no matches found: /dev/ttyUSB*

使用dmesg查找原因sudo dmesg | grep tty

[    0.223411] printk: console [tty0] enabled
[   44.099146] usb 1-1: ch341-uart converter now attached to ttyUSB0
[   44.673749] usb 1-1: usbfs: interface 0 claimed by ch34x while 'brltty' sets config #1
[   44.675063] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0

这里出现了brltty进程,通过官网得知:

BRLTTY is a background process (daemon) providing access to the Linux/Unix console (when in text mode) for a blind person using a refreshable braille display.
brltty是一个后台进程(守护进程),为盲人提供对Linux/Unix控制台的访问(当处于文本模式时),使用可刷新盲文显示。

直接删除sudo apt remove brltty

重新连接开发板ls /dev/ttyUSB*这时已经出现了/dev/ttyUSB0这个设备!!!
此时sudo minicom -c on可正常使用minicom与开发板进行通信


有关解决Ubuntu22.04无法使用ch34x串口问题的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  4. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  5. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

  6. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  7. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

  8. ruby - 如何在 Ubuntu 中清除 Ruby Phusion Passenger 的缓存? - 2

    我试过重新启动apache,缓存的页面仍然出现,所以一定有一个文件夹在某个地方。我没有“公共(public)/缓存”,那么我还应该查看哪些其他地方?是否有一个URL标志也可以触发此效果? 最佳答案 您需要触摸一个文件才能清除phusion,例如:touch/webapps/mycook/tmp/restart.txt参见docs 关于ruby-如何在Ubuntu中清除RubyPhusionPassenger的缓存?,我们在StackOverflow上找到一个类似的问题:

  9. ruby - RVM "ERROR: Unable to checkout branch ."单用户 - 2

    我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas

  10. ruby - 如何关闭 ruby​​ gem "Spreadsheet?"中的文件 - 2

    下面的代码在我第一次运行它时就可以正常工作:require'rubygems'require'spreadsheet'book=Spreadsheet.open'/Users/me/myruby/Mywks.xls'sheet=book.worksheet0row=sheet.row(1)putsrow[1]book.write'/Users/me/myruby/Mywks.xls'当我再次运行它时,我会收到更多消息,例如:/Library/Ruby/Gems/1.8/gems/spreadsheet-0.6.5.9/lib/spreadsheet/excel/reader.rb:11

随机推荐