Regarding my XP2 posts

I have found that I am going to have to pause my series on the XP2 board.  The reason is that I cannot get my USB programmer to be recognized by Lattice’s software via VirtualBox.  I use Mac OS X, and I have Windows XP2 installed in a virtual machine (VirtualBox).  Though Mac OS X recognizes the USB programmer and VirtualBox does as well, Lattice’s software does not recognize the hardware and nor does Windows XP.  I cannot seem to find a way to get it to either, so I’m essentially dead in the water.

At this point I have three options:

  1. Install BootCamp on my Mac so that I can dual boot OS X and Windows XP — I don’t particularly like this because the Windows XP install will eat up quite a bit of my disk space that I would rather use for video editing.  I suppose I could reclaim some of it by deleting my VirtualBox Windows XP install. But I hate the idea of having to reboot to use Windows or Mac OS X, what a pain!  Hopefully a native install of Window with direct access to the USB subsystem on this computer would allow the Lattice USB programmer to function.
  2. I have an old Pentium-III machine with 256 MB of memory and 10 GB of disk space that runs Windows 2000 smoothly.  I do not have a monitor for the machine, however, so I would need to purchase a monitor, then setup the machine again, and hope that the Lattice software won’t overpower this old machine that I purchased in 1999.  This machine has a parallel port on the motherboard, so I could use the parallel port programmer cable that came with the XP2 board.  This parallel port support gives me some hope that Lattice’s design software is no overbearing. After all, new Dell PCs don’t even have parallel ports!
  3. Buy a new PC with Windows 7 – I’d rather not take this route, but for the long-term it may be necessary.  My hobby and passion is electronics, and despite how much I love Mac OS X, I may have to prepare a Windows machine so that I can take advantage of all of the free tools available for Windows in the electronics world.  I could purchase a basic modern PC for less than $400 and I could get a nice monitor for $200, but that is still a lot of money when I am already happy with my Mac.

Decisions, decisions, decisions.  Once I’ve found my solution I will re-start this series about the Lattice XP2 board.  In the mean time, I have learned that despite the growth in Mac computing, Windows still rules the world.  Even though most of the FPGA vendors now support Linux, I would still go the Windows route until the industry is ready to accept Linux alongside Windows.

Software access to XP2 board

Thanksgiving has come and gone and my life is back to the usual schedule.  That means I have time to experiment with my XP2 board!  In my last post I made sure that I could access the XP2 board from a terminal.  I now want to do this in a programmable way with software. Instead of using a standard terminal interface, my long-term plan is to use a binary serial protocol to communicate between my PC software and the FPGA on the XP2 board.

I coded up some simple C language functions that access and perform I/O via the serial port using standard POSIX functions.  It was simple and did not require much effort, and I’m left wondering why if serial ports can be supported for Linux, why other POSIX platforms like Mac OS X have no support.  I suppose the GNAT supporters have their reasons…probably due to business “use cases”.

Nonetheless, using standard POSIX interfaces worked fine on Mac OS X.  For example, the following screen capture shows the result of reading 512 bytes from the serial port after resetting the XP2 board:

The output matches the terminal output I captured last time with the screen program, and my simple C code serves to prove that we are ready on the software side to interact with theXP2 board.  I will not publish the C code just yet–I plan to make it more adaptive and provide an Ada interface as well.  Just using C would be no fun, I’d learn nothing new.  But interfacing C and Ada, especially since GNAT does not provide serial port support for OS X, is  a great opportunity to learn more about Ada.

My USB programmer cable arrived in the mail recently, and now that we have the software interface working as expected, it is time to make sure the JTAG interface on the hardware works as expected.  Once we have the JTAG programmer figured out, we can try to implement some simple logic in the FPGA.

Connecting to the XP2 Brevia Board

Much to my surprise, my Lattice XP2 Brevia board arrived in the post today.  I printed out the User’s Guide with the schematic because I know I’ll be pouring over the schematics during my lunch break at work and when I get home in the evenings.  The kit contains a null-modem (serial port) cable, the 3 inch x 2 inch board, a parallel-port programming cable, and a power adapter with exchange sockets depending on the electrical standard in your region.  This is truly a versatile development kit for experimenting with FPGAs.

