Module with multiple memories have no readmem statements
See original GitHub issueChecklist
- Did you specify the current behavior?
- Did you specify the expected behavior?
- Did you provide a code example showing the problem?
- Did you describe your environment?
- Did you specify relevant external information?
What is the current behavior?
I noticed that having multiple memory objects, the readmem
statements are not generated for neither memory.
Just commenting out the mem2
and loadStorePort2
objects, mem
gets it’s readmemh
.
Here is a sample code I’m using:
package utils
import chisel3._
import chisel3.util.log2Ceil
import chisel3.util.experimental.loadMemoryFromFileInline
import chisel3.experimental.{annotate, ChiselAnnotation}
import firrtl.annotations.MemorySynthInit
class MultiMem extends Module {
val io = IO(new Bundle() {
val loadStorePort = Flipped(new MemoryPort(32, 32, true))
val loadStorePort2 = Flipped(new MemoryPort(32, 32, true))
})
annotate(new ChiselAnnotation {
override def toFirrtl =
MemorySynthInit
})
val mem1 =
Module(
new DualPortRAM(
sizeBytes = 32 * 1024,
bitWidth = 32,
memoryFile = "sample.hex"
)
)
mem1.io.loadStorePort <> io.loadStorePort
val mem2 =
Module(
new DualPortRAM(
sizeBytes = 32 * 1024,
bitWidth = 32,
memoryFile = "sample.hex"
)
)
mem2.io.loadStorePort <> io.loadStorePort2
}
class MemoryPort(val bitWidth: Int, val words: Int, val rw: Boolean)
extends Bundle {
val addr = Output(UInt(log2Ceil(words).W))
val readData = Input(UInt(bitWidth.W))
val writeEnable = if (rw) Some(Output(Bool())) else None
val writeData = if (rw) Some(Output(UInt(bitWidth.W))) else None
}
class DualPortRAM(
sizeBytes: Int = 1,
bitWidth: Int = 32,
memoryFile: String = ""
) extends Module {
val words = sizeBytes / bitWidth
val io = IO(new Bundle() {
val loadStorePort = Flipped(new MemoryPort(bitWidth, words, true))
})
val mem = SyncReadMem(words, UInt(bitWidth.W))
if (memoryFile.trim().nonEmpty) {
println(s" Load memory file: " + memoryFile)
loadMemoryFromFileInline(mem, memoryFile)
}
io.loadStorePort.readData := mem.read(io.loadStorePort.addr)
when(io.loadStorePort.writeEnable.get) {
mem.write(io.loadStorePort.addr, io.loadStorePort.writeData.get)
}
}
object MultiMem extends App {
(new chisel3.stage.ChiselStage).emitVerilog(
new MultiMem(),
Array("-X", "verilog") ++ args
)
}
Am I doing something wrong in my code or really is there is a problem in generation? Is there a real case use for this?
What is the expected behavior?
Both memories have their readmem
statements.
Steps to Reproduce
Code below
Your environment
Chisel and Firrtl SNAPSHOT.
External Information
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (14 by maintainers)
Top Results From Across the Web
I get a warning about $readmemh: Too many words in the file
[31:0] means the memory location (data) is 32 bits wide. Your inst.data file has 354 rows (or lines) in the file. Each row...
Read more >Trouble with $readmemh in ModelSim - Google Groups
Hi: I'm trying to use a memory in a Verilog testbench to generate arbitrary waveforms to stimulate my Verilog module. I'm using ModelSim...
Read more >malformed $readmem task... why? - Xilinx Support
For this test, I have an inner module and an outer module. ... WARNING: [Synth 8-2898] ignoring malformed $readmem task: invalid memory name...
Read more >Experimental Features - Chisel/FIRRTL
the experimental package introduces several new ways of defining Modules ... the inline initialization will generate the memory readmem statements inside an ...
Read more >$readmemh support : r/yosys - Reddit
The code from Magnus Karlsson substitutes two AHDL files to one verilog top ... is it possible to use "memory -nomap" in one...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tested this out with Chisel3 3.5-SNAPSHOT as of 20/07/2021 and saw that if the memory instances have different width or size and different hex files, both instances are correctly generated in the output Verilog.
But I still see some problems with some cases:
My main use-case for this feature is to have reusable memory modules that could be customized in the generation, like one 32k memory A that is initialized by A.hex and a second 32k memory B that is initialized by B.hex.
Cc. @jared-barocsi
Fixed by https://github.com/chipsalliance/firrtl/pull/2286, to be released in FIRRTL 1.4.4 (Chisel 3.4.4)