Project

General

Profile

Feature #12756

Support for CH340 USB Serial device

Added by Jorge Schrauwen 5 months ago. Updated about 1 month ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

2020-05-19T13:49:35.571019+00:00 boron usba: [ID 912658 kern.info] USB 1.10 device (usb1a86,7523) operating at full speed (USB 1.x) on USB 1.10 external hub: device@1, usb_mid3 at bus address 8
2020-05-19T13:49:35.571066+00:00 boron usba: [ID 349649 kern.info] USB2.0-Serial
2020-05-19T13:49:35.571081+00:00 boron genunix: [ID 936769 kern.info] usb_mid3 is /pci@0,0/pci15d9,95e@14/hub@e/device@1
2020-05-19T13:49:35.571092+00:00 boron genunix: [ID 408114 kern.info] /pci@0,0/pci15d9,95e@14/hub@e/device@1 (usb_mid3) online
2020-05-19T13:49:35.571379+00:00 boron usba: [ID 349649 kern.info] usba:#011no driver found for interface 0 (nodename: 'interface') of USB2.0-Serial

Looks like USB to Serial devices based on CH340 do not work.

I found this datasheet https://cdn.sparkfun.com/datasheets/Dev/Arduino/Other/CH340DS1.PDF

FreeBSD seems to use this driver when I plug it into my rasberrypi: https://github.com/freebsd/freebsd/blob/f6abce8e79ecc1992d2d0b2e53f8e92ab3102671/sys/dev/usb/serial/uchcom.c


Files

backup_vendor_1.patch (66.4 KB) backup_vendor_1.patch Jorge Schrauwen, 2020-09-20 12:16 PM
init_attempt.patch (14.9 KB) init_attempt.patch Jorge Schrauwen, 2020-09-20 12:20 PM
#1

Updated by Jorge Schrauwen 5 months ago

Could not find any better datasheets but I did find the source on OpenBSD

https://github.com/openbsd/src/blob/b66614995ab119f75167daaa7755b34001836821/sys/dev/usb/uchcom.c

#2

Updated by Jorge Schrauwen 5 months ago

[root@boron ~]# mdb -ke '::prtusb'
INDEX   DRIVER      INST  NODE          GEN  VID.PID     PRODUCT
1       xhci        0     pci15d9,95e   3.0  0000.0000   No Product String
2       scsa2usb    0     storage       2.1  0781.5583   Ultra Fit
3       hubd        0     hub           2.0  0557.7000   No Product String
4       usb_mid     0     device        1.1  0557.2419   No Product String
5       usb_mid     1     device        1.1  1a86.7523   USB2.0-Serial
[root@boron ~]# mdb -ke '::prtusb -v'
INDEX   DRIVER      INST  NODE          GEN  VID.PID     PRODUCT
1       xhci        0     pci15d9,95e   3.0  0000.0000   No Product String

Device Descriptor
{
    bLength = 0x12
    bDescriptorType = 0x1
    bcdUSB = 0x300
    bDeviceClass = 0x9
    bDeviceSubClass = 0
    bDeviceProtocol = 0x3
    bMaxPacketSize0 = 0x9
    idVendor = 0
    idProduct = 0
    bcdDevice = 0
    iManufacturer = 0
    iProduct = 0
    iSerialNumber = 0
    bNumConfigurations = 0x1
}
    -- Active Config Index 0
    Configuration Descriptor
    {
        bLength = 0x9
        bDescriptorType = 0x2
        wTotalLength = 0x1f
        bNumInterfaces = 0x1
        bConfigurationValue = 0x1
        iConfiguration = 0x0
        bmAttributes = 0x40
        bMaxPower = 0x0
    }
        Interface Descriptor
        {
            bLength = 0x9
            bDescriptorType = 0x4
            bInterfaceNumber = 0x0
            bAlternateSetting = 0x0
            bNumEndpoints = 0x1
            bInterfaceClass = 0x9
            bInterfaceSubClass = 0x0
            bInterfaceProtocol = 0x0
            iInterface = 0x0
        }
        Endpoint Descriptor
        {
            bLength = 0x7
            bDescriptorType = 0x5
            bEndpointAddress = 0x81
            bmAttributes = 0x3
            wMaxPacketSize = 0x4
            bInterval = 0x8
        }
            SuperSpeed Endpoint Companion Descriptor
            {
                bLength = 0x6
                bDescriptorType = 0x30
                bMaxBurst = 0x0
                bmAttributes = 0x0
                wBytesPerInterval = 0x2
            }

