Setup, Work-flow and Tool Introduction
Welcome to ECE 437 Lab. The purpose of this first lab is to setup your mg account and introduce you to the tools and work-flow for the upcoming labs. Then you will work on the register file for your first processor. Throughout the course of this lab we will use a Field Programmable Gate Array (FPGA) to run your designs, thus we will not only focus on the RTL design, but on designing for real hardware with delays and transient states. The FPGA is on a development board, in our case, the DE2 (or DE2-115), it comes with other components to enable interaction with your design in hardware, such as seven segment displays, switches, and push buttons.
We are factoring in Git to the work-flow as a Source Code Management (SCM) tool in order to aid in design and delivering material to you the students. This allows you to explore design options and development without breaking known working versions or should you add unintended features (bugs) you can use this tool to find and remove them from the design.
This tutorial will guide you through your basic work-flow and introduce the tools along the way. This will allow you to focus on your design rather than the tools used to make the design. If you have any concerns about the lab requirements please see the syllabus.
|
Note
|
If something does not work as you expected, please inform the TA. Should it actually be working as intended the TA will inform you to change expectations, otherwise the issue will be resolved. |
Account Setup
First, we will setup your mg account for the class. Each student will be given an account of the form mg ###. This account will most likely be given out during your first lab session. Enter the MG account information in the login window of your workstation. Check your typing as the passwords are randomly generated and some characters may not be what you expect at first glance.
|
Caution
|
If you do not yet have this account/password, please do not run the setup on your ECN account as it will override some settings you may want. If for whatever reason you need to run this script more than once, please answer 'NO' to change your password, or CTRL+c the script. ECN has a time lockout on previously used passwords. |
We are going to run a script called setup. This script will prompt you to
configure your mg account as well as change your password. Now open a
terminal and cd to your home directory, then issue the following command to
run the setup script and answer the prompts:
~ece437l/tools/setup
Once this script has run, it will inform you that the terminal needs to be restarted. Do this now, close the terminal you used to run the script and open a new terminal. You should now see some setup text scroll by as your terminal starts, this is for the tools that will be used during the semester.
|
Note
|
Check your ~/.cshrc file and see that it contains only one of the following statements, if it has more than one please remove any extra: |
# section number i.e. sec1, sec2, sec3, ...
setenv SUB_ece437l 'sec#'
The setup script, which we previously ran, added the course tools directory to your shell path so all of the course scripts can be invoked without the full path to their location. (i.e. you don’t need ~ece437l/tools/ to run any of the course tools).
Tutorial
In this tutorial we will go through a simple scenario where these tools will be used. During this tutorial an evaluation sheet is necessary to get points for completing the following steps. You can find the evaluation sheet here. This tutorial will also refresh some system verilog constructs and practices. See Tools for available tools, and Conventions, for conventions we will use in lab.
|
Note
|
In almost all of the tools/scripts used in this class you can use the
-h option to get additional help with that tool/script. |
You will use the following tools in this course:
- ModelSim
-
HDL simulator. Use it to simulate your RTL and mapped designs.
- Quartus
-
Synthesizer. It maps your RTL to an fpga and makes a net list.
- Git
-
SCM. Keeps you organized and helps debugging.
- Make
-
Build tool. Makes your design for simulation.
- Dia
-
Drawing and diagramming tool.
|
Note
|
The above tools are the core tools you will be using this semester. Most of them are wrapped in scripts your TAs provide to you. Let us introduce you to these scripts now: |
- synthesize
-
Synthesizes your design for functional or timing simulation. It will also download a design to the fpga development board.
- Makefile
-
This will build your designs for RTL simulation and synthesis.
- dirset
-
This will setup your directory structure.
- submit
-
This will turn in your labs so they may be graded by the course grading script.
- testasm
-
This will facilitate testing your processor. It will assemble programs and run them with the cpu simulator, then run those programs on your processor. With both outputs you can see if your design performs similar to the simulator, which is our reference design.
- syschk
-
This will look at the synthesis log for any issues worth your attention.
- asm
-
The assembler, takes source assembly (.asm) files and produces memory format (.hex) files.
- sim
-
Processor simulator, runs (.hex) files and executes the instruction set we will be implementing in lab. When finished it will dump the contents of memory as memsim.hex file. This allows you to test the functionality of your design.
- crc
-
Generates min, max and average for 256 crc values based of an input seed
The next section will begin the tutorial where you use a few of these tools. Other tools are really only relevant once you have a processor ready to test (testasm).
Using Git
You will get files for each of your major designs from a git repository in the course account. First go into the ece437 directory by issuing:
cd ~/ece437
Now we are going to use git to grab the tutorial files, issue the command:
git clone ~ece437l/git/tutorial.git
You will notice that it will make a directory ~/ece437/tutorial and populate this directory with files.
|
Warning
|
This is not a complete directory structure. |
We will now run the dirset script to complete the directory structure and copy the Makefile and ModelSim configuration file to the directory. Issue the following command to get into the tutorial directory
cd ~/ece437/tutorial
Once here, run the dirset script with the command:
dirset
|
Tip
|
Ask a TA for help if this script can not be located by the system. |
When you work on your design, it is a good idea to work in a branch other than master. This is for a few reasons. First, if the course staff update the master repo, any pull may cause a conflict. Second, branches let you go down different development paths without breaking a working version of your design.
Now that we have all the files for the tutorial and a complete directory structure, let us make some changes. We will create a branch in our working directory to make some changes, issue either of the following commands:
git checkout -b dev
or
git branch dev && git checkout dev
A new branch will be created called 'dev', not much else has changed, but you now want to be working in this branch. Issue the following command:
git branch
See which branch is selected. It should be 'dev'. Now we will make a few changes to the file source/test.sv. Open this file in your favorite editor. You should see a few import statements. Find the ones on line 5 and 6. Comment the one on line 6 and uncomment the one on line 5. We will go from importing a specific data type to a wild card import of all data types. Save this file. From the ~ece437/tutorial directory issue the following command:
git status
You will see that the file source/test.sv has been modified. Git lets you group files you want to stage for a commit, by adding them to git’s index. First let us make sure we did the right edit, issue the command:
git diff source/test.sv
You should see what changes you made to the file, and it should be what we told you to do above. Now we can stage the file for a commit by adding it to the index. Let us do that now, issue the commands:
git add source/test.sv
git status
You should see that the file is staged, and ready for commit. We can have multiple files in the modified state, but select which files we want to group together for the commit. We are sure this is a good idea let us now issue the command to commit:
git commit
Your favorite editor should appear and allow you to type some text. Note that you changed the import syntax and save the log message and quit your editor.
|
Tip
|
If you commit a file and later want to not have git track changes to it
the command git rm --cached filename will keep the file but stop git from
tracking it. |
|
Important
|
Let us call a TA over and show that we are on branch dev with
changes not in master with the command git diff master. |
Now let us go back to the master branch. Issue the following commands:
git checkout master
This will take us back to the master branch. Now we do a pull to see if anything is updated from the course account. Pulling from the course account when the TAs notify you that there are changes can help with issues you may be having with the lab. To check if there is anything new on the course account issue the following command from the tutorial directory:
git pull origin master
Other useful commands if you just want to see what, if anything, has changed in the master:
git fetch origin master
git diff origin master
Nothing should have changed and everything should be up to date.
Using asm and sim
The next part of the tutorial will focus on the software side of the lab. You will be required to write assembly files and use the simulator to test and verify your processors.
We will start with the assembler, from the ~/ece437/tutorial directory open the file asmFiles/sample.asm. This is a simple assembly program that will store a value at an address. Assemble the program by issuing the following from the tutorial directory.
asm asmFiles/sample.asm
To get an idea of the ISA that we use in lab, issue the command:
asm -i
Assembling asmFiles/sample.asm will make a meminit.hex file in the tutorial directory. We are using 32 bit architecture, so the word size is 4 bytes or 32 bits (8 bits in a byte). Which would mean the addresses that hold each instruction should go up by 4, right? Let us see, run the following command from the tutorial directory:
sim -t
You should see the simulator trace output which gives detailed information about each instruction executed by the simulator. See the Program Counter (PC) value, it is the left most number by the Core name, that goes up by 4 yes? Take note of the SW instruction, it stores the value 0x94 to 0x18.
Now let us open the memsim.hex file and find the address 0x18. Take note, that the addresses are incremented by 1, so the first instruction is at address 0, the next at address 1, followed by 2, and so on until 4. The halt instruction is at 4. The reason for this is that the board has a different memory layout, it is not byte addressable.
|
Note
|
The board memory is 4 byte addressable, which means address 0 holds bytes 0, 1, 2 ,3. |
|
Important
|
Call the TA over and show address 0x18, and where it is located in the memsim.hex file. |
Using ModelSim and Quartus
For this next part we should still be on our 'dev' branch Let us test the change we made earlier by simulating our test design. Issue the following command from the ~/ece437/tutorial directory:
make test.sim
You will notice your design and testbench compile and the simulator will run the testbench for our little test component. Should we need a waveform to see how our design is working, we can issue the command:
make test.wav
Now you should see the ModelSim GUI come up, as well as the waveform window and the object viewer. By default the top level signals are added to the waveform. Use the object and instance viewer to find the nvalue signal. Once you have added the signal to the waveform save the waveform as test.do in the tutorial/scripts directory.
|
Note
|
Ask a TA for help if you are having trouble with this. |
Once we have the waveform do file saved, close ModelSim and go back to the command line. Now edit the file source/test.sv to count by two instead of one in both directions. Issue the following command:
make test.wav
You should see ModelSim come up again. The wave that we saved previously should now have loaded into the waveform and the test should run.
Now let us try our luck with the synthesized design. From the same tutorial directory issue the following command:
make test.syn
You will notice Quartus doing some work on the design, if it finishes without errors you will be notified with a done status and brought back to your prompt. You should notice a new file in your tutorial directory called test.log this contains the synthesis results for your design. You should find the section called Fitter Summary to find some information you need to write down on the evaluation sheet.
We can check the synthesis output to see if anything bad happened that we missed while it was scrolling along on our terminal. Issue the following command:
syschk test | less
This will look at the test.log file and find any warnings or errors and show them to you. We pipe this through a pager so that we can scroll at our leisure.
|
Tip
|
If any complications occur call for your TA. |
Now we want to test the synthesized design and see if it still works.
Remember we synthesized the design with the command make test.syn.
Issue the following command to test the gate level design:
make test.sim
You should see the counter count up to 10 then down to 0. Let us try it on the fpga. To do this we will use the synthesize script and download the design to the board. First, let us make sure that the board is plugged into our workstation, and that the power is turned on.
You can see from the DE2 board pictured that the board has the following IO options:
|
Push Buttons
|
There are 4 push buttons labeled KEY3 down to KEY0. |
|
Switches
|
There are 18 switches labeled SW17 down to SW0. |
|
Seven Segment Displays
|
There are 8 seven segment displays HEX7 down to HEX0. |
|
LEDS
|
There are several LEDS red and green they are above the push buttons and switches. |
We will use these on occasion to test a design on the board. You will be responsible for writing the fpga wrappers when we do not provide them.
|
Warning
|
The board must be in 'Run' mode to program correctly. |
We will now place the test component on the board. Issue the following command:
synthesize -d test_fpga
This synthesizes the wrapper and downloads the test_fpga.sof file to the DE2 board. The sof file will be copied to the fpga directory if you need to make use of it later.
Open source/test_fpga.sv to see what the wrapper does. Play around with the design on the board, and get comfortable.
|
Important
|
Call a TA over to demonstrate the design working on the fpga, and simulation of RTL with your waveform and functional gate level design. |
Merging branches
You want to consolidate any new features you have made, since this is the tutorial we will merge back with the master, but you can merge any branch with another branch.
|
Warning
|
First make sure you have any changes committed on your dev branch. Remember we made changes to the source/test.sv file. |
We must go back to the master branch, this is the branch were we want our dev changes to show up. Issue the command:
git checkout master
Now we will merge our dev branch into our master branch. Issue the command:
git merge dev
Now that we are done with the dev branch issue the following commands from the tutorial directory.
git branch -d dev
This will remove the dev branch from our working repository.
|
Note
|
If you want to just abandon a branch without merging it use the option -D
instead of -d. |
Submitting your design
This is probably the most important step of any lab, submitting your design for grading. The submit script is fairly simple you tell it which lab you want to turn in and it will package up the necessary files and send them on their way.
submit -p lab1
You can see if you submitted for this lab as long as you do so before the
deadline. The -v option will let you view your submission, issue the
command:
submit -v
To view submissions for current lab, or :
submit -v -p lab1
To view submissions for a specific lab.
That is all of the basic work-flow that this tutorial covers.
Conventions
The course will use the following conventions for files, data structures, directories, and assistance in the labs.
- File Names
-
- SV modules
-
All source files should be named after the module they contain. i.e. I have a module called 'counter', my source file is named counter.sv.
- SV testbench
-
All testbench files should be named after a module with '_tb' appended to the end of the module name. i.e. I have a module called 'counter', my testbench module name is 'counter_tb', and the testbench is called counter_tb.sv.
- SV packages
-
All package files should be named after the package they define with '_pkg' appended to the end of the module name. Package source files will end with the extension '.vh'. i.e. I want a package called 'types', I name the package 'types_pkg', and my file name is types_pkg.vh.
- SV interfaces
-
All interface files should be named after the interface they define with '_if' appended to the end of the module name. Interface source files will end with the extension '.vh'. i.e. I want an interface called 'bus', I name the interface 'bus_if', and my file name is bus_if.vh. We use interfaces to help your code be more robust, and later in the semester to help interchange parts of your design in case one processor doesn’t quite work.
- FPGA wrapper
-
All source files that wrap a module for use on the FPGA will have '_fpga' appended to the end of the module name, and file name. i.e. I want to put the module 'counter' on the FPGA, I make a wrapper with the module name 'counter_fpga', and the source file named counter_fpga.sv.
- Data Structures
-
Any types defined by the course or you should end with '_t'. i.e. 'word_t'.
- Directories
-
Your project directory will contain the following directories.
- asmFiles
-
All assembly or '.asm' files go here.
- fpga
-
Programming .sof files for download to the board end up here.
- include
-
All '.vh' files go here.
- mapped
-
All synthesized gate level designs used for simulation go here.
- scripts
-
You place any '.do' files for simulation here. (waveforms etc…)
- source
-
All module source files and fpga wrapper files go here.
- testbench
-
All testbench files go here.
- work
-
This directory is your simulation working library, it comes and goes.
- Getting Help
-
There will be marked on a white board locations for each of the following:
- Evaluation sign off
-
You have your work done and are in need of TA initials. This means you are ready to show the results, not that you have a question on how to show, or what to do to show the results.
- Questions
-
You have questions on what, how, or why to do something. Even quick questions go here.
Summary
This tutorial covers the bare minimum of information on Git, it is recommended that you seek out more information on this tool as it is quite useful and will be used throughout this course. Now you should begin the register file
Register File
The register file is the central storage of a processor. Most operations involve some value stored in this structure. The register file runs at the full speed of the processor, thus it must be small and fast, so that data can be accessed within the cycle it is requested. The register file diagram shows the basic structure of the register file.
This component marks the start of our processor design. First, we will discuss the design specifications for the register file. Following that, we will walk you through setting up the single cycle project to work on the following few labs.
Design Specification
Your design must adhere to the following specification. Use the diagram as a guide while you design your register file.
|
Note
|
For the time being the value to be written will be written on the positive edge of the clock. This will change in the pipeline, and will be discussed in greater detail in the corresponding lab. |
- Specification
-
-
Each location is 32 bits wide.
-
The 0th location will have a constant value of 0x00000000.
-
The remaining 31 locations can store any value.
-
Values will be stored on the positive edge of the clock.
-
An active low asynchronous reset will reset all modifiable locations to a value of 0x00000000.
-
There are two read ports each 32 bits wide.
-
There is one write port 32 bits wide.
-
Each of the corresponding ports has a select signal 5 bits wide..
-
There is a write enable signal 1 bit wide to control storing values in the register file.
-
Setup
This is the first component of all future processor designs. Again we will be using git to setup our work repository, just as we did in the tutorial lab. From your ~/ece437 directory issue the following command:
git clone ~ece437l/git/studentlabs.git processors
This will make the processors directory and populate it with files to aid you in the design of the single cycle processor. Next we must complete the setup of the processors directory. Invoke the dirset script inside the processors directory, by issuing the following commands:
cd ~/ece437/processors
dirset
At this point its is probably a good idea to work in a dev branch of your repository. See the tutorial lab for a refresher if need be.
Files
The following files are included for your benefit.
-
interface: register_file_if.vh
-
testbench: register_file_tb.sv
-
FPGA wrapper: register_file_fpga.sv
FPGA
The following assignments are used to manipulate the board:
-
wdat: SW17..SW15
-
wsel: SW04..SW00
-
rsel1: SW09..SW05
-
rsel2: SW14..SW10
-
WEN: KEY3
-
nRST: KEY2
Deliverables
You will be required to create your own testbench for this design. This is important, as testing each component will facilitate debugging issues you have and putting components together for the larger processor designs.
These are the deliverables for this lab:
-
HDL code for verified functional register file.
-
Module name should be register_file
-
-
A testbench to test the register file.
-
Test asynchronous reset of register
-
Test writes to register 0
-
Verify writes and reads to registers
-
Requirements for Testbench Demo Sign-Offs:
-
Document test cases in testbench.
-
Comprehensive test cases that check functionality of Register File.
-
Correct assertion based checking of design outputs.
-
100% Toggle Coverage for all registers and R/W signals.
Requirements for Source Control:
-
Commit log showing source control for your design
-
Without a proper commit log we will not check-off your design and testbench
-
Completed evaluation sheet.
-
Electronic submission of your design.
-
You must turn in this lab to receive points from the grading script. You may do this by running the submit script from the processors directory. Please see the tutorial lab if you forgot how to submit.
-