Skip to content

Commit

Permalink
Merge pull request #423 from craigjb/riscv-jtag-bscane2
Browse files Browse the repository at this point in the history
Tunneled EmbeddedRiscvJtag without TAP
  • Loading branch information
Dolu1990 authored Aug 27, 2024
2 parents 2073047 + 52a2e88 commit 919f001
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,62 @@ halt

A full example can be found in GenFullWithOfficialRiscvDebug.scala

##### Tunneled JTAG

The EmbeddedRiscvJtag plugin can also be used with tunneled JTAG. This allows debugging with the same cable used to configure an FPGA.

This uses an FPGA-specific primitive for JTAG access (e.g. Xilinx BSCANE2):
```scala
val xilJtag = BSCANE2(userId = 4) // must be userId = 4
val jtagClockDomain = ClockDomain(
clock = xilJtag.TCK
)
```

Then, the EmbeddedRiscvJtag plugin must be configured for tunneling without a TAP. Note, the debug clock domain must have a separate reset from the CPU clock domain.

```scala
// in plugins
new EmbeddedRiscvJtag(
p = DebugTransportModuleParameter(
addressWidth = 7,
version = 1,
idle = 7
),
withTunneling = true,
withTap = false,
debugCd = debugClockDomain,
jtagCd = jtagClockDomain
)
```

Then connect the EmbeddedRiscvJtag to the FPGA-specific JTAG primitive:

```scala
for (plugin <- cpuConfig.plugins) plugin match {
case plugin: EmbeddedRiscvJtag => {
plugin.jtagInstruction <> xilJtag.toJtagTapInstructionCtrl()
}
case _ =>
}
```

Here is an example OpenOCD TCL script to connect on a Xilinx 7-Series FPGA:

```tcl
# ADD HERE YOUR JTAG ADAPTER SETTINGS
source [find cpld/xilinx-xc7.cfg]
set TAP_NAME xc7.tap
set _TARGETNAME cpu
target create $_TARGETNAME.0 riscv -chain-position $TAP_NAME
riscv use_bscan_tunnel 6 1
init
halt
```

#### YamlPlugin

This plugin offers a service to other plugins to generate a useful Yaml file describing the CPU configuration. It contains, for instance, the sequence of instructions required
Expand Down
12 changes: 11 additions & 1 deletion src/main/scala/vexriscv/plugin/EmbeddedRiscvJtag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import vexriscv._

class EmbeddedRiscvJtag(var p : DebugTransportModuleParameter,
var debugCd : ClockDomain = null,
var jtagCd : ClockDomain = null,
var withTap : Boolean = true,
var withTunneling : Boolean = false
) extends Plugin[VexRiscv] with VexRiscvRegressionArg{
Expand Down Expand Up @@ -61,14 +62,23 @@ class EmbeddedRiscvJtag(var p : DebugTransportModuleParameter,
dm.io.ctrl <> logic.io.bus
logic.io.jtag <> jtag
}
val dmiTunneled = if(withTap && withTunneling) new Area {
val dmiTunneledWithTap = if(withTap && withTunneling) new Area {
val logic = DebugTransportModuleJtagTapWithTunnel(
p.copy(addressWidth = 7),
debugCd = ClockDomain.current
)
dm.io.ctrl <> logic.io.bus
logic.io.jtag <> jtag
}
val dmiTunneledNoTap = if (!withTap && withTunneling) new Area {
val logic = DebugTransportModuleTunneled(
p.copy(addressWidth = 7),
debugCd = ClockDomain.current,
jtagCd = jtagCd
)
logic.io.instruction <> jtagInstruction
dm.io.ctrl <> logic.io.bus
}

val privBus = pipeline.service(classOf[CsrPlugin]).debugBus.setAsDirectionLess()
privBus <> dm.io.harts(0)
Expand Down

0 comments on commit 919f001

Please sign in to comment.