Search code examples
chisel

How to printf or println UInt in chisel?


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.


Solution

  • 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.