[SOLVED] Can't rebuild ch341.c driver in kernel

Questions about hardware,drivers and peripherals
Forum rules
Before you post please read how to get help
Post Reply
sulpakneo
Level 1
Level 1
Posts: 5
Joined: Fri Sep 30, 2016 12:26 am

[SOLVED] Can't rebuild ch341.c driver in kernel

Post by sulpakneo » Fri Sep 30, 2016 12:40 am

Hello! I'm from Kazakhstan (near Russia). I'm sorry for my very bad English. I'm asked in russian forums about this problem, but nobody is anwsered me. Please, help me!
I have a USB-COM converter. In system is registered as 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter (if I type command "lsusb"). If I type the command dmesg | grep tty, system is required "usb 2-1.2: ch341-uart converter now attached to ttyUSB0".
I want to use a WINE for my applications, that used COM-ports. I resending this device to WINE "ln -s /dev/ttyUSB0 ~/.wine/dosdevices/com1". But is not working!
Five moths earlier i'm buyed other USB-COM adapter and this working. But this adapter from other vendor. I'm read about this trouble from github about this USB-COM adapter - "This problem is fixed in this patch, please follow nest instructions".

Code: Select all

sudo apt-get source linux-source-3.19.0 linux-headers-$(uname -r)
cd /tmp
tar -xjf /usr/src/linux-source-3.19.0.tar.bz2
cd /usr/src/linux-headers-3.19.0-32/
make oldconfig
make prepare
make scripts
cp -v /usr/src/linux-headers-$(uname -r)/Module.symvers .
cp /lib/modules/$(uname -r)/kernel/drivers/usb/serial/ch341.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial/ch341.ko.orig
cd drivers/usb/serial
cp ch341.c ch341.c.orig
wget https://github.com/karlp/ch341-linux/raw/master/0001-usb-serial-ch341-Add-parity-support.patch
cat 0001-usb-serial-ch341-Add-parity-support.patch | patch -p4
patching file ch341.c
Hunk #1 succeeded at 349 (offset 3 lines).
Hunk #2 succeeded at 370 (offset 3 lines).
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
sudo cp ch341.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial/ch341.ko
sudo rmmod ch341
sudo modprobe ch341
But is not working - Linux can't find source archive... on the first command
and can't find file ch341.c
Last edited by sulpakneo on Sun Mar 26, 2017 2:58 pm, edited 2 times in total.

AlbertP
Level 16
Level 16
Posts: 6718
Joined: Sun Jan 30, 2011 12:38 pm
Location: Utrecht, The Netherlands

Re: Can't rebuild ch341.c driver in kernel

Post by AlbertP » Fri Sep 30, 2016 5:31 am

In the Software Sources program, please tick "Enable source code repositories" and try again.
Registered Linux User #528502
Image
Feel free to correct me if I'm trying to write in Spanish, French or German.

JeremyB
Level 19
Level 19
Posts: 9182
Joined: Fri Feb 21, 2014 8:17 am

Re: Can't rebuild ch341.c driver in kernel

Post by JeremyB » Fri Sep 30, 2016 5:03 pm

Just post what kernel you have

Code: Select all

uname -a
and I can upload the needed parts of the kernel source to my guthub site

sulpakneo
Level 1
Level 1
Posts: 5
Joined: Fri Sep 30, 2016 12:26 am

Re: Can't rebuild ch341.c driver in kernel

Post by sulpakneo » Sun Oct 02, 2016 3:33 am

Great Thanks! When I type command "uname -a" system is required next words:
Linux kassa22109-8 3.19.0-32-generic #37~14.04.1-Ubuntu SMP Thu Oct 22 09:37:25 UTC 2015 i686 i686 i686 GNU/Linux
My application is worked on NET.Framework 4.0. I'm using wine 1.6. Application is sending command to COM-port via WinAPI. And this fine worked with USB-COM converter other vendor, but when I buyed this new converter - wine is not viewed serial com-port... I've read on forums - this new USB-COM adapter is used asinchronical drivers... I don't know how I input new driver. I used Linux Mint 17.3 Rosa

JeremyB
Level 19
Level 19
Posts: 9182
Joined: Fri Feb 21, 2014 8:17 am

Re: Can't rebuild ch341.c driver in kernel

Post by JeremyB » Sun Oct 02, 2016 6:53 am

https://www.dropbox.com/s/u8ny4lvyxeh8v ... ar.gz?dl=0

