updating fx2pipe to work with libusb-1.0 - Page 1
Forum section: electronics / general

author: NiHaoMike
author_rank: Super Contributor
timestamp: July 18, 2020, 05:17:55 am
content: The Cypress FX2 is a cheap and very versatile high speed interface for USB 2.0. The program fx2pipe makes it easy to use.https://www.triplespark.net/elec/periph/USB-FX2/software/fx2pipe.htmlThe problem is that it was built for libusb-0.1 while nowadays libusb-1.0 is used. Therefore, it doesn't work on a modern OS.Code:mike@DX79SI /bulk/mike/downloads/fx2pipe-0.8/fx2pipe $ ./fx2pipe -i -0 -8 -ifclk=48oFirmware config: 0x12 0xe3 0xe0 0x0c 0x12IO loop running...Downloading firmware ...fx2pipe: wwusb.cc:129: WWUSBDevice::ErrorCode WWUSBDevice::_DoConnect(usb_device*): Assertion `dev_handle_to_dev(udh)==udev' failed.AbortedThe culprit is in the file wwusb.cc:Code:// Totally evil and fragile extraction of file descriptor from// guts of libusb. They don't install usbi.h, which is what we'd need// to do this nicely.//// FIXME if everything breaks someday in the future, look here...static inline int fd_from_usb_dev_handle(usb_dev_handle *udh){return( *((int*)udh) );}// This function is from SSRP: Actually, we don't need it any more.// Danger, big, fragile KLUDGE. The problem is that we want to be// able to get from a usb_dev_handle back to a usb_device, and the// right way to do this is buried in a non-installed include file.static inline struct usb_device *dev_handle_to_dev(usb_dev_handle *udh){struct usb_dev_handle_kludge {int fd;struct usb_bus *bus;struct usb_device *device;};return(((struct usb_dev_handle_kludge *) udh)->device);}As seen fromhttps://github.com/libusb/libusb/blob/master/libusb/libusbi.hthe internals of the device handle has changed considerably:Code:struct libusb_device {/* lock protects refcnt, everything else is finalized at initialization* time */usbi_mutex_t lock;int refcnt;struct libusb_context *ctx;struct libusb_device *parent_dev;uint8_t bus_number;uint8_t port_number;uint8_t device_address;enum libusb_speed speed;struct list_head list;unsigned long session_data;struct libusb_device_descriptor device_descriptor;int attached;};struct libusb_device_handle {/* lock protects claimed_interfaces */usbi_mutex_t lock;unsigned long claimed_interfaces;struct list_head list;struct libusb_device *dev;int auto_detach_kernel_driver;};The problem is that I do not see anything that corresponds to the file descriptor, unless it got renamed or is embedded into another struct. Anyone with libusb programming experience able to help out?

author: ataradov
author_rank: Super Contributor
timestamp: July 18, 2020, 05:53:35 am
content: The simple port will not work. They use FD to pass it to the poll(). And libusb1.0 does the same thing internally, you can't combine the two, since if more than one poll() waits on the FD, only one will wake up at random.The code is quite a mess. It would seriously be easier to just rewrite it from scratch.

author: magic
author_rank: Super Contributor
timestamp: July 18, 2020, 06:50:03 am
content: There was a thread about it recently. Just install libusb-0.1This program doesn't really use libusb, only initally to discover and open the device. And the libusb API for that has changed AFAIK so even that won't work anymore. You would have to rewrite the whole wwusb thing.

author: ebclr
author_rank: Super Contributor
timestamp: July 18, 2020, 04:08:32 pm
content: According to the original developer libusb has a lower performance, and was intentionally avoided

author: magic
author_rank: Super Contributor
timestamp: July 18, 2020, 05:42:49 pm
content: IIRC,His beef with libusb was that it couldn't queue multiple buffers and left the hardware idle while the software was receiving one buffer and submitting another one. This has since then been fixed in the exact version of libusb which this program doesn't work with.

