Chisel Book的第一版带有中文,但是内容并没有后面V4完善,作为第一本入门书。
前面已经写了很多关于Chisel的内容,本文紧跟 【Chisel】03 开始。
Debug
- 运行sbt的路径出现问题,需要在项目的根目录下运行。
- 中间使用了switch但是忘记引用包:
import chisel3 . util ._
- 最后一个重要的bug,还是关于switch使用。
switch报错
源代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| package seg
import chisel3._ import chisel3.util._ import chisel3.experimental._
class SegDisplay extends Module { val io = IO(new Bundle{ val input = Input(UInt(4.W)) val output = Output(UInt(8.W)) }) switch (io.input) { is (0.U) { io.output := "h7E".U(8.W) } is (1.U) { io.output := "h30".U(8.W) } is (2.U) { io.output := "h6D".U(8.W) } is (3.U) { io.output := "h79".U(8.W) } is (4.U) { io.output := "h33".U(8.W) } is (5.U) { io.output := "h5B".U(8.W) } is (6.U) { io.output := "h5F".U(8.W) } is (7.U) { io.output := "h70".U(8.W) } is (8.U) { io.output := "h7F".U(8.W) } is (9.U) { io.output := "h7B".U(8.W) } is (10.U) { io.output := "h77".U(8.W) } is (11.U) { io.output := "h1F".U(8.W) } is (12.U) { io.output := "h4E".U(8.W) } is (13.U) { io.output := "h3D".U(8.W) } is (14.U) { io.output := "h4F".U(8.W) } is (15.U) { io.output := "h47".U(8.W) } } }
|
出现报错:
1 2
| [error] (run-main-0) firrtl.passes.CheckInitialization$RefNotInitializedExc eption: : [module SegDisplay] Reference io is not fully initialized.
|
出错原因,switch赋值的时候需要给输出默认值,不能有不定状态。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| package seg
import chisel3._ import chisel3.util._ import chisel3.experimental._
class SegDisplay extends Module { val io = IO(new Bundle{ val input = Input(UInt(4.W)) val output = Output(UInt(8.W)) }) io.output := 0.U(8.W) switch (io.input) { is (0.U) { io.output := "h7E".U(8.W) } is (1.U) { io.output := "h30".U(8.W) } is (2.U) { io.output := "h6D".U(8.W) } is (3.U) { io.output := "h79".U(8.W) } is (4.U) { io.output := "h33".U(8.W) } is (5.U) { io.output := "h5B".U(8.W) } is (6.U) { io.output := "h5F".U(8.W) } is (7.U) { io.output := "h70".U(8.W) } is (8.U) { io.output := "h7F".U(8.W) } is (9.U) { io.output := "h7B".U(8.W) } is (10.U) { io.output := "h77".U(8.W) } is (11.U) { io.output := "h1F".U(8.W) } is (12.U) { io.output := "h4E".U(8.W) } is (13.U) { io.output := "h3D".U(8.W) } is (14.U) { io.output := "h4F".U(8.W) } is (15.U) { io.output := "h47".U(8.W) } } }
|