Targeting the RISC-V core on Raspberry Pi Pico 2

This tutorial shows how to build and debug projects for the RISC-V core on the Raspberry Pi 2 (RP2350). We will show how to create a basic project, configure the debugging settings, and will use VisualGDB’s Chronometer to analyze the cycle counts of individual code lines, so you can compare performance between the ARM and RISC-V cores.

Before you begin, install VisualGDB 6.1 or later.

  1. Start Visual Studio and open the VisualGDB’s Raspberry Pi Pico project wizard:
  2. Enter the name and location for your project:
  3. Targeting the RISC-V core requires using the toolchain shipped by the Raspberry Pi developers, so make sure you select that option in the toolchain selector:If you are using the PicoSDK Code extension, VisualGDB will automatically pick up the tools/SDKs installed by it. If not, click the “Install Raspberry Pi Pico SDK” link to view the versions available for download.
  4. Select the SDK version you would like to download. The package icon means that the Raspberry Pi foundation has published pre-built tools (e.g. picotool) for that version:You can also clone an arbitrary Github tag and use it as an SDK, but you would need to setup tools like the toolchain/picotool manually.
  5. Press “OK”. VisualGDB will automatically load the list of the dependencies from the PicoSDK VS Code extension, and will download the necessary tools:If you have previously downloaded them using VS Code, VisualGDB will simply reuse the existing tools.
  6. Select the latest SDK in the SDK selector, pick the board that is based on the Pico 2 chip (RP2350) and make sure the RISC-V core is selected:
  7. Pick a sample you would like to clone. In this tutorial we will clone the simplest “Blinking LED” sample:
  8. Finally, select the debug method. The RISC-V core can only be debugged using the Raspberry Pi’s own fork of OpenOCD, so make sure you have selected OpenOCD (PicoSDK) and the Debugged Device explicitly mentions RISC-V:
  9. Press”Finish”to generate the project. You can use the Disassembly view in the Embedded Memory Explorer to verify that the code is using RISC-V instructions:
  10. WARNING! If this is the first time you are running RISC-V firmware on your Raspberry Pi, the RISC-V cores won’t be running, and hence the debugging will fail! To fix this, you would need to first program the RISC-V image into the board using the bootloader. Hold the BOOTSEL button on the board, and re-plug it into the USB port. Make sure it appears as a disk drive:
  11. Right-click on the project node in Solution Explorer (with the Raspberry Pi icon) and select “Program FLASH Memory”:
  12. Select your Pico device in the list and press OK:
  13. The FLASH memory will get programmed and the RP2350 will restart in the RISC-V mode. You can now press F5 in Visual Studio to begin debugging it:
  14. Just like the ARM CPUs, RISC-V supports background memory reads, so you can use the Live Watch window to view global variables in real time without stopping the target:
  15. RISC-V also supports instruction counters. You can enable it via the Chronometer configuration in VisualGDB Project Properties -> Embedded Debug Tweaking (Custom edition or higher):
  16. Now you can see how many cycle counts it took to do a step, or reach another breakpoint, so you can fine-tune and optimize your code:
  17. If you would like to use picotool to directly control your device (e.g. reboot it into ARM/RISC-V mode), you can use the View->VisualGDB Smart Terminal command. It will open a terminal window with the PicoSDK build environment pre-loaded, and will remember the command and directory history for each individual project: