@@ -24,6 +24,11 @@ def _format_cmd(cmd, spi_width):
2424            c  &=  ~ (1 << (b * spi_width ))
2525    return  c 
2626
27+ class  SpiIF (object ):
28+     def  __init__ (self , i , o , oe ):
29+         self .i  =  i 
30+         self .o  =  o 
31+         self .oe  =  oe 
2732
2833class  SpiFlash (Module , AutoCSR ):
2934    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):
3540        Optionally supports software bitbanging (for write, erase, or other commands). 
3641        """ 
3742        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+ 
3949        if  with_bitbang :
4050            self .bitbang  =  CSRStorage (4 )
4151            self .miso  =  CSRStatus ()
@@ -59,8 +69,13 @@ def __init__(self, pads, dummy=15, div=2, with_bitbang=True):
5969
6070        pads .cs_n .reset  =  1 
6171
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." 
6479
6580        sr  =  Signal (max (cmd_width , addr_width , wbone_width ))
6681        self .comb  +=  bus .dat_r .eq (sr )
0 commit comments