Because I don’t have a PC with a built in parallel port, I have to use a USB programmer, and I’m still waiting on my Lattice USB programming cable to arrive in the post.  Note: Lattice says that USB-to-parallel converters will not work with their parallel port programming cable.

It is often helpful to evaluate the status of the board before beginning with prototyping and development.  If I had designed the board myself, I would be checking the voltage levels at critical parts in the circuit and making sure they match they intended levels.  I’d also be checking the power-up sequence and reset circuits to make sure that these basic functions behave as expected.  I trust, however, that Lattice has taken care of this.

My test plan is:

  1. Connect to the board’s serial interface via a terminal and verify that the factory-installed demo application runs as expected
  2. Connect to the board’s serial interface with my own software and make sure I can interact with the factory-installed demo application

Connecting to the board with a terminal

If you have a Microsoft Windows workstation, you can follow the Lattice QuickState guide and use HyperTerminal to connect to the board.  Though I have Windows installed through a Virtual Machine, I only use it for the Lattice FPGA design software and device programmer.  I would like to use my preferred OS, Mac OS X, for interacting with the XP2 board.  While Mac OS X does not have a graphical application like Microsoft’s HyperTerminal pre-installed, we can use a terminal tool called screen.

Screen comes installed on Mac OS X and it is accessible via the terminal (of course).  The Lattice QuickStart guide says that the serial connection parameters are 8 data bits, no parity, 1 stop bit, no flow control and a baud rate (bits per second) or 115,200.  Most of the parameters, except for the baud rate, are rather standard, so I just have to specify the baud rate when I start a new screen session.

screen /dev/tty.usbserial-A600cGQW 115200

Now I just have to press the reset button on the XP2 board:

Voila!  I am now hooked up to the factory-installed demo application.  Next I will use some custom C software and make sure I can interact with the demo application.

USB to Serial Port for Mac OS X

The LatticeXP2 development kit I selected has an RS232 connector and buffer hooked up to the FPGA.  A primitive interface, you might say?  Having professionally developed both USB and PCI solutions, I was searching for a development board that had the simplest interface with the FPGA.  Why?  Well, I don’t want to spend 50% of the time tweaking kernel mode device drivers and data transfer libraries–I want to focus on the FPGA.  What could be simpler than the good ol’ serial port, right?  Every telecom application I’ve worked on has had hardware with a serial port for debug and engineering management.

It turns out that the PC industry really feels that serial ports are legacy, however.  Apple abandoned serial ports over a decade ago, and recent Dell desktop PCs don’t even have serial and parallel ports.  For applications requiring legacy ports, we are recommended to use USB-to-Serial Port adaptors.  Having worked with such devices since 2003, I can tell you that many are flaky and high unstable.  The biggest problem I’ve seen is that the drivers are of questionable quailty. I’ve tried many devices that resulted in a Windows blue-screen of death, in modern Windows NT-based OS (WinNT/2k/XP/Vista/7), and these days the only thing that can really bring down your system to the blue-screen is a kernel-mode error–or more likely- a bad device driver.

Over the years, I’ve found that USB-to-Serial devices that implement an FTDI solution are of superior quality.  FTDI is based out of the UK and provides device drivers for all flavors of Windows, Mac OS and Linux.  I highly recommend FTDI-based USB-to-RS232 cables if you’ll be using a Mac; just purchase your cable, download the latest driver and follow the installation guide and you’ll be up and running in no time.

After you install the driver, plug in the device and use the System Profier (in Applications->Utilities) to verify the device is recognized:

While there is probably a way to access the serial ports through Mac programming libraires like Cocoa and Carbon, for my purposes I’m going to keep things simple and use the POSIX interface.  You can determine the interface using the Terminal application and executing the follow commands:

cd /dev
ls cu.usbserial*
ls tty.usbserial*

The above should match devices with a serial number following the search pattern above.  The cu.usbserial* device is a call-up interface that you would use if your were dialing into a modem (ah, the good ol’ days!).  The tty.usbserial* interface is for listening to a device on a serial interface, and this is the interface I will use to communicate with my Lattice FPGA.  My kit has not yet arrived in the post, so I think I’ll start working on a simple terminal application to access the tty interface.