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_Write returning FT_OK but BytesWritten is 0  (Read 1379 times)

Liam

  • Newbie
  • *
  • Posts: 1
    • View Profile
FT_Write returning FT_OK but BytesWritten is 0
« on: August 23, 2019, 03:02:45 PM »

Hello;

We have a project using the FTDI driver (ftd2xx.dll) that generally works for loads of customers without problems. However I recently had a customer where communication between the software and device was failing, and it turns out that the FT_Write function was returning FT_OK but the 'BytesWritten' field was returned set to 0. 

Can anyone tell me under what possible conditions this could happen? I can't find anything online or in the documentation. It looks as if a failure to write any data should return an error code, but it doesn't. It's not something I've seen before - in the past we have seen FT_Write fail with an error code of 4 (FT_IO_ERROR) and it's because the device has been unplugged.

Re-plugging the device's USB connection seems to have solved the issue for now, but it has happened a couple of times for this customer and I'd like to get to the bottom of what is causing it.

Thanks

Liam
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 354
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #1 on: August 26, 2019, 04:42:38 PM »

Hello Liam,

Which driver version and IC are you using?

Has BytesWritten been initialised correctly first? This would be good practise.

You could also try FT_Purge.

What are your timeouts set to in FT_SetTimeouts? Could it be that it's timing out before there is enough time to send the data?
Remember USB is non-deterministic. There can be lots happening on a USB bus or with the OS which can cause delays.

See the D2XX Programmer's Guide for more information.

Also AN232B-04 Data Throughput, Latency & Handshaking provides some useful information and applies to all FTDI devices.

Best Regards,
FTDI Community
Logged

gabriel.au

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #2 on: October 01, 2019, 07:45:55 PM »

Hi,
  I'm not the original poster, but I'm having the same problem.  I'm using FTD2XX Library version: 00010112 with the FT232HL.  I've tried setting the timeouts to 50000 and the problem still occurs. 

My application is programming an FPGA.  I use the FTDI in FIFO mode to talk to a CPLD which reads the data from the FTDI and then writes it out to the FPGA configuration pins.  It's a custom implementation; it doesn't follow the FPGA configuration examples that FTDI provides.  The OS in my case is linux.  The latency is not important but the bytes must all arrive correctly without any data loss or corruption or else the FPGA configuration will fail.

Resetting the USB hub can clear this error condition and make the configuration pass every time.  But when the hub is in this 'bad' state, the FPGA configuration fails 2 out of 3 tries.

When the FT_Write fails, there's no error code but 0 bytes were written.  If I dump all the USB accesses from the linux kernel (https://technolinchpin.wordpress.com/2015/10/23/usb-bus-sniffers-for-linux-system/) I see a EPROTO protocol error from the bulk OUT transfer that fails.  I don't see that error when the configuration succeeds.  I tried resending the failed block and also just ignoring the failure but both still fail to configure the FPGA.  I also tried periodically checking FT_GetStatus to see if there were bytes in the queue but it always read 0.

I've also tried using the libftdi driver and I get a similar problem but it doesn't error on the write.  It still gets the EPROTO in the linux kernel and the FPGA configuration fails so I suspect that driver just ignores whatever error is happening.

This problem just showed up recently, coinciding with a new CPU model.  This design was used with an older slower CPU without problems.  I think the faster CPU might be writing too fast.  What is the flow control method for OUT data?  How is the FTDI supposed to throttle the CPU?  Does the FT232H generate USB NAKs and/or NYETs?

thanks,
Gabe
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 354
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #3 on: October 04, 2019, 03:31:03 PM »

Hello, if you are using FIFO mode, please see the following Tech Note which should help:

TN_167 FTDI FIFO Basics

Flow control must be set to CTS_RTS in the application, even though these signals are not physically used. This will avoid any data loss.

Are you using Sync or Async FIFO mode?

Are you using known good hardware? Test with C232HD cables, UM232H-B, UM232H.

It's a custom implementation and uses an external hub so is difficult to support. Is the results the same when the USB hub is removed?

Best Regards,
FTDI Community
Logged

