Re: Getting nonstandard serial baud rates w/FTDI

2007-10-25 Thread Bernd Walter
On Thu, Oct 25, 2007 at 08:52:48AM -0700, Brooks Talley wrote:
> Thanks to everyone who applied.  The OpenBSD approach to setting UFTDI baud 
> rates is definitely superior.
> 
> However, the root of my problem turned out to be Python.  Even with the new 
> baud rate hardcoded in the UFTDI kernel module and manually added to 
> termios.h, Python was refusing to admit that it was a valid baud rate.
> 
> The issue is that Python (2.5.1) compiles its own termios interface module, 
> which builds a list of allowed baud rates from the defines in termios.h.  
> Python's termios.c does something like this:
> 
> include 
> termios_constants[] = {
>{"B300",B300},
>{"B1200",B1200},
>{"B2400",B2400},
> .
> .
> .
> #ifdef B115200
>{"B115200",B115200}
> #endif
> #ifdef B230400
>{"B230400",B230400}
> #endif
> 
> So of course my new buad rate never got added to the list.  It's a fairly 
> ugly problem, because the valud baud rates are set in #defines in termios.h 
> and Python wants an array of them, and of course there's no way (that I know 
> of) to enumerate defines and get a list of those that start with "B" followed 
> by numbers (and, of course, for all I know there's some other BX define 
> somewhere that is not intended to indicate an allowed baud rate).
> 
> The real solution would be to use the OpenBSD UFTDI baud rate generator and 
> update Python's termios.c to avoid the list of valid baud rates and have it 
> just ask the serial port to set the requested rate and report back any error. 
>  But that requires far more than my meager skills.  I just added another 
> hardcoded #ifdef to Python's termios.c and it is all working now.

I will take care about the ftdi driver within the next days, but will
not MFC it until the releases are done.
The python part is left for someone else.

