RISC-V Lab Project PDF
RISC-V Lab Project PDF
RISC-V Lab Project PDF
Lab Manual
Name:
Registration Number:
Section:
Instructions ii
A Experiment 1
1 Implementation of SPI Protocol using verilog on Nexys A7 . . . . . . . . 2
B Lab Project 12
1 Multi Cycle RISC-V Processor Design - 32bit version . . . . . . . . . . . 13
i
Important Instructions
• Read out the Manual very carefully
ii
Part A
Experiment
1
Experiment 1 2
Experiment No. 1
Implementation of SPI Protocol using verilog on
Nexys A7
1. MOSI Master Output Slave Input line is used for sending data from the master
to the slave. MSB is sent first.
2. MISO Master Input Slave Output line is used for sending data to the master from
the slave. LSB is sent first.
3. SCLK This is a serial clock signal that is transmitted by the bus master to the
slave device(s)
4. SS Slave Select line is for master to choose between different slaves to send the
data.
The SPI bus connections, for point to point communication between master and single
slave device are shown in Figure 1.1. In case of multiple devices, a separate slave select
(SS) signal is used by the bus master, to enable the desired slave device.
1. Select the Create Project in the welcome dialog. (Figure 1.3) Then click Next when
the next window pops up.
2. Name your project and choose its location. Then click Next to continue.
3. In the New Project dialog choose RTL Project and check the Do not specify sources
at the time box. Click Next to continue. (Figure 1.4)
4. In the next window select the Boards tab and it will display a list of boards. Select
your board Nexys A7 100T Click Next to Continue.(Figure 1.5)
6. In the Project Manager, under the Sources tab, right click on Design Sources and
choose Add Sources. (Figure 1.7)
7. In the window that pops up, select Add or create design sources, then click Next to
continue.
9. You will be prompted to select a File type, File name, and File location. Make sure
to pick Verilog and Local to project for the type and location. Give your file a name
ending in .v. (Figure 1.8)
10. In the Define Module dialog that appears, you can define your inputs and outputs
if you want. Otherwise they will be defined in the Verilog file.
11. Open the file from design sources and write your code.
12. If you are adding the file directly to your project, make sure to check Copy sources
into project. (Figure 1.9)
2. Copy the code of file SPI master.v (given with the manual) and synthesize it.
3. In the window that pops up, select Add or create simulation sources, then click Next
to continue.
4. Create a new source file with the name SPI master tb.v.
5. Copy the code of file SPI master tb.v (given with the manual) and synthesize it.
6. Right Click on SPI master tb.v in Source section, and make it top module.
7. Go to simulation tap, and make SPI master tb.v top module using the step men-
tioned in 5.
8. Select Run Behavioral Simulation by clicking the Run Simulation in Flow Navigator.
10. Observe the simulated waveform and compare it with the timing diagram of shown
above.
2. Copy the code of file SPI slave.v (given with the manual) and synthesize it.
3. Create a new source file with the name SPI slave tb.v.
4. Copy the code of file SPI slave tb.v (given with the manual) and synthesize it.
5. Right Click on SPI slave tb.v in Source section, and make it top module.
6. Go to simulation tap, and make SPI slave tb.v top module using the step men-
tioned in 5.
7. Observe the simulated waveform and compare it with the timing diagram of shown
above.
2. Copy the code of file main code tb.v (given with the manual) and synthesize it.
3. Right Click on main code tb.v in Source section, and make it top module.
4. Go to simulation tap, and make main code tb.v top module using the step men-
tioned in 5.
5. Observe the simulated waveform and compare it with the timing diagram of shown
above.
1. Create a new project for hardware implementation as shown in section 1.2.1 Creating
a Project in Vivado 2019.2.
2. Add the three source file with the name main code.v, SPI master.v and SPI slave.v
provided to you with the manual.
3. Right Click on main code.v in Source section, and make it top module.
4. In the Flow navigator, click Open Elaborated Design in the RTL Analysis. (Figure
1.11)
5. Open theI/O ports tab and assign your input output pin connections under Pack-
age Pin according to the given table 1.1 or you may refer Nexys A7 Reference
Manual (attached with the manual).
6. In the I/O Std choose your required voltage level (Figure 1.12) then press ctrl S
and save the XDC file by name of your choice.
9. Click Generate BitStream under Program and Debug in the Flow Navigator.
10. You can view your Schematic Design under Synthesis. (Figure 1.11)
11. Connect your FPGA Board to your computer using USB port.
12. Open the Hardware Manager under Program and Debug in the Flow Navigator or
from the pop up that appeared at the finish of generating BitStream.
15. Now its time to program the bit file into your hardware. In the dropdown of
theHardware Manager, click Program Device and choose the device (xc..) to pro-
gram.
16. The Bitstream File field should be automatically filled in with the bit file generated
earlier. If not, click the button at the right end of the field and navigate to
< P rojectDirectory > / < P rojectN ame > .runs/impl 1/
and select the bit file and click Program.
17. Your code is loaded to your FPGA. Pressing buttons or as your code chose it should
have your output displayed on your FPGA.
Lab Project
12
Lab Project 13
Experiment No. 1
Multi Cycle RISC-V Processor Design - 32bit version
Pre-Project Reading
All the reference material is available in the google link here and resources here.
Objectives
• Studying, Designing, Implementing, and testing a 32-bit multi cycle RISC-V Pro-
cessor using Verilog.
Tools
1. Intruction Fetch
2. Operand Fetch
3. Execution
4. Memory Access
It must contain a file that will be used as Random Access Memory. Memory is 8-bits
wide but the processor accesses 32-bits (4B) for operation. It has 32 Registers working
as General purpose Register. While one special purpose register (Program Counter) will
be used to hold the address of the instruction. Each Register must be 32 bit wide and
clock edge triggered. It must be designed for a total of 15 Instructions, out of which 6 are
Arithmetic instructions, 3 are logical instructions, 2 are shift instructions, and remaining
are branch, load-store instruction. These instructions include
1. Add Instruction to add contents of two registers and store in 3rd register (add
Rd, Rm, Rn ; Rd = Rm + Rn)
2. Subtract Instruction to subtract contents of two registers and store in 3rd register
(sub Rd, Rm, Rn ; Rd = Rm − Rn)
3. Add Immediate Instruction to add 12bit immediate value and content of one
registers and store in destination register (add Rd, Rm, #immed ;
Rd = Rm + immed)
4. Multiply Instruction to multiply contents of two registers and store in 3rd register
(mul Rd, Rm, Rn ; Rd = Rm ∗ Rn)
5. Divide Instruction to divide contents of two registers and store in 3rd register
(div Rd, Rm, Rn ; Rd = Rm/Rn)
7. Shift Left Logical Instruction to shift left the contents of 1st register Rn times
and store the results in destination register (sll Rd, Rm, Rn ; Rd = Rm << Rn)
8. Shift Right Logical Instruction to shift right the contents of 1st register Rn
times and store the results in destination register (srl Rd, Rm, Rn ; Rd = Rm >>
Rn)
9. AND Instruction to take logical AND of the contents of two registers and store
in 3rd register (and Rd, Rm, Rn ; Rd = Rm&Rn)
10. OR Instruction to take logical OR of the contents of two registers and store in
3rd register (or Rd, Rm, Rn ; Rd = Rm|Rn)
11. XOR Instruction to take logical XOR of the contents of two registers and store
in 3rd register (xor Rd, Rm, Rn ; Rd = Rm XOR Rn)
12. Load Word Instruction to load the contents from the memory and store it in
destination register. It will contain the 3rd operand as offset value (lw Rd, Rm,
offset)
13. Store Word Instruction to store the contents of a register inside the memory at
the address provided by the 3rd operand. (sw Rm, Rd, offset)
14. Branch Equal Instruction to jump to the any provided address if the given
operands are equal (beq Rn, Rm, label ; Jump to label if Rn==Rm)
15. Branch Not Equal Instruction to jump to the any provided address if the given
operands are not equal (bne Rn, Rm, label ; Jump to label if Rn !=Rm)
Instruction format for S-type is for store instructions.The register rs1 is the base register
that is added to the 12-bit immediate field to form the memory address. (The immediate
field is split into a 7-bit piece and a 5-bit piece.) Field rs2 is the source register whose
value should be stored into memory. Instruction format for SB-type conditional branch.
The registers rs1 and rs2 compared. The 12-bit immediate address field is sign-extended,
shifted left 1 bit, and added to the PC to compute the branch target address.
Instruction Opcode Func3 Func7
bits[6 − 0] bits[14 − 12] bits[31 − 25]
add 0110011 000 0000000
sub 0110011 000 0100000
mul 0110011 000 0000001
div 0110011 100 0000001
rem 0110011 110 0000001
and 0110011 111 0000000
or 0110011 110 0000000
xor 0110011 100 0000000
sll 0110011 001 0000000
srl 0110011 101 0000000
addI 0010011 000 Not Applicable
beq 1100011 000 Not Applicable
bneq 1100011 001 Not Applicable
lw 0000011 010 Not Applicable
sw 0100011 010 Not Applicable