Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for FTDI D2XX driver #2106

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Support for FTDI D2XX driver #2106

wants to merge 2 commits into from

Conversation

mon
Copy link

@mon mon commented Jan 28, 2024

By default in Windows 10, FTDI devices get a proprietary driver installed. This allows you to access MPSSE mode via the "D2XX" interface. The libftd2xx crate provides a safe abstraction over this.

This PR splits the FTDI driver into two parts - a new mode, using D2XX, and the old mode, using "Raw" USB comms (better names encouraged...).

This is a huge boon to user friendliness, because FTDI devices will "just work" instead of needing to grab zadig and give admin permissions and make a self-signed driver. In practice, I've also seen Windows replace the WinUSB driver, making the zadig approach unreliable.

I discovered midway through this PR that probe-rs only supports JTAG via FTDI probes, so I can't actually test it (I only have SWD devices on hand), but I wrote a similar patch for openocd, and didn't encounter any major bugs. Hopefully it's the same here.

@mon mon marked this pull request as draft January 28, 2024 00:29
@mon mon changed the title Draft: Untested support for FTDI D2XX driver Untested support for FTDI D2XX driver Jan 28, 2024
@mon mon changed the title Untested support for FTDI D2XX driver Support for FTDI D2XX driver Jan 28, 2024
"Non-default FTDI interfaces",
));
}
let Some(serial) = usb_device.serial_number() else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have multiple FTDI devices without external EEPROMs, and thus without serial numbers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, you will still have a serial number, it will just be the empty string, so I think it'll still work in your case.

Not being able to map the nusb device path to ftdi device path certainly sucks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this definitely returns an error for me with FTDIs without external EEPROMs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blast, thanks for testing. Do you often need to target a particular device? Could this just lazily use the first device instance? Or should I rework it and try another identification scheme

@bugadani
Copy link
Contributor

Unfortunately, Windows (11) seems very determined to install VCP drivers for my FT2232H. I either wasn't able to coerce it to use freshly installed D2XX drivers (whatever I do, Zadig identifies as FTDIBUS (v2.12.36.4)) or the PR simply doesn't work for me.

@mon
Copy link
Author

mon commented Jan 28, 2024

Unfortunately, Windows (11) seems very determined to install VCP drivers for my FT2232H. I either wasn't able to coerce it to use freshly installed D2XX drivers (whatever I do, Zadig identifies as FTDIBUS (v2.12.36.4)) or the PR simply doesn't work for me.

Interestingly, I get that exact same driver, and initially was setting the "use D2XX" bit in my EEPROM. But I discovered that on my machine at least, it works in d2xx mode out of the box. It might be worth me making some sort of MVP/test app to more obviously report the state of all devices.

@mon
Copy link
Author

mon commented Jan 28, 2024

Out of curiosity, what chip are you using? I'm on a FT232H, which is a little different from the classic FT232R, I wonder if chip types are perhaps treated differently.

@bugadani
Copy link
Contributor

Out of curiosity, what chip are you using?

Mainly a 2232H but I see the same behavior with a 232H.

@mon
Copy link
Author

mon commented Jan 28, 2024

Hmm - one more check (thanks for your help so far) - the libftd2xx list example, does it show anything at all? For reference, mine displays:

device: DeviceInfo { port_open: false, speed: Some(HighSpeed), device_type: FT232H, vendor_id: 0x0403, product_id: 0x6014, serial_number: 123456, description: Programmer }

I'm starting to think that perhaps my serial number filter when opening the device is the true culprit, and this'll help confirm.

@bugadani
Copy link
Contributor

FTDIBUS driver, serial number was programmed by me.

device: DeviceInfo { port_open: false, speed: Some(HighSpeed), device_type: FT232H, vendor_id: 0x0403, product_id: 0x6014, serial_number: 232H00000001, description: FT232H }

FTDI drivers, no serial number (no EEPROM in fact)

device: DeviceInfo { port_open: false, speed: Some(HighSpeed), device_type: FT2232H, vendor_id: 0x0403, product_id: 0x6010, serial_number: B, description: Dual RS232-HS B }
device: DeviceInfo { port_open: false, speed: Some(HighSpeed), device_type: FT2232H, vendor_id: 0x0403, product_id: 0x6010, serial_number: A, description: Dual RS232-HS A }

Interestingly, the 2232H sometimes outputs this for either or both interfaces:

device: DeviceInfo { port_open: true, speed: Some(FullSpeed), device_type: Unknown, vendor_id: 0x0000, product_id: 0x0000, serial_number: , description:  }
device: DeviceInfo { port_open: true, speed: Some(FullSpeed), device_type: Unknown, vendor_id: 0x0000, product_id: 0x0000, serial_number: , description:  }

FT2232H with Interface 0 WinUSB, Interface 1 FTDIBUS (serial number programmed by me)

device: DeviceInfo { port_open: false, speed: Some(HighSpeed), device_type: FT2232H, vendor_id: 0x0403, product_id: 0x6010, serial_number: FT960LNQB, description: Dual RS232-HS B }

Note the interface with WinUSB driver is missing.

- Just open the first device, don't try and be smart with serial
- Check for an empty read queue before we wait {timeout} for it to return 0 bytes
- clippy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants