Apr 13, 2013

Another simple programming FPGAs

In the last article I wrote , and that is the JTAG TAP controller. This knowledge will help us make a simple programmer for FPGA company Altera.

I want to make a very simple programmer that will work through the serial port. The serial port is good in that it is very common, easy to program and, in addition, there are low-cost devices USB-to-COM. The hope is that my programmer will work through this adapter. On the computer I'm going to run my special program that controls the programmer. We will write to her (in the sense I have already written and tell you how it works).

So, in the JTAG connector has 4 significant signal to us: TDI, TMS, TCK and TDO.
The first three signals are inputs to the programmable FPGA, so we have a computer to manage them. Each control signal to be random, any of them, we can at any time set or reset. We have several serial signals suitable for this purpose:
  • RTS - it will match the JTAG signal TDI
  • DTR - it will match the signal TMS
  • TX - would correspond to a signal TCK
In addition, the output signal has a JTAG TDO, the state of which we need to be able to read from the computer. We shall use for this purpose the CTS serial port.

With signals understood, but there is one problem. We need to do a level converter serial signals. Of course you can use a specialized chip level converters, of which there are a great many. For example, there is such a chip icon HIN202 (625.08 KB)

We are (as always) go our own way. We make the programmer's on the following scheme:

A few resistors, zener diodes, LEDs for debugging and .. that's it - simple as that.

Here are photos of our programming, top view:

View from below:

I will write a program in C language environment in Microsoft Visual Studio v10.

My program will consist of at least two logical parts. The first part - is the serial port control signals, which means it control signals JTAG. The second part of the program - it's reading *. SVF file, its interpretation and consistent performance. In the last article I wrote that the SVF file describes the sequence of commands for the TAP controller's programmable chip. Wednesday Altera Quartus II can generate SVF files to compile the project.

To control the serial port I use API functions OS Windows:
  1. CreateFile (..) - is used to open the serial port
  2. EscapeCommFunction (..) - the parameters SETRTS or CLRRTS to set or reset signal TDI
  3. EscapeCommFunction (..) - the parameters SETDTR or CLRDTR to set or reset signal TMS
  4. EscapeCommFunction (..) - the parameters SETBREAK or CLRBREAK to set or reset signal TCK
  5. GetCommModemStatus (..) - to read the state of the CTS line and thus learn the value of TDO signal from the JTAG interface
The program identifies two very important functions:
int sir (int nclk, int val);
int sdr (int nclk, int val);

The first function sir (..) writes to the command register TAP controller programmable chip val is a long nclk bit. The second function sdr (..) writes to the data register TAP controller programmable chip val is a long nclk bit.

Functions look about the same and do about the same thing. Using the TCK and TMS signals they carry TAP controller state record in the relevant register IR or DR according to the state diagram (TAP state-machine) described in the previous article. TDI signal is used for serial transmission of data on the register TAP, and the TDO signal is used to read response data from the controller.

Now for the interpreter SVF file.
So, you've done a project for the FPGA, compiled it using Quartus and got SVF file to program the chip.

SVF - a text file. Our program will read it line by line and interpret the command in this line and execute it. I do not know all the details of the standard SVF files, but what I see in the file generated kvartusom - this is a very simple file. One line - one team. There are no conditional or unconditional jumps or subroutines. Thus, reading and execution of SVF file line by line - it is a convenient solution for us.

Actually you need to implement only a few basic commands: RUNTEST, SIR, SDR. As you guessed team SIR - write down the number in the instruction register and the TAP SDR - write down the number in the data register. RUNTEST - a pause when the controller is in the state IDLE. I will say honestly that I pause in the program does not withstand strict. We've already gotten a very slow rate due to the recording software implementation protocol. So pauses according to SVF hope is not necessary.

Well, here's the program is written and compiled using Visual Studio.
You can download its source code and binary file on our website: Programming via the serial port (51.89 KB)

The program console, takes 2 parameters on the command line: the name of the serial port and the file name SVF. For example, like this:

c: \ MarsBlaster.exe COM4 my_proj.svf

Connect fee rover to our programmer, connect it to the computer has power.

It looks like it works!

To watch the video of this project from here

PS: fly in the ointment.
Via an adapter USB-to-COM works, but very slowly. Programming the Mars Exploration Rover (including verification after burning) takes about 5 minutes. The reason is that the control signal goes via USB and read the response signal TDO takes a very long time (2-3 milliseconds). Get rid of this so simply will not work. Need to do more complex programming, with more complex logic of that exchange would lead not one bit, but at least bytes, then you can do so much more quickly.

Well, a look at the programming scheme is "feedback" from the 6th to the 3rd leg connector COM port. This is the same need - just to work through the adapter USB-to-COM. This feedback allows you to accurately tell whether the data came on the status of TDO or not. I set the TCK and read through the feedback it well - he came or not. If you come, then came to him and TDO. A bit surprising happened, but it works. - source


Post a Comment