Skip to content

Commit f9a4d9c

Browse files
committed
Adding a Verilog example using PicoSoC
Signed-off-by: gatecat <[email protected]>
1 parent 9174c20 commit f9a4d9c

File tree

24 files changed

+1306
-5
lines changed

24 files changed

+1306
-5
lines changed

.github/workflows/main.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ jobs:
2323
runs-on: ubuntu-latest
2424
strategy:
2525
matrix:
26-
design: ['mcu_soc', 'minimal']
26+
design: ['mcu_soc', 'minimal', 'picosoc_verilog']
2727
steps:
2828
- name: Check out source code
2929
uses: actions/checkout@v4
30+
with:
31+
submodules: true
3032

3133
- uses: actions/setup-python@v4
3234
with:
@@ -61,10 +63,12 @@ jobs:
6163
runs-on: ubuntu-latest
6264
strategy:
6365
matrix:
64-
design: ['mcu_soc', 'minimal']
66+
design: ['mcu_soc', 'minimal', 'picosoc_verilog']
6567
steps:
6668
- name: Check out source code
6769
uses: actions/checkout@v4
70+
with:
71+
submodules: true
6872

6973
- name: Set up PDM
7074
uses: pdm-project/setup-pdm@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ __pycache__/
1919
/build
2020
/mcu_soc/build
2121
/minimal/build
22+
/picosoc_verilog/build
2223

2324
# testbenches
2425
*.vcd

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "picosoc_verilog/design/picorv32"]
2+
path = picosoc_verilog/design/picorv32
3+
url = https://github.com/YosysHQ/picorv32