2       scsa2usb    0     storage       2.1  0781.5583   Ultra Fit

Device Descriptor
{
    bLength = 0x12
    bDescriptorType = 0x1
    bcdUSB = 0x210
    bDeviceClass = 0
    bDeviceSubClass = 0
    bDeviceProtocol = 0
    bMaxPacketSize0 = 0x40
    idVendor = 0x781
    idProduct = 0x5583
    bcdDevice = 0x100
    iManufacturer = 0x1
    iProduct = 0x2
    iSerialNumber = 0x3
    bNumConfigurations = 0x1
}
    -- Active Config Index 0
    Configuration Descriptor
    {
        bLength = 0x9
        bDescriptorType = 0x2
        wTotalLength = 0x20
        bNumInterfaces = 0x1
        bConfigurationValue = 0x1
        iConfiguration = 0x0
        bmAttributes = 0x80
        bMaxPower = 0x70
    }
        Interface Descriptor
        {
            bLength = 0x9
            bDescriptorType = 0x4
            bInterfaceNumber = 0x0
            bAlternateSetting = 0x0
            bNumEndpoints = 0x2
            bInterfaceClass = 0x8
            bInterfaceSubClass = 0x6
            bInterfaceProtocol = 0x50
            iInterface = 0x0
        }
        Endpoint Descriptor
        {
            bLength = 0x7
            bDescriptorType = 0x5
            bEndpointAddress = 0x81
            bmAttributes = 0x2
            wMaxPacketSize = 0x200
            bInterval = 0x0
        }
        Endpoint Descriptor
        {
            bLength = 0x7
            bDescriptorType = 0x5
            bEndpointAddress = 0x2
            bmAttributes = 0x2
            wMaxPacketSize = 0x200
            bInterval = 0x0
        }

3       hubd        0     hub           2.0  0557.7000   No Product String

Device Descriptor
{
    bLength = 0x12
    bDescriptorType = 0x1
    bcdUSB = 0x200
    bDeviceClass = 0x9
    bDeviceSubClass = 0
    bDeviceProtocol = 0x1
    bMaxPacketSize0 = 0x40
    idVendor = 0x557
    idProduct = 0x7000
    bcdDevice = 0
    iManufacturer = 0
    iProduct = 0
    iSerialNumber = 0
    bNumConfigurations = 0x1
}
    -- Active Config Index 0
    Configuration Descriptor
    {
        bLength = 0x9
        bDescriptorType = 0x2
        wTotalLength = 0x19
        bNumInterfaces = 0x1
        bConfigurationValue = 0x1
        iConfiguration = 0x0
        bmAttributes = 0xe0
        bMaxPower = 0x32
    }
        Interface Descriptor
        {
            bLength = 0x9
            bDescriptorType = 0x4
            bInterfaceNumber = 0x0
            bAlternateSetting = 0x0
            bNumEndpoints = 0x1
            bInterfaceClass = 0x9
            bInterfaceSubClass = 0x0
            bInterfaceProtocol = 0x0
            iInterface = 0x0
        }
        Endpoint Descriptor
        {
            bLength = 0x7
            bDescriptorType = 0x5
            bEndpointAddress = 0x81
            bmAttributes = 0x3
            wMaxPacketSize = 0x1
            bInterval = 0xc
        }

4       usb_mid     0     device        1.1  0557.2419   No Product String