gabriel.au

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #4 on: October 04, 2019, 08:07:06 PM »

Thanks for responding.

We are using Async FIFO mode.  The hardware has been in use for years with a different CPU so the FTDI/CPLD/FPGA side is known good.
The USB "hub" is internal to the CPU SoC so it can't be removed.

I tried the CTS_RTS setting and it still failed the same way.
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 354
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #5 on: October 07, 2019, 04:34:49 PM »

Hello,

What are the differences between the old and new CPU models?

The hub is part of the issue, you have mentioned resetting clears the problem.

Please test with our know good hardware. Links to these are in the previous post.

Best Regards,
FTDI Community
Logged

liquidair

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #6 on: January 17, 2020, 05:58:36 PM »

Any update on this? I too am having a similar problem with the FT201X where the C# version of FT_Write will return FT_OK but nothing is written. In my case, BytesWritten gives the correct value, however. When you try to read this data via i2c the chip returns 0, as does using the 'Read Data Available" command. Been stuck for a month now.
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 354
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #7 on: January 21, 2020, 04:30:47 PM »

Hello liquidair,

The original posts seem slightly different to your issue.

Which C# wrapper are you using? Are you using custom hardware?
This is not a common issue with FT201X I2C slave.

Have you referred to AN_255 USB to I2C Example Using the FT232H and FT201x Devices for examples on how to use FT201X?
The code can be downloaded here.

The I2C routines involve using standard D2xx functions to send buffers of commands and read bytes back from the FT232H. The routines can therefore be ported over to any other operating systems which support the D2xx drivers. Likewise, the routines can be used in other languages such as Visual Basic and C# by modifying them to use the correct syntax for the required language.

Best Regards,
FTDI Community
Logged

gabriel.au

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #8 on: January 21, 2020, 10:13:15 PM »

Sorry, I ended up resolving this but never posted the final results.

It turned out to be a problem with the hub IC.  It was built into the CPU SOC and it would randomly lower the output voltage of the D+/D- signals sometimes so that the FTDI couldn't discern the signal.  We never got the vendor to admit why.  We eventually got a work around in the bios by changing the hub from xHCI to EHCI Controller.  The hub had USB 3.0 ports which we weren't using and I think they were confusing the 2.0 ports by trying to negotiate sometimes?  Not sure.  By using the EHCI controller it forced the USB 3.0 ports off and the problem went away.
Logged

liquidair

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #9 on: January 22, 2020, 09:36:46 PM »

Thank you gabriel.au! I'm definitely not having the same issue based on your response!

Logged

liquidair

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #10 on: January 22, 2020, 10:01:26 PM »

@FTDI Community,

I'm using the FTD2XX_NET_v1.1.0 wrapper from you guys and custom hardware, an AVR microcontroller. There's multiple i2c IO expanders in this design that all read and write i2c perfectly so it's not an i2c thing, and I can do everything else from the computer to the chip just fine. It's only Write (maybe read too but I haven't gotten that far).

Yes, I've referred to AN_255; I've literally read every app note of yours i can find multiple times but nothing works. I've even attempted to use the FTD2XX with a C++ console app and that won't work either.

What I think is happening is that Visual Studio updated the standard libraries with VS2019 and it broke the driver. My C++ console code, which is literally code copied out of the D2XX programmer's guide, will not compile when using the static driver (yes, I did follow along with TN_153 for this)...all errors come from inside the driver (which I can't access). When substituting the dll version, the code compiles but will not connect to the device. I contacted tech support a while back and he had no issues with the same code in VS2010 or 2017 i believe, but did have the same issues with VS2019.
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 354
    • View Profile
Re: FT_Write returning FT_OK but BytesWritten is 0
« Reply #11 on: January 24, 2020, 04:33:38 PM »

Hello,

Which driver version is installed? The latest is 2.12.28.

Can you please test with our standard hardware to rule out any issues with OEM hardware?

See our Development Modules:

FT-X Breakout Modules
FT-X Development Modules

It looks like you are also into contact with our support team via email. Please continue to work with your local support team member and feel free to post any resolution here to help other users.

Best Regards,
FTDI Community
Logged