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

Show Posts

You can view here all posts made by this member. Note that you can only see posts made in areas to which you currently have access.

Messages - ogacns94

Pages: [1]
1
Discussion - Drivers / 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.

Pages: [1]