Skip to content
Electronics 14 min read

OnionSoC v2.2: My Open-Source RISC-V SoC, Tested on FPGA

Observation recorded
OnionSoC v2.2 title in large white and gold type beside a glowing, tilted view of the core's Sky130 chip layout, with the line built from scratch, tested on a real FPGA, every number published
Quick answer OnionSoC v2.2 is my open-source RISC-V microcontroller SoC (RV32IM, 5-stage pipeline, caches, 11 peripherals), released under Apache-2.0. New in v2.2: user mode with 8-region memory protection, a priority interrupt controller, sleep and stop modes, and packed SIMD. On a real Arty A7-35T it runs at 71.4 MHz and scores 240 CoreMark (3.37 per MHz).

I have been building a RISC-V system-on-chip from scratch for a while now. Today OnionSoC v2.2 is merged to main and the whole thing is public under Apache-2.0:

github.com/oniondas/onion-soc

That means the RTL, the Python golden model, the testbenches, the firmware, the FPGA build scripts, the board logs and the reports. Nothing is held back. You can clone it, simulate it, put it on an Arty board and check every number in this post yourself.

This post covers what is new in v2.2, how it performs on real hardware, how it compares with other cores (open source and commercial), and where it is still weak.

What is OnionSoC?

OnionSoC is a microcontroller-class SoC built around my own RV32IM core. The core is a classic 5-stage pipeline with forwarding, branch prediction, an instruction cache and a data cache. Around it sit an AXI-Lite interconnect and a set of peripherals: UART, SPI, I2C, GPIO, PWM, timer, DMA, watchdog, JTAG debug, and a fixed-point MAC accelerator. The firmware is plain C.

OnionSoC v2.2 top-level block diagram: the RV32IM core with 4 KB instruction and data caches, a debug module and JTAG TAP, a 2-channel DMA engine and clock gates on the left; an AXI crossbar with 4 masters and 16 slaves in the middle; on the right the always-on timer, CLIC, interrupt controller, PMU and watchdog, the gated UART, GPIO, SPI, I2C, PWM, MAC accelerator and DMA registers, and the boot ROM, 64 KB SRAM and 8 KB scratchpad. Blocks new in v2.2 are tagged
Figure 1. OnionSoC v2.2 at the top level. Blocks tagged v2.2 are new or changed in this release. Tap to open full size. From docs/figures/v2.2/soc_top.svg in the repo.

The flow is the same for every block:

  1. Write a Python golden model first, so I know exactly what the hardware should do.
  2. Write the RTL by hand in SystemVerilog. No HLS, no Chisel, no generators.
  3. Verify against the model with cocotb, and run the official riscv-tests suite on the core.

Every module is documented with why it exists, the maths behind it and the design reasoning. Open-source SoCs were only used as references and benchmarks, never as code.

What is new in OnionSoC v2.2?

v2.1 was a fast, well-tested core. v2.2 is about making it behave like a real microcontroller you could ship firmware on.

User mode and memory protection (PMP)

The core now has a privileged machine mode and an unprivileged user mode, with a memory protection unit (RISC-V PMP, 8 regions). User code that touches memory it does not own traps instead of corrupting the system. The riscv-tests suite passes 159 of 159 in both machine and user mode, with the trace matching the instruction-set simulator.

Diagram of the OnionSoC PMP and user mode logic: privilege state and eight pmpaddr and pmpcfg registers in the CSR file feed one PMP checker at instruction fetch and one on the load and store address in the execute stage; a denied or misaligned access is registered and trapped one stage later in memory, which blocks the data cache request and redirects to the trap vector
Figure 2. Protection checks at fetch and at load/store. The trap is taken one stage later, in MEM, which is what got the clock back from 55.5 MHz to 71.4 MHz. From docs/figures/v2.2/pmp.svg.

A priority interrupt controller

The old simple interrupt block is replaced by a CLIC-style controller with priority levels and vectored handling, so an urgent interrupt can preempt a less urgent one. On the board, a vectored interrupt reaches its handler in 12 cycles, and 10 through the common entry.

Sleep and stop modes with wake-up

The SoC can gate clocks to idle parts and stop the core, then wake on an interrupt. Wake-up takes 6 cycles from sleep and 5 from stop on the board. The SoC drives an “awake” output so a board LED can show the state.

Custom SIMD and DSP instructions

