@@ -24,6 +24,11 @@ def _format_cmd(cmd, spi_width):
24
24
c &= ~ (1 << (b * spi_width ))
25
25
return c
26
26
27
+ class SpiIF (object ):
28
+ def __init__ (self , i , o , oe ):
29
+ self .i = i
30
+ self .o = o
31
+ self .oe = oe
27
32
28
33
class SpiFlash (Module , AutoCSR ):
29
34
def __init__ (self , pads , dummy = 15 , div = 2 , with_bitbang = True ):
@@ -35,7 +40,12 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True):
35
40
Optionally supports software bitbanging (for write, erase, or other commands).
36
41
"""
37
42
self .bus = bus = wishbone .Interface ()
38
- spi_width = len (pads .dq )
43
+
44
+ if hasattr (pads , "mosi" ):
45
+ spi_width = 1
46
+ else :
47
+ spi_width = len (pads .dq )
48
+
39
49
if with_bitbang :
40
50
self .bitbang = CSRStorage (4 )
41
51
self .miso = CSRStatus ()
@@ -59,8 +69,13 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True):
59
69
60
70
pads .cs_n .reset = 1
61
71
62
- dq = TSTriple (spi_width )
63
- self .specials .dq = dq .get_tristate (pads .dq )
72
+ if spi_width > 1 :
73
+ dq = TSTriple (spi_width )
74
+ self .specials .dq = dq .get_tristate (pads .dq )
75
+ else :
76
+ dq = SpiIF (pads .miso , pads .mosi , Signal ())
77
+ assert with_bitbang == False ,
78
+ "Bitbang not supported with 1-bit SPI flash."
64
79
65
80
sr = Signal (max (cmd_width , addr_width , wbone_width ))
66
81
self .comb += bus .dat_r .eq (sr )
0 commit comments