Author Topic: updating fx2pipe to work with libusb-1.0  (Read 3187 times)

0 Members and 1 Guest are viewing this topic.

Offline NiHaoMikeTopic starter

  • Super Contributor
  • ***
  • Posts: 9138
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
updating fx2pipe to work with libusb-1.0
« on: July 18, 2020, 05:17:55 am »
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.html
The 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: [Select]
mike@DX79SI /bulk/mike/downloads/fx2pipe-0.8/fx2pipe $ ./fx2pipe -i -0 -8 -ifclk=48o
Firmware config: 0x12 0xe3 0xe0 0x0c 0x12
IO loop running...
Downloading firmware [builtin]...
fx2pipe: wwusb.cc:129: WWUSBDevice::ErrorCode WWUSBDevice::_DoConnect(usb_device*): Assertion `dev_handle_to_dev(udh)==udev' failed.
Aborted
The culprit is in the file wwusb.cc:
Code: [Select]
// 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 from https://github.com/libusb/libusb/blob/master/libusb/libusbi.h the internals of the device handle has changed considerably:
Code: [Select]
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?
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 
The following users thanked this post: ebclr

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11428
  • Country: us
    • Personal site
Re: updating fx2pipe to work with libusb-1.0
« Reply #1 on: July 18, 2020, 05:53:35 am »
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.
Alex
 
The following users thanked this post: SiliconWizard

Offline magic

  • Super Contributor
  • ***
  • Posts: 6901
  • Country: pl
Re: updating fx2pipe to work with libusb-1.0
« Reply #2 on: July 18, 2020, 06:50:03 am »
There was a thread about it recently. Just install libusb-0.1 :D

This 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.
« Last Edit: July 18, 2020, 06:53:08 am by magic »
 

Offline ebclr

  • Super Contributor
  • ***
  • Posts: 2329
  • Country: 00
Re: updating fx2pipe to work with libusb-1.0
« Reply #3 on: July 18, 2020, 04:08:32 pm »
According to the original developer libusb has a lower performance, and was intentionally avoided
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 6901
  • Country: pl
Re: updating fx2pipe to work with libusb-1.0
« Reply #4 on: July 18, 2020, 05:42:49 pm »
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.
 

Offline NiHaoMikeTopic starter

  • Super Contributor
  • ***
  • Posts: 9138
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: updating fx2pipe to work with libusb-1.0
« Reply #5 on: July 18, 2020, 06:53:09 pm »
There was a thread about it recently. Just install libusb-0.1 :D
Problem 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".
The code is quite a mess. It would seriously be easier to just rewrite it from scratch.
If 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.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 
The following users thanked this post: DiTBho

Offline magic

  • Super Contributor
  • ***
  • Posts: 6901
  • Country: pl
Re: updating fx2pipe to work with libusb-1.0
« Reply #6 on: July 18, 2020, 07:39:01 pm »
Well, that's how I did it (and posted in the other thread):

Code: [Select]
LD_LIBRARY_PATH=../libusb-0.1.12/.libs/ ./fx2pipe/fx2pipe -ifclk=48 -8 -n=300000000 -0No 'make install', no patching :)
 
The following users thanked this post: RoGeorge, DiTBho

Offline NiHaoMikeTopic starter

  • Super Contributor
  • ***
  • Posts: 9138
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: updating fx2pipe to work with libusb-1.0
« Reply #7 on: July 19, 2020, 03:59:06 pm »
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.)
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 
The following users thanked this post: bingo600, SiliconWizard

Offline yombo

  • Newbie
  • Posts: 8
  • Country: es
Re: updating fx2pipe to work with libusb-1.0
« Reply #8 on: March 13, 2023, 04:14:02 pm »
If 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.

Hi! 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/cannelloni

I'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
 
The following users thanked this post: NiHaoMike, magic, DiTBho

Offline magic

  • Super Contributor
  • ***
  • Posts: 6901
  • Country: pl
Re: updating fx2pipe to work with libusb-1.0
« Reply #9 on: March 13, 2023, 06:42:34 pm »
Not the most straightforward name for an fx2pipe replacement but  :-+ for 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?
 

Offline yombo

  • Newbie
  • Posts: 8
  • Country: es
Re: updating fx2pipe to work with libusb-1.0
« Reply #10 on: March 13, 2023, 07:53:34 pm »
Not the most straightforward name for an fx2pipe replacement but  :-+ for 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?

Thanks! Yes, you can skip the firmware build and just build the program.

Edit: I've updated the readme with that.
« Last Edit: March 14, 2023, 05:41:01 pm by yombo »
 

Offline NiHaoMikeTopic starter

  • Super Contributor
  • ***
  • Posts: 9138
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: updating fx2pipe to work with libusb-1.0
« Reply #11 on: August 06, 2023, 01:06:19 am »
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.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 
The following users thanked this post: ledtester, DiTBho

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4004
  • Country: gb
Re: updating fx2pipe to work with libusb-1.0
« Reply #12 on: August 06, 2023, 09:59:35 am »
Problem is, Gentoo no longer has libusb-0.1 available in packages

it can be supported by an Overlay
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 4004
  • Country: gb
Re: updating fx2pipe to work with libusb-1.0
« Reply #13 on: August 06, 2023, 10:31:18 am »
It turns out there's a very simple patch that makes things work much better when dealing with a FPGA.

is there an example, vhdl side?
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline NiHaoMikeTopic starter

  • Super Contributor
  • ***
  • Posts: 9138
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: updating fx2pipe to work with libusb-1.0
« Reply #14 on: August 06, 2023, 08:58:44 pm »
I use Verilog. The only example I have is for a Digilent Atlys with a DIY ADC card attached.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 2006
  • Country: dk
Re: updating fx2pipe to work with libusb-1.0
« Reply #15 on: September 05, 2023, 05:14:05 am »
Looks like someone cloned/forked it here

https://github.com/jhol/cannelloni

 
The following users thanked this post: NiHaoMike


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf