简体   繁体   English

在 Chisel 中调试模块内部

[英]Debugging module internals in Chisel

I have a complex module written in Chisel.我有一个用 Chisel 编写的复杂模块。 I'm using chiseltest to verify its operation.我正在使用 chiseltest 来验证其操作。 The test is failing.测试失败。 I want to be able to inspect the module's internal wire values to debug what is going wrong.我希望能够检查模块的内部线路值以调试出了什么问题。 Since the PeekPokeTester only allows me to inspect the value of the io signals, how can I inspect the internal wires?由于 PeekPokeTester 只允许我检查 io 信号的值,我该如何检查内部电线?

Here is an example:这是一个例子:

import chisel3._

class MyModule extends Module {
  val io = IO(new Bundle {
    val a = Input(Bool())
    val b = Input(Bool())
    val c = Input(Bool())
    val d = Output(Bool())
  })

  val i = Wire(Bool())
  i := io.a ^ io.b

  io.d := i | io.c
}
import chisel3._
import chisel3.tester._
import org.scalatest.FreeSpec

class MyModuleTest extends FreeSpec with ChiselScalatestTester {
  "MyModule should work properly" in {
    test(new MyModule) { dut =>
      dut.io.a.poke(true.B)
      dut.io.b.poke(false.B)
      dut.io.c.poke(false.B)
      dut.i.expect(true.B)  // This line throws a java.util.NoSuchElementException
                            // : key not found: Bool(Wire in MyModule)
    }
  }
}

How can I inspect the intermediate value "i"?如何检查中间值“i”?

There's a few ways to do this.有几种方法可以做到这一点。

1 ) Turn on VCD output by adding an annotation to your test, as in 1 ) 通过在测试中添加注释来打开 VCD output,如

import chiseltest.experimental.TestOptionBuilder._
import treadle._
...
test(new MyModule).withAnnotations(Seq(WriteVcdAnnotation)) { dut =>

The.vcd file will be placed in the relevant test_run_dir/ you can view it with GtkWave or similar .vcd 文件会放在相关的 test_run_dir/ 你可以用 GtkWave 或类似的方式查看

2 ) add printf statements to your module. 2 ) 将printf语句添加到您的模块中。

3 ) There is a simulation shell in the Treadle Repo that allows you to peek poke and step based on a firrtl file (the firrtl file should be in the same test_run_dir/ directory as above). 3 ) Treadle Repo中有一个模拟 shell 允许你基于一个 firrtl 文件查看 poke 和 step(firrtl 文件应该在与上面相同的 test_run_dir/ 目录中)。 There is A bit of documentation here这里有一些文档

Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM