This tutorial shows how to develop firmware for the open-source RISC-V core using Visual Studio and VisualGDB. We will create a basic project for the HiFive1 board that will change the color of the on-board LED and will show how to edit it, program it into the SPI FLASH memory and easily debug it.
Before you begin, install VisualGDB 5.3 or later.
- Start Visual Studio and begin creating a project with VisualGDB Embedded Project Wizard:
- Proceed with the default “Create a new project with MSBuild” settings:
- On the next page select the RISC-V toolchain. If you have not installed it yet, simply select “download toolchain for risc-v” and VisualGDB will install and configure it automatically:
- Once the toolchain is installed, select your device. In this tutorial we will use the HiFive1 board running the FE300 microcontroller (E31 core). Select “E31 (32-bit) and then pick HiFive in the “Board/Configuration” field below:
- On the next page proceed with the default settings for the sample project:
- Connect your board to the computer over USB. VisualGDB will automatically detect it and configure the debugger. Ensure that the interface and device settings match your setup and press “Test” to test the connection:
- VisualGDB will automatically install any missing drivers so that OpenOCD can access your board out-of-the-box:
- Once the driver is installed, VisualGDB will confirm that the connection between the JTAG debugger and the chip is successful:
- Press “Finish” to generate the project. Then build it with Ctrl-Shift-B:
- Set a breakpoint inside the while(1) loop in main() and press F5 to begin debugging. VisualGDB will automatically program the FLASH memory and start debugging your program. The breakpoint will hit:
- Remove the breakpoint and resume the program. Observe how the on-board LED changes its color periodically:
- Similarly to the ARM processor, the RISC-V CPU supports reading the target memory without stopping it, enabling features like Live Variables. We will now demonstrate how to use them. Modify the handle_m_time_interrupt() function to increase the counter on each invocation:
- Press F5 to automatically build the firmware and program the new version:
- Once the firmware is running, open the Live Variables window and add “g_Counter” to it. Then enable plotting for it:VisualGDB will automatically plot the value of g_Counter without stopping the program. You can add multiple variables to the Live Variables window and plot all of them.
- The reset logic of the RISC-V core is not fully integrated with the debug-related logic, so resetting the device during a programming session sometimes doesn’t work. VisualGDB includes several workarounds for this issue (e.g. manual reset mode activated via the Debug Settings page). If nothing works, try using the “Program and Start Without Debugging” command, resetting the device manually and then running the “Attach to Running Embedded Firmware” command: