0
\$\begingroup\$

I've designed a small circuit board with a Cyclone 10 LP FPGA and an EZ-USB FX2LP microcontroller. My current revision has a 10-pin header for connecting a USB Blaster, and it works just fine that way. However, I would like to program the FPGA using the on-board microcontroller so I can directly transfer the programming file over USB and avoid connecting the programming cable. The EZ-USB has some GPIO pins that I can connect to the JTAG pins of the Cyclone 10 LP as in Figure 97 of the Cyclone 10 LP Handbook, so in principle this should work.

At this point, I have only a rudimentary understanding of JTAG so my question is pretty broad: how does programming FPGAs via JTAG work? Is there some reference implementation of software in C that outputs the TCK, TDO, TDI, and TMS signals that I can adapt for the microcontroller? I just need some good references or keywords to do further research... I think Section 6.1.4.7 of the handbook above is the beginning of what I need, but I need some more detail and I'm not sure where to begin.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Could this be helpful: github.com/mithro/ixo-usb-jtag \$\endgroup\$
    – Codo
    Commented Oct 21, 2021 at 15:10
  • \$\begingroup\$ @Codo looking at the readme... yes, definitely! thanks \$\endgroup\$
    – Andrew
    Commented Oct 21, 2021 at 15:15

4 Answers 4

1
\$\begingroup\$

Altera (now part of Intel) used to provide reference software for this. It was called Jam STAPL player. It was up to the user to port this to the target host. You may be able to find this on the internet somewhere or request access from Intel.

In order to use it, you would generate a .jam or .jbc format file in Quartus, and use that with the Jam STAPL player.

We use this capability regularly at my place of employment.

About JTAG:
TMS, TCK, and TDI are all inputs to the FPGA. They are essentially: select, clock and Input Data. TDO is output data. JTAG isn't all that complicated, but it is arcane enough that using the reference code is preferable to reinventing the wheel.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks, I'll take a look, I found github.com/margro/jam-stapl that I can use as a starting point. I'll mark this the answer if I can get it working :) \$\endgroup\$
    – Andrew
    Commented Oct 23, 2021 at 1:13
0
\$\begingroup\$

I realize you're looking at an Intel part and not Xilinx, but the following application note from Xilinx does a relatively good job of explaining some popular methods for in-system programming.

XAPP058

\$\endgroup\$
0
\$\begingroup\$

One of the standard formats for that is Serial Vector Format (SVF). You'd use the quartus_cpf tool to convert the .sof configuration file to SVF format.

This file then describes the exact JTAG sequence. Replaying that sequence with an FX2 will require a bit of trickery if you want it to be fast, you might need to set up an extra pipeline that you can connect to TDI for the bulk download so the bitstream can bypass the 8051.

\$\endgroup\$
2
  • \$\begingroup\$ IThanks, I did some more digging and found this myself. I wonder, could you point me to some reference on how to convert an SVF into a waveform? I don't think I need it to be fast (although maybe I'll eat my words later :) \$\endgroup\$
    – Andrew
    Commented Oct 26, 2021 at 22:38
  • \$\begingroup\$ @Andrew, most people use an FTDI USB-to-serial converter and something like openocd for programming, the FX2 setup is kind of unusual (but that and the TUSB1210 are pretty much your only options for high-speed USB). The SVF is just text that lists the JTAG state transitions (on a high level, as instructions to go to a specific state or stay there for a number of cycles) and the data to be shifted into TDI or expected back from TDO. If you use the PAUSE-DR states, you can probably get away with a few vendor-defined setup packets for "send these bits to TMS" and "send these bits to TDI". \$\endgroup\$ Commented Oct 27, 2021 at 9:16
0
\$\begingroup\$

Find the JAM Player source code online and pull the code into your project. In it, you'll see a readme file that contains pretty good instructions. The jam_player is universal - it can be compiled for windows, DOS, Linux, or embedded into a firmware application. Basically, there is a jam_stub.c file that you will modify to use PORT=EMBEDDED. That will remove most of the file IO. The you'll have to edit to jam_stub.c file to provide data to access your JAM Stapl source code. For mine, I wrote a bash script that takes the JAM file and puts it all into a C array (include \r at the end of each line - the player needs it). The build that array into your code, and modify the "getc" function in jam_stub.c to read one byte of that array each time it is called. You also have to modify some code to get length of the C array that getc will use to determine EOF.
Then you'll have to modify the JTAG IO code in jam_stub.c. Use the Raspberry Pi code as an option, and modify those routines for your 3 output lines and 1 input line (TDO).

Then you need to modify you firmware to call "jam_main" with some fake command line options - ie you'll have to make argv up manually. I use "-AProgram -V dummy.fil" as options.

Good luck

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.