This repository has been archived by the owner on Apr 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
WCH RVSWD protocol
fxsheep edited this page Feb 28, 2022
·
7 revisions
The following info is only guessed via sniffing using a logic analyzer. No further testing has been done yet!
RVSWD
is the name of the proprietary two-wire debug interface on WCH's RISC-V MCU. Similar to ARM's SWD
interface, RWSWD
has two wires named SWDIO
and SWCLK
respectively, but the protocol is not compatible.
This protocol has some characteristics of I2C. Specifically:
-
SWCLK
andSWDIO
are high when there's no transaction. -
SWDIO
changing to low whileSWCLK
is high marks a START condition. -
SWDIO
changing to high whileSWCLK
is high marks a STOP condition. -
SWDIO
should change only whenSWCLK
is low during transaction. - When
SWCLK
is high, a bit is interpreted as 1 ifSWDIO
is high, interpreted as 0 ifSWDIO
is low.
A transaction is always initiated by the host(WCH-Link). The protocol is point-to-point, thus there's no slave address. There's no ACK/NACK either.
Type | START | Address | Data | Operation | Parity1 | Address | Data | Status | Parity2 | STOP |
---|---|---|---|---|---|---|---|---|---|---|
From | Host | Host | Host | Host | Host | Target | Target | Target | Target | Host |
Length(bit) | - | 7 | 32 | 2 | 1 | 7 | 32 | 2 | 1 | - |
Note:
- All fields are MSB first.
- Parity1 (Host) is odd parity of Address, Data and Operation field.
- Parity2 (Target) is even parity of Address, Data and Status field.
As one can see, this protocol basically exposes(addr+data+op/status) the dmi
(0x11) register of DTM (Debug Transport Module) in a typical JTAG implementation.
- When WCH-Link is booted into RISC-V mode, both
SWDIO
andSWCLK
are first set high. The link then sends 100 ones (100 clocks with IO high), and a STOP condition(IO low, then clock high, then IO high). This is likely a wakeup sequence. - When the host PC(OpenOCD) sends
Read status
command, WCH-Link will send some debug operations to the target autonomously to retrieve chip info. (I didn't look into it carefully. It basically consists of running some code viaprogbuf
and probably reads some registers in the address space.) - During normal operations, WCH-Link acts as a simple USB to DMI bridge, which fills
Host
fields above fromDMI Read(Write) Request
from PC, then sendsDMI Read(Write) Response
with data read fromTarget
field (send by MCU) back to PC.