无法在 Chisel3 中使用 PeekPokeTester 进行打印

Can't printf with PeekPokeTester in Chisel3

在使用此测试平台代码测试我的 chisel3 设计时,我试图打印一些值:

package taptempo

import chisel3._
import chisel3.iotesters
import chisel3.iotesters.{ChiselFlatSpec, Driver, PeekPokeTester}
import scala.language.reflectiveCalls

class TapTempoUnitTester(t: TapTempo) extends PeekPokeTester(t) {
  val tptmp = t


  printf("Begin of test\n")

  def pushbutton(button: Bool) {
   poke(button, 0)
   step(1)
   print("Push \n")
   poke(button, 1)
   step(10)
   poke(button, 0)
  }


  val tclk = tptmp.tclk_ns //ns

  val tms = 10*tclk
  val ts = 1000*tms

  for(i <- 0 to 6) {
    peek(tptmp.io.button)
    pushbutton(tptmp.io.button)
    step(1*tms)
  }

  printf("End of Test\n")

}


class TapTempoTester extends ChiselFlatSpec {
  behavior of "TapTempoTester"

  it should "launch a simple test" in {
    chisel3.iotesters.Driver(() => new TapTempo(100000)) {
      c => new TapTempoUnitTester(c)
    } should be(true)
  }
}

但是我在使用命令启动测试台时遇到了这个错误:

sbt 'test:runMain taptempo.TapTempoMain'

错误:

