You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Case 1: When I don't use any peek/poke or step function the memory is initialized properly.
Case 2: When I use any peek/poke or step 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 proper initial block with the correct path.
Respective Chisel/ChiselSim code
importchisel3._importtywaves.simulator.TywavesSimulator._importtywaves.simulator.simulatorSettings._importorg.scalatest.flatspec.AnyFlatSpecimportchisel3.util.experimental.loadMemoryFromFileInline// <<-- new import hereclassUsesMem(memoryDepth: Int, memoryType: Data, filename: String) extendsModule {
valio=IO(newBundle {
valaddress=Input(UInt(memoryType.getWidth.W))
valvalue=Output(memoryType)
})
valmemory=Mem(memoryDepth, memoryType)
io.value := memory(io.address)
loadMemoryFromFileInline(memory, filename) // <<-- Note the annotation here
}
classLoadMemoryextendsAnyFlatSpec {
valbits=64valwords=4valfilename=System.getProperty("user.dir") +"/MemoryInit.hex"valfrequency=50000000
scala.reflect.io.File(filename).writeAll("0001020304050607\r\n08090A0B0C0D0E0F\r\n0F0E0D0C0B0A0908\r\n8080808080808080\r\n")
behavior of "LoadMemory"
it should "pass a unit test" in {
simulate(newUsesMem(words, UInt(bits.W), filename), Seq(VcdTrace, WithTywavesWaveforms(true), WithFirtoolArgs(Seq("--disable-all-randomization")), SaveWorkdirFile("workDir")))
{ m =>
m.clock.step()
m.reset.poke(true.B)
m.clock.step()
m.reset.poke(false.B)
m.clock.step()
m.clock.step()
m.clock.step()
m.io.address.poke(0.U)
m.clock.step()
m.io.address.poke(2.U)
}
}
}
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.
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.
Is there any way to make it working atm? I found a workaround which consists of reading the file from Scala and initializing the memory during the reset signal. But it's not the best way I guess.
classUsesMem(memoryDepth: Int, memoryType: Data, filename: String) extendsModule {
valio=IO(newBundle {
valaddress=Input(UInt(memoryType.getWidth.W))
valvalue=Output(memoryType)
})
valmemory=Mem(memoryDepth, memoryType)
io.value := memory(io.address)
defreadFileToSequence(filename: String):Seq[BigInt] = {
valbufferedSource= scala.io.Source.fromFile(filename)
try {
bufferedSource.getLines().map(line =>BigInt(line, 16)).toSeq
} finally {
bufferedSource.close()
}
}
// Set the memoryvalmemContent= readFileToSequence(filename)
when(reset.asBool) {
if(memContent.nonEmpty) {
// Read the file and initialize itvals=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: