-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong memory initialization with ChiselSim #4340
Comments
I think this bug has same root cause as #3962. Currently ChiselSim runs simulation main body from an initial block in testharness so initial blocks in other modules may or may not be executed. |
Yes, I think it's the same problem. I haven't seen it before. class UsesMem(memoryDepth: Int, memoryType: Data, filename: String) extends Module {
val io = IO(new Bundle {
val address = Input(UInt(memoryType.getWidth.W))
val value = Output(memoryType)
})
val memory = Mem(memoryDepth, memoryType)
io.value := memory(io.address)
def readFileToSequence(filename: String): Seq[BigInt] = {
val bufferedSource = scala.io.Source.fromFile(filename)
try {
bufferedSource.getLines().map(line => BigInt(line, 16)).toSeq
} finally {
bufferedSource.close()
}
}
// Set the memory
val memContent = readFileToSequence(filename)
when(reset.asBool) {
if(memContent.nonEmpty) {
// Read the file and initialize it
val s = if (memContent.length < memoryDepth) memContent.length else words
for (i <- 0 until s) {
memory(i) := memContent(i).asUInt
}
}
}
} |
I am trying to use
chisel3.util.experimental.loadMemoryFromFileInline
to initialize memory.When I use it with ChiselSim, the memory seems to not be initialized properly, so I inspected the output VCD and I made some tests. Here is what I found:
peek
/poke
orstep
function the memory is initialized properly.peek
/poke
orstep
function the memory seems to be initialized at the end. I inspected the VCD file and the initial value is available only at the end of the simulation. However, the Verilog code generated has a properinitial
block with the correct path.Respective Chisel/ChiselSim code
VCD Case 1: No
peek
/poke
orstep
VCD Case 2: using any
peek
/poke
orstep
causes initialization in the endThe text was updated successfully, but these errors were encountered: