libftdi Archives

Subject: RE: Help with FT2232H flow control

From: Dave McMahan <dmcmahan@xxxxxxxxxxxx>
To: "libftdi@xxxxxxxxxxxxxxxxxxxxxxx" <libftdi@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 18 Aug 2015 22:22:47 +0000
Anders,

I really would prefer not to have to rebuild the entire Android kernel to solve 
this problem.  There are all kinds of logistical and technical issues for me if 
I have to go that way.  For example, it would mean I would need to instruct my 
users to reflash their Nexus9 image with my new kernel changes.  They would not 
be happy to do this.  I know the chip can do what I need  because I have seen 
it work when using the D2XX libraries on other platforms.



I think I may have found something interesting.

Originally, I was only calling these functions (error checking removed for 
clarity, but I have it in the code):

    ftdiComm = ftdi_new();
    ftdiStatus = ftdi_set_interface(ftdiComm, INTERFACE_B);
    ftdiStatus = ftdi_usb_open(ftdiComm, VID, PID);
    ftdiStatus = ftdi_set_line_property(ftdiComm, BITS_8, STOP_BIT_1, NONE);
    ftdiStatus = ftdi_set_baudrate(ftdiComm, baudrate);    // baudrate = 921600
    ftdiStatus = ftdi_setflowctrl(ftdiComm, SIO_RTS_CTS_HS);      //  Enable 
CTS/RTS hardware flow control

    ftdiComm->usb_read_timeout  = 1;        //  1 millisecond timeout for read 
and write.  There is no API function to set this, so we just write to the 
structure directly
    ftdiComm->usb_write_timeout = 1;

    ftdiStatus = ftdi_set_latency_timer(ftdiComm, 1);           //  Set latency 
to 1 millisecond, the minimum


The code above never sets the RTS pin low on my logic analyzer.

I was reading some forum on this and it gave me an idea.  I added this line 
after setting flow control:

    ftdiStatus = ftdi_setrts(ftdiComm, 1);      //  Set RTS low by default


I assumed that using hardware handshake flow control would automatically 
control the RTS output based on the receive buffer fullness.   Apparently, 
that's not totally true.  It seems like there is a 'default' state defined by 
ftdi_setrts().  I must set that default state to 1 (which makes it come out of 
the pin as 0 volts).   I tried setting it setting it to 0 at first but found 
RTS was always 3.3 volts output, the wrong value for correct flow control.

With this change, I can see RTS goes low at startup.  I then write/read many 
100 byte chunks and that works with RTS never going high because I always read 
the buffer before it fills.

Then, I stop reading and just write 10,000 bytes (some arbitrarily big number 
to fill the receive buffer).  I see RTS goes high during the transmission.  
Woot!!!   After writing 10,000 bytes, I read whatever I can from the buffer.  
RTS goes low when I start pulling data out of the buffer  Woot!!  Woot!!  :-)   
I can read 7,768 bytes from a full receive buffer.

I need to do more testing tomorrow to really make sure all this works like I 
expect.   I also have to implement the GPIO controls on the other port.

Does my understanding of the need to call ftdi_setrts() make sense?  I believed 
it would be useless until I did this test.

   -dave





-----Original Message-----
From: Anders Larsen [mailto:al@xxxxxxxxxxx] 
Sent: Tuesday, August 18, 2015 5:54 PM
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Help with FT2232H flow control

Hi Dave,

On 2015-08-18 23:29, Dave McMahan wrote:
> Anders,
> 
> Thanks for your quick response.
> 
> Unfortunately, I can't use only plain serial communications.  I must  
> use GPIO signals connected to Port A and serial communications on  
> Port B.

that alone is not a problem, it's just a bit tricky to set up.

You must "unbind" Port A from the serial driver in order to use the
GPIO pins with libftdi (will check tomorrow @work how I did that and
report back).

> As far as I can tell on Android Lollipop running on a Nexus9 tablet,  
> there is no kernel driver for ftdi.

It should not be too difficult to build the ftdi_sio kernel module
since the Google has published the Kernel sources.

http://www.androidpolice.com/2014/11/05/google-releases-kernel-source-for-nexus-9-volantis-and-nexus-player-fugu/

> In any event, I must use libftdi to control the GPIO signals (both  
> inputs and outputs) and I thought it would be a bad idea to mix a  
> kernel driver with libftdi calls on the same device at the same time.

It is not a problem using separate drivers to handle the separate USB
endpoints of the FT2232H chip - the ports really are independent.

Cheers
Anders

> > From: Anders Larsen [mailto:al@xxxxxxxxxxx]
> > Sent: Tuesday, August 18, 2015 5:22 PM
> > To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
> > Subject: Re: Help with FT2232H flow control
> >
> > Hi,
> >
> > On 2015-08-18 22:01, Dave McMahan wrote:
> > > Hello,
> > >
> > > I am using the FT2232H chip in an Android (linux) environment.  I  
> am
> > > working with the latest libftdi (version 1.2), libusb (version  
> 1.0).
> > >
> >
> > It sounds as if you are using plain serial communications?
> >
> > If so, the FT2232H should Just Work (tm) - the Kernel driver  
> ftdi_sio.ko
> > should take care of everything, including hardware flow control
> > (without any special libraries like libftdi or D2XX)
> >
> > Cheers
> > Anders
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx

Current Thread