[PATCH] Use BM/R series baud rate computation for FT230X

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH] Use BM/R series baud rate computation for FT230X

Joe Zbiciak
I've reformatted my suggested tweak below as a proper git patch.

commit 3f1f92238eacf6019e985c90013d7d8e1bdf6281
Author: Joe Zbiciak <[hidden email]>
Date:   Sat Aug 13 12:46:16 2016 -0700

    Use BM/R series baud rate computation for FT230X.
    
    The current code uses the AM series baud rate computation for FT230X,
    and this results in incorrect divisor calculation for high baud rates.
    Use the BM/R series logic instead.
    
    This matches the corresponding code paths in the Linux kernel ftdi_sio
    driver.  See ftdi_sio.c:1323 here:
    
    
    Specifically attempts to set 2000000 on an FT230X fail currently due to
    the if-statement at ftdi.c:1106.  The computed divisor (12) gets clamped
    to 16, and thus the for-loop it's in doesn't converge on a usable divisor.
    
    The if-statement at ftdi.c:1152 never fires, as the if-statement at
    ftdi.c:1106 in the for-loop precludes a divisor of 12 (which is required
    for *encoded_divisor to become 0x4001).


On Fri, Aug 12, 2016 at 10:23 PM, Joe Zbiciak <[hidden email]> wrote:
Hello,

I'm trying to use an FT230X with libftdi. 

It appears libftdi doesn't correctly compute the FT230X baud rate divisor.  AFAICT, it's supposed to be computed the same as the FT232R and related devices.  I determined this by looking at the corresponding code in the Linux kernel's fdti_sio.c.

I patched my local copy by modifying line 1255 in ftdi.c.  It currently reads as follows:

else if ((ftdi->type == TYPE_BM) || (ftdi->type == TYPE_2232C) || (ftdi->type == TYPE_R ))

I changed it to read:

else if ((ftdi->type == TYPE_BM) || (ftdi->type == TYPE_2232C) || (ftdi->type == TYPE_R) || (ftdi->type == TYPE_230X))

Prior to the change, I was unable to set a baud rate of 2000000.  After the change, it worked correctly.  I haven't tested other baud rates.  I did, however, compare the code to the Linux kernel code, and it uses the same baud rate computation for the X series as it does for the BM and R series.

I haven't seen any discussion of this issue recently in the list archives.  I did find one thread from over 2 years ago, but it didn't end with a fix.


--



--


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]



0001-Use-BM-R-series-baud-rate-computation-for-FT230X.patch (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] Use BM/R series baud rate computation for FT230X

Thomas Jarosch
Hello Joe,

On Saturday, 13. August 2016 12:49:17 Joe Zbiciak wrote:
> I've reformatted my suggested tweak below as a proper git patch.

good catch and thanks for the git-consumable patch! Applied.

I've also added TYPE_230X to the baudrate unit test.
Can you verify the "fractional_bits" parts is correct?
I just added it to the "correct looking" place.

Cheers,
Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] Use BM/R series baud rate computation for FT230X

Joe Zbiciak
I assume you're referring to this patch to the test case: 


Yes, that looks like the right place in the code to add it, as it includes TYPE_230X under the same branch as TYPE_R and TYPE_BM.  The 'H' devices pack the INTERFACE_{A,B,C,D} into the 8 LSBs of index, while the others do not.  The FT230X data sheet points to the same AN232B-05 app-note for computing divisors as used for the FT232R, FT2232 and FT232B, so based on FTDI's documentation, it matches their recommendations for FT230X.

I looked through why that code is there (reassembling the 3-bit frac_code field, effectively), and that looks right too.  It's taking the 2 MSBs of 'value' and 1 LSB of 'index' to reassemble the 3-bit frac_code, correct?

—J



On Tue, Aug 16, 2016 at 5:57 AM, Thomas Jarosch <[hidden email]> wrote:
Hello Joe,

On Saturday, 13. August 2016 12:49:17 Joe Zbiciak wrote:
> I've reformatted my suggested tweak below as a proper git patch.

good catch and thanks for the git-consumable patch! Applied.

I've also added TYPE_230X to the baudrate unit test.
Can you verify the "fractional_bits" parts is correct?
I just added it to the "correct looking" place.

Cheers,
Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]




--


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Re: [PATCH] Use BM/R series baud rate computation for FT230X

Thomas Jarosch
On Tuesday, 16. August 2016 08:55:54 Joe Zbiciak wrote:
> I assume you're referring to this patch to the test case:
>
> http://developer.intra2net.com/git/?p=libftdi;a=commitdiff;h=71030195f48bb
> f49b84de66a425ae10e5577774e

yes

> Yes, that looks like the right place in the code to add it, as it includes
> TYPE_230X under the same branch as TYPE_R and TYPE_BM.  The 'H' devices
> pack the INTERFACE_{A,B,C,D} into the 8 LSBs of index, while the others
> do not.  The FT230X data sheet points to the same AN232B-05 app-note for
> computing divisors as used for the FT232R, FT2232 and FT232B, so based on
> FTDI's documentation, it matches their recommendations for FT230X.
>
> I looked through why that code is there (reassembling the 3-bit frac_code
> field, effectively), and that looks right too.  It's taking the 2 MSBs of
> 'value' and 1 LSB of 'index' to reassemble the 3-bit frac_code, correct?

I must admit I'm not too deep into the details
of the baudrate calculation code anymore.
You probably know more about than I do :)

Thomas


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Loading...