Skip to content

Commit

Permalink
soc: add l2 cache to spi_ram
Browse files Browse the repository at this point in the history
Signed-off-by: Fin Maaß <[email protected]>
  • Loading branch information
maass-hamburg committed Jul 2, 2024
1 parent 5fb03cb commit 5e739f5
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions litex/soc/integration/soc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,11 @@ def add_spi_flash(self, name="spiflash", mode="4x", clk_freq=20e6, module=None,
self.add_constant(f"{name}_DEBUG")

# Add SPI RAM --------------------------------------------------------------------------------
def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=None, rate="1:1", software_debug=False, **kwargs):
def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=None, rate="1:1", software_debug=False,
l2_cache_size = 8192,
l2_cache_reverse = False,
l2_cache_full_memory_we = True,
**kwargs):
# Imports.
from litespi import LiteSPI
from litespi.phy.generic import LiteSPIPHY
Expand All @@ -2110,8 +2114,28 @@ def add_spi_ram(self, name="spiram", mode="4x", clk_freq=20e6, module=None, phy=
spiram_core = LiteSPI(spiram_phy, mmap_endianness=self.cpu.endianness, with_mmap_write=True, **kwargs)
self.add_module(name=f"{name}_core", module=spiram_core)
spiram_region = SoCRegion(origin=self.mem_map.get(name, None), size=module.total_size)
self.bus.add_slave(name=name, slave=spiram_core.bus, region=spiram_region)

# Create Wishbone Slave.
wb_spiram = wishbone.Interface(data_width=32, address_width=32, addressing="word")
self.bus.add_slave(name=name, slave=wb_spiram, region=spiram_region)
self.comb += spiram_core.mmap.offset.eq(self.bus.regions.get(name, None).origin)

# L2 Cache
if l2_cache_size != 0:
# Insert L2 cache inbetween Wishbone bus and LiteSPI
l2_cache_size = max(l2_cache_size, int(2*32/8)) # Use minimal size if lower
l2_cache_size = 2**int(log2(l2_cache_size)) # Round to nearest power of 2
l2_cache = wishbone.Cache(
cachesize = l2_cache_size//4,
master = wb_spiram,
slave = spiram_core.bus,
reverse = l2_cache_reverse)
if l2_cache_full_memory_we:
l2_cache = FullMemoryWE()(l2_cache)
self.l2_cache = l2_cache
self.add_config("L2_SIZE", l2_cache_size)
else:
self.submodules += wishbone.Converter(wb_spiram, spiram_core.bus)

# Constants.
self.add_constant(f"{name}_PHY_FREQUENCY", clk_freq)
Expand Down

0 comments on commit 5e739f5

Please sign in to comment.