Skip to content

Lab 4: TinyRV1 Processor
Part D: FPGA Prototype V2

Lab 4 will give you experience designing, implementing, testing, and prototyping a single-cycle processor microarchitecture and a specialized accelerator. The processor will implement the TinyRV1 instruction set. The instruction set manual is located here:

The lab will continue to leverage concepts from Topic 2: Combinational Logic, Topic 3: Boolean Algebra, Topic 4: Combinational Building Blocks, Topic 6: Sequential Logic, Topic 7: Finite-State Machines, and Topic 8: Sequential Building Blocks. The lab will also leverage concepts from Topic 9: Instruction Set Architecture and Topic 10: Single-Cycle Processors The lab will continue to provide opportunities to leverage the three key abstraction principles: modularity, hierarchy, and regularity. The lab includes seven parts:

  • Part A: Processor Components

    • Due 11/5 @ 11:59pm via GitHub
    • Students should work on Part A before, during, and after your assigned lab section during the week of 11/2
    • Pre-lab survey on Canvas is (roughly) due by end of lab section during the week of 11/2
  • Part B: TinyRV1 Processor

    • Due 11/12 @ 11:59pm via GitHub
    • Students should work on Part B before, during, and after your assigned lab section during the week of 11/9
  • Part C: Accumulate Accelerator

    • Due 11/24 @ 11:59pm via GitHub
    • Students should plan to submit Part C before they leave for Thanksgiving Break
  • Part D: FPGA Prototype v1

    • Due week of 11/16 during assigned lab section
    • This part will focus on prototyping the code developed in Part A+B
    • Even though completed with a partner, every student must turn in their own paper check-off sheet in their lab section!
  • Part E: FPGA Prototype v2

    • Due week of 11/30 during assigned lab section
    • This part will focus on prototyping the code developed in Part A+B+C
    • Even though completed with a partner, every student must turn in their own paper check-off sheet in their lab section!
  • Part F: TinyRV1 Assembly

    • Due 12/3 @ 11:59pm via GitHub
    • This part will include all of the assembly developed during Part D+E
  • Part G: Datasheet and Report

    • Due on 12/8 at 11:59pm for all groups!
    • Post-lab survey on Canvas is due at the same time as the report

This handout assumes that you have read and understand the course tutorials and that you have attended the discussion sections. This handout assumes you have successfully completed Parts A and B meaning your processor and memory bus are working in simulation with all mix, wait, and integration tests passing.

What do we do if Parts A and B is not done?

If Parts A and B are not done then you cannot get started on this part. You must focus on getting your processor and memory bus full working and passing all of the tests before you can complete anything in this part. You may not have time to finish all of this part, but you should do your best. There are no extensions and students cannot complete this part at any other time except during their assigned lab section.

Here are the steps to get started:

  • Step 1. Find your lab partner
  • Step 2. Find a free workstation
  • Step 3. Ask the TAs for a lab check-off sheet and lab worksheet (each student needs their own check-off sheet, use one worksheet per group)

You can also find a copy of the lab worksheet online here:

For each lab check-off task you must raise your hand and have a TA come to check-off your work. The TA will ask you the questions included as part of the lab check-off task and the assess your understanding using the following rubric: mastery; accomplished; emerging; beginning. If the TA and students together feel the students have not mastered the lab check-off task, the students are encouraged to take a few minutes and try again.

When the lab handout requires you to collect data or save a screenshot, place it in the corresponding location in your group's Lab 4 datasheet. These datasheets will be used to organize important information for the modules you are evaluating in lab. We provide you a template for your datasheets here:

Create a copy of this template for your own use by choosing File > Make a copy. Share this spreadsheet with your partner so you can work together on your datasheets. You do not need to have your datasheets completely finished by the end of Part D, but you do need to have the datasheets completed and submitted on Canvas for Part G.

What do we do if the TAs are busy?

Students must maintain a sense of urgency throughout the three hour lab section. When you get to a lab check-off task, raise your hand for 2-3 minutes. If no TA is available you must keep going; if nothing else read ahead and make a plan for the next section of the lab handout. If you do nothing and wait 20-30mins with your hand raised for a TA then you will not be able to finish this part. You must be strategic. Keep moving through the handout and bring over a TA when they are free to possibly look at multiple lab check-off tasks. If you are truly stuck and no TA is available, ask your neighbors. We need to all work together to make sure every student can complete this part. There are no extensions and students cannot complete this part at any other time except during their assigned lab section.

Lab Check-Off Task 1: Setup Lab Kit

The TAs will pass out an ECE 2300 Lab Kit to each group. The TAs will record the kit number on your check-off sheet. For this lab, you will receive the FPGA board, a USB-B cable, a USB-C cable, and a component box with some jumper wires and a USB flash drive. Use the USB-B cable to plug the FPGA board into the workstation.

1. Simulate the Single-Cycle Processor

Before starting to work on an FPGA prototype, you must make sure you have a working Verilog hardware design that has been thoroughly tested in simulation. We will be both running test simulations and also using two different interactive simulators to ensure our hardware design is fully functional. One student should start VS Code on the workstation using the following steps:

  • Open the ECE 2300 folder on the desktop
  • Double click on ECE 2300 VS Code
  • Enter an ecelinux server number and your password

