Friday, October 15, 2010

How to compile Opal Kelly's flashloader.exe

The XEM-3005 has a serial configuration EEPROM (I guess its actually Flash RAM? The XEM-3005 UM refers to it as an SPI PROM) from which the Spartan 3E 1200 can be self-configured at power-up. Self-configuration setup is easy, you just set the tiny switch from the "USB Config" position to the "PROM Config" position, and remember to include a line in the VHDL to set the MUXSEL pin to '0' after configuration is complete to allow the USB port to still work for all other regular communication. However that EEPROM is not on the JTAG chain, so you can't just push a bitfile into it like you normally would with a Xilinx serial PROM. Apparently, the only way to program the bit file into the EEPROM is through the FPGA itself. The XEM-3005 says "This PROM may be programmed using the Opal Kelly FrontPanel Application or through API calls from your own software. NOTE: This feature is not yet available in FrontPanel." Later, the UM says "Opal Kelly’s FrontPanel application software and API both provide methods to program the SPI Configuration PROM." (Meaning that the API can be used to program the PROM, since this feature is not yet available in FrontPanel.)

The Opal Kelly Front Panel UM talks about the EEPROM used to store parameters for the PLL (which I'm not utilizing) but does not mention what methods are used to write to the boot PROM. However, in the Samples directory installed with the FrontPanel software, there is a folder called "flashloader". The README.TXT file in this directory explains the SPI PROM loading process in a roundabout way. The process is that you set up flashloader.exe in a directory with a bitfile supplied by OK, and the DLL that has all the OK API stuff in it, and the bitfile to be loaded to the PROM. You then run flashloader.exe from a DOS command line, and it will configure the OK FPGA with the bitfile supplied by OK, and then communicate with the configured FPGA to load your bitfile to the PROM.

However, OK does not supply flashloader.exe. Instead they helpfully supply just the source code. So you have to compile it yourself for whatever platform you're running on. Now, you can always compile in Cygwin, which requires you drag around their runtime DLL on a ball and chain with your executable. However, I found that M$ also supplies a C compiler, naturally wrapped up in the "Express" version of their huge, bloated do-everything development platform called "Visual Studio". Visual Studio Express can be downloaded from here: http://www.microsoft.com/express/ . When you click through to Download, it seems that you are offered four separate pieces, including VB, C#, C++, and "Web Developer". I picked just the C++ piece.

What I discovered is that it turns out that you'd better use Visual Studio, because that's how Opal Kelly did it. Their "source code" also comes with a VS project file that has all of the preprocessing directives and other compile options all set up perfectly. Once you've installed VS, you can compile flashloader.exe in two ways. First, you can use a DOS command window that's launched from a shortcut in the VS start menu folder, and follow the instructions in this M$ tutorial: http://msdn.microsoft.com/en-us/library/bb384838.aspx. Or, you can just open VS, go get a snack while it opens, and then from File->Open->Project/Solution select the .vcproj file in the "Cxx" subdirectory of the source code folder and (after converting to a .vcxproj file because nothing is allowed to be backwards compatible after 2010) just right-click on the flashloader project top level to get "Build". It will first build a "Debug" version because that's VS's default setting. Then you can set the build type to "Release" and build it again. The debug executable is placed in a "Debug" subfolder, and the release executable is placed in a "Release" subfolder. Both seem to run fine, and it is now possible to follow the procedure given in the README.TXT file.