77
88from amaranth_soc import csr , wishbone
99from amaranth_soc .memory import MemoryMap
10+ from chipflow_lib .platforms import BidirPinSignature ,OutputPinSignature
1011
1112__all__ = ["QSPIPins" , "SPIMemIO" ]
1213
@@ -15,12 +16,10 @@ class QSPIPins(wiring.PureInterface):
1516 class Signature (wiring .Signature ):
1617 def __init__ (self ):
1718 super ().__init__ ({
18- "clk_o" : Out (1 ),
19- "csn_o" : Out (1 ),
20- "d_o" : Out (4 ),
21- "d_oe" : Out (4 ),
22- "d_i" : In (4 ),
23- })
19+ "clk" : Out (OutputPinSignature (1 )),
20+ "csn" : Out (OutputPinSignature (1 )),
21+ } |
22+ {f"d{ n } " : Out (BidirPinSignature (1 )) for n in range (4 )})
2423
2524 def create (self , * , path = (), src_loc_at = 0 ):
2625 return QSPIPins (path = path , src_loc_at = 1 + src_loc_at )
@@ -85,32 +84,28 @@ def elaborate(self, platform):
8584 spi_ready = Signal ()
8685 # TODO : QSPI
8786
88- m .submodules .spimemio = Instance (
89- "spimemio" ,
90- i_clk = ClockSignal (),
91- i_resetn = ~ ResetSignal (),
92- i_valid = self .data_bus .cyc & self .data_bus .stb ,
93- o_ready = spi_ready ,
94- i_addr = Cat (Const (0 , 2 ), self .data_bus .adr ), # Hack to force a 1MB offset
95- o_rdata = self .data_bus .dat_r ,
96- o_flash_csb = self .flash .csn_o ,
97- o_flash_clk = self .flash .clk_o ,
98- o_flash_io0_oe = self .flash .d_oe [0 ],
99- o_flash_io1_oe = self .flash .d_oe [1 ],
100- o_flash_io2_oe = self .flash .d_oe [2 ],
101- o_flash_io3_oe = self .flash .d_oe [3 ],
102- o_flash_io0_do = self .flash .d_o [0 ],
103- o_flash_io1_do = self .flash .d_o [1 ],
104- o_flash_io2_do = self .flash .d_o [2 ],
105- o_flash_io3_do = self .flash .d_o [3 ],
106- i_flash_io0_di = self .flash .d_i [0 ],
107- i_flash_io1_di = self .flash .d_i [1 ],
108- i_flash_io2_di = self .flash .d_i [2 ],
109- i_flash_io3_di = self .flash .d_i [3 ],
110- i_cfgreg_we = ctrl_bridge .cfgreg_we ,
111- i_cfgreg_di = ctrl_bridge .cfgreg_di ,
112- o_cfgreg_do = ctrl_bridge .cfgreg_do ,
113- )
87+ verilog_map = {
88+ "i_clk" : ClockSignal (),
89+ "i_resetn" : ~ ResetSignal (),
90+ "i_valid" : self .data_bus .cyc & self .data_bus .stb ,
91+ "o_ready" : spi_ready ,
92+ "i_addr" : Cat (Const (0 , 2 ), self .data_bus .adr ), # Hack to force a 1MB offset
93+ "o_rdata" : self .data_bus .dat_r ,
94+ "o_flash_csb" : self .flash .csn .o ,
95+ "o_flash_clk" : self .flash .clk .o ,
96+ "i_cfgreg_we" : ctrl_bridge .cfgreg_we ,
97+ "i_cfgreg_di" : ctrl_bridge .cfgreg_di ,
98+ "o_cfgreg_do" : ctrl_bridge .cfgreg_do ,
99+ } | {
100+ f"o_flash_io{ n } _oe" : getattr (self .flash , f"d{ n } " ).oe for n in range (4 )
101+ } | {
102+ f"o_flash_io{ n } _o" : getattr (self .flash , f"d{ n } " ).o for n in range (4 )
103+ } | {
104+ f"o_flash_io{ n } _i" : getattr (self .flash , f"d{ n } " ).i for n in range (4 )
105+ }
106+
107+ m .submodules .spimemio = Instance ("spimemio" , ** verilog_map )
108+
114109 # From https://github.com/im-tomu/foboot/blob/master/hw/rtl/picorvspi.py
115110 read_active = Signal ()
116111 with m .If (self .data_bus .stb & self .data_bus .cyc & ~ read_active ):
@@ -123,7 +118,7 @@ def elaborate(self, platform):
123118 m .d .sync += self .data_bus .ack .eq (0 )
124119
125120 if platform is not None :
126- path = Path (__file__ ).parent / f "verilog/spimemio.v"
121+ path = Path (__file__ ).parent / "verilog/spimemio.v"
127122 with open (path , 'r' ) as f :
128123 platform .add_file (path .name , f )
129124
0 commit comments