[info] Loading project definition from /usr/local/opt/TapTempoChisel/project
[info] Set current project to TapTempo (in build file:/usr/local/opt/TapTempoChisel/)
[info] Compiling 1 Scala source to /usr/local/opt/TapTempoChisel/target/scala-2.11/test-classes...
[info] Running taptempo.TapTempoMain 
[info] [0,004] Elaborating design...
[info] [1,018] Done elaborating.
Total FIRRTL Compile Time: 2209,9 ms
Total FIRRTL Compile Time: 530,3 ms
End of dependency graph
Circuit state created
[info] [0,002] SEED 1523361961609
chisel3.internal.ChiselException: Error: No implicit clock and reset.
    at chisel3.internal.throwException$.apply(Error.scala:13)
    at chisel3.internal.Builder$.forcedClockAndReset(Builder.scala:209)
    at chisel3.internal.Builder$.forcedReset(Builder.scala:212)
    at chisel3.core.Module$.reset(Module.scala:75)
    at chisel3.core.printf$$anonfun$apply.apply(Printf.scala:89)
    at chisel3.core.printf$$anonfun$apply.apply(Printf.scala:89)
    at chisel3.core.WhenContext$$anonfun.apply(When.scala:72)
    at chisel3.core.WhenContext$$anonfun.apply(When.scala:72)
    at scala.Option.foreach(Option.scala:257)
    at chisel3.core.WhenContext.<init>(When.scala:72)
    at chisel3.core.when$.apply(When.scala:32)
    at chisel3.core.printf$.apply(Printf.scala:89)
    at chisel3.core.printf$.apply(Printf.scala:73)
    at taptempo.TapTempoUnitTester.<init>(TapTempoUnitTest.scala:12)
    at taptempo.TapTempoMain$$anonfun.apply(TapTempoMain.scala:26)
    at taptempo.TapTempoMain$$anonfun.apply(TapTempoMain.scala:26)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp$$anonfun$apply$mcZ$sp.apply$mcZ$sp(Driver.scala:62)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp$$anonfun$apply$mcZ$sp.apply(Driver.scala:61)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp$$anonfun$apply$mcZ$sp.apply(Driver.scala:61)
    at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp.apply$mcZ$sp(Driver.scala:60)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp.apply(Driver.scala:38)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp.apply(Driver.scala:38)
    at logger.Logger$$anonfun$makeScope.apply(Logger.scala:129)
    at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
    at logger.Logger$.makeScope(Logger.scala:127)
    at chisel3.iotesters.Driver$$anonfun$execute.apply$mcZ$sp(Driver.scala:38)
    at chisel3.iotesters.Driver$$anonfun$execute.apply(Driver.scala:38)
    at chisel3.iotesters.Driver$$anonfun$execute.apply(Driver.scala:38)
    at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
    at chisel3.iotesters.Driver$.execute(Driver.scala:37)
    at chisel3.iotesters.Driver$.execute(Driver.scala:94)
    at taptempo.TapTempoMain$.delayedEndpoint$taptempo$TapTempoMain(TapTempoMain.scala:25)
    at taptempo.TapTempoMain$delayedInit$body.apply(TapTempoMain.scala:24)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main.apply(App.scala:76)
    at scala.App$$anonfun$main.apply(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.App$class.main(App.scala:76)
    at taptempo.TapTempoMain$.main(TapTempoMain.scala:24)
    at taptempo.TapTempoMain.main(TapTempoMain.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sbt.Run.invokeMain(Run.scala:67)
    at sbt.Run.run0(Run.scala:61)
    at sbt.Run.sbt$Run$$execute(Run.scala:51)
    at sbt.Run$$anonfun$run.apply$mcV$sp(Run.scala:55)
    at sbt.Run$$anonfun$run.apply(Run.scala:55)
    at sbt.Run$$anonfun$run.apply(Run.scala:55)
    at sbt.Logger$$anon.apply(Logger.scala:84)
    at sbt.TrapExit$App.run(TrapExit.scala:248)
    at java.lang.Thread.run(Thread.java:748)
[error] (run-main-0) chisel3.internal.ChiselException: Error: No implicit clock and reset.
chisel3.internal.ChiselException: Error: No implicit clock and reset.
    at chisel3.internal.throwException$.apply(Error.scala:13)
    at chisel3.internal.Builder$.forcedClockAndReset(Builder.scala:209)
    at chisel3.internal.Builder$.forcedReset(Builder.scala:212)
    at chisel3.core.Module$.reset(Module.scala:75)
    at chisel3.core.printf$$anonfun$apply.apply(Printf.scala:89)
    at chisel3.core.printf$$anonfun$apply.apply(Printf.scala:89)
    at chisel3.core.WhenContext$$anonfun.apply(When.scala:72)
    at chisel3.core.WhenContext$$anonfun.apply(When.scala:72)
    at scala.Option.foreach(Option.scala:257)
    at chisel3.core.WhenContext.<init>(When.scala:72)
    at chisel3.core.when$.apply(When.scala:32)
    at chisel3.core.printf$.apply(Printf.scala:89)
    at chisel3.core.printf$.apply(Printf.scala:73)
    at taptempo.TapTempoUnitTester.<init>(TapTempoUnitTest.scala:12)
    at taptempo.TapTempoMain$$anonfun.apply(TapTempoMain.scala:26)
    at taptempo.TapTempoMain$$anonfun.apply(TapTempoMain.scala:26)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp$$anonfun$apply$mcZ$sp.apply$mcZ$sp(Driver.scala:62)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp$$anonfun$apply$mcZ$sp.apply(Driver.scala:61)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp$$anonfun$apply$mcZ$sp.apply(Driver.scala:61)
    at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp.apply$mcZ$sp(Driver.scala:60)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp.apply(Driver.scala:38)
    at chisel3.iotesters.Driver$$anonfun$execute$$anonfun$apply$mcZ$sp.apply(Driver.scala:38)
    at logger.Logger$$anonfun$makeScope.apply(Logger.scala:129)
    at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
    at logger.Logger$.makeScope(Logger.scala:127)
    at chisel3.iotesters.Driver$$anonfun$execute.apply$mcZ$sp(Driver.scala:38)
    at chisel3.iotesters.Driver$$anonfun$execute.apply(Driver.scala:38)
    at chisel3.iotesters.Driver$$anonfun$execute.apply(Driver.scala:38)
    at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
    at chisel3.iotesters.Driver$.execute(Driver.scala:37)
    at chisel3.iotesters.Driver$.execute(Driver.scala:94)
    at taptempo.TapTempoMain$.delayedEndpoint$taptempo$TapTempoMain(TapTempoMain.scala:25)
    at taptempo.TapTempoMain$delayedInit$body.apply(TapTempoMain.scala:24)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main.apply(App.scala:76)
    at scala.App$$anonfun$main.apply(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.App$class.main(App.scala:76)
    at taptempo.TapTempoMain$.main(TapTempoMain.scala:24)
    at taptempo.TapTempoMain.main(TapTempoMain.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
[trace] Stack trace suppressed: run last test:runMain for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
    at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last test:runMain for the full output.
[error] (test:runMain) Nonzero exit code: 1
[error] Total time: 12 s, completed 10 avr. 2018 14:06:06

如果我删除 'printf' 行,则测试台可以正常工作。

是否可以使用 chisel3 iotester 在 testbench 中打印一些文本和值?

完整项目源自凿子模板 github,可在我的 github 存储库 TapTempoChisel.

中找到

好的,终于找到问题了。这是一个 导入 问题。在源文件的头部有一个 :

import chisel3._

听起来和printf有冲突。我需要这个导入 Bool,然后如果我们直接导入 Bool :

import chisel3.Bool

并删除 chisel3._ 导入,效果很好。

如果不想放弃方便的chisel3._导入:

System.out.printf("haha, this works\n")

通过这种方式,它直接调用 Java System.out.printf 函数,从而绕过了失败的 printf 的 Chisel-overridden 版本。