-- 
B.Walterhttp://www.bwct.de  http://www.fizon.de
[EMAIL PROTECTED]   [EMAIL PROTECTED][EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Getting nonstandard serial baud rates w/FTDI

2007-10-25 Thread Brooks Talley
Thanks to everyone who applied.  The OpenBSD approach to setting UFTDI baud 
rates is definitely superior.

However, the root of my problem turned out to be Python.  Even with the new 
baud rate hardcoded in the UFTDI kernel module and manually added to termios.h, 
Python was refusing to admit that it was a valid baud rate.

The issue is that Python (2.5.1) compiles its own termios interface module, 
which builds a list of allowed baud rates from the defines in termios.h.  
Python's termios.c does something like this:

include 
termios_constants[] = {
   {"B300",B300},
   {"B1200",B1200},
   {"B2400",B2400},
.
.
.
#ifdef B115200
   {"B115200",B115200}
#endif
#ifdef B230400
   {"B230400",B230400}
#endif

So of course my new buad rate never got added to the list.  It's a fairly ugly 
problem, because the valud baud rates are set in #defines in termios.h and 
Python wants an array of them, and of course there's no way (that I know of) to 
enumerate defines and get a list of those that start with "B" followed by 
numbers (and, of course, for all I know there's some other BX define 
somewhere that is not intended to indicate an allowed baud rate).

The real solution would be to use the OpenBSD UFTDI baud rate generator and 
update Python's termios.c to avoid the list of valid baud rates and have it 
just ask the serial port to set the requested rate and report back any error.  
But that requires far more than my meager skills.  I just added another 
hardcoded #ifdef to Python's termios.c and it is all working now.

-Brooks
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Getting nonstandard serial baud rates w/FTDI

2007-10-24 Thread Bernd Walter
On Thu, Oct 25, 2007 at 10:11:36AM +1000, Antony Mawer wrote:
> On 25/10/2007 8:59 AM, Bernd Walter wrote:
> >On Wed, Oct 24, 2007 at 09:53:06AM -0700, Brooks Talley wrote:
> >>Hi, everyone.  I'm pulling my hair out in great chunks.
> >>
> >>I need to get Python 2.5, using pyserial 2.2, to open a FTDI-based usb to 
> >>serial port at 25 baud.  The FTDI chip definitely supports this rate. 
> >>The port mounts at /dev/cuaU0.
> >>
> >>The problem is that 
> >>/usr/local/lib/python2.5/site-packages/serial/serialposix.py fails on 
> >>this line:
> >>ispeed = ospeed = getattr(TERMIOS,'B%s' % (self._baudrate))
> ...
> >>Any ideas on how to get this to work?  It doesn't seem like it should be 
> >>this difficult!
> >
> >You need to add support in the uftdi driver itself.
> >There is an enum containing ftdi_8u232am_* fields and a switch/case in
> >the driver.
> >
> >The hex value divides the 48MHz clock and leaves a factor 8.
> >So 0x0018 should be the right value for 25bps.
> >
> >There is an OpenBSD patch to calculate the rates dynamically:
> >http://archive.openbsd.nu/?ml=openbsd-tech&a=2006-06&m=2083975
> >Something similar (but in better style IMHO) is commited to OpenBSD,
> >which we should merge into our source.
> 
> 
> There looks to me to be an issue with an assignment operation (=) rather 
> than equality test (==) in the following section of the patch:
> 
> 
> + /* Special cases for 2M and 3M. */
> + if ((speed >= UI(300 * 0.97)) && (speed = UI(200 * 0.97)) \
> && (speed <= UI(200 * 1.03))) { result = 1; goto done; }
> 
> 
> I would imagine the "(speed = UI(200 * 0.97))" should be == rather 
> than = for this to make sense...?

Use the OpenBSD code instead - it is tested and generaly looks better.
You can easily get their diffs via cvs.
Rev 1.11 of uftdireg.h and 1.29 of uftdi.c

-- 
B.Walterhttp://www.bwct.de  http://www.fizon.de
[EMAIL PROTECTED]   [EMAIL PROTECTED][EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Getting nonstandard serial baud rates w/FTDI

2007-10-24 Thread Antony Mawer

On 25/10/2007 8:59 AM, Bernd Walter wrote:

On Wed, Oct 24, 2007 at 09:53:06AM -0700, Brooks Talley wrote:

Hi, everyone.  I'm pulling my hair out in great chunks.

I need to get Python 2.5, using pyserial 2.2, to open a FTDI-based usb to 
serial port at 25 baud.  The FTDI chip definitely supports this rate.  The 
port mounts at /dev/cuaU0.

The problem is that 
/usr/local/lib/python2.5/site-packages/serial/serialposix.py fails on this line:
ispeed = ospeed = getattr(TERMIOS,'B%s' % (self._baudrate))

...

Any ideas on how to get this to work?  It doesn't seem like it should be this 
difficult!


You need to add support in the uftdi driver itself.
There is an enum containing ftdi_8u232am_* fields and a switch/case in
the driver.

The hex value divides the 48MHz clock and leaves a factor 8.
So 0x0018 should be the right value for 25bps.

There is an OpenBSD patch to calculate the rates dynamically:
http://archive.openbsd.nu/?ml=openbsd-tech&a=2006-06&m=2083975
Something similar (but in better style IMHO) is commited to OpenBSD,
which we should merge into our source.



There looks to me to be an issue with an assignment operation (=) rather 
than equality test (==) in the following section of the patch:



+   /* Special cases for 2M and 3M. */
+   if ((speed >= UI(300 * 0.97)) && (speed = UI(200 * 0.97)) \
&& (speed <= UI(200 * 1.03))) { result = 1; goto done; }


I would imagine the "(speed = UI(200 * 0.97))" should be == rather 
than = for this to make sense...?


--Antony
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: Getting nonstandard serial baud rates w/FTDI

2007-10-24 Thread Bernd Walter
On Wed, Oct 24, 2007 at 09:53:06AM -0700, Brooks Talley wrote:
> 
> Hi, everyone.  I'm pulling my hair out in great chunks.
> 
> I need to get Python 2.5, using pyserial 2.2, to open a FTDI-based usb to 
> serial port at 25 baud.  The FTDI chip definitely supports this rate.  
> The port mounts at /dev/cuaU0.
> 
> The problem is that 
> /usr/local/lib/python2.5/site-packages/serial/serialposix.py fails on this 
> line:
> ispeed = ospeed = getattr(TERMIOS,'B%s' % (self._baudrate))
> 
> So far, I have applied these patches to uftdi.c and uftdireg.h:
> http://tinyurl.com/2yye2l
> 
> Approaching this with a machete, I have also updated 
> /usr/src/lib/libc/gen/termios.h to add B25, and rebuilt world and the 
> kernel, and confirmed that the updated termios.h made it to /usr/include and 
> /usr/include/sys.

termios.h is not important - they are just constants, you should be able
to use raw values in software.

> Any ideas on how to get this to work?  It doesn't seem like it should be this 
> difficult!

You need to add support in the uftdi driver itself.
There is an enum containing ftdi_8u232am_* fields and a switch/case in
the driver.

The hex value divides the 48MHz clock and leaves a factor 8.
So 0x0018 should be the right value for 25bps.

There is an OpenBSD patch to calculate the rates dynamically:
http://archive.openbsd.nu/?ml=openbsd-tech&a=2006-06&m=2083975
Something similar (but in better style IMHO) is commited to OpenBSD,
which we should merge into our source.

-- 
B.Walterhttp://www.bwct.de  http://www.fizon.de
[EMAIL PROTECTED]   [EMAIL PROTECTED][EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Getting nonstandard serial baud rates w/FTDI

2007-10-24 Thread Brooks Talley

Hi, everyone.  I'm pulling my hair out in great chunks.

I need to get Python 2.5, using pyserial 2.2, to open a FTDI-based usb to 
serial port at 25 baud.  The FTDI chip definitely supports this rate.  The 
port mounts at /dev/cuaU0.

The problem is that 
/usr/local/lib/python2.5/site-packages/serial/serialposix.py fails on this line:
ispeed = ospeed = getattr(TERMIOS,'B%s' % (self._baudrate))

So far, I have applied these patches to uftdi.c and uftdireg.h:
http://tinyurl.com/2yye2l

Approaching this with a machete, I have also updated 
/usr/src/lib/libc/gen/termios.h to add B25, and rebuilt world and the 
kernel, and confirmed that the updated termios.h made it to /usr/include and 
/usr/include/sys.

Any ideas on how to get this to work?  It doesn't seem like it should be this 
difficult!

Thanks
-Brooks
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"