FPGA Implementation of Educational RISC - V Processor Suitable For Embedded Applications
FPGA Implementation of Educational RISC - V Processor Suitable For Embedded Applications
Dept. of Computer Science & Engineering Dept. of Computer Science & Engineering Dept. of Computer Science & Engineering
Rajshahi University of Engineering & Technology Rajshahi University of Engineering & Technology Rajshahi University of Engineering & Technology
Rajshahi-6204, Bangladesh Rajshahi-6204, Bangladesh Rajshahi-6204, Bangladesh
[email protected] [email protected] [email protected]
Abstract—Learning computer architecture has been a tough CPUs and dynamic pipelined CPUs using field programmable
task for the learners. Sometimes it is not very effective when an gate arrays (FPGAs) in their article.
architecture is learnt theoretically. Learning an architecture like Sulk et al. in [5] published design of an 8-bit RISC
RISC-V which has huge industrial interest has an additional
benefit. The RISC-V instruction set architecture that is free microcontroller using Handel-C. Carpinelli [6] described a
to use was developed with flexibility and durability in mind. Java-based emulator that facilitates understanding how an 8-
The adaptability of RISC-V enables a wide range of hardware bit processor obtains, decodes, and executes instructions. The
implementations. Interests in Field Programmable Gate Array simulator puts together assembly language instructions to run
(FPGA) is growing in recent times due to its feasibility, flexibility a cycle-accurate simulation of the processor.
and efficiency. In this paper, we implemented an educational
processor based on the RISC-V architecture on FPGA with McGrew et al. [7] aimed is to implement a CPU on
support for interfacing intended for embedded applications. An FPGA which is based on the 32-bit RISC-V architecture.
assembler was also designed and developed which can convert The design specification, analysis, and simulation are all key
assembly codes into RISC-V standard machine codes that can components in determining how the overall system design will
help the users to operate the CPU easily. be developed.
Index Terms—FPGA, RISC-V, CPU Design, Assembler
All the references mentioned above except the last one
focused on architectures other than RISC-V architecture. We
I. LITERATURE REVIEW
used RISC-V architecture for building our CPU because RISC-
Computer Architecture is one of the most significant courses V architecture is an open standard Instruction Set Architecture
in Computer Engineering discipline. Our traditional computer (ISA) and is free for everyone to implement & use unlike many
architecture course provides only theoretical knowledge. Such proprietary architectures like x86-64 and ARM architecture.
course typically uses pen and paper to cover theoretical mate- Although some references had implemented assembler, none
rial and at best they demonstrate how computers are structured of them had support for interfacing.
using architectural simulators. It would be helpful for learners The contribution of our paper is to develop an educational
if they could learn it by practical experiments. 32-bit RISC-V processor on FPGA that is simple to understand
Field Programmable Gate Array (FPGA) can be an ideal and will support assembler and interfacing with external I/O
choice due to its soft programmability. Learners can get devices for embedded applications that will help the learners
the perfect environment to develop and practice computer to learn about embedded applications of CPU. The goal of this
architecture in a variety of unique and imaginative ways thanks paper is three tiered: (1) To actualize the theoretical knowledge
to the combination of HDL and FPGA [1]. This paper’s with practical experiments, (2) To design an assembler & (3)
purpose is to teach learners how to design CPU using FPGA Interfacing the CPU. Our implementation is compared with
in a simpler way. references in later section.
Lee et al. [1] targets the undergrad students to educate com-
II. CPU D ESIGN
puter architecture via hands-on learning in their research paper.
They showed a five-stage pipelined 32-bit MIPS processor. A. Proposed Model
One of their key goals in developing the project was to allevi- There are three major tasks in our proposed model. First
ate the workload on the pupils. Li et al. [2] proposed an 8-bit one is to build a 32-bit CPU. The next one is to make
pipelined processor’s design and implementation. The design assembler & the last task is to do interfacing with input-
of the processor, functional simulations, implementation of the output registers A 32-bit RISC-V processor is constructed in
design, and other tasks were assigned to the students. the initial stage using Verilog HDL. This processor is created
Yıldız et al. [3] introduced the Very Simple CPU (VSCPU), and implemented on a Xilinx Spartan 6 LX16 FPGA Board
a straightforward and adaptable soft CPU that can be quickly using Verilog HDL. Verilog RTL codes are then fed into
constructed on FPGAs with a full toolchain that includes an FPGA Design Flow. We simulated our design on GTKWave
assembler, instruction set simulator, and C compiler. In this to verify its functionality. The second stage involves getting
paper, no. of instructions is 16 and it is a multi-cycle CPU. our FPGA board ready to test the interfacing code with our
Qin et al. [4] outlined the design process for static pipelined CPU design. The interface assembly code is written and given
B. RISC-V ISA Formats Our CPU supports a numbers of arithmetic and logical
As we have discussed before, we implemented the CPU operations as shown in Table I.
based on RISC-V 32I ISA as shown in Figure 2. We imple-
TABLE I
mented 4 types of instructions: Register type, Immediate type, O PERATIONS S UPPORTED BY THE ALU
Store Type and Branch Type. The ISA size is 32 bits where
each instruction is divided into several parts. First 7 bits are AluControl Operation Expression
used to represent the opcode in all the instructions. The opcode 0000 AND a&b
is different for different operations. 0001 OR a|b
0010 ADD a+b
In the R-type and I-type operations, 5 bits are used to 0100 SUB a–b
represent rd which indicates the destination register (where 1 if a <b
the data is written). Moreover, there are rs1 and rs2 which are 1000 Set on Less Than
also 5-bits long. They are used to select the register for reading 0 otherwise
0011 Shift Left a <<b
data. The func3 and func7 portions are used to be of different 0101 Shift Right a >>b
values for different types of ALU operations. Finally, the Imm 0110 MUL a*b
pin is used to show the immediate value which is 12-bits long. 0111 XOR a ˆb
uthorized licensed use limited to: AMRITA VISHWA VIDYAPEETHAM AMRITA SCHOOL OF ENGINEERING. Downloaded on January 24,2024 at 05:23:15 UTC from IEEE Xplore. Restrictions apply
TABLE II
R EGISTER - TYPE A SSEMBLY C ODE F ORMATS
uthorized licensed use limited to: AMRITA VISHWA VIDYAPEETHAM AMRITA SCHOOL OF ENGINEERING. Downloaded on January 24,2024 at 05:23:15 UTC from IEEE Xplore. Restrictions apply
V. S IMULATION R ESULTS & C OMPARISON
We simulated our design using GTKwave software to verify
our designs.
A. ALU Simulation
We implemented 9 operations for our CPU. The ALU-
Control pin selects any of the operations to be performed.
Testbench simulation for a multiplication operation of the
ALU circuit is shown in Figure 8.
D. Interfacing Simulation
The waveform of a simulation of the interfacing between
the CPU and input output registers is shown in Figure 11.
uthorized licensed use limited to: AMRITA VISHWA VIDYAPEETHAM AMRITA SCHOOL OF ENGINEERING. Downloaded on January 24,2024 at 05:23:15 UTC from IEEE Xplore. Restrictions apply
E. Comparison with Other Papers [11] “About RISC-V - RISC-V international,” RISC, 23-Aug-2021. [Online].
Available: https://riscv.org/about/. [Accessed: 08-Oct-2022].
The main goal of our paper was to develop an educational [12] “Chapter 8: ASSEMBLERS,” www.jklp.org.
CPU based on the RISC-V architecture which also supports http://www.jklp.org/profession/books/mix/c08.html
assembler and interfacing for embedded applications. Table III
shows a simple comparison among the mentioned papers and
our paper.
TABLE III
C OMPARISON WITH OTHER PAPERS
uthorized licensed use limited to: AMRITA VISHWA VIDYAPEETHAM AMRITA SCHOOL OF ENGINEERING. Downloaded on January 24,2024 at 05:23:15 UTC from IEEE Xplore. Restrictions apply