I added a set of packed integer instructions (37 of them, based on a draft of the RISC-V P extension) for 8-bit and 16-bit data. This is where the biggest wins are:

  • int8 dot products: 3.4x to 6.3x faster than scalar code
  • a small neural-network layer: 5.5x faster
  • a Q15 FIR filter: 4x faster
  • every result is bit-exact against the scalar reference, checked on the board, not only in simulation.
Bar chart: speed-up of OnionSoC v2.2 packed SIMD over plain RV32IM code on the Arty A7-35T. int8 dot product with 64 elements 3.44 times, Q15 FIR filter with 16 taps 4.01 times, int8 neural-network layer 64 to 16 5.53 times, int8 dot product with 256 elements 6.32 times. All results bit-exact
Figure 3. SIMD speed-ups measured on the board, from simdbench_71m4.log. Longer vectors gain more because the fixed loop overhead is spread over more elements.

Why does a dot product get faster with SIMD? A scalar loop does one multiply-accumulate per element. With four int8 lanes in one 32-bit register, one instruction does four of them, so the ideal ceiling is 4x for the arithmetic. The measured 6.3x on 256 elements beats that because the packed loop also needs a quarter of the loads, a quarter of the loop branches and no separate sign-extension per byte. The 64-element case lands at 3.4x because setup and the final reduction take a bigger share of a short loop.

Datapath of the OnionSoC packed SIMD unit: a three-read-port register file, a one-cycle lane ALU with four 8-bit or two 16-bit lanes, four 9 by 9 lane multipliers feeding three carry-save adder levels with the accumulator, and the existing multiplier adder in the memory stage producing the final sum
Figure 4. The SIMD datapath reuses the multiplier's adder in MEM, so dot products add no new carry chain in EX. From docs/figures/v2.2/simd.svg.

How does OnionSoC v2.2 perform on real hardware?

I do not own an FPGA. All board testing was done on an Arty A7-35T (Xilinx Artix-7) through fpgas.online, a free remote FPGA service, with the board watched over a webcam while the logs came back over UART.

Metricv2.1v2.2
Clock on Arty A7-35T62.5 MHz71.4 MHz
CoreMark212240 (+13%)
CoreMark/MHz3.393.37
CPI on CoreMark1.111.12
v1 demo firmware9/1010/10
v2 demo firmware15/1816/18

CoreMark is a score per second, so it is the per-clock figure times the clock. You can check the headline number from the two values in the table:

CoreMark=CoreMark/MHz×f=3.367×71.4≈240\begin{aligned}\text{CoreMark} &= \text{CoreMark/MHz} \times f \\ &= 3.367 \times 71.4 \\ &\approx \mathbf{240}\end{aligned}
gain=240/212≈1.13(+13%)\begin{aligned}\text{gain} &= 240 / 212 \\ &\approx 1.13 \quad (+13\%)\end{aligned}

The +13% comes from the higher clock, not from a faster core. Per clock, v2.2 is very slightly slower than v2.1 (3.367/3.390≈0.9933.367 / 3.390 \approx 0.993, a 0.7% drop). The cause is a registered grant in the bus crossbar that I added to help timing; it costs one cycle per bus transaction and buys more MHz. I would rather report that than round it away.

The two v2 demo failures are one real gap: that test talks to an I2C EEPROM, and the remote board does not have one fitted. Everything else passes. The board runs also take exactly the cycle counts the Verilator model predicts: 11,878,431 cycles for 40 CoreMark iterations, in simulation and on the board.

Eight webcam frames, two seconds apart, of the remote Arty A7-35T board running OnionSoC: the RGB LED cycles through red, green, blue, yellow, magenta, cyan, white and off, with UART labels for each colour and timestamps from 15:05:56 to 15:06:10 UTC
Figure 5. How you test hardware you do not own: the remote Arty A7-35T on fpgas.online, watched by a webcam while firmware cycles the RGB LED. These frames are from the v2.1 bring-up; v2.2 runs on the same board.

I posted the first board bring-up (v2.1, 212 CoreMark at 62.5 MHz) as a thread on X, with the webcam video:

One side note, to be complete: a build without the v2.2 features closed timing at 80 MHz and scored 269 CoreMark. So the new features cost about 9 MHz of clock (8.6 MHz exactly). That is the price of protection checks and wider datapaths, and I think it is worth paying, but it is there.

Bar chart of CoreMark on the Arty A7-35T for three builds: v2.1 at 62.5 MHz scores 212, a v2.2 baseline without the new features at 80.0 MHz scores 269, and the released v2.2 at 71.4 MHz scores 240. CoreMark per MHz is 3.390, 3.367 and 3.367
Figure 6. Same CoreMark binary, three builds. The per-clock figure barely moves; the clock is what changes.

How does it compare with other RISC-V and Arm cores?

CoreMark/MHz is the fairest single number for comparing cores at different clock speeds, because it removes the clock and the process from the picture. It does not capture area, power or features, so read the table with that in mind.

CoreTypeCoreMark/MHz
Arm Cortex-M33commercial~4.0
Andes N22commercial~3.95
Hazard3 (RP2350)open source3.8 to 4.15
Arm Cortex-M4commercial~3.42
OnionSoC v2.2open source3.37
Arm Cortex-M3commercial~3.34
Ibex (max perf config)open source3.13
CV32E40Popen source3.11
VexRiscvopen source2.57
Arm Cortex-M0+commercial~2.4
PicoRV32open source~0.5
Horizontal bar chart of CoreMark per MHz: Arm Cortex-M33 about 4.0, Andes N22 about 3.95, Hazard3 3.8 to 4.15, Arm Cortex-M4 about 3.42, OnionSoC v2.2 3.37 highlighted in gold, Arm Cortex-M3 about 3.34, Ibex 3.13, CV32E40P 3.11, VexRiscv 2.57, Arm Cortex-M0+ about 2.4 and PicoRV32 about 0.5
Figure 7. Per clock, OnionSoC v2.2 lands between the Cortex-M3 and Cortex-M4. Open-source cores in cyan, commercial in orange.

Commercial figures are the vendors’ published numbers; open-source figures are from each project’s own reports. SiFive’s E20 and E31 class cores also land below OnionSoC per clock.

Source note Published Cortex-M figures vary with compiler and edition. Arm's own 2022 comparison table lists the Cortex-M33 at 4.10 and the Cortex-M4 at 3.54 CoreMark/MHz, a little higher than the commonly quoted 4.02 and 3.42 used above. With Arm's numbers, OnionSoC is about 5% behind the Cortex-M4 rather than about 1%. The ordering does not change.

What I take from this:

  • Among open-source cores, only Hazard3 is clearly ahead per clock. OnionSoC beats Ibex, CV32E40P, VexRiscv and PicoRV32. Those are mature, well-engineered projects, so I am happy with that, but it is per-clock only.
  • Against commercial parts, OnionSoC sits around Cortex-M3 and close to Cortex-M4, and ahead of Cortex-M0+. It is behind Cortex-M33 and Andes N22.
  • Feature-wise, v2.2 closes the gap that bothered me most in v2.1: no user mode and no memory protection. Those are now in.

Where is OnionSoC still weak?

Being honest about this matters more to me than the table above.

  • It is bigger than the small cores. Ibex is roughly 1.7x smaller. The v2.2 SoC uses about 17k LUTs on the Artix-7, around 82% of the 35T part. That is not small.
  • Fmax is low for Artix-7. 71.4 MHz is fine for a microcontroller, but good designs on this FPGA family run faster. There are known timing paths I still need to cut.
  • It is FPGA, not silicon. The v2.1 core has been taken through a full RTL-to-GDS flow in the open Sky130 process, but nothing has been fabricated, and v2.2 has not been laid out yet.
  • No compressed instructions. Without the RISC-V C extension, code is roughly 25 to 30% bigger than on most competing cores. That matters on a microcontroller with small memory.
  • Some of it rests on draft specs. The interrupt controller and the SIMD instructions follow RISC-V drafts that are not ratified yet. If the specs change, the compiler intrinsics will need to follow.

The 82% figure is easy to check. The Artix-7 35T has 20,800 LUTs, and the v2.2 build uses 17,123 of them:

LUT use=17,123/20,800≈82%\begin{aligned}\text{LUT use} &= 17{,}123 / 20{,}800 \\ &\approx \mathbf{82\%}\end{aligned}

That leaves under 3,700 LUTs for anything else you might want to add on this part. The repo notes where some could come back: the four 9×9 SIMD lane multipliers are built from LUTs today, and moving them into the DSP48 blocks (6 of 90 used) would free several hundred.

