FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: FT_Read returns 0 bytes using D2XX driver  (Read 11456 times)

ogacns94

  • Newbie
  • *
  • Posts: 1
    • View Profile
FT_Read returns 0 bytes using D2XX driver
« on: November 19, 2020, 01:12:56 PM »



I have been having lots of problems when using the FTDI FT2232HL chip on Linux. My application is writing and reading some data to the chip repetitively using the D2XX driver, and then after a random number of repetitions, the read returns zero bytes.

Here is a bit more information on my setup. The FTDI chip I am using is mounted on a side-channel evaluation board called Sakura-X (http://satoh.cs.uec.ac.jp/SAKURA/hardware/SAKURA-X.html). The board has two FPGAs, one of which (Spartan-6) communicates with the FT2232HL chip. From the host side, I am using Ubuntu 18.04 with the latest D2XX driver from the FTDI website (https://www.ftdichip.com/Drivers/D2XX.htm). I set it up as per the instructions in the README. In the software, I use the FT_Read() and FT_Write() functions to write commands and data to the FPGA and read the status and data from the FPGA. The data I send is encrypted on the FPGA, which I then read from the FPGA using the FTDI. I usually need a very large amount of data to be encrypted (for example 500k plaintexts) consecutively, so I have a loop that repeats the same read/write operations just on different data. The system works in most cases. I write the data to the FPGA and read the correct encrypted data. However, sometimes, the FT_Read() function returns zero bytes (BytesRecieved != RxBytes), causing my software to fault (as per instructions in the FTDI programmer's guide https://www.ftdichip.com/Support/Documents/ProgramGuides/D2XX_Programmer%27s_Guide(FT_000071).pdf). In this case, if I retry the read, it fails until I close the connection with the device and reestablish it again.

On windows, I use a different code that I did not write, but with it, everything works fine. I managed to record up to 1 million encryptions without a read fault. This would indicate that there is no error in the FPGA design, and that there is an error somewhere in my code/D2XX driver. My code on Linux is heavily inspired by the windows code, with the write/read functions basically copy-pasted from C# to C++ and C.

To solve the timeout, I tried many different solutions:

   * Setting the correct data characteristics (FT_SetDataCharacteristics()), to be the same as in the windows code (https://stackoverflow.com/questions/18549270/ft-read-fails-unless-reading-byte-by-byte-where-every-ft-read-is-followed-by-ft)
   * Setting the DTR to low before every read, as it is high by default on ubuntu
   * Using FT_Purge before every read
   * Changing the settings in /etc/udev/rules.d (UDEV rules for FTDI not completely working)
   * Adding delay before each read using usleep() and changing the timeout time

The problem is that I cannot have an unreliable connection with the FPGA device because I need to run a large number of encryptions without any faults. Do you have any advice/ideas on how I should address this problem, and how to solve it?

Thank you very much in advance.
Logged

fcona

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: FT_Read returns 0 bytes using D2XX driver
« Reply #1 on: November 23, 2020, 03:01:16 PM »

Hi ogacns94,
I don't know if you are having my same problem, so I'll describe it here, together with the workaround that worked for me, hoping it will be useful for you too.
My company has been using the D2XX library for quite a long while, mainly on Windows and macOS. Last week we tried it on Linux with our new Raspberry Pi 400.
Basically my application communicates with an FPGA, which can receive some configuration commands (using FT_Write) and streams data continuously (which I read using FT_GetStatus and FT_Read). Now, even if the device streams the data correctly, as can be checked with the windows and mac applications, on linux I receive a bunch of data until the FT_GetStatus stops notifying the presence of new data available in the driver buffer, and the stream stucks. This happens everytime, even if the amount of data received before the driver refuse to work changes with each execution.

This very same thing already happened to me in the past, but in macOS. At the time the latest release of the driver for mac was 1.4.4, and the funny thing was that the application worked just fine with the release I used before, 1.2.2. After a brief email exchange with FTDI support they released version 1.4.16 which fixed my problem. So, I tried to look for an older version of the linux driver, more specifically 1.3.6, and guess what? It worked!

Now, of course you can try an older version of the driver too and hopefully that will solve your issue. However, the version numbers of the drivers for macOS and for linux are suspiciously similar, and probably the underlying source code is very similar too in many respects since they are both unix systems. So maybe, just maybe, the same issue is present in version 1.4.8 of the linux driver, and a merge of the latest bug fixes for the mac driver can fix that too.

Best,

Filippo
Logged

rbwest

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: FT_Read returns 0 bytes using D2XX driver
« Reply #2 on: May 19, 2021, 12:24:31 PM »

Hi, I was wondering whether the Original Poster resolved their problem and how? I have a very similar issue on an FPGA board running Ubuntu when sending lots of short messages. However I am using d2xx V 1.4.22 which is newer than the version which fcona said fixed their problem.
Thanks
Logged