Make sure your group repository is up to date.

% source setup-ece2300.sh
% cd ${HOME}/ece2300/groupXX
% git pull
% tree

Where XX is your group number.

1.1. Running Tests

Now run all of the tests from a clean build to ensure your design is fully functional.

% cd ${HOME}/ece2300/groupXX
% trash build
% mkdir build
% cd build
% ../configure
% make check

It is ok if you are failing tests from Lab 4C, since that part of the lab is not due until later.

Lab Check-Off Task 2: Verify Design in Simulation

Show a TA that your hardware designs are passing all of your tests. The TA will ask the students to explain their testing strategy for two different instructions. Students should show the TA their tests and explain how these tests ensure correct functionality of the TinyRV1 processor.

1.1. Running Interactive ISA Simulator

We now want to assemble a test program and run it on the ISA simulator. Start by taking a look at the following very simple assembly test program that we provide you.

% cd ${HOME}/ece2300/groupXX/build
% code ../lab4/asm/test1.asm

This assembly test program simply adds 3 and 4 and displays the result on out0. You can use tinyrv1-assemble to translate this assembly program into a machine program like this:

% cd ${HOME}/ece2300/groupXX/build
% ../scripts/tinyrv1-assemble ../lab4/asm/test1.asm

You can use the -o command line option to save the machine program to a binary file.

% cd ${HOME}/ece2300/groupXX/build
% ../scripts/tinyrv1-assemble ../lab4/asm/test1.asm -o test1.bin

The build system can also do this for us like this:

% cd ${HOME}/ece2300/groupXX/build
% make test1.bin

Now let's build the ISA simulator and then execute this test program.

% cd ${HOME}/ece2300/groupXX/build
% make proc-isa-sim
% ./proc-isa-sim +bin=test1.bin

You should be able to see that out0 is 7. You can use the +step command line option to single step through your test program.

% cd ${HOME}/ece2300/groupXX/build
% make proc-isa-sim
% ./proc-isa-sim +bin=test1.bin +step

Step through several instructions then enter r and press enter to finish the executing the test program without stepping. You can use the +tui command line option to see the program, PC, registers, physical memory, and memory mapped I/O.

% cd ${HOME}/ece2300/groupXX/build
% make proc-isa-sim
% ./proc-isa-sim +bin=test1.bin +tui

Here are the possible commands you can use in TUI mode.

  • Enter executes the current instruction
  • /quit quits the simulator
  • /run finishes executing the program without stepping
  • /N runs simulation for N cycles (where N is a decimal number)
  • /inN=M sets input N to value M where M can be a decimal number (i.e., 10), hex number (i.e., 0xa), or binary number (0b1010)

Verify that out0 is being set to 7. There is also a +tui-tall mode that shows more instructions, registers, and memory.

% cd ${HOME}/ece2300/groupXX/build
% ./proc-isa-sim +bin=test1.bin +tui-tall

Now let's experiment with the test5 assembly test program.

% cd ${HOME}/ece2300/groupXX/build
% code ../lab4/asm/test5.asm

This assembly test program reads in0, in1, and in2 and writes each one to out0, out1, and out2 respectively. It also writes in2 to out3. Let's make the corresponding machine program and run it on the ISA simulator.

% cd ${HOME}/ece2300/groupXX/build
% make test5.bin
% ./proc-isa-sim +bin=test5.bin +in0=12 +in1=13 +in2=14

Confirm that out0 is 12, out1 is 13, out2 is 14, and out3 is also 14. Try executing this same machine program using both the +step and +tui mode.

% cd ${HOME}/ece2300/groupXX/build
% ./proc-isa-sim +bin=test5.bin +in0=12 +in1=13 +in2=14 +step
% ./proc-isa-sim +bin=test5.bin +in0=12 +in1=13 +in2=14 +tui

In TUI mode step through the program for a few cycles then try changing one of the inputs and run the simulation for 100 cycles like this:

(tui) /in0=42
(tui) /100

Verify that out0 changes to 42. Try changing other MMIO inputs, simulating for 100 cycles, and verifying the expected MMIO outputs change.

1.3. Running Interactive Single-Cycle Processor Simulator

Now we are ready to run these two assembly tests programs on your TinyRV1 single-cycle processor integrated with your memory bus. Build the interactive single-cycle processor simulator like this:

% cd ${HOME}/ece2300/groupXX/build
% make proc-scycle-sim

What do we do if we get a 'Can't find definition of m' error?

You may see an error like this:

%Error: ../lab4/sim/proc-scycle-sim.v:226:68:
  Can't find definition of 'm' in dotted variable: 'proc.dpath.rf.m'

The interactive simulator needs to poke into your design to display the value of reach register in your register file, but this means it needs to know the name of the 2D array of signals you are using to store the register file state. For example, you might have a single like this in your register file:

logic [31:0] rf [31];

You need to rename this signal to be m like this:

logic [31:0] m [31];

Then rerun all of your tests. After this change, you should be able to build the interactive single-cycle processor simulator.

