soc/cores/spi: make dynamic clk divider optional (can be enabled with add_clk_divider...
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 27 Mar 2020 17:44:48 +0000 (18:44 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Fri, 27 Mar 2020 17:44:48 +0000 (18:44 +0100)
litex/soc/cores/spi.py
litex/soc/integration/soc.py

index 58f3b6ca2cf9717e487dd6d05bf4891e3291e530..afa0b9506e0c7638b1d79e7a43648b6369263310 100644 (file)
@@ -137,7 +137,6 @@ class SPIMaster(Module, AutoCSR):
             CSRField("sel", len(self.cs), reset=1, description="Write ``1`` to corresponding bit to enable Xfer for chip.")
         ], description="SPI Chip Select.")
         self._loopback = CSRStorage(description="SPI loopback mode.\n\n Write ``1`` to enable MOSI to MISO internal loopback.")
-        self._clk_divider = CSRStorage(16, description="SPI Clk Divider.", reset=self.clk_divider.reset)
 
         self.comb += [
             self.start.eq(self._control.fields.start),
@@ -145,12 +144,15 @@ class SPIMaster(Module, AutoCSR):
             self.mosi.eq(self._mosi.storage),
             self.cs.eq(self._cs.storage),
             self.loopback.eq(self._loopback.storage),
-            self.clk_divider.eq(self._clk_divider.storage),
 
             self._status.fields.done.eq(self.done),
             self._miso.status.eq(self.miso),
         ]
 
+    def add_clk_divider(self):
+        self._clk_divider = CSRStorage(16, description="SPI Clk Divider.", reset=self.clk_divider.reset)
+        self.comb += self.clk_divider.eq(self._clk_divider.storage)
+
 # SPI Slave ----------------------------------------------------------------------------------------
 
 class SPISlave(Module):
index fb2bfb74d07bffd351de1042d89e7318c5a14900..b06abdef7b27592d702b2f405822e67562240668 100644 (file)
@@ -1154,5 +1154,6 @@ class LiteXSoC(SoC):
         if hasattr(pads, "rst"):
             self.comb += pads.rst.eq(0)
         spisdcard = SPIMaster(pads, 8, self.sys_clk_freq, 400e3)
+        spisdcard.add_clk_divider()
         setattr(self.submodules, name, spisdcard)
         self.add_csr(name)