Skip to content

Commit 90cb442

Browse files
committed
Adding a Verilog example using PicoSoC
Signed-off-by: gatecat <gatecat@ds0.me>
1 parent 9427f34 commit 90cb442

File tree

19 files changed

+1192
-28
lines changed

19 files changed

+1192
-28
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:
@@ -56,10 +58,12 @@ jobs:
5658
runs-on: ubuntu-latest
5759
strategy:
5860
matrix:
59-
design: ['mcu_soc', 'minimal']
61+
design: ['mcu_soc', 'minimal', 'picosoc_verilog']
6062
steps:
6163
- name: Check out source code
6264
uses: actions/checkout@v4
65+
with:
66+
submodules: true
6367

6468
- name: Set up PDM
6569
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

pdm.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

picosoc_verilog/design/design.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
from chipflow_lib.platforms import InputIOSignature, OutputIOSignature, BidirIOSignature
10+
11+
__all__ = ["MySoC"]
12+
13+
# Define signatures for the top level interface types
14+
class _QSPISignature(wiring.Signature):
15+
def __init__(self):
16+
super().__init__({
17+
"clk": Out(OutputIOSignature(1)),
18+
"csn": Out(OutputIOSignature(1)),
19+
"d": Out(BidirIOSignature(4, all_have_oe=True)),
20+
})
21+
22+
class _UARTSignature(wiring.Signature):
23+
def __init__(self):
24+
super().__init__({
25+
"tx": Out(OutputIOSignature(1)),
26+
"rx": Out(InputIOSignature(1)),
27+
})
28+
29+
class _GPIOSignature(wiring.Signature):
30+
def __init__(self, pin_count=1):
31+
if pin_count > 32:
32+
raise ValueError(f"Pin pin_count must be lesser than or equal to 32, not {pin_count}")
33+
super().__init__({
34+
"gpio": Out(BidirIOSignature(pin_count, all_have_oe=True))
35+
})
36+
37+
class MySoC(wiring.Component):
38+
def __init__(self):
39+
# Top level interfaces
40+
41+
super().__init__({
42+
"flash": Out(_QSPISignature()),
43+
"uart_0": Out(_UARTSignature()),
44+
"gpio_0": Out(_GPIOSignature(pin_count=8)),
45+
})
46+
47+
def elaborate(self, platform):
48+
m = Module()
49+
50+
base = os.path.dirname(__file__)
51+
52+
verilog_sources = [
53+
f"{base}/picosoc_asic_top.v",
54+
f"{base}/picorv32/picosoc/spimemio.v",
55+
f"{base}/picorv32/picosoc/simpleuart.v",
56+
f"{base}/picorv32/picosoc/picosoc.v",
57+
f"{base}/picorv32/picorv32.v",
58+
]
59+
60+
for verilog_file in verilog_sources:
61+
with open(verilog_file, 'r') as f:
62+
platform.add_file(verilog_file, f)
63+
64+
m.submodules.soc = soc = Instance("picosoc_asic_top",
65+
# Clock and reset
66+
i_clk=ClockSignal(),
67+
i_resetn=~ResetSignal(),
68+
69+
# UART
70+
o_ser_tx=self.uart_0.tx.o,
71+
i_ser_rx=self.uart_0.rx.i,
72+
73+
# SPI flash
74+
o_flash_csb=self.flash.csn.o,
75+
o_flash_clk=self.flash.clk.o,
76+
77+
o_flash_io0_oe=self.flash.d.oe[0],
78+
o_flash_io1_oe=self.flash.d.oe[1],
79+
o_flash_io2_oe=self.flash.d.oe[2],
80+
o_flash_io3_oe=self.flash.d.oe[3],
81+
82+
o_flash_io0_do=self.flash.d.o[0],
83+
o_flash_io1_do=self.flash.d.o[1],
84+
o_flash_io2_do=self.flash.d.o[2],
85+
o_flash_io3_do=self.flash.d.o[3],
86+
87+
i_flash_io0_di=self.flash.d.i[0],
88+
i_flash_io1_di=self.flash.d.i[1],
89+
i_flash_io2_di=self.flash.d.i[2],
90+
i_flash_io3_di=self.flash.d.i[3],
91+
92+
# LEDs
93+
o_leds=self.gpio_0.gpio.o
94+
)
95+
96+
# Hardwire GPIO to output enabled
97+
m.d.comb += self.gpio_0.gpio.oe.eq(0xFF)
98+
99+
return m

picosoc_verilog/design/picorv32

Submodule picorv32 added at 87c89ac

0 commit comments

Comments
 (0)