Device Descriptor
{
    bLength = 0x12
    bDescriptorType = 0x1
    bcdUSB = 0x110
    bDeviceClass = 0
    bDeviceSubClass = 0
    bDeviceProtocol = 0
    bMaxPacketSize0 = 0x8
    idVendor = 0x557
    idProduct = 0x2419
    bcdDevice = 0x100
    iManufacturer = 0
    iProduct = 0
    iSerialNumber = 0
    bNumConfigurations = 0x1
}
    -- Active Config Index 0
    Configuration Descriptor
    {
        bLength = 0x9
        bDescriptorType = 0x2
        wTotalLength = 0x3b
        bNumInterfaces = 0x2
        bConfigurationValue = 0x1
        iConfiguration = 0x0
        bmAttributes = 0xe0
        bMaxPower = 0x50
    }
        Interface Descriptor
        {
            bLength = 0x9
            bDescriptorType = 0x4
            bInterfaceNumber = 0x0
            bAlternateSetting = 0x0
            bNumEndpoints = 0x1
            bInterfaceClass = 0x3
            bInterfaceSubClass = 0x1
            bInterfaceProtocol = 0x1
            iInterface = 0x0
        }
            HID Descriptor
            {
                bLength = 0x9
                bDescriptorType = 0x21
                bcdHID = 0x100
                bCountryCode = 0x0
                bNumDescriptors = 0x1
                bReportDescriptorType = 0x22
                wReportDescriptorLength = 0x40
            }
        Endpoint Descriptor
        {
            bLength = 0x7
            bDescriptorType = 0x5
            bEndpointAddress = 0x81
            bmAttributes = 0x3
            wMaxPacketSize = 0x8
            bInterval = 0xa
        }
        Interface Descriptor
        {
            bLength = 0x9
            bDescriptorType = 0x4
            bInterfaceNumber = 0x1
            bAlternateSetting = 0x0
            bNumEndpoints = 0x1
            bInterfaceClass = 0x3
            bInterfaceSubClass = 0x1
            bInterfaceProtocol = 0x2
            iInterface = 0x0
        }
            HID Descriptor
            {
                bLength = 0x9
                bDescriptorType = 0x21
                bcdHID = 0x100
                bCountryCode = 0x0
                bNumDescriptors = 0x1
                bReportDescriptorType = 0x22
                wReportDescriptorLength = 0x4f
            }
        Endpoint Descriptor
        {
            bLength = 0x7
            bDescriptorType = 0x5
            bEndpointAddress = 0x82
            bmAttributes = 0x3
            wMaxPacketSize = 0x6
            bInterval = 0x5
        }

5       usb_mid     1     device        1.1  1a86.7523   USB2.0-Serial

Device Descriptor
{
    bLength = 0x12
    bDescriptorType = 0x1
    bcdUSB = 0x110
    bDeviceClass = 0xff
    bDeviceSubClass = 0
    bDeviceProtocol = 0
    bMaxPacketSize0 = 0x8
    idVendor = 0x1a86
    idProduct = 0x7523
    bcdDevice = 0x262
    iManufacturer = 0
    iProduct = 0x2
    iSerialNumber = 0
    bNumConfigurations = 0x1
}
    -- Active Config Index 0
    Configuration Descriptor
    {
        bLength = 0x9
        bDescriptorType = 0x2
        wTotalLength = 0x27
        bNumInterfaces = 0x1
        bConfigurationValue = 0x1
        iConfiguration = 0x0
        bmAttributes = 0x80
        bMaxPower = 0x31
    }
        Interface Descriptor
        {
            bLength = 0x9
            bDescriptorType = 0x4
            bInterfaceNumber = 0x0
            bAlternateSetting = 0x0
            bNumEndpoints = 0x3
            bInterfaceClass = 0xff
            bInterfaceSubClass = 0x1
            bInterfaceProtocol = 0x2
            iInterface = 0x0
        }
        Endpoint Descriptor
        {
            bLength = 0x7
            bDescriptorType = 0x5
            bEndpointAddress = 0x82
            bmAttributes = 0x2
            wMaxPacketSize = 0x20
            bInterval = 0x0
        }
        Endpoint Descriptor
        {
            bLength = 0x7
            bDescriptorType = 0x5
            bEndpointAddress = 0x2
            bmAttributes = 0x2
            wMaxPacketSize = 0x20
            bInterval = 0x0
        }
        Endpoint Descriptor
        {
            bLength = 0x7
            bDescriptorType = 0x5
            bEndpointAddress = 0x81
            bmAttributes = 0x3
            wMaxPacketSize = 0x8
            bInterval = 0x1
        }

We do seem to reference the CH341 variant which seems to have the same driver on *BSD.

http://src.illumos.org/source/xref/illumos-gate/usr/src/uts/common/io/usb/usbdevs

#3

Updated by Jorge Schrauwen 5 months ago