author: NiHaoMike
author_rank: Super Contributor
timestamp: July 18, 2020, 06:53:09 pm
content: Quote from: magic on July 18, 2020, 06:50:03 amProblem is, Gentoo (and basically all modern distros) no longer has libusb-0.1 available in packages - just a compatibility layer that doesn't work with the hack used by the program. However, I'm going to share how I worked around it.* Download fx2pipe and libusb-0.1. Unzip fx2pipe, then unzip libusb-0.1 inside it.* The Makefile for libusb-0.1 errors out on warnings, so disable that by removing -Werror from line 260 of Makefile.in.* Compile libusb with " CFLAGS=-O2 ./configure --prefix=`pwd` ", "make", and "make install". Note that because the install was set to use the current directory, root is not necessary for "make install".* Go down one directory and start patching fx2pipe to use the libusb you just built rather than the system libusb:** On line 163 of fx2pipe/Makefile.in, replace " -lusb " with " ../libusb-0.1.12/lib/libusb.a ".** On line 18 of usbio/cycfx2dev.h and line 24 of usbio/wwush.h, replace ' #include <usb.h> ' with ' #include "../libusb-0.1.12/include/usb.h" '.* Compile fx2pipe with " ./configure" and "make".Quote from: ataradov on July 18, 2020, 05:53:35 amIf anyone is up to do that, might as well make "fx3pipe" for the FX3 that is also backwards compatible with the FX2. The 40MBps or so the FX2 can do (at least on my PC) is a lot but some applications can use more.Now I'll have to see if there's an easy way for GNUradio to use fx2pipe as a real time input.

author: magic
author_rank: Super Contributor
timestamp: July 18, 2020, 07:39:01 pm
content: Well, that's how I did it (and posted in the other thread):Code:LD_LIBRARY_PATH=../libusb-0.1.12/.libs/ ./fx2pipe/fx2pipe -ifclk=48 -8 -n=300000000 -0No 'make install', no patching

author: NiHaoMike
author_rank: Super Contributor
timestamp: July 19, 2020, 03:59:06 pm
content: It turns out there's a very simple patch that makes things work much better when dealing with a FPGA.On line 322 of fx2pipe/main.cc, change this:p.fc.FC_EPFIFOCFG = 0x0cU; // 0000 110W (W = wordwide)to this:p.fc.FC_EPFIFOCFG = 0x4cU; // 0100 110W (W = wordwide)That gets the FX2 to assert the buffer full signal one byte early, making it a lot easier to properly handle the case. (Previously, I was getting dropped bytes.)

author: yombo
author_rank: Newbie
timestamp: March 13, 2023, 04:14:02 pm
content: Quote from: NiHaoMike on July 18, 2020, 06:53:09 pmHi! I've made a replacement for fx2pipe from scratch using libusb-1.0. I've called it Cannelloni.I've been registered on this forums for years but I haven't posted much. So hi everyone!The project is here, let me know anything missing:https://github.com/yomboprime/cannelloniI've made a concise README.md where there is a migration guide for the program arguments from fx2pipe to cannelloni. FX3 is not implemented but there is support to upload its firmware, so maybe in the future (README.md has more info on this)Greetings

author: magic
author_rank: Super Contributor
timestamp: March 13, 2023, 06:42:34 pm
content: Not the most straightforward name for an fx2pipe replacement butfor the effort. Will try to remember about it if I ever play with FX2 again.Your build instructions make it sound like compiling the FW is necessary, but I see there are some .ihx files already there, so I think it's fair game to simply use them?

author: yombo
author_rank: Newbie
timestamp: March 13, 2023, 07:53:34 pm
content: Quote from: magic on March 13, 2023, 06:42:34 pmThanks! Yes, you can skip the firmware build and just build the program.Edit: I've updated the readme with that.

author: NiHaoMike
author_rank: Super Contributor
timestamp: August 06, 2023, 01:06:19 am
content: The link is broken, is the project abandoned? I attached a zip of the copy I have from April if someone else wants to make a fork of it.

author: DiTBho
author_rank: Super Contributor
timestamp: August 06, 2023, 09:59:35 am
content: Quote from: NiHaoMike on July 18, 2020, 06:53:09 pmit can be supported by an Overlay

author: DiTBho
author_rank: Super Contributor
timestamp: August 06, 2023, 10:31:18 am
content: Quote from: NiHaoMike on July 19, 2020, 03:59:06 pmis there an example, vhdl side?

author: NiHaoMike
author_rank: Super Contributor
timestamp: August 06, 2023, 08:58:44 pm
content: I use Verilog. The only example I have is for a Digilent Atlys with a DIY ADC card attached.

author: bingo600
author_rank: Super Contributor
timestamp: September 05, 2023, 05:14:05 am
content: Looks like someone cloned/forked it herehttps://github.com/jhol/cannelloni