Skip to content

Commit 7bbe058

Browse files
committed
Modified SPI flash core to support 1x non-IO SPI flash
1 parent 26f039f commit 7bbe058

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

misoc/cores/spi_flash.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True, endianness="big", d
4040
"""
4141
adr_width = 32-log2_int(dw//8)
4242
self.bus = bus = wishbone.Interface(data_width=dw, adr_width=adr_width)
43-
spi_width = len(pads.dq)
43+
if hasattr(pads, "dq"):
44+
spi_width = len(pads.dq)
45+
else:
46+
spi_width = 1
4447
if with_bitbang:
4548
self.bitbang = CSRStorage(4)
4649
self.miso = CSRStatus()
@@ -62,8 +65,16 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True, endianness="big", d
6265

6366
pads.cs_n.reset = 1
6467

65-
dq = TSTriple(spi_width)
66-
self.specials.dq = dq.get_tristate(pads.dq)
68+
if spi_width > 1:
69+
dq = TSTriple(spi_width)
70+
self.specials.dq = dq.get_tristate(pads.dq)
71+
else:
72+
class TripleMock:
73+
def __init__(self):
74+
self.i = pads.miso
75+
self.o = pads.mosi
76+
self.oe = Signal()
77+
dq = TripleMock()
6778

6879
sr = Signal(max(cmd_width, addr_width, dw))
6980
if endianness == "big":
@@ -88,7 +99,8 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True, endianness="big", d
8899
dq.oe.eq(1)
89100
),
90101
If(self.bitbang.storage[1],
91-
self.miso.status.eq(dq.i[1])
102+
self.miso.status.eq(dq.i) if spi_width == 1 \
103+
else self.miso.status.eq(dq.i[1])
92104
)
93105
]
94106
if spi_width > 1:

0 commit comments

Comments
 (0)