prtconf -v info

            device, instance #1
                Driver properties:
                    name='pm-components' type=string items=3 dev=none
                        value='NAME= usb_mid1 Power' + '0=USB D3 State' + '3=USB D0 State'
                Hardware properties:
                    name='driver-minor' type=int items=1
                        value=00000000
                    name='driver-major' type=int items=1
                        value=00000002
                    name='full-speed' type=boolean
                    name='configuration#' type=int items=1
                        value=00000001
                    name='usb-product-name' type=string items=1
                        value='USB2.0-Serial'
                    name='usb-raw-cfg-descriptors' type=byte items=39
                        value=09.02.27.00.01.01.00.80.31.09.04.00.00.03.ff.01.02.00.07.05.82.02.20.00.00.07.05.02.02.20.00.00.07.05.81.03.08.00.01
                    name='usb-dev-descriptor' type=byte items=18
                        value=12.01.10.01.ff.00.00.08.86.1a.23.75.62.02.00.02.00.01
                    name='usb-release' type=int items=1
                        value=00000110
                    name='usb-num-configs' type=int items=1
                        value=00000001
                    name='usb-revision-id' type=int items=1
                        value=00000262
                    name='usb-product-id' type=int items=1
                        value=00007523
                    name='usb-vendor-id' type=int items=1
                        value=00001a86
                    name='compatible' type=string items=9
                        value='usb1a86,7523.262' + 'usb1a86,7523' + 'usb1a86,classff.0.0' + 'usb1a86.classff.0' + 'usb1a86.classff' + 'usb,classff.0.0' + 'usb,classff.0' + 'usb,classff' + 'usb,device'
                    name='reg' type=int items=1
                        value=0000000d
                    name='assigned-address' type=int items=1
                        value=00000005
                Device Minor Nodes:
                    dev=(142,512)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:usb_mid
                            spectype=chr type=minor
                            dev_link=/dev/usb/device1
                    dev=(142,513)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:1a86.7523.devstat
                            spectype=chr type=minor
                            dev_link=/dev/usb/1a86.7523/0/devstat
                    dev=(142,514)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:1a86.7523.cntrl0
                            spectype=chr type=minor
                            dev_link=/dev/usb/1a86.7523/0/cntrl0
                    dev=(142,515)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:1a86.7523.cntrl0stat
                            spectype=chr type=minor
                            dev_link=/dev/usb/1a86.7523/0/cntrl0stat
                    dev=(142,516)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:1a86.7523.if0in2
                            spectype=chr type=minor
                            dev_link=/dev/usb/1a86.7523/0/if0in2
                    dev=(142,517)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:1a86.7523.if0in2stat
                            spectype=chr type=minor
                            dev_link=/dev/usb/1a86.7523/0/if0in2stat
                    dev=(142,518)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:1a86.7523.if0out2
                            spectype=chr type=minor
                            dev_link=/dev/usb/1a86.7523/0/if0out2
                    dev=(142,519)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:1a86.7523.if0out2stat
                            spectype=chr type=minor
                            dev_link=/dev/usb/1a86.7523/0/if0out2stat
                    dev=(142,520)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:1a86.7523.if0in1
                            spectype=chr type=minor
                            dev_link=/dev/usb/1a86.7523/0/if0in1
                    dev=(142,521)
                        dev_path=/pci@0,0/pci15d9,95e@14/device@d:1a86.7523.if0in1stat
                            spectype=chr type=minor
                            dev_link=/dev/usb/1a86.7523/0/if0in1stat

#4

Updated by Jorge Schrauwen 5 months ago

After some back and forth on IRC, it looks like it indeed needs a new driver as the above file is just a vendor/product list.

A usbser client most be written: https://code.illumos.org/plugins/gitiles/illumos-gate/+/master/usr/src/uts/common/io/usb/clients/usbser

Comparing some existing devices and the openbsd/freebsd driver, I don't think this is something I can do.

#5

Updated by Jorge Schrauwen about 1 month ago

It's a really horrible chip, I've given up on it after poking it on and off for 3+ months.
Mostly succeeded in getting the stick to lock up and needing 5-10 min of no power to recover.

Attached is the latest backup that does not brick the stick, in case anyone in the future comes looking for it.
It doesn't do mutch aside attach.

#6

Updated by Jorge Schrauwen about 1 month ago

Latest version of what I have, I'm struggling with the initialization.

Also available in: Atom PDF