Now run the test1 machine program on the interactive single-cycle processor simulator including using step and TUI modes.

% cd ${HOME}/ece2300/groupXX/build
% make test1.bin
% ./proc-scycle-sim +bin=test1.bin
% ./proc-scycle-sim +bin=test1.bin +step
% ./proc-scycle-sim +bin=test1.bin +tui

You can use +dump-vcd=waves.vcd to debug any issues using waveforms.

% cd ${HOME}/ece2300/groupXX/build
% ./proc-scycle-sim +bin=test1.bin +dump-vcd=waves.vcd

Now run the the test5 program on the interactive single-cycle processor simulator including using step and TUI modes.

% cd ${HOME}/ece2300/groupXX/build
% make test5.bin
% ./proc-scycle-sim +bin=test5.bin +in0=12 +in1=13 +in2=14
% ./proc-scycle-sim +bin=test5.bin +in0=12 +in1=13 +in2=14 +step
% ./proc-scycle-sim +bin=test5.bin +in0=12 +in1=13 +in2=14 +tui

Try changing the inputs in TUI mode and verify the outputs change.

Lab Check-Off Task 3: Verify Interactive Simulator

Show a TA your TinyRV1 single-cycle processor running test5.bin in TUI mode. The TA will ask you to change the inputs, simulate for some number of cycles, and verify that the outputs are changing to the desired values.

1.4. Copying Files to Workstation

We now need to get the files for your design from ecelinux onto the workstation. This requires multiple steps.

  • Step 1. Click Microsoft Edge on the desktop to open a web-browser on the workstation to log into GitHub and then find your repository

  • Step 2. Start PowerShell by clicking the Start menu then searching for Windows PowerShell

  • Step 3. Use the following command to change to your home directory on the workstation in the lab (where netid is your Cornell NetID)

% cd C:\Users\netid
  • Step 4. Clone your repo onto the workstation by using this command in PowerShell (where netid is your Cornell NetID, notice we are using https!):

% git clone https://github.com/cornell-ece2300/groupXX
If your group repo already exists then you need to instead do a pull!

% cd groupXX
% git pull
  • Step 5. In the Connect to GitHub pop-up, click Sign in with your browser

  • Step 6. You may be asked for your GitHub username again and you may be asked to authorize the Git Credential Manager; click authorize git-ecosystem

  • Step 7. Verify that you have successfully cloned your repo by changing into your repo and using tree on the workstation:

% cd groupXX
% tree

2. Setup Quartus Project

Click Quartus (Quartus Prime 18.1) on the desktop to start Quartus. Important: Ensure that the Quartus Version is 18.1 and not 23.1. Then, click Run the Quartus Prime software. You might need to try starting Quartus twice. Setup a new Quartus project using the New Project Wizard:

  • Directory, Name, Top-Level Entity
    • You must enter the working directory as follows with your NetID!
    • Working directory: C:\Users\netid\lab4d
    • Name of this project: lab4d
    • Name of top-level design entity: lab4d
    • Click Next
  • Directory does not exist. Do you want to create it?
    • Click yes
  • Project Type
    • Choose Empty Project
    • Click Next
  • Add Files
    • Click User Libraries...
    • Click triple dots to the right of Project library name
    • Click on This PC, then navigate to your cloned repo by choosing Windows (C:) > Users > netid > groupXX where XX is your group number
    • Click Select Folder
    • Click Add
    • Click OK
    • Click triple dots to right of File name
    • Click on This PC, then navigate to your cloned repo by choosing Windows (C:) > Users > netid > groupXX > lab4 where XX is your group number
    • Shift-click on every Verilog hardware design file (do not include any files in the test or sim subdirectories)
    • Click Open
    • Click Next
  • Family, Device, and Board Settings
    • Click Board tab
    • Family: Cyclone V
    • Select DE0-CV Development Board
    • Make sure Create top-level design file is checked
    • Click Next
  • EDA Tool Settings
    • Click Next
  • Summary
    • Click Finish

As in previous labs, you must use the following steps to ensure Quartus knows your design includes RTL modeling:

  • Choose Assignments > Settings from the menu
  • Select the category Compiler Settings > Verilog HDL Input
  • Under Verilog version click SystemVerilog
  • Click OK

3. Processor FPGA Prototype

We are now ready to integrate your TinyRV1 single-cycle processor into a full embedded system with 512 bytes of physical memory. We will then synthesize the design and configure the FPGA so we can run much larger machine programs on the prototype.

3.1. Integrate

We want to implement a TinyRV1 processor FPGA prototype with the following specification:

  • Input to clock divider is connected to the 50MHz clock on the FPGA board
  • rst (ACTIVE LOW!) is connected to the reset button on the board using a synchronizer
  • The left most push button will be the go button (see below)
  • The left five switches are in0
  • The right five switches are in1
  • The right three push buttons are the three least significant bits of in2 (ACTIVE LOW!)
  • The two seven-segment displays on the left are out0
  • The two seven-segment displays in the middle are out1
  • The two seven-segment displays on the right are out2
  • The left most LED shows the go bit
  • The second left most LED is an error signal
  • The right eight LEDs are for out3
  • The general-purpose pins will be used to connect to the SPI
    • SCLK connects to GPIO_1[1] which connects to D0 on USB-to-SPI adapter
    • MOSI connects to GPIO_1[3] which connects to D1 on USB-to-SPI adapter
    • MISO connects to GPIO_1[5] which connects to D2 on USB-to-SPI adapter
    • CS connects to GPIO_1[7] which connects to D3 on USB-to-SPI adapter

