ubuntu16.04 using USB to TTL (ch340) serial to USB debugging process

Source: Internet
Author: User
Tags system log dmesg

I've done this once before, but it's been a long time and forgotten.

Today with ch340 in Linux debugging, with a previously written serial debugging program can not send data. Just remember window under the need to install the driver, the actual Linux also need to drive to normal use. The default Linux has this driver, but some old, not used.

In today's commissioning process, first plug the ch340 one end into the computer
Input command: lsmod | grep usbserial

Output: usbserial 53248 1 ch341
Successfully found the device, the identification of the ch341 I remember the wrong??
Input: Lsusb
Output information:
Bus 002 Device 003:id 17ef:4810 Lenovo Integrated Webcam [r5u877]
Bus 002 Device 001:id 1d6b:0002 Linux Foundation 2.0 root Hub
Bus 008 Device 001:id 1d6b:0001 Linux Foundation 1.1 root Hub
Bus 007 Device 001:id 1d6b:0001 Linux Foundation 1.1 root Hub
Bus 006 Device 002:id 1a81:1004 Holtek Semiconductor, Inc.
Bus 006 Device 003:id 1a86:7523 Qinheng Electronics HL-340 usb-serial Adapter
Bus 006 Device 001:id 1d6b:0001 Linux Foundation 1.1 root Hub
Bus 001 Device 001:id 1d6b:0002 Linux Foundation 2.0 root Hub
Bus 005 Device 001:id 1d6b:0001 Linux Foundation 1.1 root Hub
Bus 004 Device 001:id 1d6b:0001 Linux Foundation 1.1 root Hub
Bus 003 Device 001:id 1d6b:0001 Linux Foundation 1.1 root Hub
Found some information about ch341.
Input command (view USB to serial port status): DMESG
Output related information, some of the following information:
[429.184170] USB 6-1: New Full-speed USB device number 3 using UHCI_HCD
[429.345937] USB 6-1: New USB device found, idvendor=1a86, idproduct=7523
[429.345944] USB 6-1: New USB device strings:mfr=0, product=2, serialnumber=0
[429.345948] USB 6-1: product:usb2.0-ser!
[429.368123] usbcore:registered new Interface driver usbserial
[429.368396] usbcore:registered new Interface driver Usbserial_generic
[429.368875] USBSERIAL:USB Serial support registered for generic
[429.374125] usbcore:registered new Interface driver ch341
[429.374143] USBSERIAL:USB Serial support registered for Ch341-uart
[429.374165] ch341 6-1:1.0:ch341-uart Converter detected
[429.386851] USB 6-1: Ch341-uart Converter now attached to ttyUSB0
The ID information is consistent with the LSUSB detection, Ch341-uart Converter now attached to ttyUSB0 successfully driven, the port is ttyUSB0.

Again, you can actually see the driver, but don't be happy too early. and then down.

The second step: Install the serial terminal software, search for a minicom, try to try:

First: Suggest refreshing the source sudo apt-get update
Then install: sudo apt-get install minicom


Print some information and enter ' Y '.
Wait for the installation to succeed, and then use sudo minicom-s to set the minicom port corresponding to ttyUSB0 (corresponding to the information you see with the DMESG command).
The Configuration menu appears:

Select "Serial Port Setup" and a serial port configuration menu appears:

Enter a, modify serial device modified by/DEV/TTY0 to/dev/ttyusb0, the baud rate according to the actual hardware parameters of the change, I modified to 115200 8N1, there are 19200 8N1 hardware and so on.

and then return

Select Save Setup as DFL

Then select Exit to exit.

You can go through the sudo minicom-s again to see if the parameters are stored properly.

At this point, using the Serial debugging tool, you can see the ttyUSB0, but still unable to communicate.

Run DMESG, shown below

The reason is that the driver version is too old to reload the driver

1. First go to the official website to download the latest driver, see a tall man's blog: CH340 each platform under the drive

2. Download the Linux version of the driver

Copy it to a Linux system, before you use it, you need to remove the old driver before it can be used to prevent the old driver from even installing the new driver. The default driver directory for the system is:/lib/modules/$ (uname-r)/kernel/drivers, the full pathname of the old driver:/lib/modules/$ (uname-r)/kernel/drivers/usb/serial/ Ch341.ko, we go into that directory and then delete it, as shown below:

3. Unzip the new driver and compile the installation, the specific process such as.

In fact, it's four steps to get it done:

    1. [Email protected]:/#unzip ch341ser_linux. ZIP
    2. [Email protected]:/#cd ch341ser_linux
    3. [Email protected]:/#make
    4. [Email protected]:/#make load

In particular, pay attention to the third step after making the execution process and results, if not successfully generated Ch34x.ko then you need to check the prompt for the cause of the error, and then to find or consult the corresponding problem [email protected]. Insert the CH340 hardware after make load, enter the command: DMESG view the System log information as shown in:

If the information shown is successful and the resulting device node name is ttyUSB0, we can view it in the/dev directory, find the device file/dev/ttyusb0, and then leave the operation as simple as the Windows system operating COM port.

4. If make of step 3rd is wrong, Error:unknown type name ' wait_queue_t ' and implicit declaration of function ' signal_pending ' [-werror= Implicit-function-declaration] Error prompt.

That is, when compiling the official ch34x Drive source code, appears:

1.error:unknown type name ' wait_queue_t ';

2.implicit declaration of function ' signal_pending ' [-werror=implicit-function-declaration]

The error prompt.

The following solutions are required:

Need to use VI editor, WAIT_QUEUE_T has not been used, find wait_queue_t (/wait_queue_t directed to find it, only one line), so directly in the source code comments out.

2 Introduction of header file # include <linux/sched/signal.h>.

Then the problem is solved, which can be directly compiled using make and made load, loaded into the system driver.

At this point, the serial port can finally communicate.

If you want the system to automatically load the driver after each boot, it is very simple to just two steps, copy the generated Ch34x.ko file to the original old driver directory, and then execute the depmod command. If not clear enough, refer to the blog: Linux system boot auto-load driver module

ubuntu16.04 using USB to TTL (ch340) serial to USB debugging process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.