Getting Started
The TinyFPGA A-Series boards use Lattice Semiconductor’s MachXO2 FPGAs. There are a number of existing software and hardware tools available as well as documentation from Lattice for these FPGAs. This guide will help get you started with the A-Series boards and the tools and information specific to them as well as the tools and documentation available for the FPGA chips themselves.
Hardware
Of course you will need to purchase one or more A-Series boards, but you will also need a few other things to get working.
- TinyFPGA A1 or A2 Board.
- Pins if you want to solder the board to another PCB, insert it into a socket, or use with a solderless breadboard.
- 3.3 volt power supply. You can use a 3.3 volt regulator, a lab power supply, or use an existing 3.3 volt power supply from your project.
- TinyFPGA Programmer. This is a low-cost JTAG programmer board designed specifically for the A-series boards.
- Something interesting to control or interface with. If you are just starting out you could use some LEDs or maybe a logic analyzer. Otherwise you might have something more specific in mind ;)
Software
You will need to install the latest development environment and other support tools for the MachXO2 FPGAs and the A-Series boards.
- Download and install Lattice Diamond. It is available for both Windows and Linux.
- Request a free license file in order to use the Lattice Diamond software.
- The TinyFPGA A-Series GitHub Repository has Lattice Diamond template projects that you may find useful. They include an empty top-level verilog module with pin constraints to map board pins to the correct IOs on the MachXO2 FPGA chip. You could download the latest files directly in a zip file or clone the repo using git.
- Download and install the latest release of the TinyFPGA Programmer Application. This programmer application is used for both the A-series and B-series boards.
Serial Port Driver
IMPORTANT: If you plan on using the TinyFPGA Programmer and you are using a Windows version older than Windows 10, you need to install a universial USB serial port INF that tells Windows to use the USB serial port driver for the TinyFPGA Programmer. Paul Stoffregen, the creator of the Teensy series of microcontroller boards has an installer that works very well for this.
Download and run the Virtual Serial Driver Installer.
First Project Tutorial
Once you have all of your hardware and software ready you can get started developing some digital logic. This first project won’t go into all the details of designing and implementing digital logic circuits in general, but it will guide you through the specifics of setting up a simple project, writing verilog, generating a bitstream for your TinyFPGA A1 or A2 board, and programming your board with the bitstream.
1. Solder Pins to your board
This tutorial will use the TinyFPGA board in a breadboard. If you want to follow along you will need to solder pins to the board for it to drive the LEDs and to provide a connection for the JTAG programmer.
The JTAG pins are on the board twice. There is a header at the bottom of the board where the pins can be soldered on facing up. This is most convenient if you want to connect your JTAG programmer directly to the board. The JTAG pins are also on the right side of the board. This is useful if you are taking advantage of the JTAGENB
feature and want to use the JTAG pins for IO. They are also useful if you want to add the TinyFPGA board to an existing JTAG chain in your project.
2. Build LED blinker circuit
Now that your board has pins on it it can be inserted into a solderless breadboard. In my breadboard I am using a 3.3 volt regulator to convert a 5 volt power source. I connected LEDs to pins 9, 10, and 11 with 220 ohm resistors in series.
3. Connect JTAG programmer
Option 1: Use the TinyFPGA Programmer
Connect the TinyFPGA Programmer to the TinyFPGA board. Make sure the programmer is connected in the correct orientation. You should be able to see the labels of the JTAG header pins on both the programmer and the TinyFPGA board. If you need a 3.3 volt power source, there is a location on the TinyFPGA Programmer board where you can solder a header or wire to power your project.
Option 2: Use a Lattice Programming Cable
I had originally bought the official Lattice Programming Cable. I think the generic lattice programming cables on eBay will work as well. They use the same FTDI chip. The colors in my setup might not match the colors on your cable. Pay attention to the JTAG names on the FPGA board and connect them to the correct wires on your programming cable.
In my circuit I’m using the 5V Out
from the programming cable to drive the 3.3 volt regulator. Make sure you connect the VCC
wire from the programmer to 3.3 volts on your board. That’s the voltage level the programmer will use when communicating with the FPGA.
4. Copy the template project from the TinyFPGA A-Series Repository
Copy either the template_a1
or template_a2
directories to a new directory and rename it blink_project
.
5. Open your newly copied template project
Open the Lattice Diamond application. From the File
menu select Open
and Project...
. In the newly opened file chooser, navigate to the blink_project
directory you just created and select the template_a1.ldf
or template_a2.ldf
project file.
6. Implement your logic
Now that we have opened our new project we can write some verilog code. Make sure the File List
tab is open on the left-hand side view and open up the TinyFPGA_A1.v
or TinyFPGA_A2.v
verilog file.
This is a very simple top-level verilog module that represents the IO pins available on the TinyFPGA A-Series boards. Right now this top-level is assigning all the pins to 1'bz
. This means the pins will be left floating or disconnected. Let’s implement some logic to blink a few LEDs.
Before we can do anything, we need a clock source. The MachXO2 FPGAs have an internal oscillator we can use. To use the internal oscillator we need to instantiate the OSCH
module and tell it what frequency we want.
wire clk;
OSCH #(
.NOM_FREQ("2.08")
) internal_oscillator_inst (
.STDBY(1'b0),
.OSC(clk)
);
Since we are just blinking some LEDs we don’t need a high frequency so we can use the lowest internal frequency available which is 2.08 MHz. For more details on the clock resources available in the MachXO2 FPGAs please see the MachXO2 sysCLOCK PLL Design and Usage Guide.
NOTE: If you are familiar with VHDL or Verilog you may decide to quickly skim through the rest of this step or skip it completely. If you are not at all familiar with Verilog you should pay close attention and take a look at the additional resources at the end of this tutorial.
Now that we have a clock we can implement some sequential logic. We will create a simple counter to time the blinking of our LEDs.
reg [23:0] led_timer;
always @(posedge clk) begin
led_timer <= led_timer + 1;
end
The timer will increment by 1 every clock period. We can use the upper bits to blink our LEDs but we need to assign them to external pins. Edit the corresponding assign
statements so they match the code below.
assign pin9_jtgnb = led_timer[23];
assign pin10_sda = led_timer[22];
assign pin11_scl = led_timer[21];
At this point you should save all your changes by clicking the floppy disk icon below the menubar or by using the CTRL + SHIFT + S
keyboard shortcut.
TIP: The mapping of TinyFPGA A-series board pin names to the FPGA pin names can be found in the template_a1.lpf or template_a2.lpf file.
7. Generate JEDEC programming file
Select the Process
tab on the left hand side view. This will bring up a tree of tasks that need to be executed in order to generate the JEDEC programming file. At the very bottom of the tree you should see an entry labeled JEDEC File
. Double-click that entry and the programming file should be created. When it is done it will have a green checkmark next to it.
8. Program the FPGA board
Option 1: Use the TinyFPGA Programmer
Open up the TinyFPGA Programmer Application.
Navigate to your project’s impl
directory and select the .jed
bitstream file.
If your TinyFPGA Programmer is connected correctly, it should indicate it is Connected to TinyFPGA A1. Ready to program.
. Press the Program FPGA
button to program the design onto the FPGA.
Option 2: Use a Lattice Programming Cable
From the Tools
menu select Programmer
.
In the Programmer: Getting Started
dialog make sure the Create a new project from a JTAG scan
option is selected as well as the Import file to current implementation
checkbox.
Click on the program button to program the design onto the FPGA.
9. Verify the design works on the board as intended
If you followed this tutorial exactly you should see the three LEDs counting in binary. One will stay on for about a second, then off for a second. The next will be on for two seconds and off for two seconds. The last will be on for four seconds and off for four seconds.
If you see the LEDs blinking congratulations! You’ve successfully programmed your FPGA board. If you are familiar with Verilog and digital design you are ready to implement more complicated designs on your board(s).
Extra Resources
- TinyFPGA A-Series Repository
- Generic FPGA and Verilog Tutorials
- Lattice MachXO2 Page