2
votes

I am trying to execute the following code:

val num1 = 10.U
printf(p"num1 = $num1")

I am getting the following error when running this code in an example class.

[error] (run-main-8) chisel3.internal.ChiselException: Error: No implicit clock and reset.
[error] chisel3.internal.ChiselException: Error: No implicit clock and reset.

I am running the code using test:runMain <package.class>

I tried the other options in https://github.com/freechipsproject/chisel3/wiki/Printing-in-Chisel using the printf and none of them worked.

Also tried the C style printing printf("num1 = %d",num1) and this results in the same error.

2
Please give more code context. Where did you wrote these two lines ? In a chisel module ? - FabienM
No this is not written in a module. Its written in the test directory object TestPrinting extends App { ... } Maybe this is the problem. - caylus
So seems liken the printf(p"num1 - $num1") will generate and fwrite() verilog statement, all I am trying to do here is print thing in the test bench side. - caylus

2 Answers

1
votes

The following ought to work. The withClockAndReset provides the clock needed to trigger the printf. Its a little picky here, because withClock or withClock and a nested withReset will not work.

class Hello extends RawModule {
  val io = IO(new Bundle {
    val out = Output(UInt(8.W))
    val myClock = Input(Clock())
    val myReset = Input(Bool())
  })

  withClockAndReset(io.myClock, io.myReset) {
      printf("out is %d\n", io.out)
  }
  io.out := 42.U
}
0
votes

There is a workaround. Printing of UInt type signals from the Chisel PeekPokeTester can be done with the help of the peek() function wrapped in a println().

println(peek(module_name.io.signal_name).toString(16))

Still have not found a way to directly print the actual signal module_name.io.signal_name the UInt type does not even have toString function so I am not sure if this can even be done.