common/sim/models.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct uart_model {
7373

7474
// model state
7575
struct {
76-
bool tx_last;
76+
bool tx_last = true;
7777
int rx_counter = 0;
7878
uint8_t rx_sr = 0;
7979
bool tx_active = false;

common/sim/vendor/cxxrtl/cxxrtl_replay.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,14 @@ class recorder {
624624

625625
CXXRTL_ALWAYS_INLINE
626626
void on_update(size_t chunks, const chunk_t *base, const chunk_t *value) {
627-
writer->write_change(ident_lookup->at(base), chunks, value);
627+
if (ident_lookup->count(base))
628+
writer->write_change(ident_lookup->at(base), chunks, value);
628629
}
629630

630631
CXXRTL_ALWAYS_INLINE
631632
void on_update(size_t chunks, const chunk_t *base, const chunk_t *value, size_t index) {
632-
writer->write_change(ident_lookup->at(base), chunks, value, index);
633+
if (ident_lookup->count(base))
634+
writer->write_change(ident_lookup->at(base), chunks, value, index);
633635
}
634636
} record_observer;
635637
record_observer.ident_lookup = &ident_lookup;

picosoc_verilog/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
ARG ?= SPI
2+
3+
.PHONY: init # Init local environemnt
4+
init:
5+
pdm install
6+
7+
.PHONY: sim-build # Builds a local binary to run the design in simulation
8+
sim-build:
9+
pdm run chipflow sim
10+
11+
.PHONY: software-build # Builds the RISC-V software/bios to run on the design
12+
software-build: sim-build
13+
pdm run chipflow software
14+
15+
.PHONY: board-build # Build a bitstream for the board
16+
board-build:
17+
pdm run chipflow board
18+
19+
.PHONY: board-load-software-ulx3s # Load the software/bios onto a ulx3s board
20+
board-load-software-ulx3s:
21+
openFPGALoader -fb ulx3s -o 0x00100000 build/software/software.bin
22+
23+
.PHONY: board-load-ulx3s # Load the design onto a ulx3s board
24+
board-load-ulx3s:
25+
openFPGALoader -b ulx3s build/top.bit
26+
27+
.PHONY: sim-run # Run the simulation of the design
28+
sim-run: sim-build software-build
29+
cd build/sim && ./sim_soc
30+
31+
.PHONY: sim-check
32+
sim-check: sim-run
33+
pdm run json-compare design/tests/events_reference.json build/sim/events.json
34+
35+
.PHONY: silicon-prepare # Build RTLIL for the design
36+
silicon-prepare:
37+
pdm run chipflow silicon prepare
38+
39+
.PHONY: silicon-submit # Send to API to submit for manufacture
40+
silicon-submit:
41+
pdm run chipflow silicon submit
42+
43+
.PHONY: clean # Clean/delete the builds
44+
clean:
45+
rm -fr build

picosoc_verilog/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# PicoSoC (Verilog)
2+
3+
This example design shows how an existing Verilog design (picosoc) can be wrapped in a minimal layer of Amaranth and submitted to the ChipFlow platform.
4+

picosoc_verilog/chipflow.toml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[chipflow]
2+
project_name = "chipflow-examples-picosoc"
3+
4+
[chipflow.top]
5+
soc = "design.design:MySoC"
6+
7+
[chipflow.steps]
8+
sim = "design.steps.sim:MySimStep"
9+
silicon = "chipflow_lib.steps.silicon:SiliconStep"
10+
software = "design.steps.software:MySoftwareStep"
11+
12+
[chipflow.clocks]
13+
default = 'sys_clk'
14+
15+
[chipflow.resets]
16+
default = 'sys_rst_n'
17+
18+
[chipflow.silicon]
19+
process = "ihp_sg13g2"
20+
package = "pga144"
21+
22+
[chipflow.silicon.pads]
23+
# System
24+
sys_clk = { type = "clock", loc = "114" }
25+
sys_rst_n = { type = "reset", loc = "115" }
26+
27+
[chipflow.silicon.power]
28+
dvss0 = { type = "power", loc = "1" }
29+
dvdd0 = { type = "ground", loc = "9" }
30+
vss0 = { type = "power", loc = "17" }
31+
vdd0 = { type = "ground", loc = "25" }
32+
dvss1 = { type = "power", loc = "33" }
33+
dvdd1 = { type = "ground", loc = "41" }
34+
vss1 = { type = "power", loc = "49" }
35+
vdd1 = { type = "ground", loc = "57" }
36+
dvss2 = { type = "power", loc = "65" }
37+
dvdd2 = { type = "ground", loc = "73" }
38+
vss2 = { type = "power", loc = "81" }
39+
vdd2 = { type = "ground", loc = "89" }
40+
dvss3 = { type = "power", loc = "97" }
41+
dvdd3 = { type = "ground", loc = "105" }
42+
vss3 = { type = "power", loc = "113" }
43+
vdd3 = { type = "ground", loc = "121" }
44+
dvss4 = { type = "power", loc = "129" }
45+
dvdd4 = { type = "ground", loc = "137" }

picosoc_verilog/design/design.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
3+
from chipflow_lib.platforms.sim import SimPlatform
4+
5+
from amaranth import Module, Instance, ClockSignal, ResetSignal
6+
from amaranth.lib import wiring
7+
from amaranth.lib.wiring import In, Out, flipped, connect
8+
9+
# We don't actually use these peripherals - they are just imported for the pin signatures
10+
from amaranth_orchard.memory import QSPIFlash
11+
from amaranth_orchard.io import GPIOPeripheral
12+
from amaranth_orchard.io import UARTPeripheral
13+
14+
from chipflow_lib.platforms import InputPinSignature, OutputPinSignature
15+
16+
__all__ = ["MySoC"]
17+
18+
19+
class MySoC(wiring.Component):
20+
def __init__(self):
21+
# Top level interfaces
22+
23+
super().__init__({
24+
"flash": Out(QSPIFlash.Signature()),
25+
"uart_0": Out(UARTPeripheral.Signature()),
26+
"gpio_0": Out(GPIOPeripheral.Signature(pin_count=8)),
27+
})
28+
29+
def elaborate(self, platform):
30+
m = Module()
31+
32+
base = os.path.dirname(__file__)
33+
34+
verilog_sources = [
35+
f"{base}/picosoc_asic_top.v",
36+
f"{base}/picorv32/picosoc/spimemio.v",
37+
f"{base}/picorv32/picosoc/simpleuart.v",
38+
f"{base}/picorv32/picosoc/picosoc.v",
39+
f"{base}/picorv32/picorv32.v",
40+
]
41+
42+
for verilog_file in verilog_sources:
43+
with open(verilog_file, 'r') as f:
44+
platform.add_file(verilog_file, f)
45+
46+
m.submodules.soc = soc = Instance("picosoc_asic_top",
47+
# Clock and reset
48+
i_clk=ClockSignal(),
49+
i_resetn=~ResetSignal(),
50+
51+
# UART
52+
o_ser_tx=self.uart_0.tx.o,
53+
i_ser_rx=self.uart_0.rx.i,
54+
55+
# SPI flash
56+
o_flash_csb=self.flash.csn.o,
57+
o_flash_clk=self.flash.clk.o,
58+
59+
o_flash_io0_oe=self.flash.d.oe[0],
60+
o_flash_io1_oe=self.flash.d.oe[1],
61+
o_flash_io2_oe=self.flash.d.oe[2],
62+
o_flash_io3_oe=self.flash.d.oe[3],
63+
64+
o_flash_io0_do=self.flash.d.o[0],
65+
o_flash_io1_do=self.flash.d.o[1],
66+
o_flash_io2_do=self.flash.d.o[2],
67+
o_flash_io3_do=self.flash.d.o[3],
68+
69+
i_flash_io0_di=self.flash.d.i[0],
70+
i_flash_io1_di=self.flash.d.i[1],
71+
i_flash_io2_di=self.flash.d.i[2],
72+
i_flash_io3_di=self.flash.d.i[3],
73+
74+
# LEDs
75+
o_leds=self.gpio_0.gpio.o
76+
)
77+
78+
# Hardwire GPIO to output enabled
79+
m.d.comb += self.gpio_0.gpio.oe.eq(0xFF)
80+
81+
return m

picosoc_verilog/design/picorv32

Submodule picorv32 added at 87c89ac

0 commit comments

Comments
 (0)