[英]Can't printf with PeekPokeTester in Chisel3
I'm trying to print some value when testing my chisel3 design with this testbench code : 我正在尝试使用此测试平台代码测试我的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)
}
}
But I've got this error when launching testbench with command: 但是在使用命令启动testbench时出现此错误:
sbt 'test:runMain taptempo.TapTempoMain'
Error: 错误:
[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$2.apply(Printf.scala:89)
at chisel3.core.printf$$anonfun$apply$2.apply(Printf.scala:89)
at chisel3.core.WhenContext$$anonfun$1.apply(When.scala:72)
at chisel3.core.WhenContext$$anonfun$1.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$2.apply(TapTempoMain.scala:26)
at taptempo.TapTempoMain$$anonfun$2.apply(TapTempoMain.scala:26)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1$$anonfun$apply$mcZ$sp$2.apply$mcZ$sp(Driver.scala:62)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1$$anonfun$apply$mcZ$sp$2.apply(Driver.scala:61)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1$$anonfun$apply$mcZ$sp$2.apply(Driver.scala:61)
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1.apply$mcZ$sp(Driver.scala:60)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1.apply(Driver.scala:38)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1.apply(Driver.scala:38)
at logger.Logger$$anonfun$makeScope$1.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$1.apply$mcZ$sp(Driver.scala:38)
at chisel3.iotesters.Driver$$anonfun$execute$1.apply(Driver.scala:38)
at chisel3.iotesters.Driver$$anonfun$execute$1.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$1(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$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.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$1(Run.scala:51)
at sbt.Run$$anonfun$run$1.apply$mcV$sp(Run.scala:55)
at sbt.Run$$anonfun$run$1.apply(Run.scala:55)
at sbt.Run$$anonfun$run$1.apply(Run.scala:55)
at sbt.Logger$$anon$4.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$2.apply(Printf.scala:89)
at chisel3.core.printf$$anonfun$apply$2.apply(Printf.scala:89)
at chisel3.core.WhenContext$$anonfun$1.apply(When.scala:72)
at chisel3.core.WhenContext$$anonfun$1.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$2.apply(TapTempoMain.scala:26)
at taptempo.TapTempoMain$$anonfun$2.apply(TapTempoMain.scala:26)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1$$anonfun$apply$mcZ$sp$2.apply$mcZ$sp(Driver.scala:62)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1$$anonfun$apply$mcZ$sp$2.apply(Driver.scala:61)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1$$anonfun$apply$mcZ$sp$2.apply(Driver.scala:61)
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1.apply$mcZ$sp(Driver.scala:60)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1.apply(Driver.scala:38)
at chisel3.iotesters.Driver$$anonfun$execute$1$$anonfun$apply$mcZ$sp$1.apply(Driver.scala:38)
at logger.Logger$$anonfun$makeScope$1.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$1.apply$mcZ$sp(Driver.scala:38)
at chisel3.iotesters.Driver$$anonfun$execute$1.apply(Driver.scala:38)
at chisel3.iotesters.Driver$$anonfun$execute$1.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$1(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$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.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
If I delete 'printf' lines, the testbench works. 如果我删除'printf'行,测试平台就可以了。
Is it possible to print some text and value in testbench with chisel3 iotester ? 是否可以使用chisel3 iotester在testbench中打印一些文本和值?
The full project is derivated from chisel template github and available on my github repository TapTempoChisel . 整个项目源自凿子模板github,可在我的github存储库TapTempoChisel上获得 。
Ok, finally I found the problem. 好的,最后我发现了问题。 It's an import problem.
这是一个进口问题。 In head of source file there is a :
在源文件的头部有一个:
import chisel3._
It sounds to be in conflict with printf . 听起来与printf有冲突。 I need this import for Bool , then if we just import Bool as it :
我需要Bool的这个导入,然后如果我们只导入Bool:
import chisel3.Bool
And remove the chisel3._ import, that works well. 并删除chisel3._ import,这很好用。
If you don't want to give up the convenient chisel3._
import: 如果你不想放弃方便的
chisel3._
import:
System.out.printf("haha, this works\n")
This way it calls the Java System.out.printf
function directly and thus bypasses the Chisel-overridden version of printf
that fails. 这样它就可以直接调用Java
System.out.printf
函数,从而绕过失败的Chisel覆盖版本的printf
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.