Sending data through the USB port to an FPGA

Thread Starter

tstana

Joined Apr 2, 2009
1
Hello!

I'd like to implement a 16-bit ALU on a Xilinx Spartan-3E FPGA using VHDL. Of course, the VHDL code for this ALU isn't the problem here.

My problem is that I would like to send the data from a C# or C++ interface in Windows through the USB port and then display the result on the board's LED display (again, the VHDL code isn't a problem). As I'm relatively (read: very) inexperienced in C#/C++ programming, I would like some hints on:
1. which is better for my project: C# or C++ ?
2. how can I send data through the USB port to the FPGA?

Some help would really be appreciated!
 

DonQ

Joined May 6, 2009
321
There should be libraries with the system to let you read/write the USB port. If there isn't, you don't want to be writing it yourself. You will also need to use some sort of driver on the PC side. You could probably use one of the serial-port emulators like those from FTDI (or is it FDTI?). I would bet that there is a tutorial in the manual about doing exactly this type of communication.

There may also be a USB to "regular" serial converter on whatever development board you are using. Writing a "regular" serial receiver is something that is not too involved.
 

Papabravo

Joined Feb 24, 2006
21,158
Problem is not on the PC side. Isn't the problem on the FPGA side? A USB slave device might just be an FPGA project all by itself. Worse would be having to get the CPU working well enough so you could write the firmware for a USB driver that would enumerate correctly. BTW -- do you have any idea how badly your registry will become polluted by enumerations that don't complete correctly. Fixing the registry manually is kind of a PITA.
 
You should be able to use the System class to bang data through the USB port. On the FPGA end however you'll need to manage the data that's presented to the FPGA. Are you using a USB core on the FPGA side? Is this an FPGA-based "system" and if so, do you have a USB software stack on the FPGA-end? Is there USB hardware on the FPGA side you can use (like the FTDI chip someone mentioned). You might err on the side of simplicity and have a go at using something like the FT232 or some other USB-serial converter to convert USB to serial and serial to USB. That way you can use a UART on the FPGA-end, if you don't require USB functionality on the FPGA side.

These guys (below) have a hardware board and software that make USB comms really easy. They supply the whole stack including HW, SW, and programmable HW. They also have the full PC-USB-FPGA comms sorted out. They also have a 3E board: www<dot>altium<dot>com Not sure if it'll be useful at this stage in your design but it may be worth a look. Alternatively, I believe Xilinx has a USB controller available and working as a part of the Microblaze developer's kit. (Again, only if you haven't already made accomodation on that end).

Regarding languages, C++ will be more typed, C# will feel more abstract. Both will get you where you want to go. You should look at the examples on Experts-Exchange and you'll find more code than you know what to do with. It's a paid site but pretty cheap considering. www<dot>experts-exchange<dot>com . You can pick what language you want help with and I trust you'll see what I mean about C++ just being more typed. C# may feel like you're giving up a lot of control but I guess this is the trade-off anytime you go up a notch in terms of abstraction.

If you're going to debug the USB data on the PC side, you might favor C++ if you know C and have never used C# before. Just my experience. C# was a little goofy getting used to debugging when I didn't know all of the libraries and calls being made the way I did in C++.
 
One thing: I would look at the IO class. I mentioned the System class but I think what you're after is the IO class.

You should be able to use the System class to bang data through the USB port. On the FPGA end however you'll need to manage the data that's presented to the FPGA. Are you using a USB core on the FPGA side? Is this an FPGA-based "system" and if so, do you have a USB software stack on the FPGA-end? Is there USB hardware on the FPGA side you can use (like the FTDI chip someone mentioned). You might err on the side of simplicity and have a go at using something like the FT232 or some other USB-serial converter to convert USB to serial and serial to USB. That way you can use a UART on the FPGA-end, if you don't require USB functionality on the FPGA side.

These guys (below) have a hardware board and software that make USB comms really easy. They supply the whole stack including HW, SW, and programmable HW. They also have the full PC-USB-FPGA comms sorted out. They also have a 3E board: www<dot>altium<dot>com Not sure if it'll be useful at this stage in your design but it may be worth a look. Alternatively, I believe Xilinx has a USB controller available and working as a part of the Microblaze developer's kit. (Again, only if you haven't already made accomodation on that end).

Regarding languages, C++ will be more typed, C# will feel more abstract. Both will get you where you want to go. You should look at the examples on Experts-Exchange and you'll find more code than you know what to do with. It's a paid site but pretty cheap considering. www<dot>experts-exchange<dot>com . You can pick what language you want help with and I trust you'll see what I mean about C++ just being more typed. C# may feel like you're giving up a lot of control but I guess this is the trade-off anytime you go up a notch in terms of abstraction.

If you're going to debug the USB data on the PC side, you might favor C++ if you know C and have never used C# before. Just my experience. C# was a little goofy getting used to debugging when I didn't know all of the libraries and calls being made the way I did in C++.
 
oops, yep. guess I didn't catch the date on that one. just saw it in the list of topics and responded. oh well...at least it's in the archive.
 
Top