• Stars
    star
    671
  • Rank 67,266 (Top 2 %)
  • Language AGS Script
  • License
    ISC License
  • Created about 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RISC-V Linux SoC, marchID: 0x2b

Kianv Soc

kianv RISC-V Harris MultiCycle Edition (SOC)

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.

Linux SOC

       _                   __ _
  /\ /(_) __ _ _ __/\   /\/ /(_)_ __  _   ___  __
 / //_/ |/ _` | '_ \ \ / / / | | '_ \| | | \ \/ /
/ __ \| | (_| | | | \ V / /__| | | | | |_| |>  <
\/  \/|_|\__,_|_| |_|\_/\____/_|_| |_|\__,_/_/\_\

With the KianV RISC-V Linux, you can boot Linux. Yes, you read that right. Booting Linux is fun. Go to implementation or check a video from Kian Linux Soc in action

CPU

The processor supports RV32IM instruction set

  • RV: RISC-V
  • 32: 32-Bit registers, 3-address instructions
  • I : integer instructions
  • M : 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

Harris MultiCycle RISC-V Architecture

Verilog Implementation

My 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

Register Transfer Logik (RTL)

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:

Top CPU Layer

The top layer of the CPU consist only from a control unit and data unit.

top layer kianv riscv cpu

Top Layer from Kianv RISC-V CPU

Control Unit

The control unit controls the complete data flow of the CPU and consits of a main FSM and many decoders.

ControlUnit

Main FSM

The 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.

Main FSM

Data Unit

The data unit consits of units are perform operations on data and store elements,

DataUnit

FPGA-Soc Implementation

The 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
  • digilent arty7, nexys a7 nexys video, CmodA7-35t and genesys2

Synthesis of SOC

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

Simulation of whole SOC

./sim.sh # for iverilog simulation
./verilator.sh # for verilator simulation

Simulation of CPU only

cd kianv_harris_mcycle_edition
./sim.sh # for iverilog simulation

Unittest of CPU

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

Toolchain

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

Trying Firmware

The firmware will flashed on nor memory! Firmware:\

cd ./firmware\
flash with\
./flash_firmware.sh \
ulx3s|ice|colori5|arty7|nexysa7|nexysa_video|genesys2|cmoda7_35t| stick <*.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
spi_nor_ice40hx1k.ld # boot and execute instructions only from spi-nor, e.g. icestick

Try for icestick all mandel, raytracer, main_seed.c oled or uart demos. Firmware is very restricted, will hang currently if you use hw registers they are not implemented. icestick could be configured as soc with oled xor uart. icestick is configured as rv32i and needs rv32i toolchain which will selected in flash_firmware.

 ./flash_firmware.sh stick spi_nor_ice40hx1k.ld main_raytrace.c -Ofast # would flash firmware for icestick and uses the rv32i firmware

Preparing Uart

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

latest fw version needs no raw mode anymore!

stty -F /dev/ttyUSBx 11520 \
cat /dev/ttyUSBx

to get output like pi.c, main_prime.c, main_rv32m.c, main_rv32m_printf.c, ....

GPIO interface

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.

DMA Controller

KianRiscV has an optional DMA-Controller to speedup memset, memcopy wordwise!

PMODs

Xilinx

Check the XilinxVivado folder and

./build.sh

Kian RiscV Single Cycle CPU

Check the new single cycle CPU with CPI=1 and prepared for a KINTEX-7. You can also run smaller FPGAs with less firmware. Firmware can build with standard BRAM linker script and reset address 0. Raytracer is still their as hex got from https://github.com/WyattAutomation/Simple-Raytracer-in-C.git. I have provided a 80MHz bitstream file with firmware for genesys2. The CPU operates with 80MHz => 80 MIPS and 3000000 Baud uart!

Simulation

cd kianv_harris_scycle_edition/processor/
make verilator && ./obj/Vtop

or

cd kianv_harris_scycle_edition/processor/
make isim && ./a.out

Kian RiscV 5-staged Pipelined CPU

This is a 5-staged pipelined cpu and is the base of my future work. The cpu is rv32i complaint and tested with the riscv testsuite. In future I will share an advanced soc from it: interrupts, sdram/ddr, caches, branch predition, linux bootable.

Hirosh

More Repositories

1

my_hdmi_device

New clean hdmi implementation for ulx3s, icestick, icoboard, arty7, colorlight i5 and blackicemx! With tmds encoding hacked down from dvi standard. Supports DDR and SRD tranfser!
GLSL
88
star
2

lets_build_a_compiler_for_riscv

A c/RISCV of "Let's Build a Compiler" by Jack Crenshaw
C
50
star
3

my_sdram

simple sdram controller
Verilog
17
star
4

fpga_rtc_alarm_clock

fpga i2c rtc oled based clock with alarm supports buzzer
Verilog
12
star
5

i2c_oled_fpga_bresenham

i2c fpga oled sdd1306 bresenham implementation
Verilog
12
star
6

kianFpgaPong

Basic Pong you can extend with rotary, sound, vga generator and autopilot
Verilog
11
star
7

KianV_rv32ia_uLinux_SoC

Verilog
10
star
8

i2c_sdd1306_framebuffer

It is a fpga implementation of an i2c master, framebuffer for sdd1306 display
Verilog
9
star
9

KianV-RV32IMA-RISC-V-uLinux-SoC

Verilog
3
star
10

fpga_neo_pixel

My approach is using a SPI to collect 24-RGBs-Strips-Data and a SYNC from a impeded SoC. Another approach I came up with is to reuse the Adafruit-Neopixel-Library. I attached my FPGA_NeoPixel.h file. Technically it inherits from Adafruit_NeoPixel and overwrites the void show() with SPI-Code so you are able to use the methods from Adafruit_Neopixel to set leds or calculate color spaces. I have tested it on an Arduiono-Nano but it is easy to port the Libs to other SoCs.
Verilog
2
star
11

my_multiplier

one cycle unsigned multiplier, don't cares of resources fpga or asic structures
Verilog
1
star
12

my_uart

UART implementation with a top module implements a loopback. I was able to have 3MBaud error-free!
Verilog
1
star