RISC-V QingKeV2 Microprocessor Debug Manual
RISC-V QingKeV2 Microprocessor Debug Manual
V1.0
Overview
QingKe V2 series microprocessor is a 32-bit general-purpose MCU microprocessor based on the standard RISC-V
instruction set RV32I subset RV32E, with only 16 general-purpose registers, half of RV32I, and a more streamlined
structure for deep embedded scenarios. V2 series supports standard RV32EC instruction extensions, in addition to
custom XW extensions, Hardware Prologue/Epilogue (HPE), Vector Table Free (VTF), a more streamlined single-
wire serial debug interface (SDI), and support for "WFE" instructions.
QingKe V2 series microprocessor supports online debugging. The debug module conforms to the RISC-V debug
specification and enables online debugging of the microprocessor through a more streamlined single-wire debug
interface. This manual will introduce in detail the debug transport protocol of the debug interface, the debug module
and its operation method.
QingKeV2 Microprocessor Debug Manual http://wch.cn
Chapter 1 Overview
The simple block diagram of the debug system is shown in Figure 1-1 below. A debug module is designed inside
the QingKe V2 microprocessor, and the debug module can implement functions such as halt, reset and resume of
the microprocessor. It also accesses the General-purpose Registers (GPRs) and Control Status Registers (CSRs)
inside the processor and memory or peripherals mapped to specific functions, etc. by means of abstract commands
or Program Buffer.
SWIO(Single Line)
Reset/halt
Control GPRs
Abstract
commands
CSRs
Program
Buffers(8)
MEM
The debug module communicates with the debug transmission device through the single-wire debug interface. The
debug transmission device is usually WCH-LINK, which uses USB communication with the debug host and
communicates with the debug module through the single-wire interface to control and query the microprocessor
status to achieve debug functions.
V1.0 1
QingKeV2 Microprocessor Debug Manual http://wch.cn
bits 6 0
0 5-1 0 0 31 30 29 28-1 0
V1.0 2
QingKeV2 Microprocessor Debug Manual http://wch.cn
l Stop bit: a sustained high level of 10T will generate a stop bit.
l Data 1: Low level time (T, 2T), high level time (T, 8T).
l Data 0: Low level time (4T, 32T), high level time (T, 8T).
Stop Bit
(10T,inf)
Data 1 (T,2T)
(T,8T)
Data 0 (4T,32T)
(T,8T)
Stop Bit
(18T,inf)
Data 1 (T,4T)
(T,16T)
Data 0 (6T,64T)
(T,16T)
The debug interface speed mode and enable are configured by the relevant registers, which are coded using 7-bit
addresses as follows.
V1.0 3
QingKeV2 Microprocessor Debug Manual http://wch.cn
V1.0 4
QingKeV2 Microprocessor Debug Manual http://wch.cn
V1.0 5
QingKeV2 Microprocessor Debug Manual http://wch.cn
V1.0 6
QingKeV2 Microprocessor Debug Manual http://wch.cn
The internal registers of the debug module use a 7-bit address code, and the following registers are implemented
inside QingKe V2 series microprocessors.
Table 3-1 Debug module register list
Name Access address Description
data0 0x04 Data register 0, can be used for temporary storage of data
data1 0x05 Data register 1, can be used for temporary storage of data
dmcontrol 0x10 Debug module control register
dmstatus 0x11 Debug module status register
hartinfo 0x12 Microprocessor status register
abstractcs 0x16 Abstract command status register
command 0x17 Abstract command register
abstractauto 0x18 Abstract command auto-execution
progbuf0-7 0x20-0x27 Instruction cache registers 0-7
haltsum0 0x40 Halt status register
The debug host can control the microprocessor's halt, resume, reset, etc. by configuring the dmcontrol register. The
RISC-V standard defines three types of abstract commands: access registers, fast access, and access memory.
QingKe V2 microprocessor supports register (GPRs, CSRs, FPRs) access through abstract commands.
The debug module implements eight instruction cache registers progbuf0-7, and the debug host can cache multiple
instructions (which can be compressed instructions) to the buffer, and can choose to continue to execute the
instructions in the instruction cache registers after executing the abstract command or execute the cached
instructions directly. It should be noted that if the instruction in progbufs is less than 32 bytes, the last instruction
needs to be an "ebreak" or "c.ebreak" instruction, and if the instruction fills 32 bytes, the debug module
V1.0 7
QingKeV2 Microprocessor Debug Manual http://wch.cn
automatically adds an "ebreak" instruction. The debug host can access the abstract command and the instructions
cached in the progbufs, and also the storage, peripherals, etc.
V1.0 8
QingKeV2 Microprocessor Debug Manual http://wch.cn
0: Invalid
18 anyhavereset RO 0
1: Microprocessor reset
0: Invalid
17 allresumeack RO 0
1: Microprocessor reset
0: Invalid
16 anyresumeack RO 0
1: Microprocessor reset
[15:14] Reserved RO Reserved 0
0: Invalid
13 allavail RO 0
1: Microprocessor is not available
0: Invalid
12 anyavail RO 0
1: Microprocessor is not available
0: Invalid
11 allrunning RO 0
1: Microprocessor is running
0: Invalid
10 anyrunning RO 0
1: Microprocessor is running
0: Invalid
9 allhalted RO 0
1: Microprocessor is in suspension
0: Invalid
8 anyhalted RO 0
1: Microprocessor out of suspension
0: Authentication is required before using the
7 authenticated RO debug module 0x1
1: The debug module has been certified
[6:4] Reserved RO Reserved 0
Debug system support architecture version
[3:0] version RO 0x2
0010: V0.13
V1.0 9
QingKeV2 Microprocessor Debug Manual http://wch.cn
This register is used to indicate the execution of the abstract command. The debug host can read this register to
know whether the last abstract command is executed or not, and can check whether an error is generated during the
execution of the abstract command and the type of the error, which is described in detail as follows.
V1.0 10
QingKeV2 Microprocessor Debug Manual http://wch.cn
001: 16-bit
010: 32-bit
011: 64-bit (not supported)
100: 128-bit (not supported)
Note: When accessing floating-point registers
FPRs, only 32-bit access is supported.
0: No effect
19 aarpostincrement WO 1: Automatically increase the value of regno after 0
accessing the register
0: No effect
18 postexec WO 1:Execute the abstract command and then execute 0
the command in progbuf
0: Do not execute the operation specified by write
17 transfer WO 0
1: Execute the manipulation specified by write
0: Copy data from the specified register to data0
16 write WO 1: Copy data from data0 register to the specified 0
register
Specify access registers
0x0000-0x0fff are CSRs
[15:0] regno WO 0
0x1000-0x101f are GPRs
0x1020-0x103f are FPRs (not supported by V2)
V1.0 11
QingKeV2 Microprocessor Debug Manual http://wch.cn
V1.0 12
QingKeV2 Microprocessor Debug Manual http://wch.cn
Debug PC (dpc)
This register is used to store the address of the next instruction to be executed after the microprocessor enters debug
mode, and its value is updated with different rules depending on the reason for entering debug. dpc register is
described in detail as follows.
The rules for updating the registers are shown in the following table.
Table 3-14 dpc update rules
Enter the debug method dpc Update rules
ebreak Address of the Ebreak instruction
single step Instruction address of the next instruction of the current instruction
trigger module Temporarily not supported
halt request Address of the next instruction to be executed when entering Debug
V1.0 13
QingKeV2 Microprocessor Debug Manual http://wch.cn
Resume Microprocessor
This process is used to resume a microprocessor that is in suspension, and the steps are as follows.
Table 3-16 Microprocessor resume process
Debug register address R/W Value Description
Dmcontrol(0x10) W-1 0x80000001 Make the debug module work properly.
Dmcontrol(0x10) W-1 0x80000001 Initiate a halt request.
Dmcontrol(0x10) W-1 0x00000001 Clear the halt request bit.
Initiate a resume request. The resume request bit is
Dmcontrol(0x10) W-1 0x40000001 valid for writing 1, and the hardware clears 0 after
recovery.
Get the debug module status information, check
Dmstatus(0x11) R-0 rdata rdata[17:16], if the value is 0b11, it means the processor
has recovered.
Reset Microprocessor
This process is used to reset the microprocessor, after which the microprocessor can either enter halt mode again or
start running again, as follows.
(1) Microprocessor re-runs after reset
V1.0 14
QingKeV2 Microprocessor Debug Manual http://wch.cn
V1.0 15
QingKeV2 Microprocessor Debug Manual http://wch.cn
CMD
Command(0x17) W-1 Set abstract command to copy x6 data to Data0 register.
(0x00221006)
Check rdata[12], i.e. whether the query busy bit is 0b1,
if yes, it means the abstract command is executing,
otherwise it means no abstract command is executing;
check rdata[10:8], i.e. whether the cmderr value is
Abstracts(0x16) R-0 rdata
0b000, if yes, the abstract command is executing
normally, otherwise the abstract command is executing
incorrectly, check to fix the error according to the error
type.
Read the Data0 data rdata, which is the x6 register
Data0(0x04) R-0 rdata
value.
V1.0 16
QingKeV2 Microprocessor Debug Manual http://wch.cn
(2) Write CSR, take mepc as an example, its CSR address is 0x341
Read/write Memory
V2 microprocessor debug module abstract command only supports the register access mode, solid for a memory
address to read and write the way to use the abstract command and pre-set progbufx instructions, read and write.
Note that when there are 8 progbufx, which can store a total of 32B bytes of instructions, when less than 32B, the
last instruction is required to be an "ebreak" instruction, and when 32B is stored, the module automatically adds the
"ebreak" instruction at the end. "instruction, when the specific following.
(1) Memory reading
For FLASH, RAM, MCU peripheral registers, etc., all can be read using memory read mode, taking address
0x20000000 as an example.
Table 3-24 Read memory process
Debug register address R/W Value Description
Dmcontrol(0x10) W-1 0x80000001 Make the debug module work properly.
Dmcontrol(0x10) W-1 0x80000001 Initiate a halt request.
Dmcontrol(0x10) W-1 0x00000001 Clear the halt request.
Write the machine code wcode of the instruction to be
Progbuf0(0x20) W-1 wcode
executed to progbuf0, for example, "lw x6,0(x5)" wcode is
V1.0 17
QingKeV2 Microprocessor Debug Manual http://wch.cn
0x0002a303.
If it is less than 32B, add the "ebreak" instruction to
Progbuf1(0x21) W-1 0x00100073
progbuf1.
Data0(0x04) W-1 0x20000000 Write the address to be read to Data0.
Set the abstract command to copy the Data0 data to the x5
CMD
Command(0x17) W-1 register and set the abstract command to execute the
(0x00271005)
instruction in progbufx after execution.
Check rdata[12], i.e. whether the query busy bit is 0b1, if
yes, it means the abstract command is executing, otherwise
it means no abstract command is executing; check
Abstracts(0x16) R-0 rdata rdata[10:8], i.e. whether the cmderr value is 0b000, if yes,
the abstract command is executing normally, otherwise the
abstract command is executing incorrectly, check to fix the
error according to the error type.
CMD Set the abstract command to copy the x6 register value to
Command(0x17) W-1
(0x00221006) Data0.
Check rdata[12], i.e. whether the query busy bit is 0b1, if
yes, it means the abstract command is executing, otherwise
it means no abstract command is executing; check
Abstracts(0x16) R-0 rdata rdata[10:8], i.e. whether the cmderr value is 0b000, if yes,
the abstract command is executing normally, otherwise the
abstract command is executing incorrectly, check to fix the
error according to the error type.
Read the Data0 data rdata, which is the 0x20000000
address value. It should be noted that the method operates
Data0(0x04) R-0 rdata the register value, the corresponding register value should
be saved before the operation, and restored after the
operation.
V1.0 18
QingKeV2 Microprocessor Debug Manual http://wch.cn
Single-step Execution
By setting the status and control registers under debug, single-step execution in debug mode can be realized and
whether interrupts are enabled under single-step can be controlled, as detailed below.
V1.0 19
QingKeV2 Microprocessor Debug Manual http://wch.cn
V1.0 20
QingKeV2 Microprocessor Debug Manual http://wch.cn
V1.0 21