On Mon, Dec 19, 2016 at 2:58 AM, Johan Hovold <jo...@kernel.org> wrote: > On Sat, Dec 17, 2016 at 03:27:43AM -0800, Russell Senior wrote: >> All testing is with minicom. > > Thanks for this through report. > >> Starting with 00013-gc510871: >> >> In 8-bit mode, interoperates correctly with pl2303. Switching to >> 5-bit mode on both sides (I get unicode boxes of indeterminate >> values). Switching back to 8-bit mode on both sides, I get correct >> text out both sides. Switching just the ch341 side back to 5-bit >> mode, I get 0xff's out on the pl2303 side (still in 8-bit mode). This >> would seem to imply that byte-size changes are working on this >> version. Changing baud rate also works. > > Can you verify also what comes through in 5-bit mode is indeed what's > expected (e.g. 'a' -> 0x01, 'b' -> 0x02, ...)? > > You can enable usb-serial debugging to get a log of what is received: > > modprobe usbserial dyndbg==p >
Yes, it does seem that I'm getting the 5-bit truncation. Here is an excerpt from the prodigious logs, in this case sending a 'Z' from pl2303 and receiving an 0x5a on the ch341. The same sort of thing, e.g. 'A' (0x41) from the ch341 lands as an 0x01 on the pl2303, 0x42 -> 0x02, etc. Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_chars_in_buffer Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_chars_in_buffer - returns 0 Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_write_room Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_write_room - returns 4096 Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_tiocmget Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_ioctl - cmd 0x5401 Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_chars_in_buffer Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_chars_in_buffer - returns 0 Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_write_room Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_write_room - returns 4096 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_chars_in_buffer Dec 19 08:22:53 willard kernel: pl2303 ttyUSB1: usb_serial_generic_chars_in_buffer - returns 0 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_write_room Dec 19 08:22:53 willard kernel: pl2303 ttyUSB1: usb_serial_generic_write_room - returns 4096 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_tiocmget Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_ioctl - cmd 0x5401 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_chars_in_buffer Dec 19 08:22:53 willard kernel: pl2303 ttyUSB1: usb_serial_generic_chars_in_buffer - returns 0 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_write_room Dec 19 08:22:53 willard kernel: pl2303 ttyUSB1: usb_serial_generic_write_room - returns 4096 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_chars_in_buffer Dec 19 08:22:53 willard kernel: pl2303 ttyUSB1: usb_serial_generic_chars_in_buffer - returns 0 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_write_room Dec 19 08:22:53 willard kernel: pl2303 ttyUSB1: usb_serial_generic_write_room - returns 4096 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_write - 1 byte(s) Dec 19 08:22:53 willard kernel: pl2303 ttyUSB1: usb_serial_generic_write_start - length = 1, data = 5a Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_tiocmget Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_ioctl - cmd 0x5401 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_chars_in_buffer Dec 19 08:22:53 willard kernel: pl2303 ttyUSB1: usb_serial_generic_chars_in_buffer - returns 1 Dec 19 08:22:53 willard kernel: tty ttyUSB1: serial_write_room Dec 19 08:22:53 willard kernel: pl2303 ttyUSB1: usb_serial_generic_write_room - returns 4096 Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_read_bulk_callback - urb 1, len 1 Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_read_bulk_callback - length = 1, data = 1a Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_submit_read_urb - urb 1 Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_chars_in_buffer Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_chars_in_buffer - returns 0 Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_write_room Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_write_room - returns 4096 Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_tiocmget Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_ioctl - cmd 0x5401 Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_chars_in_buffer Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_chars_in_buffer - returns 0 Dec 19 08:22:53 willard kernel: tty ttyUSB0: serial_write_room Dec 19 08:22:53 willard kernel: ch341-uart ttyUSB0: usb_serial_generic_write_room - returns 4096 >> 00014-g79e475a: >> >> dmesg shows on insert: >> >> [ 1430.504116] usb 6-2: new full-speed USB device number 3 using uhci_hcd >> [ 1430.682143] usb 6-2: New USB device found, idVendor=1a86, idProduct=7523 >> [ 1430.682148] usb 6-2: New USB device strings: Mfr=0, Product=2, >> SerialNumber=0 >> [ 1430.682152] usb 6-2: Product: USB2.0-Ser! >> [ 1430.686294] ch341 6-2:1.0: ch341-uart converter detected >> [ 1430.689122] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (pre version) >> [ 1430.693121] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post init-0) >> [ 1430.693124] usb 6-2: ch341_set_baudrate_lcr - speed = 9600, lcr = >> c3, a = b202 >> [ 1430.696120] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post divisor) >> [ 1430.699119] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post lcr) >> [ 1430.700501] usb 6-2: ch341-uart converter now attached to ttyUSB0 >> >> Changing baud rate and then byte-size: >> >> [ 1621.189700] usb 6-2: ch341_set_baudrate_lcr - speed = 9600, lcr = >> c3, a = b202 >> [ 1621.193556] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post divisor) >> [ 1621.196557] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post lcr) >> [ 1621.199565] usb 6-2: ch341_set_baudrate_lcr - speed = 115200, lcr = >> c3, a = cc03 >> [ 1621.202571] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post divisor) >> [ 1621.205569] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post lcr) >> [ 1621.207572] usb 6-2: ch341_set_baudrate_lcr - speed = 115200, lcr = >> c3, a = cc03 >> [ 1621.210570] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post divisor) >> [ 1621.213573] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post lcr) >> [ 1644.117396] usb 6-2: ch341_set_baudrate_lcr - speed = 9600, lcr = >> c3, a = b202 >> [ 1644.120933] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post divisor) >> [ 1644.123952] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post lcr) >> [ 1666.950341] usb 6-2: ch341_set_baudrate_lcr - speed = 9600, lcr = >> c0, a = b202 >> [ 1666.954320] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post divisor) >> [ 1666.957316] usb 6-2: ch341_dbg - [0x2518] = c0 00, [0x1213] = 00 00 >> (post lcr) >> [ 1700.500318] usb 6-2: ch341_set_baudrate_lcr - speed = 9600, lcr = >> c3, a = b202 >> [ 1700.503845] usb 6-2: ch341_dbg - [0x2518] = c0 00, [0x1213] = 00 00 >> (post divisor) >> [ 1700.506866] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post lcr) >> >> It works in 8-bit mode, I can change to 5-bit mode and then back, as >> before. And I can change baud rate. > > Note that you only need to test this commit, which simply adds the > debugging printks on top of the previous. > > The log indicates that the LCR is updated correctly, but also reveals > that the divisor registers always read back as zero even if changing > speeds appear to work. Both my devices read back the values set either > through direct register write or using the init commmand. > > We may be able to use this to detect these devices and fall back to > direct register writes. > >> 00015-gee5a27b: > >> I can switch baud rate and byte size back and forth and it seems to >> work. In 5-bit mode, I guess minicom just doesn't know how to render >> the values, so that makes sense, switching back to 8-bit mode and I >> get readable text again. So, this one is working too, afaict. > > Good, this one only differs from the previous in that the 7th bit of the > divisor register is set, something which is required for CH341A. Good to > know it does not seem to have any negative effects for this device. > >> 00016-ga06b45d: >> >> dmesg on insert: >> >> [ 2588.016052] usb 6-2: new full-speed USB device number 5 using uhci_hcd >> [ 2588.189182] usb 6-2: New USB device found, idVendor=1a86, idProduct=7523 >> [ 2588.189187] usb 6-2: New USB device strings: Mfr=0, Product=2, >> SerialNumber=0 >> [ 2588.189192] usb 6-2: Product: USB2.0-Ser! >> [ 2588.193366] ch341 6-2:1.0: ch341-uart converter detected >> [ 2588.196146] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (pre version) >> [ 2588.200162] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post init-0) >> [ 2588.200165] usb 6-2: ch341_set_baudrate_lcr - speed = 9600, lcr = >> c3, a = b202 >> [ 2588.203182] usb 6-2: ch341_dbg - [0x2518] = c3 00, [0x1213] = 00 00 >> (post init) >> [ 2588.204488] usb 6-2: ch341-uart converter now attached to ttyUSB0 >> >> This doesn't work. Even when matching baud rate and byte size, the >> best I get is 0xff's out on the ch341. Nothing decodes as printable >> anything at the pl2303 side. > > Ok, so the init command cannot be used to switch baud rate for these > devices. > > Could you see if you can communicate using 19200 baud (when using this > or the next commit), which is the default baud rate for the devices I > have (i.e. default settings are 19200 8N1). 19200 8N1 on this commit does not work. > >> 00017-g6edc283: > >> This doesn't work either. At 9600 8N1, I get 0xff's on the pl2303, >> and some unicode on the ch341. > > If the baud rate cannot be set using the init command, then this should > behave as the previous commit. 19200 baud might work. > >> Let me know if I can test anything else! > > Apart from the two additional tests mentioned above, can you also > provide a log from when connecting the device using the following commit > that I just pushed to the ch341 branch: > > f341ee36198d ("dbg: ch341: add register dumps to probe") > > which provides dumps of the register settings during initialisation. > (Make sure ch341 dynamic debugging is not enabled to avoid cluttering > the log.) I'll send this in a followup, need to rebuild. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html