MounRiver Studio (MRS) can work with online debugging downloaders such as GD-Link, WCH-Link, and JLink to support code debugging functions for RISC-V/ARM core MCU projects such as GDVFx series, CH56x, CH57x, CH58x, CH32Fx, and CH32Vx. This article mainly introduces the code debugging operation of MRS for RISC-V core MCUs.
[Start debugging] Take the CH32V103C8T6 chip project as an example. First, make sure the project can be compiled, then click the menu bar button to start the debugging mode. Normally, the debugging mode will stop at the position shown in the figure. There is a temporary breakpoint at this position:
[Change the default breakpoint position] Of course, if you want the project to stop directly at the beginning of the main function, you can also manually change the position of this breakpoint. Click the drop-down button next to the debug icon, select "Debug Configurations", select the Startup tab in the pop-up page, and set set breakpoint at to main.
After the configuration is completed, click Debug in the lower right corner, or save and exit the configuration, click the menu bar button, and enter the debug mode and it will stop at the position just set.
[View machine code] After entering debugging, you can see the Disassembly window in the lower left corner. This window can display the assembly and address of the code near the PC. You can also right-click the blank space on the left and select show opcodes to display the machine code.
[Machine code breakpoints and jumps] You can also set breakpoints by double-clicking the blank space on the left side of the disassembly window. You can fill in the hexadecimal address in the red frame to jump to the assembly code at the location you want to view. The main window is used to display the code running location. You can double-click the left window position to add or cancel breakpoints.
[Software breakpoints] Because software breakpoints are used, there is no limit on the number of breakpoints in theory, but too many breakpoints will cause the program simulation to slow down.
[Variable View] The Variables window on the right will display the values of the variables in the current function. You can also modify the value of the variable you want to change in this window, but please note that it is only modified to Ram. After power is restarted, the value will return to the actual size.
[Add monitoring variables] Expertions can customize the variables to be monitored and can also modify them. The effect is the same as in the Variables window.
[Error Interrupt] The Registers window below displays the CSR+GPR registers of the RISCV kernel, which can be used to observe the kernel status. Several registers can help locate the problem when a HARDFAULT error occurs. When entering the hardware error interrupt processing function, mepc displays the address at the time of the error, mcause displays the cause, and mtval displays the value taken by the CPU when the error occurs. The meaning of the mcause value is shown in the figure below.
[Breakpoints Window] The Breakpoints window can display the locations of all set breakpoints, and you can enable or delete segment breakpoints here.
[Memory Window] The Memory window can be used to query the values of different addresses. For example, if we query 0x2000000, click the green plus sign under the window and enter the address to be queried in the pop-up window. You can also change the data in different addresses here. Please note that you should check whether this address can be read and written according to the chip manual.
[Peripheral Register Window] The Peripherals window allows you to select the peripheral registers you want to observe. In addition to the peripheral register name, the content displayed also includes the address and description information.