Here is a block diagam and annotated FPGA board and breadboard diagram illustrating the system we will be prototyping.

Executing a program on our TinyRV1 processor FPGA prototype involves the following four steps illustrated below.

  • Step 1: Press Reset Button -- We need to reset the system through a synchronizer to avoid metastability. This reset signal will reset all components in the system and will also initialize the physical memory with a simple default program. The "go" bit is reset to zero, and we connect the go bit through a NOT gate to the instruction and data memory wait inputs. This means after reset the processor will be waiting and will not execute any instructions.

  • Step 2: Load Program -- While the processor is waiting we can load a program into physical memory from the workstation. We will use a Python-based loader on the workstation which takes as input a .bin file and translates each line into a 48-bit SPI message which then gets sent over the USB-C cable to the USB-to-SPI adapter on the breadboard. The USB-to-SPI adapter sends the SPI messages to the FPGA through four jumper wires which connect to four general-purpose I/O pins (one each for SCLK, MOSI, MISO, CS). We will also probe the SCLK and MOSI signals on the oscilloscope.

  • Step 3: Press Go Button -- Now that the program has been fully loaded into physical memory we can go ahead an tell the processor to start executing this program by pressing the go button. Notice how pressing the go button enables the DFFRE which is has its input hardwired to 1. So when we press the go button this DFFRE is enabled which then stores a 1. The DFFRE will continue to store a 1 until the system is reset.

  • Step 4: Program Starts Executing -- Now that the instructions and data memory wait signals are zero, the processor will fetch the first instruction at address zero and start executing the program.

Here is a template you can use for your top-level design. Replace every __TODO__ with the correct connection to the top-level pins on the FPGA.

//----------------------------------------------------------------------
// Setup Quartus
//----------------------------------------------------------------------
// A typo can result in using an undeclared wire, but this is usually
// just a warning. The following makes using undeclared wires an error.