That is the /drivers/usb/serial folder with the ch341 already patched from the 3.19.0 kernel
Backup the existing module if you haven't yet

Code: Select all

cp /lib/modules/$(uname -r)/kernel/drivers/usb/serial/ch341.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial/ch341.ko.orig
You can download the source with

Code: Select all

wget https://www.dropbox.com/s/u8ny4lvyxeh8v5u/serial.tar.gz
Extract it

Code: Select all

tar -zxvf serial.tar.gz
Make sure you have the tools to build modules

Code: Select all

sudo apt-get install linux-headers-generic build-essential
Change into the directory and copy a copy files in before you build

Code: Select all

cd serial

Code: Select all

cp /usr/src/linux-headers-`uname -r`/.config ./

Code: Select all

cp -v /usr/src/linux-headers-$(uname -r)/Module.symvers .
Then build

Code: Select all

make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
If it finishes without errors you can copy the new module

Code: Select all

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

Code: Select all

sudo rmmod ch341

Code: Select all

sudo modprobe ch341
See if it works

sulpakneo
Level 1
Level 1
Posts: 5
Joined: Fri Sep 30, 2016 12:26 am

Re: Can't rebuild ch341.c driver in kernel

Post by sulpakneo » Sun Oct 02, 2016 12:56 pm

Thank you very mach!!!!
Tomorrow I'm testing your method!!!! You're BEST!

sulpakneo
Level 1
Level 1
Posts: 5
Joined: Fri Sep 30, 2016 12:26 am

Re: Can't rebuild ch341.c driver in kernel

Post by sulpakneo » Tue Oct 04, 2016 8:09 am

You're GREAT MAN!
Thank you! It's working! You safe my head!)
:P :P :P :P :P

JeremyB
Level 19
Level 19
Posts: 9182
Joined: Fri Feb 21, 2014 8:17 am

Re: Can't rebuild ch341.c driver in kernel

Post by JeremyB » Tue Oct 04, 2016 5:21 pm

If it worked well, edit the subject line in your original post to add [SOLVED} as it may help others searching for a solution

MintSlow2Boot
Level 1
Level 1
Posts: 22
Joined: Tue Dec 27, 2016 2:08 pm

Re: Can't rebuild ch341.c driver in kernel

Post by MintSlow2Boot » Sun Jan 01, 2017 2:01 pm

JeremyB wrote:add [SOLVED} as it may help others searching for a solution
:) I am searching for this solution too, Mint 18.1 x64 to use Arduino with Wine. My Windows program cannot see any comports.

uname -a
returns...
Linux AcerV5 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Will that Dropbox download work for this too?

p.s.
dmsg shows this at boot

Code: Select all

[    6.659601] usbcore: registered new interface driver usbserial
[    6.659765] usbcore: registered new interface driver usbserial_generic
[    6.659923] usbserial: USB Serial support registered for generic
[    6.666048] usbcore: registered new interface driver ch341
[    6.666158] usbserial: USB Serial support registered for ch341-uart
[    6.666219] ch341 3-2.4.4:1.0: ch341-uart converter detected
[    6.667963] usb 3-2.4.4: ch341-uart converter now attached to ttyUSB0

JeremyB
Level 19
Level 19
Posts: 9182
Joined: Fri Feb 21, 2014 8:17 am

Re: Can't rebuild ch341.c driver in kernel

Post by JeremyB » Sun Jan 01, 2017 2:20 pm

It isn't likely that it would work, but this one should
https://www.dropbox.com/s/ve8pmh2ldn4gc ... ar.gz?dl=0

MintSlow2Boot
Level 1
Level 1
Posts: 22
Joined: Tue Dec 27, 2016 2:08 pm

Re: Can't rebuild ch341.c driver in kernel

Post by MintSlow2Boot » Sun Jan 01, 2017 7:11 pm

JeremyB wrote:It isn't likely that it would work, but this one should
https://www.dropbox.com/s/ve8pmh2ldn4gc ... ar.gz?dl=0
Awesome, thanks very much Jeremy. I'll give it a try tonight.

MintSlow2Boot
Level 1
Level 1
Posts: 22
Joined: Tue Dec 27, 2016 2:08 pm

Re: Can't rebuild ch341.c driver in kernel

Post by MintSlow2Boot » Mon Jan 02, 2017 1:35 pm

All good, thanks JeremyB.

Post Reply

Return to “Hardware Support”