16769 views|6 replies

17

Posts

0

Resources
The OP
 

Linux driver programming - ch340x driver transplantation [Copy link]

Linux driver programming - ch340x driver transplantation

Key concepts:

ch340x driver transplantation

As a universal device, manufacturers provide drivers for various platforms. Linux usually provides driver source code.

Generally speaking, driver transplantation means modifying the manufacturer's driver source code and compiling it into a driver that is compatible with your own system version.

Introduction to ch340

USB to serial port chip, you need to write a driver.

Purpose:

Transplant, compile and load the official ch34x driver to realize the USB to serial port function.

Hardware circuit:

Development board, a CH340 module.

Driver source code download:

Download address: http://www.wch.cn/download/CH341SER_LINUX_ZIP.html

Here I choose Linux driver

CH341SER_LINUX.ZIP contains three files

ch34x.c ch34x driver source code

Makefile Compilation

readme.txt Some version and command descriptions

Code:

We mainly modify two places in ch34x.c

Comment out the following two lines

Modify the Makefile. I did not use the built-in Makefile, but wrote my own.

KERNELDIR := /home/sixer/imx_kernel/linux-imx-rel_imx_4.1.15_2.1.0_ga
CURRENT_PATH := $(shell pwd)

export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-

target := ch34x
obj-m := $(target).o
APP_NAME := $(target)_app

build: kernel_modules

kernel_modules:
    $(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) modules

clean:
    $(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) clean
#   rm -rf $(APP_NAME)

dir_exist = $(shell if [ -d "/nfsroot/$(target)/" ]; then echo "exist"; else echo "noexist"; fi)
$(info $(dir_exist))

install:
ifeq ("$(dir_exist)", "noexist")
    $(shell mkdir /nfsroot/$(target))
    #"The folder does not exist and has been recreated"
endif
#   arm-linux-gnueabihf-gcc $(APP_NAME).c -o  $(APP_NAME)
    cp *.ko /nfsroot/$(target)/

Compile and run:

makeCompile

Generate target filech34x.ko

make installCopy the target to the NFS directory

Plug in my ch340 module

insmod ch34x.koLoad ch34x driver

Experimental phenomenon:

[root@iTOP-iMX6UL]# cd /mnt/nfs_dir/ch34x/
[root@iTOP-iMX6UL]# ls
ch34x.ko
[root@iTOP-iMX6UL]# insmod ch34x.ko
usbcore: registered new interface driver ch34x
usbserial: USB Serial support registered for ch34x
[root@iTOP-iMX6UL]# usb 2-1.3: new full-speed USB device number 4 using ci_hdrc
ch34x 2-1.3:1.0: ch34x converter detected
usb 2-1.3: ch34x converter now attached to ttyUSB0

[root@iTOP-iMX6UL]# 

Summarize:

After loading the ch34x driver and plugging in the module, the system immediately recognized a serial port, indicating that my transplantation was successful.

WeChat ID:

InsertingAll

This post is from Linux and Android

Latest reply

This should be the installation of the ch34x driver, it cannot be called a transplant!   Details Published on 2021-9-16 11:36
Personal signaturehappy more day

23

Posts

0

Resources
2
 

ch340 should have supported it a long time ago

This post is from Linux and Android
 
 

305

Posts

0

Resources
3
 

I want to give this a try. I communicated with Qinheng’s technical staff several times half a year ago, but to no avail.

This post is from Linux and Android
 
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 

305

Posts

0

Resources
4
 

Just identifying a USB port may not mean that the transplantation is successful. You need to try actual serial port communication.

This post is from Linux and Android
 
Personal signature

“Everyone wants the project to be good, fast, and cheap... pick two.”

- Unknown

 
 

7462

Posts

2

Resources
5
 

The ch34x driver is already supported by the official Linux code, it seems to be under driver/usb/serial.

This post is from Linux and Android
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

2

Posts

0

Resources
6
 

This is good, I will test it to see if it works. Thanks for sharing

This post is from Linux and Android
 
 
 

1942

Posts

2

Resources
7
 

This should be the installation of the ch34x driver, it cannot be called a transplant!

This post is from Linux and Android
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Design experience exchange: Matters needing attention in AD sampling

Mainly for high-precision measurement AD. 1: The reference voltage needs to be accurate enough, and it is recommende ...

WAN Acceleration - Wide Area Network Optimization Technology and Application Analysis

Wide Area Network ( WAN ) bandwidth is expensive, so most users can only have limited WAN bandwidth. On the contrary ...

Malicious web virus symptoms and simple fixes

1. Web virus that damages IE browser: (I) . The default homepage is modified 1. Destructive characteristics: The default ...

Brief analysis of the functional block diagram of the MSP430 series microcontroller

This post was last edited by tiankai001 on 2018-12-6 16:55 This content is originally created by EEWORLD forum user tian ...

MATLAB APP Designer serial port debugging tool writing

This post was last edited by lb8820265 on 2019-5-9 23:11 Previously, we introduced two ways to use VC6 to make serial ...

[RISC-V MCU CH32V103 Review] DHT22 temperature and humidity measurement

This post was last edited by jennyzhaojie on 2021-2-9 17:47 DHT22 is a digital temperature and humidity sensor. Compare ...

Super low price | Try cheap and easy-to-use power chips, MPS Thanksgiving and feedback season!

MPS conducted a survey on cheap and easy-to-use power chips . Among the dozens of replies, there were several students w ...

600 Questions on Microcontrollers and Embedded Systems

This topic mainly focuses on the basic knowledge of single-chip microcomputers and embedded systems, system hardware, sy ...

Why do graphics cards have such a big advantage when running AI algorithms?

AI algorithms, especially deep learning algorithms, are highly dependent on a large number of parallel calculations when ...

Understanding of high voltage safety design of power battery packs for new energy vehicles

The high-voltage safety design of the power battery pack is an important part of the safety of electric vehicles. It is ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list