Built with no hardware budget

The whole project was built with zero hardware cost. I do not own an FPGA, and my laptop has 8 GB of RAM, which is not enough for Vivado or a full physical-design run. So:

  • Simulation, Vivado synthesis and place-and-route, and the OpenLane RTL-to-GDS runs all happened on cloud servers paid for with free credits.
  • Board testing happened on the free remote Arty, with a webcam pointed at the LEDs.

If you are a student and think you need a lab and an expensive board to do serious digital design, you do not. You need patience and a good test plan. If you are starting from the basics, the posts on logic gates and truth tables, UART baud-rate error, I2C pull-up resistor values and how PWM works cover the ideas behind several of the blocks in Figure 1.

How to try OnionSoC

The repository has everything:

  • rtl/ for the SoC and core, model/ for the golden model, tb/ for the cocotb tests
  • sw/ for firmware, including CoreMark and the SIMD benchmark
  • fpga/ for the Vivado build and the raw board logs behind every number above
  • docs/ for per-module design notes, the generation-by-generation comparison and the reports

Issues and pull requests are welcome, especially from anyone who wants to run it on a different board or push the Fmax up.

What comes next

The next big step is v3: a ground-up rewrite of the core, with compressed instructions, a better timing structure, and one genuinely new idea rather than another catch-up feature. Before that, I want v2.2 taken through the Sky130 flow the same way v2.1 was.

If you build something with it, or find a bug, I would like to hear about it.

Repo: github.com/oniondas/onion-soc · License: Apache-2.0

Frequently asked questions

What is OnionSoC?

OnionSoC is an open-source, microcontroller-class system-on-chip built around a hand-written RV32IM RISC-V core with a 5-stage pipeline, branch prediction and instruction and data caches. Around it sit an AXI interconnect, UART, SPI, I2C, GPIO, PWM, timer, DMA, watchdog, JTAG debug and a fixed-point MAC accelerator. It is released under Apache-2.0.

How fast is OnionSoC v2.2?

On an Arty A7-35T board at 71.4 MHz it scores 240 CoreMark, which is 3.37 CoreMark per MHz. That is 13% more than v2.1 on the same board, and the gain comes from the higher clock, not from a faster core.

How does OnionSoC compare with Arm Cortex-M cores?

Per clock, OnionSoC v2.2 (3.37 CoreMark/MHz) sits around the Cortex-M3 (about 3.34) and a little below the Cortex-M4 (about 3.42 to 3.54 depending on the source). It is ahead of the Cortex-M0+ (about 2.4) and behind the Cortex-M33 and Andes N22 (about 4).

Can I run OnionSoC without owning an FPGA board?

Yes. The whole SoC simulates in Verilator and cocotb, and all board testing for v2.2 was done on a free remote Arty A7-35T through fpgas.online, with the board watched over a webcam and the logs returned over UART.

Does OnionSoC support compressed RISC-V instructions?

Not yet. v2.2 has no C extension, so its code is roughly 25 to 30% larger than on cores that run compressed code. Compressed instructions are planned for v3.

Sources

  1. OnionSoC repository, v2.2 results and board logs: github.com/oniondas/onion-soc (docs/v2.2/RESULTS.md, fpga/vivado/results/v2.2/board_71mhz/)
  2. EEMBC CoreMark benchmark: eembc.org/coremark
  3. Arm Cortex-M comparison table (2022): documentation-service.arm.com
  4. CoreMark/MHz table for Cortex-M cores: WikiChip
  5. Andes N22 (3.95 CoreMark/MHz): CNX Software
  6. Hazard3: github.com/Wren6991/Hazard3
  7. Ibex: github.com/lowRISC/ibex
  8. CV32E40P CoreMark (Gallmann et al., CARRV 2021): carrv.github.io
  9. VexRiscv: github.com/SpinalHDL/VexRiscv
  10. PicoRV32: github.com/YosysHQ/picorv32
  11. riscv-tests: github.com/riscv-software-src/riscv-tests
  12. Remote FPGA boards: fpgas.online
Related observations
Electronics 555 Timer Astable Circuit Explained with Waveforms Electronics 555 Timer Frequency Formula: Where 1.44 Comes From Electronics ADC Resolution vs Accuracy: ENOB, INL and the Reference
Transmit