`default_nettype none

//----------------------------------------------------------------------
// Clock Divider
//----------------------------------------------------------------------
// We are dividing the clock by a factor of four for a target clock
// period of 80ns. You need to connect the ports to the appropriate
// top-level ports.

logic clk;

ClockDiv_RTL clock_div
(
  .init       (0),
  .clk_in     (__TODO__),
  .divide_sel (1),
  .clk_out    (clk)
);

//----------------------------------------------------------------------
// Reset Synchronizer
//----------------------------------------------------------------------
// You need to connect the ports to the appropriate top-level ports.

logic rst;

Synchronizer_RTL reset_sync
(
  .clk (clk),
  .d   (__TODO__), // REMEMBER: Reset port is active low!
  .q   (rst)
);

//----------------------------------------------------------------------
// DFFRE for go bit
//----------------------------------------------------------------------
// You need to connect the ports to the appropriate top-level ports.

logic go;

DFFRE_RTL go_reg
(
  .clk (clk),
  .rst (rst),
  .d   (1'b1),
  .en  (__TODO__), // REMEMBER: Push buttons are active low!
  .q   (go)
);

assign LEDR[9] = go;

//----------------------------------------------------------------------
// Processor
//----------------------------------------------------------------------

logic        imem_val;
logic        imem_wait;
logic [31:0] imem_addr;
logic [31:0] imem_rdata;

logic        dmem_val;
logic        dmem_wait;
logic        dmem_type;
logic [31:0] dmem_addr;
logic [31:0] dmem_wdata;
logic [31:0] dmem_rdata;

logic        trace_val;
logic [31:0] trace_pc;
logic [31:0] trace_data;
logic        trace_wen;
logic [4:0]  trace_wreg;
logic [31:0] trace_wdata;

assign imem_wait = ~go;
assign dmem_wait = ~go;

ProcScycle proc
(
  .*
);

//----------------------------------------------------------------------
// Memory Bus
//----------------------------------------------------------------------

logic        hmem_val;
logic [31:0] hmem_addr;
logic [31:0] hmem_wdata;

logic        mem0_val;
logic        mem0_type;
logic [31:0] mem0_wdata;
logic [31:0] mem0_addr;
logic [31:0] mem0_rdata;

logic        mem1_val;
logic        mem1_type;
logic [31:0] mem1_addr;
logic [31:0] mem1_wdata;
logic [31:0] mem1_rdata;

logic [31:0] in0, in1, in2, in3;
logic [31:0] out0, out1, out2, out3;

MemoryBus_RTL memory_bus
(
  .*
);

//----------------------------------------------------------------------
// Physical Memory
//----------------------------------------------------------------------

logic error;

Memory_512B_RTL physical_memory
(
  .*
);

//----------------------------------------------------------------------
// SPI
//----------------------------------------------------------------------
// You need to connect sclk, mosi, miso, and cs to the appropriate
// top-level ports.

logic        sclk;
logic        mosi;
logic        miso;
logic        cs;
logic        out_val;
logic [47:0] out_msg;

assign sclk = __TODO__;
assign mosi = __TODO__;
assign miso = __TODO__;
assign cs   = __TODO__;

SPI_RTL minion
(
  .*
);

assign hmem_val   = out_val;
assign hmem_addr  = { 16'b0, out_msg[47:32] };
assign hmem_wdata = out_msg[31:0];

//----------------------------------------------------------------------
// External Inputs
//----------------------------------------------------------------------
// You need to connect the ports to the appropriate top-level ports.

assign in0 = { 27'b0, __TODO__ };
assign in1 = { 27'b0, __TODO__ };

// REMEMBER: The push buttons are active low!
assign in2 = { 29'b0, __TODO__ };

assign in3 = '0;

//----------------------------------------------------------------------
// External Outputs
//----------------------------------------------------------------------
// You need to connect the ports to the appropriate top-level ports.

DisplayOpt_GL display_out0
(
  .in       (out0[4:0]),
  .seg_tens (__TODO__),
  .seg_ones (__TODO__)
);

DisplayOpt_GL display_out1
(
  .in       (out1[4:0]),
  .seg_tens (__TODO__),
  .seg_ones (__TODO__)
);

DisplayOpt_GL display_out2
(
  .in       (out2[4:0]),
  .seg_tens (__TODO__),
  .seg_ones (__TODO__)
);

assign __TODO__ = out3[7:0];

//----------------------------------------------------------------------
// Error
//----------------------------------------------------------------------
// The memory sets an error flag if it detects unaligned or
// out-of-range accesses. We connect this error flag to an LED so we
// can detect a memory access error.

assign __TODO__ = error;

You will need to also include the following modules.

`include "lab1/DisplayOpt_GL.v"
`include "lab3/DFFRE_RTL.v"
`include "lab3/DFF_RTL.v"
`include "lab3/ClockDiv_RTL.v"

Use the following steps when you are ready to integrate the counter.

  • Double-click on DE0_CV_golden_top
  • Instantiate the template shown above
  • Fill in the connections to the top-level ports
  • Be sure to include all the required modules at the top
  • Choose File > Save from the menu

Then make sure to hook up the SPI interface on the breadboard as mentioned above.

  • SCLK connects to GPIO_1[1] which connects to D0 on USB-to-SPI adapter
  • MOSI connects to GPIO_1[3] which connects to D1 on USB-to-SPI adapter
  • MISO connects to GPIO_1[5] which connects to D2 on USB-to-SPI adapter
  • CS connects to GPIO_1[7] which connects to D3 on USB-to-SPI adapter

Connect the two oscilloscope probes to the SCLK and MOSI pins of the SPI interface.

Lab Check-Off Task 4: Discuss Processor Integration

Show a TA your breadboard wiring and your top-level integration. Discuss how the connections provided in the template implement the specification. Confirm with the TA that you have correctly accounted for the fact that reset and all push-buttons are active low! Show how you have connected SCLK and MOSI to the oscilloscope. Take your time and double check all connections! Synthesizing the processor takes 10 minutes so get your connections right the first time!

3.2. Synthesize

You will need to update the timing constraint file as follows:

set_max_delay -from [all_inputs] -to [all_outputs] 20
set_min_delay -from [all_inputs] -to [all_outputs] 0

create_clock -period 20 [get_ports {CLOCK_50}]
create_generated_clock -name clk -divide_by 4 -source CLOCK_50 \
  [get_nets {clock_div|*|q[1]}]

set_output_delay -add_delay -clock clk -max 0 [all_outputs]
set_output_delay -add_delay -clock clk -min 0 [all_outputs]

set_input_delay  -add_delay -clock clk -max 0 [all_inputs]
set_input_delay  -add_delay -clock clk -min 0 [all_inputs]

As in Lab 3, we must specify the clock constraints in two steps. First, we create specify that the top-level CLOCK_50 port has a clock period of 20ns. Then, we we must carefully constrain the output of the clock divider so the tools know that this is also a clock signal. We will be using a clock period of 80ns which should be sufficient for your processor to meet timing.

Now use the following steps to synthesize your design.

  • Choose Processing > Start Compilation from the menu
  • Wait 10 minutes for synthesis to complete
  • While you are waiting go ahead and start working on your calculator assembly program. See Section 4!

How do I fix "can't open Verilog Design File" errors?

This probably means you did not setup the user library correctly, so Quartus cannot find the files you are including using the include Verilog preprocessor directive. You can use the following steps to fix this:

  • Choose Assignments > Settings from the menu
  • Select the category Libraries
  • Click triple dots to the right of Project library name
  • Click on This PC, then navigate to your cloned repo by choosing Windows (C:) > Users > netid > groupXX where XX is your group number
  • Click Select Folder
  • Click Add
  • Click OK
  • Choose Processing > Start Compilation from the menu to see if this fixes the issue

How do I fix "Verilog HDL syntax" errors?

This might be because you did not configure Quartus to use SystemVerilog! You can use the following steps to ensure Quartus knows your design includes RTL modeling:

  • Choose Assignments > Settings from the menu
  • Select the category Compiler Settings > Verilog HDL Input
  • Under Verilog version click SystemVerilog
  • Click OK

Once synthesis is completed, we can collect the data you need for your datasheet.

  • Chip Planner

    • Choose Tools > Chip Planner from the menu
    • Identify where the logic used to implement your design is located in the FPGA
    • Save a screenshot of the Chip Planner (just the rectangular view of the FPGA) using WindowsKEY+SHIFT+S for your datasheet
    • Choose File > Close from the menu to close the chip planner
  • Area

    • Choose Processing -> Compilation Report from the menu
    • Under Table of Contents choose Fitter > Resource Section > Resource Usage Summary
    • Record the number of logic gates (i.e., combinational ALUT usage for logic) in the Area section of the datasheet.
    • Record the number of flip-flops (i.e., each dedicated logic registers in the report is one flip-flop) in the Area section of the datasheet.
  • Timing

    • Choose Tools > Timing Analyzer from the menu
    • Double-click Update Timing Netlist
    • Choose Reports > Custom Reports > Report Timing from the menu
    • Report Timing
      • Clocks - From clock: clk
      • Clocks - To clock: clk
      • Targets - From: [get_registers *]
      • Targets - To: [get_registers *]
      • Report number of paths: 100
      • Detail level: Path Only (click Set Default)
      • Click Report Timing

You now need to annotate the critical path on the worksheet using two diagrams. First, you must clearly show the critical path on the prototype diagram. Then you must clearly show the critical path on the single-cycle processor datapath and control unit diagram. You must also label the delays in nanoseconds of all components along the critical path!

Update Datasheet for Processor Prototype V1

Make sure the module name, designers, and group number sections of your datasheet are finished. Update the area, chip planner, timing, and critical path sections of the datasheet. The block diagram in the datasheet will be the block diagrams from the worksheet annotated with the actual delays. You can update the interface, functionality, and block diagrams later as you prepare your datasheets for submission in Part G.

3.3. Configure

Now we are ready to configure the FPGA for TinyRV1 single-cycle processor prototype.

  • Choose Tools > Programmer from the menu
  • Click Hardware Setup
  • Currently selected hardware: USB-Blaster [USB-0]
  • Click Close
  • Click Start

The provided physical memory has a default program which is automatically loaded into memory on reset. The default program has the following four instructions:

  addi x1, x0, 2
  addi x2, x1, 2
  sw   x2, 0x210(x0)

done:
  jal  x0, done

This program should just display 2+2=4 on out0. Go ahead and press reset then the go button (i.e., the left-most push button). You must press reset first before pressing the go button! You should see 4 displayed on out0.

Now want to try loading in a new program from the workstation over SPI. You will need to use the USB-C cable to connect the SPI adapter on the breadboard to the top-left USB port of the workstation. You must use the top-left USB port of the workstation; any other port will not work!

Setup the oscilloscope so we can see the SPI packets being sent from the workstation to the TinyRV1 processor FPGA prototype. Revisit previous lab handouts if you need a refresher on using the oscilloscope. Here are the steps we will need.

  • Turn on the oscilloscope
  • Press Default Setup
  • Press 2 to turn on Channel 2
  • Rotate the Channel 2 Vertical Position knob to shift Channel 2 down so it does not overlap with Channel 1
  • Rotate the Trigger Level knob to shift the trigger for Channel 1 up so it is around 1.5V

Now use PowerShell on the workstation to assemble our test program and load it into the physical memory in our FPGA prototype over SPI. These commands should be done on the workstation not on ecelinux!

% cd C:\Users\netid\groupXX
% mkdir build
% cd build
% python ..\scripts\tinyrv1-assemble ..\lab4\asm\test1.asm -o test1.bin
% python ..\scripts\tinyrv1-load test1.bin

You should see the oscilloscope flicker. The USB-to-SPI adapter sets SCLK and MOSI to be high for ~20ms during configuration before it actually starts sending SPI messages. We want to get a clean screenshot of the first SPI message without this 20ms pulse. We can use the --pause command line option to tell the loader to pause after configuration and before starting to send SPI messages.

% cd C:\Users\netid\groupXX\build
% python ..\scripts\tinyrv1-load test1.bin --pause

While the TinyRV1 loader is pausing you can now press the Single button on the oscilloscope. Then press enter to enable the TinyRV1 loader to send the SPI messages to the FPGA. You should see a clean capture of the first few periods of SCLK.

The TinyRV1 loader configures the USB-to-SPI adapter to use an SCLK frequency of 100KHz which means an SCLK period of 10us. We need to adjust the scope so we can see an entire SPI message:

  • Rotate the Horizontal Scale knob to set the x-axis scale to 40us

Now go ahead and reload the program using --pause and capture the SPI waveform. You will only be able to capture the first half, so now you need to shift the capture in time.

  • Rotate the Scale knob to set the x-axis scale to 40us

Using the following steps to get a screen shot of the SPI packets on the oscilloscope.

  • Rotate the Horizontal Position knob to shift the waveforms to the left so that the beginning of the SPI message is close to the beginning of the screen

Now go ahead and reload the program using --pause and capture the SPI waveform. Hopefully will now have captured the entire SPI message! You can tell it is the entire message because you will see a break where SCLK stays low before the next message is sent. Spend a few minutes checking to ensure the MOSI data matches your expections. The following diagram illustrates the desired oscilloscope capture.

Once you have your oscilloscope capture, use the USB Flash Drive to take a screenshot of the waveform for your datasheet. Now that we are sure SPI packets are being sent to the processor prototype let's try out the simple test program.

  • Press reset on the FPGA
  • Load the program
  • Press the go button

If everything is working then you should see 7 on out0.

You can now move on to trying test5. Recall that this program reads from three MMIO inputs and writes four MMIO outputs. Use PowerShell on the workstation to assemble this test program and load it into the physical memory in our FPGA prototype over SPI. These commands should be done on the workstation not on ecelinux!

% cd C:\Users\netid\groupXX\build
% python ..\scripts\tinyrv1-assemble ..\lab4\asm\test5.asm -o test5.bin
% python ..\scripts\tinyrv1-load test5.bin

Update Datasheet for Processor Prototype V1

Update the waveform section of your datasheet using the oscilloscope screen capture of a complete SPI message. Use Insert > Insert image in Cell from the menubar to insert screenshots.

Lab Check-Off Task 5: Demonstrate the Processor FPGA Prototype

Show a TA the progress you have made on your datasheet for the processor. The TA will ask you to explain why the MOSI data you captured from the oscilloscope is reasonable. Explain why the number of flip-flops is reasonble. Hint: Calculate the total number of bits in the 512-byte physical memory and the register file. Explain to the TA where your critical path goes using the TinyRV1 block diagrams. Then demonstrate to the TA that your processor can successfully execute the test1 and test5 asesembly programs. Try all various switches and push buttons and confirm the seven-segment displays and LEDs behave as expected.

4. Calculator Assembly Program

In this part, we will implement a TinyRV1 assembly program that has the same behavior as the two-function calculator we implemented in Lab 2, and then we will extend the calculator to support subtraction. This illustrates the tremendous power of using a general-purpose processor; adding more functionality to specialized hardware requires adding more specialized hardware, while adding new functionality to a general-purpose processor simply requires adding more software.

We require taking an incremental approach:

  • Step 1: Implement and test calculator that supports addition
  • Step 2: Implement and test calculator that supports addition and multiplication
  • Step 3: Implement and test calculator that supports addition, multiplication, and subtraction

For each step, we will start by developing an assembly program on ecelinux and use the ISA and single-cycle processor simulator to verify its correctness before loading the program onto the FPGA prototype.

4.1. Step 1: Addition

Open up the calculator-step1.asm file on ecelinux using VS Code.

% cd ${HOME}/ece2300/groupXX/build
% code ../lab4/asm/calculator-step1.asm

Here is the pseudocode for step 1.

loop:

  # load inputs

  x1 = in0
  x2 = in1

  # display outputs

  out0 = x1
  out1 = x2

  # addition

  x4 = x1 + x2

  # done

  out2 = x4
  goto loop

Implement this pseudo-code in assembly in the calculator-step1.asm file. Then assemble it and verify it works on both the ISA simulator and your single-cycle processor.

% cd ${HOME}/ece2300/groupXX/build
% make calculator-step1.bin
% ./proc-isa-sim    +bin=calculator-step1.bin +in0=3 +in1=2
% ./proc-scycle-sim +bin=calculator-step1.bin +in0=3 +in1=2

Use git to commit your calculator assembly program and push to GitHub. Then pull the new program to the workstation by using PowerShell as follows:

% cd C:\Users\netid\groupXX\build
% git pull

Double check that your new assembly program has been correctly pulled onto the workstation!

% cd C:\Users\netid\groupXX\build
% cat ..\lab4\asm\calculator-step1.asm

Assemble step 1 into a machine program and load it onto the processor.

% cd C:\Users\netid\groupXX\build
% python ..\scripts\tinyrv1-assemble ..\lab4\asm\calculator-step1.asm -o calculator-step1.bin
% python ..\scripts\tinyrv1-load calculator-step1.bin

Remember to make sure the FPGA board is reset before you load the program. Then press the go button to start the program. Once your step 1 program is working then move on to step 2.

4.1. Step 2: Addition and Multiplication

Open up the calculator-step2.asm file on ecelinux using VS Code.

% cd ${HOME}/ece2300/groupXX/build
% code ../lab4/asm/calculator-step2.asm

Here is the pseudocode for step 2.

loop:

  # load inputs

  x1 = in0
  x2 = in1
  x3 = in2

  # display outputs

  out0 = x1
  out1 = x2

  # addition

  if ( x3 == 0 ):
    x4 = x1 + x2

  # multiplication

  else:
    x4 = x1 * x2

  # done

  out2 = x4
  goto loop

Implement this pseudo-code in assembly in the calculator-step2.asm file. Then assemble it and verify it works on both the ISA simulator and your single-cycle processor.

% cd ${HOME}/ece2300/groupXX/build
% make calculator-step2.bin
% ./proc-isa-sim    +bin=calculator-step2.bin +in0=3 +in1=2 +in2=0
% ./proc-isa-sim    +bin=calculator-step2.bin +in0=3 +in1=2 +in2=1
% ./proc-scycle-sim +bin=calculator-step2.bin +in0=3 +in1=2 +in2=0
% ./proc-scycle-sim +bin=calculator-step2.bin +in0=3 +in1=2 +in2=1

Use git to commit your calculator assembly program and push to GitHub. Then pull the new program to the workstation by using PowerShell as follows:

% cd C:\Users\netid\groupXX\build
% git pull

Double check that your new assembly program has been correctly pulled onto the workstation!

% cd C:\Users\netid\groupXX\build
% cat ..\lab4\asm\calculator-step2.asm

Assemble step 2 into a machine program and load it onto the processor.

% cd C:\Users\netid\groupXX\build
% python ..\scripts\tinyrv1-assemble ..\lab4\asm\calculator-step2.asm -o calculator-step2.bin
% python ..\scripts\tinyrv1-load calculator-step2.bin

Remember to make sure the FPGA board is reset before you load the program. Then press the go button to start the program. Once your step 2 program is working then move on to step 3.

4.1. Step 3: Addition, Multiplication, and Subtraction

Open up the calculator-step3.asm file on ecelinux using VS Code.

% cd ${HOME}/ece2300/groupXX/build
% code ../lab4/asm/calculator-step3.asm

Here is the pseudocode for step 3.

loop:

  # load inputs

  x1 = in0
  x2 = in1
  x3 = in2

  # display outputs

  out0 = x1
  out1 = x2

  # addition

  if ( x3 == 0 ):
    x4 = x1 + x2

  # multiplication

  elif ( x3 == 1 ):
    x4 = x1 * x2

  # subtraction

  else:
    x4 = x1 - x2

  # done

  out2 = x4
  goto loop

Implement this pseudo-code in assembly in the calculator-step3.asm file. Then assemble it and verify it works on both the ISA simulator and your single-cycle processor.

% cd ${HOME}/ece2300/groupXX/build
% make calculator-step3.bin
% ./proc-isa-sim    +bin=calculator-step3.bin +in0=3 +in1=2 +in2=0
% ./proc-isa-sim    +bin=calculator-step3.bin +in0=3 +in1=2 +in2=1
% ./proc-isa-sim    +bin=calculator-step3.bin +in0=3 +in1=2 +in2=2
% ./proc-scycle-sim +bin=calculator-step3.bin +in0=3 +in1=2 +in2=0
% ./proc-scycle-sim +bin=calculator-step3.bin +in0=3 +in1=2 +in2=1
% ./proc-scycle-sim +bin=calculator-step3.bin +in0=3 +in1=2 +in2=2

Use git to commit your calculator assembly program and push to GitHub. Then pull the new program to the workstation by using PowerShell as follows:

% cd C:\Users\netid\groupXX\build
% git pull

Double check that your new assembly program has been correctly pulled onto the workstation!

% cd C:\Users\netid\groupXX\build
% cat ..\lab4\asm\calculator-step3.asm

Assemble step 3 into a machine program and load it onto the processor.

% cd C:\Users\netid\groupXX\build
% python ..\scripts\tinyrv1-assemble ..\lab4\asm\calculator-step3.asm -o calculator-step3.bin
% python ..\scripts\tinyrv1-load calculator-step3.bin

Remember to make sure the FPGA board is reset before you load the program. Then press the go button to start the program.

Lab Check-Off Task 6: Demonstrate the Calculator Assembly Program

Show a TA the final three-function calculator assembly program working in simulation on both the ISA simulator and the single-cycle RTL simulator. Show a TA your completed three-function calculator assembly program working on the FPGA prototype. The TA will ask you to compare the timing (i.e., time for one calculation) and area (i.e., number of logic gates and number of flip-flops) for your Lab 2 calculator prototype and your Lab 4 processor prototype running the calculator assembly program. Look back at your previous datasheets so you have the data ready. Be ready to discuss the trade-off between general-purpose hardware (i.e., the TinyRV1 processor FPGA prototype) and specalized hardware (i.e., the two-function calculator FPGA prototype) both in terms of area, delay, and flexibility.

Lab Check-Off Task 7: Turn in Lab Kit

When you are finished with your demo, pack up your ECE 2300 Lab Kit. Put the wires back and USB flash drive in the component box. Return the FPGA board, USB cables, and component box to a TA who will then record the kit number on your check-off sheet, initial the final check-off, and then collect your check-off sheet.

5. Optional Extension: Four-Function Function

This section is an optional extension to the main lab and is meant for students who have already completed all of the above tasks. Students can exploit the power of a truly programmable processor to add yet another function to their calculator.

  • Option 1: Add a power function which calculates in0 raised to in1. So if in0 is 2 and in1 is 3 then the result should be 8.

  • Option 2: Add a factorial function which calculates in0 factorial. Be careful though because factorials get large fast! You will only be able to caculate 4! without overflow.

Your calculator should use the fourth function when the third pushbutton is pressed.