Skip to content

Commit 2220d09

Browse files
committed
wip: board configuration
1 parent 9a21033 commit 2220d09

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

chipflow_lib/__init__.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
import sys
88
import tomli
99
from pathlib import Path
10+
from dataclasses import dataclass
11+
1012
from pydantic import ValidationError
1113

14+
from amaranth.lib.wiring import Signature
15+
1216
__version__ = importlib.metadata.version("chipflow_lib")
1317

1418
class ChipFlowError(Exception):
@@ -64,3 +68,63 @@ def _parse_config_file(config_file):
6468

6569
error_str = "\n".join(error_messages)
6670
raise ChipFlowError(f"Validation error in chipflow.toml:\n{error_str}")
71+
72+
73+
def _wire_ulx3s_spi_flash(m: Module, platform: _ULX3SPlatform, port_name: str, flash: Interface) -> None:
74+
flash_port = platform.request("spi_flash", dir=dict(cs='-', copi='-', cipo='-', wp='-', hold='-'))
75+
# Flash clock requires a special primitive to access in ECP5
76+
m.submodules.usrmclk = Instance(
77+
"USRMCLK",
78+
i_USRMCLKI=flash.clk.o,
79+
i_USRMCLKTS=ResetSignal(), # tristate in reset for programmer accesss
80+
a_keep=1,
81+
)
82+
83+
# Flash IO buffers
84+
m.submodules += Instance(
85+
"OBZ",
86+
o_O=flash_port.cs.io,
87+
i_I=flash.csn.o,
88+
i_T=ResetSignal(),
89+
)
90+
91+
# Connect flash data pins in order
92+
data_pins = ["copi", "cipo", "wp", "hold"]
93+
for i in range(4):
94+
m.submodules += Instance(
95+
"BB",
96+
io_B=getattr(flash_port, data_pins[i]).io,
97+
i_I=flash.d.o[i],
98+
i_T=~flash.d.oe[i],
99+
o_O=flash.d.i[i]
100+
)
101+
102+
PortName = str
103+
WiringFunc = Callable[[Module, Platform, PortName, Interface], None]
104+
"""
105+
A :py:WiringFunc declares a function that is used to wire an :py:`wiring.Interface` to a given named :py:`io.PortLike` on the given :py:`build.Platform`
106+
"""
107+
108+
@dataclass
109+
class BoardPrimitive:
110+
interface_type: type[amaranth.Signature]
111+
wiring_func: WiringFunc
112+
113+
@dataclass
114+
class BoardVariant:
115+
"Specification of an FPGA board"
116+
board_platform: type[Platform]
117+
"The :py:`type` of the :py:`build.Platform` to use for this board."
118+
reset_button: Optional[str] = None
119+
"Resource name to wire to reset"
120+
default_clock: Optional[str] = None
121+
"Default clock to use for this BoardVariant or BoardType"
122+
primitives: Optional[Dict[str, BoardPrimitive]] = None
123+
"A mapping of a Platform Resource name to the primitive that should be used to wire it up"
124+
125+
@dataclass
126+
class BoardType:
127+
types: List[
128+
129+
SUPPORTED_BOARDS = {
130+
'ULX3S'

chipflow_lib/config_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ def validate_pad_dicts(cls, v, info: ValidationInfo):
5858
return v
5959

6060

61+
class BoardType(BaseModel):
62+
"""Configuration for silicon in chipflow.toml."""
63+
board_name: Literal["ULX3S"]
64+
board_type: Literal["85F"]
65+
66+
67+
6168
class StepsConfig(BaseModel):
6269
"""Configuration for steps in chipflow.toml."""
6370
silicon: str
@@ -69,6 +76,7 @@ class ChipFlowConfig(BaseModel):
6976
top: Dict[str, Any] = {}
7077
steps: StepsConfig
7178
silicon: SiliconConfig
79+
board: BoardConfig
7280
clocks: Optional[Dict[str, str]] = None
7381
resets: Optional[Dict[str, str]] = None
7482

0 commit comments

Comments
 (0)