4

I need to run my /dev/ttyUSB0 (prolific pl2303 USB-RS232 converter) at 250kbps using c. Everywhere I looked everyone said that the nearest achievable speed is 230400 bps (http://lxr.linux.no/#linux+v3.9.5/drivers/usb/serial/pl2303.c and a few lines later (line 325) "NOTE: Only the values defined in baud_sup are supported !"). But I'm 100% sure that it can be done, because on windows (using c# default SerialPort component) I can just set 250000 as the baudrate, and it wil happily put out data at that speed (measured with an oscilloscope, so it's not switching to the nearest available or to 9600 as described in the linux driver at line 325!).

Does anyone know a way to set tat custom baudrate in linux?

And before you ask, I have developed a device that communicates at 250kbps, that speed is needed and is the highest I can get without errors, so no I can't change it.

Bhavin
  • 27,155
  • 11
  • 55
  • 94
MGG
  • 93
  • 1
  • 9
  • termios2 doesn't work, the code posted [here](http://mail.python.org/pipermail/python-list/2012-October/633871.html) sets the baudrate to the nearest available (230.4k) – MGG Jun 08 '13 at 17:58
  • Looks like it's an issue with PL2303 linux drivers. All the code works great on an FTDI-based converter, so I'm using that one for the time being. I'm still curious about the tricks used by windows to get 250k from a device clocked at 460800 (got that info from 'setserial -a /dev/ttyUSB0') so I might try to sniff USB traffic in windows when I have time. – MGG Jun 08 '13 at 18:31
  • I suspect the `460800` is not the port's internal clock but a divided value. In any case, sounds like you are on you way. Please post your own answer when you find the solution. BTW, windows 250000 maybe only be 250000-ish. As I am sure you know the baud can tolerate a few % error. – chux - Reinstate Monica Jun 08 '13 at 18:49
  • 1
    It's a problem in the linux driver. From [line 333](http://lxr.free-electrons.com/source/drivers/usb/serial/pl2303.c#L333) to line 348, the driver forces a baudrate. Removing that code, the baudrate gets calculated with the formula [12*1000*1000*32 / baud](http://lxr.free-electrons.com/source/drivers/usb/serial/pl2303.c#L364), and that gives an error of 0% at 250kbps, perfectly in line with what I get on windows. I'm looking forward to improve the official driver, if you know how [please help me](http://stackoverflow.com/questions/17002921/propose-modification-of-a-linux-driver)! :) – MGG Jun 08 '13 at 19:14
  • We're currently working on support for arbitrary baud rates in the PL2303 driver: http://thread.gmane.org/gmane.linux.usb.general/87717/focus=89380 –  Jul 12 '13 at 14:05
  • FWIW, I'm using FTDI chips with their VCP driver on x86 Linux at 250000 baud and I see 250000 baud. – Jim Fred Sep 12 '13 at 16:47

1 Answers1

5

It's a problem in the linux driver. From line 333 to line 348, the driver forces a baudrate. Removing that code, the baudrate gets calculated with the formula 12 * 1000 * 1000 * 32 / baud, and that gives an error of 0% at 250kbps, perfectly in line with what I get on windows. I'm looking forward to improve the official driver.

Diego
  • 5,326
  • 1
  • 35
  • 32
MGG
  • 93
  • 1
  • 9
  • 1
    Note: since I posted this comment, after a discussion on the mailing list the driver has been edited. To see the code I was referring to, follow this [link](http://lxr.free-electrons.com/source/drivers/usb/serial/pl2303.c?v=3.10#L333). – MGG Feb 09 '14 at 13:57