RISC-V is an open standard instruction set architecture (ISA) according to the principles of reduced instruction set computer (RISC) principles. Afterward when I sucessfully completed my HarveyMuddX-ENGR85B Exam certificate. I learned howto design a RISC-V CPU hierarchical. Last year I have sucessfully completed an exam in Building a RISC-V CPU Core and finalized my previous RISC-V soc kianv simple edition. But was a hack and got much experience. The code was created by try and error without simulation and was a good experience to think in logical design.
The processor supports RV32IM
instruction set
RV
: RISC-V32
: 32-Bit registers, 3-address instructionsI
: integer instructionsM
: multiply/divide/modulo instructions
and passes the RISC-V unit tests for RISC-V processors. The cpu is implemented with strong hierarchical method design rules I have learned from Computer Architecture RISC-V Edition, Harris, Harris. As you can see here (taken from my exam documents):
Harris MultiCycle RISC-V ArchitectureMy architecture will presented by following verilog files:
- kianv_harris_mc_edition.v
- control_unit.v
- alu_decoder.v
- csr_decoder.v
- divider_decoder.v
- load_decoder.v
- main_fsm.v
- multiplier_decoder.v
- multiplier_extension_decoder.v
- store_decoder.v
- datapath_unit.v
- alu.v
- csr_unit.v
- design_elements.v
- divider.v
- extend.v
- load_alignment.v
- multiplier.v
- register_file.v
- store_alignment.v
- control_unit.v
Some examples of CPU components shown in RTL of the top layer of the cpu, control unit, data unit and the main finite state machine (FSM) here:
The top layer of the CPU consist only from a control unit and data unit.
Top Layer from Kianv RISC-V CPUThe control unit controls the complete data flow of the CPU and consits of a main FSM and many decoders.
ControlUnitThe most important unit is the main FSM and is a part of the control unit.
It controls the sequence of fetch
, decode
, execution
and write back
.
The data unit consits of units are perform operations on data and store elements,
DataUnitThe soc has some controllers implemented:
- nor spi controller
- oled spi controller
- psram qspi controller
- direct map cache controller
- hdmi framebuffer controller, vga controller
- tx uart controller up to 3MBaud
- spram controller (ice40up)
Supported fpgas:
- ulx3s ecp5
- icebreaker ice40
- colorlighi5, colorlighti9 ecp5
- icefun ice40
You should study defines.vh
file you can choose the sytemfrequency,
hdmi or oled on ulx3s, psram with/without cache, cachesize, ...
Please use oss-cad-suite to have all tools for synthesis.
cd gateware
./build_ulx3s.sh # build ulx3s and flash design
./build_ice.sh # build icebreaker and flash design
./build_colori9.sh # build colorlighti9 and flash design
./build_colori5.sh # build build_colori5 and flash design
./build_fun.sh # build icefun and flash design
./sim.sh # for iverilog simulation
./verilator.sh # for verilator simulation
cd kianv_harris_mcycle_edition
./sim.sh # for iverilog simulation
This will test all supported instructions of a RV32IM
user mode CPU.
Took the picorv32 test cases and adjusted them for my testbench.
cd kianv_harris_mcycle_edition
cd firmware
. ./start_test.sh
Build RISC-V GNU toolchain Invoke the build_toolchain.sh script to have a riscv toolchain for rv32im and will build under /opt/riscv32im
cd ./kianv_harris_mcycle_edition/firmware/
./build_toolchain.sh
Or use another toolchain and adjust:\
./firmware/kianv_firmware_bram_gcc.sh
./firmware/kianv_firmware_gcc.sh
The firmware will flashed on nor memory! Firmware:\
cd ./firmware\
flash with\
./flash_firmware.sh \
ulx3s|ice|colori5 <*.ld> <*.c>
spi_nor2bram_fun.ld # boot from spi-nor icefun and copy code to bram\
spi_nor2bram.ld # boot from spi-nor icebreaker and copy to bram\
spi_nor2bram_colori5.ld # boot from spi-nor colorlighti5 also ulx3s and copy to bram\
spi_nor2spram.ld # boot from spi-nor icebreaker and copy to spram\
spi_nor2sram.ld # boot from spi-nor and copy to sram icoboard\
spi_nor_fun.ld # boot and execute instructions only from spi-nor on icefun\
spi_nor.ld # boot and execute instructions only from spi-nor all boards, excluded icefun
spi_nor2spram.d # boot from spi and copy to spram (only icebreaker, ice40up)
spi_nor2psram.d # boot from spi and copy to psram
some programs are using external uart hw, check pcfs but icebreaker, breakout and ulx3s don't need external uart hw. Check for ttyUSB devices and try
stty -F /dev/ttyUSBx 11520 raw\
cat /dev/ttyUSBx
to get output like pi.c, main_prime.c, main_rv32m.c, main_rv32m_printf.c, ....
Added a generic purpose io interface for each soc. You can drive the IOs from firmwarespace. The firmware folder provides an i2c and spi lib. There are some bitbang examples like to drive via i2c a liquidchrystal or an oled sdd1306 display. The highlight is the spi bitbanging example to read, write files from fat16/32 sd card...The driver is from ultraembedded I stripped down to an one file implementation. Check the .pcf or .lcf files to remap or to expand the ios to 32 with current implementation.
- PSRAM 32MByte: https://machdyne.com/product/qqspi-psram32/
Hirosh