Search code examples
chisel

Error while passing values using peekpoketester


I am trying to pass some random integers (which I have stored in an array) to my hardware as an Input through the poke method in peekpoketester. But I am getting this error:

chisel3.internal.ChiselException: Error: Not in a UserModule. Likely cause: Missed Module() wrap, bare chisel API call, or attempting to construct hardware inside a BlackBox.

What could be the reason? I don't think I need a module wrap here as this is not hardware.

class TesterSimple (dut: DeviceUnderTest)(parameter1 : Int)(parameter2 : Int) extends
PeekPokeTester (dut) {
 var x = Array[Int](parameter1) 
 var y = Array[Int](parameter2) 
 var z = 1 
 poke(dut.io.IP1, z.asUInt)
 for(i <- 0 until parameter1){poke(dut.io.IP2(i), x(i).asUInt)}
 for(j <- 0 until parameter2){poke(dut.io.IP3(j), y(j).asUInt)}
}

object TesterSimple extends App {
 implicit val parameter1 = 2
 implicit val parameter2 = 2
 chisel3.iotesters.Driver (() => DeviceUnderTest(parameter1 :Int, parameter2 :Int)) { c =>
 new TesterSimple (c)(parameter1, parameter2)}
}

Solution

  • I'd suggest a couple of things.

    1. Main problem, I think you are not initializing your arrays properly
      1. Try using Array.fill or Array.tabulate to create and initialize arrays
      val rand = scala.util.Random
      var x = Array.fill(parameter1)(rand.nextInt(100))
      var y = Array.fill(parameter2)(rand.nextInt(100))
    
    1. You don't need the .asUInt in the poke, it accepts Ints or BigInts
    2. When defining hardware constants, use .U instead of .asUInt, the latter is a way of casting other chisel types, it does work but it a backward compatibility thing.
    3. It's better to not start variables or methods with capital letters
    4. I suggest us class DutName(val parameter1: Int, val parameter2: Int) or class DutName(val parameter1: Int)(val parameter2: Int) if you prefer.
      1. This will allow to use the dut's paremeters when you are writing your test.
      2. E.g. for(i <- 0 until dut.parameter1){poke(dut.io.IP2(i), x(i))}
      3. This will save you have to duplicate parameter objects on your DUT and your Tester

    Good luck!