Skip to content

Commit 70d83f2

Browse files
committed
Start with UART debugger
1 parent 29d4be2 commit 70d83f2

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

src/main/scala/debug/UartDebug.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@ import chisel3._
55
import chisel3.util._
66

77
/**
8-
* This is the top level to for the UART output and a test blinking LED.
8+
* Poor mans debugger, using a UART instead of JTAG.
99
*/
10-
class UartDebug(frequ: Int) extends Module {
10+
class UartDebug(frequ: Int, baudRate: Int = 115200) extends Module {
1111
val io = IO(new Bundle {
1212
val rx = Input(Bool())
1313
val tx = Output(Bool())
1414
val dout = Output(UInt(32.W))
1515
val din = Input(UInt(32.W))
1616
})
1717

18-
val tx = Module(new BufferedTx(100000000, 115200))
19-
val rx = Module(new Rx(100000000, 115200))
18+
val tx = Module(new BufferedTx(100000000, baudRate))
19+
val rx = Module(new Rx(100000000, baudRate))
2020

2121
io.tx := tx.io.txd
2222
rx.io.rxd := io.rx
2323

24+
tx.io.channel.bits := rx.io.channel.bits + 1.U
25+
tx.io.channel.valid := rx.io.channel.valid
26+
rx.io.channel.ready := tx.io.channel.ready
2427

28+
io.dout := 0x1234.U
29+
when (tx.io.channel.valid && tx.io.channel.ready) {
30+
io.dout := tx.io.channel.bits
31+
}
2532
}
2633

27-
// generate Verilog
2834
object UartDebug extends App {
2935
emitVerilog(new UartDebug(100000000), Array("--target-dir", "generated"))
3036
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package debug
2+
3+
import chisel.lib.uart._
4+
import chisel3._
5+
import chisel3.util._
6+
import chiseltest._
7+
import org.scalatest.flatspec.AnyFlatSpec
8+
9+
class UartDebugTestTop extends Module {
10+
val io = IO(new Bundle {
11+
val inRx = new UartIO()
12+
val outTx = Flipped(new UartIO())
13+
val dout = Output(UInt(32.W))
14+
val din = Input(UInt(32.W))
15+
})
16+
17+
val tx = Module(new BufferedTx(100000000, 100000000/16))
18+
val rx = Module(new Rx(100000000, 100000000/16))
19+
20+
io.outTx <> tx.io.channel
21+
io.inRx <> rx.io.channel
22+
23+
val dbg = Module(new UartDebug(100000000, 100000000/16))
24+
25+
dbg.io.rx := tx.io.txd
26+
rx.io.rxd := dbg.io.tx
27+
io.dout := dbg.io.dout
28+
dbg.io.din := io.din
29+
}
30+
31+
class UartDebugTest extends AnyFlatSpec with ChiselScalatestTester {
32+
"UartDebug" should "work" in {
33+
test(new UartDebugTestTop()).withAnnotations(Seq(WriteVcdAnnotation)) { dut =>
34+
dut.io.din.poke(0xabcd.U)
35+
dut.clock.setTimeout(10001)
36+
dut.io.outTx.valid.poke(true.B)
37+
dut.io.outTx.bits.poke(0x42.U)
38+
dut.clock.step(10)
39+
dut.io.outTx.valid.poke(false.B)
40+
dut.clock.step(1000)
41+
}
42+
}
43+
}

src/test/scala/spi/TestSpiMaster.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class TopTest extends Module {
7272

7373
io.dout := ctrl.io.dataOut
7474
}
75-
class TestSpiMaster extends AnyFlatSpec with ChiselScalatestTester {
75+
class TestSpiMaster(doNotRun: String) extends AnyFlatSpec with ChiselScalatestTester {
7676

7777
/*
7878
"SpiMaster" should "work" in {

0 commit comments

Comments
 (0)