FX2 CyStream throughput test with SDCC and fx2lib

I’ve been optimizing my firmware for throughput and I thought a good benchmark would be to test it against the CyStream example provided by Cypress. I modified their CyStream.c file to be compatible with the latest firmware file provided by fx2lib.

Here is a summary of the changes needed:

  • Include the appropriate header files
  • Change the functions for vendor commands to match the fx2lib functions.
  • Change the interrupt handlers
  • Probably the most work of the whole process, rewrite the dscr.a51 file to be in asx8051 format.

Anyhow, The attached zip files contains the sources for the modified CyStream. Here are some of my benchmark results:

Firmware/Test Speed
CyStream Application on Windows with Keil firmware ~41 MBps
Keil firmware, Linux Host with included speed.py ~40 MBps
SDCC firmware, unchanged, speed.py ~35.6 MBps
SDCC firmware, optimization 1, speed.py ~40.9 MBps
SDCC firmware, optimization 2, speed.py ~41.9 MBps
SDCC firmware, optimization 3, speed,py ~42.9 MBps
SDCC firmware, optimization 3, CyStream App on Windows ~43.8

  1. Optimization: remove two if checks for interrupts in main loop and handle them directly in the interrupts
  2. Optimization: remove another if in main loop.
  3. Optimization: completely remove everything in main loop, commit packets directly in main loop, don’t write to ep buffer before committing data. Note that the fastest I could get this to go was 42.9 (or 43.8 on Windows). Further removing things didn’t make it go any faster so I think I hit my Host PC limits.

You’ll need to download fetch the latest fx2lib from github and then modify the Makefile to compile the attached firmware. You’ll need to install the fx2load package for Python from fx2lib in order to run the speed test.

CyStream for SDCC and fx2lib

Enjoy. I hope fx2lib helps someone out. Check out my other posts on fx2lib to find our mailing list and more SDCC examples for the Cypress FX2.

This entry was posted in Hardware, Programming and tagged , , , , , , , . Bookmark the permalink.

12 Responses to FX2 CyStream throughput test with SDCC and fx2lib

  1. bali.asur says:

    Dennis:

    Do you have any samples of your host application side
    code?

    Regards,

    bali

  2. Dennis says:

    The fx2load package has some example of talking to the device with libusb-1.0. You can see sending vendor commands and doing bulk reads. I use that in the speed.py file too. Really though, everyone’s device is different so I haven’t found much utility in adding a host side example. Perhaps I’ll add a CyStream C++ equivalent that uses libusb0 one of these days.

  3. joebre says:

    Hi, first of all great job !
    Just a question… I built your cystream using the latest FX2Lib, I programmed the binary into the EPROM of my custom EZ-USB board. Everything worked well at the first trial. Now the question… when I use your firmware in conjunction with the Streamer.exe delivered by Cypress I only get up tu a maximum of 36 MB/s in bulk mode which is quite far from the results you got. I’ve a IHC9 as host controller which should guarantee the maximum bandwidth… Where do you think is the problem? did you ever tried to use Streamer.exe of Cypress? with which results ?
    Thanks Joebre

  4. Dennis says:

    Been a while since I tried. Is there much different about streamer.exe and CyStream? I got it to go faster by eliminating any work the firmware was doing that wasn’t involved with committing the packets. Did you make those changes?

    It’s a good learning activity to see how fast you can get it to go, but in the end, you’ll probably use slave fifo or gpif to transfer data from a peripheral directly through the buffers to the PC. We do this at 43MB/s which seems about as fast as the host will handle it.

    Lastly, have you tried more than one machine to see if you get different results? You can post messages and firmware bits to the fx2lib mailing list too by the way: http://bit.ly/9xj8M5

  5. joebre says:

    Hi, thanks for your rapid answer.
    I used your code as it comes from your web site, which I suppose has already the changes you’re speaking about (correct?). Yes I tried on several machines both Vista and XP and the throughput seems kind of hardwired to a maximum of 35/36 MB/S. You are right at the end I’ll use a synchronous slave fifo approach. At this stage of the project I need just to get a list of requirements for the host and to validate the throughput for Bulk unidirectional transfers (IN). 36 MB/s is good but it gives me a really small margin.

  6. joebre says:

    Sorry, I did a mistake… in the EProm image I got the old version of fw.c, this explains what I was seeing. Using your fw.c the throughput goes immediately and stably up to 43 MB/s. Thanks again for your support.

    Job

  7. Dennis says:

    Glad it’s working. If you haven’t already, you’ll probably want to download fx2lib from the latest github master as opposed to 0.1 There are quite a few fixes, new samples, better build system and other things. I’m about ready to tag it 0.2 but I’ve been waiting on giving it a new website/home.

  8. Richard says:

    I think I have the latest copy of fx2lib as I used github to download just a few days ago. I had to fix the fx2/cpp files to work under Ubuntu 10.04 as follows:

    void
    fx2::open(int vid, int pid, int idx) {
    libusb_device **list;
    int devices = libusb_get_device_list(libusb_ctx, &list);
    int cur_idx = 0;
    for (int i = 0; i < devices; ++i) {
    libusb_device_descriptor dscr;
    if (!libusb_get_device_descriptor(list[i], &dscr) ) {
    if (dscr.idVendor == vid && dscr.idProduct == pid) {
    if (idx == cur_idx++ ) {
    int rv = libusb_open(list[i], &dev_handle);
    if (!rv) {
    if (libusb_kernel_driver_active(dev_handle, 0)) {
    // Probably should re-attach, but we don't!!!
    libusb_detach_kernel_driver(dev_handle, 0);
    }
    rv = libusb_claim_interface(dev_handle, 0);
    if (!rv) {
    interface = 0;
    rv = libusb_set_interface_alt_setting(dev_handle,
    0, 0);
    if (rv) {
    libusb_close(dev_handle);
    dev_handle = NULL;
    }
    alt_setting=0;
    } else {
    libusb_close(dev_handle);
    dev_handle=NULL;
    }
    } else {
    printf ( "Unable to open device idx: %d, ret: %d\n",
    idx, rv );
    }
    }
    }
    }
    }

    if (!dev_handle) {
    printf ( "Device not opened.\n" );
    }
    libusb_free_device_list(list,1);
    }

    The change I made was the libusb_kernel_driver_active if statement that finally does libusb_detach_kernel_driver function. I haven't tried this solution in any other context, so it may not be general.

    Does this change make sense?

  9. Richard says:

    Sorry for the above, I noticed the indentation didn’t stay.

  10. Dennis says:

    No problem. The driver included is a bit of a sample driver. It works for testing but probably isn’t going to get anyone anywhere too fast on a real project. Ubixum released a driver that works on both windows and Linux:

    http://github.com/ubixum/nitro
    Also, a couple firmwares for various projects we did.
    http://github.com/ubixum

    In addition to the basic USB connectivity, that firmware provides a convenient way to map hardware addresses to a human readable terminal/register structure that you can get and set values from. We then built our software on top of that.

    Anyway, Best way to contribute changes is to create a github repo with a fork of fx2lib and then commit the changes and submit a change request that I can pull.

    Also, consider joining the fx2lib mailing list

    Thanks for your interest!

  11. Richard says:

    I’ve been out of the country and just got back. Thanx for the pointers and I’ll check out nitro and see if it can help.

    Also, I went to ubixum.com. Am I missing something as I do not see any products, etc.?

    I joined the mailing list.

  12. Kurt says:

    look great. thanks your sharing.

Comments are closed.