OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [README.md] - Blame information for rev 14

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 zero_gravi
# [The NEORV32 Processor](https://github.com/stnolting/neorv32) (RISC-V-compliant)
2 2 zero_gravi
 
3
[![Build Status](https://travis-ci.com/stnolting/neorv32.svg?branch=master)](https://travis-ci.com/stnolting/neorv32)
4
[![license](https://img.shields.io/github/license/stnolting/neorv32)](https://github.com/stnolting/neorv32/blob/master/LICENSE)
5
[![release](https://img.shields.io/github/v/release/stnolting/neorv32)](https://github.com/stnolting/neorv32/releases)
6
 
7
 
8
## Table of Content
9
 
10
* [Introduction](#Introduction)
11
* [Features](#Features)
12
* [FPGA Implementation Results](#FPGA-Implementation-Results)
13
* [Performance](#Performance)
14
* [Top Entity](#Top-Entity)
15
* [**Getting Started**](#Getting-Started)
16 9 zero_gravi
* [Contribute](#Contribute)
17 2 zero_gravi
* [Legal](#Legal)
18
 
19
 
20
 
21
## Introduction
22
 
23 14 zero_gravi
The **NEORV32 processor** is a customizable full-scale mikrocontroller-like processor system based on the RISC-V-compliant
24
`rv32i` NEORV32 CPU with optional `M`, `E`, `C` and `Zicsr` and `Zifencei` extensions. The CPU was built from scratch and
25
is compliant to the *Unprivileged ISA Specification Version 2.2* and a subset of the *Privileged Architecture
26
Specification Version 1.12-draft*.
27 2 zero_gravi
 
28 14 zero_gravi
The **processor** is intended as auxiliary processor within a larger SoC designs or as stand-alone
29
custom microcontroller. Its top entity can be directly synthesized for any FPGA without modifications and
30
provides a full-scale RISC-V based microcontroller with common peripherals like GPIO, serial interfaces for
31
UART, I²C and SPI, timers, external bus interface and embedded memories. All optional features beyond the
32
base CPU can be enabled and configured via VHDL generics.
33 11 zero_gravi
 
34 14 zero_gravi
Alternatively, you can use the **NEORV32 CPU** as stand-alone central processing unit and build your own microcontroller
35
or processor system around it.
36 2 zero_gravi
 
37 14 zero_gravi
This project comes with a complete software ecosystem that features core libraries for high-level
38
usage of the provided functions and peripherals, application makefiles, a runtime environment and
39
several example programs. All software source files provide a doxygen-based documentary.
40 2 zero_gravi
 
41 14 zero_gravi
The project is intended to work "out of the box". Just synthesize the test setup from this project,
42
upload it to your FPGA board of choice and start playing with the NEORV32. If you do not want to
43
[compile the GCC toolchains](https://github.com/riscv/riscv-gnu-toolchain) by yourself, you can also
44
download [pre-compiled toolchains](https://github.com/stnolting/riscv_gcc_prebuilt) for Linux.
45 2 zero_gravi
 
46
For more information take a look a the [![NEORV32 datasheet](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/figures/PDF_32.png) NEORV32 datasheet](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/NEORV32.pdf).
47
 
48
 
49
### Design Principles
50
 
51
 * From zero to main(): Completely open source and documented.
52
 * Plain VHDL without technology-specific parts like attributes, macros or primitives.
53
 * Easy to use – working out of the box.
54
 * Clean synchronous design, no wacky combinatorial interfaces.
55
 * The processor has to fit in a Lattice iCE40 UltraPlus 5k FPGA running at 20+ MHz.
56
 
57
 
58
### Status
59 3 zero_gravi
 
60 6 zero_gravi
The processor is synthesizable (tested with Intel Quartus Prime, Xilinx Vivado and Lattice Radiant/LSE) and can successfully execute
61
all the [provided example programs](https://github.com/stnolting/neorv32/tree/master/sw/example) including the CoreMark benchmark.
62 2 zero_gravi
 
63 8 zero_gravi
The processor passes the official `rv32i`, `rv32im`, `rv32imc`, `rv32Zicsr` and `rv32Zifencei` [RISC-V compliance tests](https://github.com/riscv/riscv-compliance).
64 2 zero_gravi
 
65 11 zero_gravi
| Project component                                                               | CI status | Note     |
66
|:--------------------------------------------------------------------------------|:----------|:---------|
67 14 zero_gravi
| [NEORV32 processor](https://github.com/stnolting/neorv32)                       | [![Build Status](https://travis-ci.com/stnolting/neorv32.svg?branch=master)](https://travis-ci.com/stnolting/neorv32) | [![sw doc](https://img.shields.io/badge/SW%20documentation-gh--pages-blue)](https://stnolting.github.io/neorv32/files.html) |
68
| [Pre-built toolchain](https://github.com/stnolting/riscv_gcc_prebuilt)          | [![Build Status](https://travis-ci.com/stnolting/riscv_gcc_prebuilt.svg?branch=master)](https://travis-ci.com/stnolting/riscv_gcc_prebuilt) | |
69
| [RISC-V compliance test](https://github.com/stnolting/neorv32_riscv_compliance) | [![Build Status](https://travis-ci.com/stnolting/neorv32_riscv_compliance.svg?branch=master)](https://travis-ci.com/stnolting/neorv32_riscv_compliance) | |
70 6 zero_gravi
 
71
 
72 12 zero_gravi
### Non RISC-V-Compliant Issues
73 7 zero_gravi
 
74 14 zero_gravi
* No exception is triggered for the `E` CPU extension when using registers above `x15` (*needs fixing*)
75 12 zero_gravi
* `misa` CSR is read-only - no dynamic enabling/disabling of implemented CPU extensions during runtime
76 14 zero_gravi
* `mcause` CSR is read-only
77 12 zero_gravi
* The `[m]cycleh` and `[m]instreth` CSR counters are only 20-bit wide (in contrast to original 32-bit)
78 7 zero_gravi
 
79
 
80 14 zero_gravi
### Custom CPU Extensions
81
 
82
* Four *fast interrupt* request channels with according control/status bits in `mie` and `mip` and custom exception codes in `mcause`
83
 
84
 
85 9 zero_gravi
### To-Do / Wish List
86 7 zero_gravi
 
87 13 zero_gravi
- Add instructions how to use the NEORV32 CPU without the processor surroundings
88
- Add AXI / AXI-Lite bridges
89
- Option to use DSP-based multiplier in `M` extension (would be so much faster)
90 9 zero_gravi
- Synthesis results for more platforms
91 13 zero_gravi
- Implement user mode (`U` extension)
92 7 zero_gravi
- Port Dhrystone benchmark
93 13 zero_gravi
- Implement atomic operations (`A` extension) and floating-point operations (`F` extension)
94
- Maybe port an RTOS (like [Zephyr](https://github.com/zephyrproject-rtos/zephyr), [freeRTOS](https://www.freertos.org) or [RIOT](https://www.riot-os.org))
95
- Make a 64-bit branch someday
96 7 zero_gravi
 
97
 
98
 
99 2 zero_gravi
## Features
100
 
101
### Processor Features
102
 
103 11 zero_gravi
![neorv32 Overview](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/figures/neorv32_processor.png)
104
 
105 14 zero_gravi
  - RISC-V-compliant `rv32i` CPU with optional `C`, `E`, `M`, `Zicsr` and `rv32Zifencei` extensions
106 2 zero_gravi
  - GCC-based toolchain ([pre-compiled rv32i and rv32 etoolchains available](https://github.com/stnolting/riscv_gcc_prebuilt))
107 3 zero_gravi
  - Application compilation based on [GNU makefiles](https://github.com/stnolting/neorv32/blob/master/sw/example/blink_led/makefile)
108 11 zero_gravi
  - [Doxygen-based](https://github.com/stnolting/neorv32/blob/master/docs/doxygen_makefile_sw) documentation of the software framework: available on [GitHub pages](https://stnolting.github.io/neorv32/files.html)
109
  - Detailed [datasheet](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/NEORV32.pdf) (pdf)
110 2 zero_gravi
  - Completely described in behavioral, platform-independent VHDL – no primitives, macros, etc.
111
  - Fully synchronous design, no latches, no gated clocks
112
  - Small hardware footprint and high operating frequency
113 7 zero_gravi
  - Highly customizable processor configuration
114 12 zero_gravi
  - _Optional_ processor-internal data and instruction memories (DMEM/IMEM)
115 7 zero_gravi
  - _Optional_ internal bootloader with UART console and automatic SPI flash boot option
116
  - _Optional_ machine system timer (MTIME), RISC-V-compliant
117
  - _Optional_ universal asynchronous receiver and transmitter (UART)
118
  - _Optional_ 8/16/24/32-bit serial peripheral interface controller (SPI) with 8 dedicated chip select lines
119
  - _Optional_ two wire serial interface controller (TWI), compatible to the I²C standard
120
  - _Optional_ general purpose parallel IO port (GPIO), 16xOut & 16xIn, with pin-change interrupt
121
  - _Optional_ 32-bit external bus interface, Wishbone b4 compliant (WISHBONE)
122
  - _Optional_ watchdog timer (WDT)
123
  - _Optional_ PWM controller with 4 channels and 8-bit duty cycle resolution (PWM)
124
  - _Optional_ GARO-based true random number generator (TRNG)
125
  - _Optional_ dummy device (DEVNULL) (can be used for *fast* simulation console output)
126 12 zero_gravi
  - System configuration information memory to check hardware configuration by software (SYSINFO)
127 2 zero_gravi
 
128
### CPU Features
129
 
130 11 zero_gravi
![neorv32 Overview](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/figures/neorv32_cpu.png)
131
 
132
The CPU is [compliant](https://github.com/stnolting/neorv32_riscv_compliance) to the
133 12 zero_gravi
[official RISC-V specifications (2.2)](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/riscv-spec.pdf) including a subset of the
134
[RISC-V privileged architecture specifications (1.12-draft)](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/riscv-spec.pdf).
135 2 zero_gravi
 
136 11 zero_gravi
More information regarding the CPU including a detailed list of the instruction set and the available CSRs can be found in
137
the [![NEORV32 datasheet](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/figures/PDF_32.png) NEORV32 datasheet](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/NEORV32.pdf).
138
 
139
 
140
**General**:
141 12 zero_gravi
  * Modified Harvard architecture (separate CPU interfaces for data and instructions; single processor-bus via bus switch)
142
  * Two stages in-order pipeline (FETCH, EXECUTE); each stage uses a multi-cycle processing scheme
143 11 zero_gravi
  * No hardware support of unaligned accesses - they will trigger and exception
144
 
145
 
146 3 zero_gravi
**RV32I base instruction set** (`I` extension):
147 2 zero_gravi
  * ALU instructions: `LUI` `AUIPC` `ADDI` `SLTI` `SLTIU` `XORI` `ORI` `ANDI` `SLLI` `SRLI` `SRAI` `ADD` `SUB` `SLL` `SLT` `SLTU` `XOR` `SRL` `SRA` `OR` `AND`
148 7 zero_gravi
  * Jump and branch instructions: `JAL` `JALR` `BEQ` `BNE` `BLT` `BGE` `BLTU` `BGEU`
149 2 zero_gravi
  * Memory instructions: `LB` `LH` `LW` `LBU` `LHU` `SB` `SH` `SW`
150 8 zero_gravi
  * System instructions: `ECALL` `EBREAK` `FENCE`
151 2 zero_gravi
 
152 3 zero_gravi
**Compressed instructions** (`C` extension):
153 2 zero_gravi
  * ALU instructions: `C.ADDI4SPN` `C.ADDI` `C.ADD` `C.ADDI16SP` `C.LI` `C.LUI` `C.SLLI` `C.SRLI` `C.SRAI` `C.ANDI` `C.SUB` `C.XOR` `C.OR` `C.AND` `C.MV` `C.NOP`
154 7 zero_gravi
  * Jump and branch instructions: `C.J` `C.JAL` `C.JR` `C.JALR` `C.BEQZ` `C.BNEZ`
155 2 zero_gravi
  * Memory instructions: `C.LW` `C.SW` `C.LWSP` `C.SWSP`
156
  * Misc instructions: `C.EBREAK` (only with `Zicsr` extension)
157
 
158 3 zero_gravi
**Embedded CPU version** (`E` extension):
159 2 zero_gravi
  * Reduced register file (only the 16 lowest registers)
160
 
161 3 zero_gravi
**Integer multiplication and division hardware** (`M` extension):
162 2 zero_gravi
  * Multiplication instructions: `MUL` `MULH` `MULHSU` `MULHU`
163
  * Division instructions: `DIV` `DIVU` `REM` `REMU`
164
 
165 8 zero_gravi
**Privileged architecture / CSR access** (`Zicsr` extension):
166 2 zero_gravi
  * Privilege levels: `M-mode` (Machine mode)
167
  * CSR access instructions: `CSRRW` `CSRRS` `CSRRC` `CSRRWI` `CSRRSI` `CSRRCI`
168 8 zero_gravi
  * System instructions: `MRET` `WFI`
169 12 zero_gravi
  * Counter CSRs: `[m]cycle[h]` `[m]instret[h]` `time[h]`
170 14 zero_gravi
  * Machine CSRs: `mstatus` `misa`(read-only!) `mie` `mtvec` `mscratch` `mepc` `mcause`(read-only!) `mtval` `mip` `mvendorid` `marchid` `mimpid` `mhartid`
171 2 zero_gravi
  * Supported exceptions and interrupts:
172
    * Misaligned instruction address
173
    * Instruction access fault
174
    * Illegal instruction
175 4 zero_gravi
    * Breakpoint (via `ebreak` instruction)
176 2 zero_gravi
    * Load address misaligned
177
    * Load access fault
178 4 zero_gravi
    * Store address misaligned
179 2 zero_gravi
    * Store access fault
180 4 zero_gravi
    * Environment call from M-mode (via `ecall` instruction)
181 9 zero_gravi
    * Machine timer interrupt `mti` (via MTIME unit)
182
    * Machine external interrupt `mei` (via CLIC unit)
183 2 zero_gravi
 
184 8 zero_gravi
**Privileged architecture / FENCE.I** (`Zifencei` extension):
185
  * System instructions: `FENCE.I`
186
 
187 2 zero_gravi
 
188
## FPGA Implementation Results
189
 
190
This chapter shows exemplary implementation results of the NEORV32 processor for an **Intel Cyclone IV EP4CE22F17C6N FPGA** on
191
a DE0-nano board. The design was synthesized using **Intel Quartus Prime Lite 19.1** ("balanced implementation"). The timing
192 4 zero_gravi
information is derived from the Timing Analyzer / Slow 1200mV 0C Model. If not otherwise specified, the default configuration
193 12 zero_gravi
of the processor's generics is assumed. No constraints were used at all.
194 2 zero_gravi
 
195 11 zero_gravi
### CPU
196
 
197 14 zero_gravi
Results generated for hardware version: `1.3.0.0`
198 2 zero_gravi
 
199 12 zero_gravi
| CPU Configuration                | LEs        | FFs      | Memory bits | DSPs | f_max   |
200
|:---------------------------------|:----------:|:--------:|:-----------:|:----:|:-------:|
201 14 zero_gravi
| `rv32i`                          |       1122 |      481 |       2048  |    0 | 110 MHz |
202
| `rv32i`   + `Zicsr` + `Zifencei` |       1891 |      819 |       2048  |    0 | 100 MHz |
203
| `rv32im`  + `Zicsr` + `Zifencei` |       2496 |     1067 |       2048  |    0 | 100 MHz |
204
| `rv32imc` + `Zicsr` + `Zifencei` |       2734 |     1066 |       2048  |    0 | 100 MHz |
205
| `rv32emc` + `Zicsr` + `Zifencei` |       2722 |     1066 |       1024  |    0 | 100 MHz |
206 2 zero_gravi
 
207 6 zero_gravi
### Processor-Internal Peripherals and Memories
208 2 zero_gravi
 
209 14 zero_gravi
Results generated for hardware version: `1.3.0.0`
210 11 zero_gravi
 
211 14 zero_gravi
| Module    | Description                                     | LEs | FFs | Memory bits | DSPs |
212
|:----------|:------------------------------------------------|:---:|:---:|:-----------:|:----:|
213
| BOOT ROM  | Bootloader ROM (4kB)                            |   4 |   1 |      32 768 |    0 |
214
| BUSSWITCH | Mux for CPU I & D interfaces                    |  62 |   8 |           0 |    0 |
215
| DEVNULL   | Dummy device                                    |   3 |   1 |           0 |    0 |
216
| DMEM      | Processor-internal data memory (8kB)            |  12 |   2 |      65 536 |    0 |
217
| GPIO      | General purpose input/output ports              |  40 |  33 |           0 |    0 |
218
| IMEM      | Processor-internal instruction memory (16kb)    |   7 |   2 |     131 072 |    0 |
219
| MTIME     | Machine system timer                            | 266 | 166 |           0 |    0 |
220
| PWM       | Pulse-width modulation controller               |  72 |  69 |           0 |    0 |
221
| SPI       | Serial peripheral interface                     | 198 | 125 |           0 |    0 |
222
| SYSINFO   | System configuration information memory         |  10 |   9 |           0 |    0 |
223
| TRNG      | True random number generator                    | 105 |  93 |           0 |    0 |
224
| TWI       | Two-wire interface                              |  75 |  44 |           0 |    0 |
225
| UART      | Universal asynchronous receiver/transmitter     | 153 | 108 |           0 |    0 |
226
| WDT       | Watchdog timer                                  |  59 |  45 |           0 |    0 |
227 2 zero_gravi
 
228
 
229 11 zero_gravi
### Exemplary FPGA Setups
230 6 zero_gravi
 
231 11 zero_gravi
Exemplary implementation results for different FPGA platforms. The processor setup uses *all provided peripherals*,
232 12 zero_gravi
no external memory interface and only internal instruction and data memories. IMEM uses 16kB and DMEM uses 8kB memory space. The setup's top entity connects most of the
233 11 zero_gravi
processor's [top entity](https://github.com/stnolting/neorv32/blob/master/rtl/core/neorv32_top.vhd) signals
234 12 zero_gravi
to FPGA pins - except for the Wishbone bus and the interrupt signals.
235 6 zero_gravi
 
236 14 zero_gravi
Results generated for hardware version: `1.3.0.0`
237 6 zero_gravi
 
238 14 zero_gravi
| Vendor  | FPGA                              | Board            | Toolchain               | Impl. strategy |CPU                               | LUT / LE   | FF / REG   | DSP    | Memory Bits  | BRAM / EBR | SPRAM    | Frequency      |
239
|:--------|:----------------------------------|:-----------------|:------------------------|:---------------|:---------------------------------|:-----------|:-----------|:-------|:-------------|:-----------|:---------|---------------:|
240
| Intel   | Cyclone IV `EP4CE22F17C6N`        | Terasic DE0-Nano | Quartus Prime Lite 19.1 | balanced       | `rv32imc` + `Zicsr` + `Zifencei` | 3934 (18%) | 1799  (8%) | 0 (0%) | 231424 (38%) |          - |        - |        100 MHz |
241
| Lattice | iCE40 UltraPlus `iCE40UP5K-SG48I` | Upduino v2.0     | Radiant 2.1 (LSE)       | timing         | `rv32ic`  + `Zicsr` + `Zifencei` | 4895 (92%) | 1636 (31%) | 0 (0%) |            - |   12 (40%) | 4 (100%) | *c* 22.875 MHz |
242
| Xilinx  | Artix-7 `XC7A35TICSG324-1L`       | Arty A7-35T      | Vivado 2019.2           | default        | `rv32imc` + `Zicsr` + `Zifencei` | 2432 (12%) | 1852  (4%) | 0 (0%) |            - |    8 (16%) |        - |    *c* 100 MHz |
243 2 zero_gravi
 
244 11 zero_gravi
**Notes**
245
* The Lattice iCE40 UltraPlus setup uses the FPGA's SPRAM memory primitives for the internal IMEM and DEMEM (each 64kb).
246 12 zero_gravi
The FPGA-specific memory components can be found in [`rtl/fpga_specific`](https://github.com/stnolting/neorv32/blob/master/rtl/fpga_specific/lattice_ice40up).
247
* The clock frequencies marked with a "c" are constrained clocks. The remaining ones are _f_max_ results from the place and route timing reports.
248 11 zero_gravi
* The Upduino and the Arty board have on-board SPI flash memories for storing the FPGA configuration. These device can also be used by the default NEORV32
249
bootloader to store and automatically boot an application program after reset (both tested successfully).
250 2 zero_gravi
 
251
## Performance
252
 
253
### CoreMark Benchmark
254
 
255
The [CoreMark CPU benchmark](https://www.eembc.org/coremark) was executed on the NEORV32 and is available in the
256
[sw/example/coremark](https://github.com/stnolting/neorv32/blob/master/sw/example/coremark) project folder. This benchmark
257
tests the capabilities of a CPU itself rather than the functions provided by the whole system / SoC.
258
 
259 14 zero_gravi
Results generated for hardware version: `1.3.0.0`
260 2 zero_gravi
 
261
~~~
262
**Configuration**
263 12 zero_gravi
Hardware:    32kB IMEM, 16kB DMEM, 100MHz clock
264
CoreMark:    2000 iterations, MEM_METHOD is MEM_STACK
265 14 zero_gravi
Compiler:    RISCV32-GCC 10.1.0
266 12 zero_gravi
Peripherals: UART for printing the results
267 2 zero_gravi
~~~
268
 
269 14 zero_gravi
| CPU                              | Executable Size | Optimization | CoreMark Score | CoreMarks/MHz |
270
|:---------------------------------|:---------------:|:------------:|:--------------:|:-------------:|
271
| `rv32i`   + `Zicsr` + `Zifencei` |    21 600 bytes |        `-O2` |          27.02 |        0.2702 |
272
| `rv32im`  + `Zicsr` + `Zifencei` |    20 976 bytes |        `-O2` |          57.14 |        0.5714 |
273
| `rv32imc` + `Zicsr` + `Zifencei` |    16 348 bytes |        `-O2` |          57.14 |        0.5714 |
274 2 zero_gravi
 
275
 
276
### Instruction Cycles
277
 
278 11 zero_gravi
The NEORV32 CPU is based on a two-stages pipelined architecutre. Each stage uses a multi-cycle processing scheme. Hence,
279 9 zero_gravi
each instruction requires several clock cycles to execute (2 cycles for ALU operations, ..., 40 cycles for divisions).
280
The average CPI (cycles per instruction) depends on the instruction mix of a specific applications and also on the available
281 2 zero_gravi
CPU extensions.
282
 
283
Please note that the CPU-internal shifter (e.g. for the `SLL` instruction) as well as the multiplier and divider of the
284
`M` extension use a bit-serial approach and require several cycles for completion.
285
 
286 6 zero_gravi
The following table shows the performance results for successfully running 2000 CoreMark
287 9 zero_gravi
iterations, which reflects a pretty good "real-life" work load. The average CPI is computed by
288 12 zero_gravi
dividing the total number of required clock cycles (only the timed core to avoid distortion due to IO wait cycles; sampled via the `cycle[h]` CSRs)
289
by the number of executed instructions (`instret[h]` CSRs). The executables were generated using optimization `-O2`.
290 2 zero_gravi
 
291 14 zero_gravi
Results generated for hardware version: `1.3.0.0`
292 2 zero_gravi
 
293 12 zero_gravi
| CPU                              | Required Clock Cycles | Executed Instructions | Average CPI |
294
|:---------------------------------|----------------------:|----------------------:|:-----------:|
295 14 zero_gravi
| `rv32i`   + `Zicsr` + `Zifencei` |         7 433 933 906 |         1 494 298 800 |        4.97 |
296
| `rv32im`  + `Zicsr` + `Zifencei` |         3 589 861 906 |           628 281 454 |        5.71 |
297
| `rv32imc` + `Zicsr` + `Zifencei` |         3 587 131 226 |           628 282 016 |        5.70 |
298 2 zero_gravi
 
299
 
300 12 zero_gravi
 
301 14 zero_gravi
## Top Entities
302 2 zero_gravi
 
303 14 zero_gravi
The top entity of the **processor** is [**neorv32_top.vhd**](https://github.com/stnolting/neorv32/blob/master/rtl/core/neorv32_top.vhd) (from the `rtl/core` folder).
304 2 zero_gravi
Just instantiate this file in your project and you are ready to go! All signals of this top entity are of type *std_ulogic* or *std_ulogic_vector*, respectively
305
(except for the TWI signals, which are of type *std_logic*).
306
 
307 14 zero_gravi
The top entity of the **CPU** is [**neorv32_cpu.vhd**](https://github.com/stnolting/neorv32/blob/master/rtl/core/neorv32_cpu.vhd) (from the `rtl/core` folder).
308
 
309
Use the generics to configure the processor/CPU according to your needs. Each generic is initilized with the default configuration.
310 2 zero_gravi
Detailed information regarding the signals and configuration generics can be found in the [NEORV32 documentary](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/NEORV32.pdf).
311
 
312 14 zero_gravi
Alternative top entities can be found in [`rtl/top_templates`](https://github.com/stnolting/neorv32/blob/master/rtl/top_templates) folder.
313
 
314
### Processor
315
 
316 2 zero_gravi
```vhdl
317
entity neorv32_top is
318
  generic (
319
    -- General --
320 12 zero_gravi
    CLOCK_FREQUENCY              : natural := 0;      -- clock frequency of clk_i in Hz
321 8 zero_gravi
    BOOTLOADER_USE               : boolean := true;   -- implement processor-internal bootloader?
322
    CSR_COUNTERS_USE             : boolean := true;   -- implement RISC-V perf. counters ([m]instret[h], [m]cycle[h], time[h])?
323 12 zero_gravi
    USER_CODE                    : std_ulogic_vector(31 downto 0) := x"00000000"; -- custom user code
324 2 zero_gravi
    -- RISC-V CPU Extensions --
325 14 zero_gravi
    CPU_EXTENSION_RISCV_C        : boolean := false;  -- implement compressed extension?
326 8 zero_gravi
    CPU_EXTENSION_RISCV_E        : boolean := false;  -- implement embedded RF extension?
327 14 zero_gravi
    CPU_EXTENSION_RISCV_M        : boolean := false;  -- implement muld/div extension?
328 8 zero_gravi
    CPU_EXTENSION_RISCV_Zicsr    : boolean := true;   -- implement CSR system?
329
    CPU_EXTENSION_RISCV_Zifencei : boolean := true;   -- implement instruction stream sync.?
330 2 zero_gravi
    -- Memory configuration: Instruction memory --
331 8 zero_gravi
    MEM_ISPACE_BASE              : std_ulogic_vector(31 downto 0) := x"00000000"; -- base address of instruction memory space
332
    MEM_ISPACE_SIZE              : natural := 16*1024; -- total size of instruction memory space in byte
333 14 zero_gravi
    MEM_INT_IMEM_USE             : boolean := true;   -- implement processor-internal instruction memory
334 8 zero_gravi
    MEM_INT_IMEM_SIZE            : natural := 16*1024; -- size of processor-internal instruction memory in bytes
335 14 zero_gravi
    MEM_INT_IMEM_ROM             : boolean := false;  -- implement processor-internal instruction memory as ROM
336 2 zero_gravi
    -- Memory configuration: Data memory --
337 8 zero_gravi
    MEM_DSPACE_BASE              : std_ulogic_vector(31 downto 0) := x"80000000"; -- base address of data memory space
338
    MEM_DSPACE_SIZE              : natural := 8*1024; -- total size of data memory space in byte
339
    MEM_INT_DMEM_USE             : boolean := true;   -- implement processor-internal data memory
340
    MEM_INT_DMEM_SIZE            : natural := 8*1024; -- size of processor-internal data memory in bytes
341 2 zero_gravi
    -- Memory configuration: External memory interface --
342 8 zero_gravi
    MEM_EXT_USE                  : boolean := false;  -- implement external memory bus interface?
343
    MEM_EXT_REG_STAGES           : natural := 2;      -- number of interface register stages (0,1,2)
344 14 zero_gravi
    MEM_EXT_TIMEOUT              : natural := 15;     -- cycles after which a valid bus access will timeout
345 2 zero_gravi
    -- Processor peripherals --
346 8 zero_gravi
    IO_GPIO_USE                  : boolean := true;   -- implement general purpose input/output port unit (GPIO)?
347
    IO_MTIME_USE                 : boolean := true;   -- implement machine system timer (MTIME)?
348
    IO_UART_USE                  : boolean := true;   -- implement universal asynchronous receiver/transmitter (UART)?
349
    IO_SPI_USE                   : boolean := true;   -- implement serial peripheral interface (SPI)?
350
    IO_TWI_USE                   : boolean := true;   -- implement two-wire interface (TWI)?
351
    IO_PWM_USE                   : boolean := true;   -- implement pulse-width modulation unit (PWM)?
352
    IO_WDT_USE                   : boolean := true;   -- implement watch dog timer (WDT)?
353
    IO_TRNG_USE                  : boolean := false;  -- implement true random number generator (TRNG)?
354
    IO_DEVNULL_USE               : boolean := true    -- implement dummy device (DEVNULL)?
355 2 zero_gravi
  );
356
  port (
357
    -- Global control --
358 14 zero_gravi
    clk_i      : in  std_ulogic := '0'; -- global clock, rising edge
359
    rstn_i     : in  std_ulogic := '0'; -- global reset, low-active, async
360 2 zero_gravi
    -- Wishbone bus interface (available if MEM_EXT_USE = true) --
361 14 zero_gravi
    wb_adr_o   : out std_ulogic_vector(31 downto 0); -- address
362
    wb_dat_i   : in  std_ulogic_vector(31 downto 0) := (others => '0'); -- read data
363
    wb_dat_o   : out std_ulogic_vector(31 downto 0); -- write data
364
    wb_we_o    : out std_ulogic; -- read/write
365
    wb_sel_o   : out std_ulogic_vector(03 downto 0); -- byte enable
366
    wb_stb_o   : out std_ulogic; -- strobe
367
    wb_cyc_o   : out std_ulogic; -- valid cycle
368
    wb_ack_i   : in  std_ulogic := '0'; -- transfer acknowledge
369
    wb_err_i   : in  std_ulogic := '0'; -- transfer error
370 12 zero_gravi
    -- Advanced memory control signals (available if MEM_EXT_USE = true) --
371 14 zero_gravi
    fence_o    : out std_ulogic; -- indicates an executed FENCE operation
372
    fencei_o   : out std_ulogic; -- indicates an executed FENCEI operation
373 2 zero_gravi
    -- GPIO (available if IO_GPIO_USE = true) --
374 14 zero_gravi
    gpio_o     : out std_ulogic_vector(15 downto 0); -- parallel output
375
    gpio_i     : in  std_ulogic_vector(15 downto 0) := (others => '0'); -- parallel input
376 2 zero_gravi
    -- UART (available if IO_UART_USE = true) --
377 14 zero_gravi
    uart_txd_o : out std_ulogic; -- UART send data
378
    uart_rxd_i : in  std_ulogic := '0'; -- UART receive data
379 2 zero_gravi
    -- SPI (available if IO_SPI_USE = true) --
380 14 zero_gravi
    spi_sck_o  : out std_ulogic; -- SPI serial clock
381
    spi_sdo_o  : out std_ulogic; -- controller data out, peripheral data in
382
    spi_sdi_i  : in  std_ulogic := '0'; -- controller data in, peripheral data out
383
    spi_csn_o  : out std_ulogic_vector(07 downto 0); -- SPI CS
384 2 zero_gravi
    -- TWI (available if IO_TWI_USE = true) --
385 14 zero_gravi
    twi_sda_io : inout std_logic := 'H'; -- twi serial data line
386
    twi_scl_io : inout std_logic := 'H'; -- twi serial clock line
387 2 zero_gravi
    -- PWM (available if IO_PWM_USE = true) --
388 14 zero_gravi
    pwm_o      : out std_ulogic_vector(03 downto 0); -- pwm channels
389
    -- Interrupts --
390
    msw_irq_i  : in  std_ulogic := '0'; -- machine software interrupt
391
    mext_irq_i : in  std_ulogic := '0'  -- machine external interrupt
392 2 zero_gravi
  );
393
end neorv32_top;
394
```
395
 
396 14 zero_gravi
### CPU
397 2 zero_gravi
 
398 14 zero_gravi
```vhdl
399
entity neorv32_cpu is
400
  generic (
401
    -- General --
402
    CSR_COUNTERS_USE             : boolean := true;  -- implement RISC-V perf. counters ([m]instret[h], [m]cycle[h], time[h])?
403
    HW_THREAD_ID                 : std_ulogic_vector(31 downto 0):= (others => '0'); -- hardware thread id
404
    CPU_BOOT_ADDR                : std_ulogic_vector(31 downto 0):= (others => '0'); -- cpu boot address
405
    -- RISC-V CPU Extensions --
406
    CPU_EXTENSION_RISCV_C        : boolean := false; -- implement compressed extension?
407
    CPU_EXTENSION_RISCV_E        : boolean := false; -- implement embedded RF extension?
408
    CPU_EXTENSION_RISCV_M        : boolean := false; -- implement muld/div extension?
409
    CPU_EXTENSION_RISCV_Zicsr    : boolean := true;  -- implement CSR system?
410
    CPU_EXTENSION_RISCV_Zifencei : boolean := true;  -- implement instruction stream sync.?
411
    -- Bus Interface --
412
    BUS_TIMEOUT                  : natural := 15     -- cycles after which a valid bus access will timeout
413
  );
414
  port (
415
    -- global control --
416
    clk_i          : in  std_ulogic := '0'; -- global clock, rising edge
417
    rstn_i         : in  std_ulogic := '0'; -- global reset, low-active, async
418
    -- instruction bus interface --
419
    i_bus_addr_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
420
    i_bus_rdata_i  : in  std_ulogic_vector(data_width_c-1 downto 0) := (others => '0'); -- bus read data
421
    i_bus_wdata_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
422
    i_bus_ben_o    : out std_ulogic_vector(03 downto 0); -- byte enable
423
    i_bus_we_o     : out std_ulogic; -- write enable
424
    i_bus_re_o     : out std_ulogic; -- read enable
425
    i_bus_cancel_o : out std_ulogic; -- cancel current bus transaction
426
    i_bus_ack_i    : in  std_ulogic := '0'; -- bus transfer acknowledge
427
    i_bus_err_i    : in  std_ulogic := '0'; -- bus transfer error
428
    i_bus_fence_o  : out std_ulogic; -- executed FENCEI operation
429
    -- data bus interface --
430
    d_bus_addr_o   : out std_ulogic_vector(data_width_c-1 downto 0); -- bus access address
431
    d_bus_rdata_i  : in  std_ulogic_vector(data_width_c-1 downto 0) := (others => '0'); -- bus read data
432
    d_bus_wdata_o  : out std_ulogic_vector(data_width_c-1 downto 0); -- bus write data
433
    d_bus_ben_o    : out std_ulogic_vector(03 downto 0); -- byte enable
434
    d_bus_we_o     : out std_ulogic; -- write enable
435
    d_bus_re_o     : out std_ulogic; -- read enable
436
    d_bus_cancel_o : out std_ulogic; -- cancel current bus transaction
437
    d_bus_ack_i    : in  std_ulogic := '0'; -- bus transfer acknowledge
438
    d_bus_err_i    : in  std_ulogic := '0'; -- bus transfer error
439
    d_bus_fence_o  : out std_ulogic; -- executed FENCE operation
440
    -- system time input from MTIME --
441
    time_i         : in  std_ulogic_vector(63 downto 0) := (others => '0'); -- current system time
442
    -- interrupts (risc-v compliant) --
443
    msw_irq_i      : in  std_ulogic := '0'; -- machine software interrupt
444
    mext_irq_i     : in  std_ulogic := '0'; -- machine external interrupt
445
    mtime_irq_i    : in  std_ulogic := '0'; -- machine timer interrupt
446
    -- fast interrupts (custom) --
447
    firq_i         : in  std_ulogic_vector(3 downto 0) := (others => '0')
448
  );
449
end neorv32_cpu;
450
```
451 2 zero_gravi
 
452 14 zero_gravi
 
453
 
454 2 zero_gravi
## Getting Started
455
 
456
This overview is just a short excerpt from the *Let's Get It Started* section of the NEORV32 documentary:
457
 
458
[![NEORV32 datasheet](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/figures/PDF_32.png) NEORV32 datasheet](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/NEORV32.pdf)
459
 
460
 
461 14 zero_gravi
### Toolchain
462 2 zero_gravi
 
463
At first you need the **RISC-V GCC toolchain**. You can either [download the sources](https://github.com/riscv/riscv-gnu-toolchain)
464
and build the toolchain by yourself, or you can download a prebuilt one and install it.
465
 
466 14 zero_gravi
:warning: Keep in mind that – for instance – a `rv32imc` toolchain only provides library code compiled with compressed and
467
`mul`/`div` instructions! Hence, this code cannot be executed (without emulation) on an architecture without these extensions!
468 2 zero_gravi
 
469 14 zero_gravi
To build the toolchain by yourself, follow the official [build instructions](https://github.com/riscv/riscv-gnu-toolchain.
470
Make sure to use the `ilp32` or `ilp32e` ABI.
471 2 zero_gravi
 
472 14 zero_gravi
Alternatively, you can download a prebuilt toolchain. I have uploaded the toolchain(s) I am using to GitHub. This toolchain
473
has been compiled on a 64-bit x86 Ubuntu (Ubuntu on Windows, actually). Download the toolchain of choice:
474 2 zero_gravi
 
475
[https://github.com/stnolting/riscv_gcc_prebuilt](https://github.com/stnolting/riscv_gcc_prebuilt)
476
 
477
 
478 11 zero_gravi
### Dowload the NEORV32 and Create a Hardware Project
479 2 zero_gravi
 
480 12 zero_gravi
Get the sources of the NEORV32 Processor project. You can either download a [release](https://github.com/stnolting/neorv32/releases)
481
or get the most recent version of this project as [`*.zip` file](https://github.com/stnolting/neorv32/archive/master.zip) or using `git clone` (suggested for easy project updates via `git pull`):
482
 
483 2 zero_gravi
    $ git clone https://github.com/stnolting/neorv32.git
484
 
485 12 zero_gravi
Create a new project with your FPGA design tool of choice and add all the `*.vhd` files from the [`rtl/core`](https://github.com/stnolting/neorv32/blob/master/rtl)
486
folder to this project. Make sure to add them to a **new library** called `neorv32`.
487 2 zero_gravi
 
488 11 zero_gravi
You can either instantiate the [processor's top entity](https://github.com/stnolting/neorv32#top-entity) in your own project or you
489
can use a simple [test setup](https://github.com/stnolting/neorv32/blob/master/rtl/top_templates/neorv32_test_setup.vhd) (from the project's
490
[`rtl/top_templates`](https://github.com/stnolting/neorv32/blob/master/rtl/top_templates) folder) as top entity.
491 12 zero_gravi
This test setup instantiates the processor and implements most of the peripherals and some ISA extensions. Only the UART, clock, reset and some GPIO output sginals are
492 11 zero_gravi
propagated (basically, its a FPGA "hello world" example):
493 2 zero_gravi
 
494
```vhdl
495 9 zero_gravi
  entity neorv32_test_setup is
496
    port (
497
      -- Global control --
498
      clk_i      : in  std_ulogic := '0'; -- global clock, rising edge
499
      rstn_i     : in  std_ulogic := '0'; -- global reset, low-active, async
500
      -- GPIO --
501
      gpio_o     : out std_ulogic_vector(7 downto 0); -- parallel output
502
      -- UART --
503
      uart_txd_o : out std_ulogic; -- UART send data
504
      uart_rxd_i : in  std_ulogic := '0' -- UART receive data
505
    );
506
  end neorv32_test_setup;
507 2 zero_gravi
```
508
 
509
 
510
### Compiling and Uploading One of the Example Projects
511
 
512 11 zero_gravi
Make sure `GNU Make` and a native `GCC` compiler are installed. To test the installation of the RISC-V toolchain navigate to an example project like
513 2 zero_gravi
`sw/example/blink_led` and run:
514
 
515
    neorv32/sw/example/blink_led$ make check
516
 
517 9 zero_gravi
The NEORV32 project includes some [example programs](https://github.com/stnolting/neorv32/tree/master/sw/example) from
518
which you can start your own application. Simply compile one of these projects. This will create a NEORV32
519
executable `neorv32_exe.bin` in the same folder.
520 2 zero_gravi
 
521
    neorv32/sw/example/blink_led$ make clean_all compile
522
 
523
Connect your FPGA board via UART to you computer and open the according port to interface with the NEORV32 bootloader. The bootloader
524
uses the following default UART configuration:
525
 
526
- 19200 Baud
527
- 8 data bits
528
- 1 stop bit
529
- No parity bits
530
- No transmission / flow control protocol (raw bytes only)
531
- Newline on `\r\n` (carriage return & newline)
532
 
533 9 zero_gravi
Use the bootloader console to upload the `neorv32_exe.bin` file and run your application image.
534 2 zero_gravi
 
535 9 zero_gravi
```
536
  << NEORV32 Bootloader >>
537
 
538
  BLDV: Jul  6 2020
539
  HWV:  1.0.1.0
540
  CLK:  0x0134FD90 Hz
541 13 zero_gravi
  USER: 0x0001CE40
542 9 zero_gravi
  MISA: 0x42801104
543
  CONF: 0x03FF0035
544
  IMEM: 0x00010000 bytes @ 0x00000000
545
  DMEM: 0x00010000 bytes @ 0x80000000
546
 
547
  Autoboot in 8s. Press key to abort.
548
  Aborted.
549
 
550
  Available CMDs:
551
   h: Help
552
   r: Restart
553
   u: Upload
554
   s: Store to flash
555
   l: Load from flash
556
   e: Execute
557
  CMD:> u
558
  Awaiting neorv32_exe.bin... OK
559
  CMD:> e
560
  Booting...
561
 
562
  Blinking LED demo program
563
```
564 2 zero_gravi
 
565 9 zero_gravi
Going further: Take a look at the _Let's Get It Started!_ chapter of the [![NEORV32 datasheet](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/figures/PDF_32.png) NEORV32 datasheet](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/NEORV32.pdf).
566 2 zero_gravi
 
567
 
568
 
569 9 zero_gravi
## Contribute
570 2 zero_gravi
 
571 9 zero_gravi
I'm always thankful for help! So if you have any questions, bug reports, ideas or if you want to give some kind of feedback, feel free
572
to open a [new issue](https://github.com/stnolting/neorv32/issues).
573 2 zero_gravi
 
574 9 zero_gravi
If you want to get involved you can also directly drop me a line (mailto:stnolting@gmail.com).
575
Please also check out the project's [code of conduct](https://github.com/stnolting/neorv32/tree/master/CODE_OF_CONDUCT.md).
576 2 zero_gravi
 
577
 
578 9 zero_gravi
 
579 11 zero_gravi
## Legal
580 2 zero_gravi
 
581 12 zero_gravi
This project is released under the BSD 3-Clause license. No copyright infringement intended.
582 11 zero_gravi
Other implied or used projects might have different licensing - see their documentation to get more information.
583
 
584
#### Citation
585
 
586 2 zero_gravi
If you are using the NEORV32 Processor in some kind of publication, please cite it as follows:
587
 
588
> S. Nolting, "The NEORV32 Processor", github.com/stnolting/neorv32
589
 
590 9 zero_gravi
#### BSD 3-Clause License
591 2 zero_gravi
 
592
Copyright (c) 2020, Stephan Nolting. All rights reserved.
593
 
594
Redistribution and use in source and binary forms, with or without modification, are
595
permitted provided that the following conditions are met:
596
 
597
1. Redistributions of source code must retain the above copyright notice, this list of
598
conditions and the following disclaimer.
599
2. Redistributions in binary form must reproduce the above copyright notice, this list of
600
conditions and the following disclaimer in the documentation and/or other materials
601
provided with the distribution.
602
3. Neither the name of the copyright holder nor the names of its contributors may be used to
603
endorse or promote products derived from this software without specific prior written
604
permission.
605
 
606
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
607
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
608
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
609
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
610
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
611
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
612
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
613
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
614
OF THE POSSIBILITY OF SUCH DAMAGE.
615
 
616
 
617 9 zero_gravi
#### Limitation of Liability for External Links
618
 
619
Our website contains links to the websites of third parties („external links“). As the
620
content of these websites is not under our control, we cannot assume any liability for
621
such external content. In all cases, the provider of information of the linked websites
622
is liable for the content and accuracy of the information provided. At the point in time
623
when the links were placed, no infringements of the law were recognisable to us. As soon
624
as an infringement of the law becomes known to us, we will immediately remove the
625
link in question.
626
 
627
 
628 11 zero_gravi
#### Proprietary  Notice
629 9 zero_gravi
 
630 2 zero_gravi
"Windows" is a trademark of Microsoft Corporation.
631
 
632
"Artix" and "Vivado" are trademarks of Xilinx Inc.
633
 
634 11 zero_gravi
"Cyclone", "Quartus Prime", "Quartus Prime Lite" and "Avalon Bus" are trademarks of Intel Corporation.
635 2 zero_gravi
 
636 11 zero_gravi
"Artix" and "Vivado" are trademarks of Xilinx, Inc.
637
 
638 2 zero_gravi
"iCE40", "UltraPlus" and "Lattice Radiant" are trademarks of Lattice Semiconductor Corporation.
639
 
640 13 zero_gravi
"AXI" and "AXI-Lite" are trademarks of Arm Holdings plc.
641 2 zero_gravi
 
642
 
643 11 zero_gravi
## Acknowledgement
644 9 zero_gravi
 
645 11 zero_gravi
[RISC-V](https://riscv.org/) - Instruction Sets Want To Be Free :heart:
646
 
647 2 zero_gravi
[![Continous Integration provided by Travis CI](https://travis-ci.com/images/logos/TravisCI-Full-Color.png)](https://travis-ci.com/stnolting/neorv32)
648
 
649
Continous integration provided by [Travis CI](https://travis-ci.com/stnolting/neorv32) and powered by [GHDL](https://github.com/ghdl/ghdl).
650
 
651
 
652
![Open Source Hardware Logo https://www.oshwa.org](https://raw.githubusercontent.com/stnolting/neorv32/master/docs/figures/oshw_logo.png)
653
 
654
This project is not affiliated with or endorsed by the Open Source Initiative (https://www.oshwa.org / https://opensource.org).
655
 
656
 
657 14 zero_gravi
 
658 6 zero_gravi
Made with :coffee: in Hannover, Germany.

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.