Raspberry Pi Pico

This tutorial will show you how to use Windows to build the Raspberry Pi Pico version of OpenOCD and picotool used to debug programs on the RP2040.

Chapter 5 and Appendix B of the Getting Started with Raspberry Pi Pico PDF talk about how to build these tools. However, they focus mostly on building the tools for Linux and maxOS. Understandably, building tools on these operating systems is easier, but we can still build them on Windows.

Note that you have the option of skipping the steps below and downloading the executables that I created here. If they do not work or you don’t trust them (no hard feelings), you can continue with the steps below to build your own OpenOCD and picotool.

Directory Setup

I recommend following the steps in my first Raspberry Pi Pico on Windows tutorial to set up the RP2040 build system. We will use the directory structure in that tutorial to hold the source code and executables for these tools.

Specifically, you will want to check out the repositories mentioned in this tutorial into C:\VSARM\sdk\pico.

Install Git for Windows SDK

Git for Windows SDK is different than Git for Windows, as the former contains a number of tools that help us build programs on Windows (including a package manager). Regular Git Bash does not have these features.

Head to https://gitforwindows.org/#download-sdk and download Git for Windows SDK. Download the latest installer for your version of Windows (likely the 64-bit version).

Run the installer, accepting all the defaults. This will open a command prompt window and begin to download/install Git for Windows SDK. It will take some time, as it’s a rather large set of files.

Installing Git for Windows SDK

Note that Git for Windows SDK installs (by default) in C:\git-sdk-64. This directory contains everything as part of the SDK, which means you can delete the directory when you are done using it.

Install Packages

One of the best features of Git for Windows SDK is the pacman package manager. It allows you to install libraries and software similar to how you might do it in Linux.

Run C:\git-sdk-64\git-bash.exe. Note that you must use this executable to run Git for Windows SDK and not the one you may have installed in the previous tutorial! The window should say “SDK-64:/” at the top if you’re running the correct version.

In the terminal, enter the following commands:

pacman -Syu 
pacman -Su
pacman -S mingw-w64-x86_64-toolchain git make libtool pkg-config autoconf automake texinfo wget

When pacman asks which members to install in the mingw-w64-x86_64-toolchain, press ‘enter’ to install all.

Install packages in Git for Windows SDK

When asked “pkg-config and pkgconf are in conflict. Remove pkgconf? [Y/n],” enter Y.

When asked “Proceed with installation? [Y/n],” enter Y again.

This will take some time to download and install all of the packages.

Note: there is an issue with libusb-1.0.24 on MSYS2. We will manually install v1.0.23 to prevent the segmentation fault from occurring when running OpenOCD or picotool. If you run pacman -Su to update packages after this manual installation process, it will remove version 1.0.23 and update libusb to the latest (1.0.24 at the time of writing). For more information, see this forum post.

Enter the following commands to install libusb-1.0.23:

cd ~/Downloads
wget http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-libusb-1.0.23-1-any.pkg.tar.xz
pacman -U mingw-w64-x86_64-libusb-1.0.23-1-any.pkg.tar.xz

Enter Y when asked “Proceed with installation? [Y/n].”

Installing libusb

At this point, we’re ready to build our tools!

Build OpenOCD

OpenOCD (Open On-Chip Debugger) is an open-source tool that communicates with GDB to send commands over JTAG or SWD to a number of different microcontrollers. The RP2040 is not officially supported in OpenOCD at the time of writing, so we need to build a special branch of OpenOCD.

In your Git for Windows SDK terminal, enter the following commands:

cd /c/VSARM/sdk/pico
git clone https://github.com/raspberrypi/openocd.git --branch picoprobe --depth=1
cd openocd
./bootstrap
./configure --enable-picoprobe --disable-werror
make

When OpenOCD is done building, you will need to copy in the libusb-1.0.dll library file from your Git for Windows SDK directory. This .dll file must be in the same directory as your openocd.exe file for the tool to work. If you move openocd.exe, you’ll need to copy libusb-1.0.dll to the same folder.

Enter the following command to copy the file into the current directory:

cp /c/git-sdk-64/mingw64/bin/libusb-1.0.dll src/libusb-1.0.dll

You can test running OpenOCD with the following command:

src/openocd.exe

You should expect it to throw some errors and exit, as we haven’t given it any parameters.

Testing OpenOCD

Note: I do not recommend calling make install as shown in the Getting Started guide! This will make the Pico version of OpenOCD the default OpenOCD for your whole system. If you plan to use OpenOCD for other embedded debugging, you’ll want to keep the Pico version separate. For now, just leave the executable in the src folder. You can call this executable explicitly from the command line or set VS Code to use it on a per-project basis.

Build Picotool

Picotool is a program used to inspect RP2040 binaries and interact with the RP2040 in bootloader mode.

Note that to build picotool, you will need to have the SDK_PICO_PATH environment variable set to the location of your pico-sdk (e.g. C:\VSARM\sdk\pico\pico-sdk) as we did in the previous tutorial.

Open C:\git-sdk-64\git-bash.exe (if it’s not already open).

Run the following commands to clone the picotool repository and build it:

cd /c/VSARM/sdk/pico
git clone -b master https://github.com/raspberrypi/picotool.git
cd picotool
mkdir build
cd build
cmake -G "MinGW Makefiles" -DPC_LIBUSB_INCLUDEDIR="/c/git-sdk-64/mingw64/include/libusb-1.0" ..
make

Just like with OpenOCD, we’ll need a copy of libusb-1.0.dll to be in the same folder as picotool.exe. Enter the following command to copy it into the build folder:

cp /c/git-sdk-64/mingw64/bin/libusb-1.0.dll .

We also need a copy of libgcc_s_seh-1.dll:

cp /c/git-sdk-64/mingw64/bin/libgcc_s_seh-1.dll .

You can test picotool by entering the following:

./picotool.exe

It should spit out a help message and exit.

Testing picotool

Optional: You can add picotool.exe to your Path, if you feel so inclined. This will allow you to call “picotool” from any terminal.

  1. Search for “environment variables” in the Windows search bar
  2. Open “Edit the system environment variables”
  3. Click “Environment Variables…”
  4. Select Path under “User variables” and click “Edit…”
  5. Add a new entry: C:\VSARM\sdk\pico\picotool\build (or whever you’re keeping picotool.exe)
  6. Click OK on all the windows to save the settings

Note: At the time of writing, I could only get this build of picotool to run inside of Git Bash. I’m assuming that the MinGW environment is somehow necessary for its execution. If I find a way to make the .exe run in Command Prompt or PowerShell, I will post it here.

Update Driver

Windows does not have a native driver to send commands over USB to the Pico from picotool. So, we have to install one manually.

Put your Pico board into bootloader mode (press and hold BOOTSEL and plug in the USB cable). It should enumerate on your computer as a storage drive.

Head to https://zadig.akeo.ie and download Zadig.

Run Zadig. Select Options > List All Devices.

You should see 2 Pico devices in the drop-down menu: RP2 Boot (Interface 0) and RP2 Boot (Interface 1). Select RP2 Boot (Interface 1).

The driver should be listed as (NONE). Select libusb-win32 (some version) as the replacement driver.

Install USB driver with Zadig

Click Install Driver. When it’s done, the current driver should be listed as “libusb-win32.”

If you break something in Zadig (like I did), you can fix it. For example, the Pico will not enumerate as a mass storage device drive in bootloader mode. Zadig will show something other than “USBSTOR” as the driver for RP2 (Interface 0). Here is how to delete the bad drivers and let Windows fix the mess you made:

  1. Put Pico into bootloader mode
  2. Open Device Manager
  3. Click View > Devices by container
  4. Expand RP2 Boot
  5. For all entries under RP2 Boot:
    • Right-click on entry
    • Select Uninstall Device
    • Check “Delete the driver software for this device” (if asked)
    • Click Uninstall
  6. Unplug Pico
  7. Hold BOOTSEL and plug it back in to put it into bootloader mode again
  8. Windows should automatically reinstall all the correct drivers

Test Picotool

With your Pico in bootloader mode, enter the following command:

/c/VSARM/sdk/pico/picotool/build/picotool.exe info

Note that you can run picotool without specifying the path name if you added its location to your Path.

If it is able to communicate with your connected Pico, you should see that printed.

Testing picotool

Going Further

Once you have finished building OpenOCD and picotool, you can uninstall Git for Windows SDK by simply deleting the C:\git-sdk-64 directory.

Hopefully, this has helped you get started with some advanced tools for programming and debugging on your Raspberry Pi Pico. If you would like to set up step-through debugging using VS Code, see this tutorial (link coming soon).

Happy hacking!

17 thoughts on “How to Build OpenOCD and Picotool for the Raspberry Pi Pico on Windows

  1. Shavaj Kallamkote on August 3, 2021 at 9:03 pm Reply

    Here is another method to compile picotool using cmake and nmake

    https://gist.github.com/shavaj/30454a84903f1b69dd2c3a4097524cdb

  2. Roger Tannous on September 5, 2021 at 4:19 pm Reply

    Weird, the make command for picotool did not generate the executable file (picotool.exe), although no error was generated!

    I’ve just brought the file from the zip file on Dropbox

  3. Phil on November 30, 2021 at 10:54 pm Reply

    I have the same issue where the make command fails to build picotool
    I followed the previous guide and this guide with 100% success but this step is failing for me. And i cant work out why!

    1. Phil on December 1, 2021 at 9:26 pm Reply

      To add more context: I get no errors on the make command, it’s strange… instead it returns a windows command line prompt *inside* the bash window (with a classic path prompt e.g. C:\git\picotool\build> rather than the dollar prompt). But when I try and close bash i get a warning that there are other processes running: “C:\WINDOWS\System32\cmd.exe” and “make”.
      I’m at a bit of a loss as to how to diagnose this further (or preferably fix it!)
      Thanks for the excellent guides!

      1. ShawnHymel on December 1, 2021 at 11:49 pm Reply

        Hmm…I wonder if it’s a version thing. Do any of the issues listed in the GitHub repo match what you’re seeing? https://github.com/raspberrypi/openocd/issues?q=is%3Aissue+

      2. JonHanmann on December 29, 2021 at 2:16 am Reply

        For the CMake replace the “MinGW Makefiles” with “MSYS Makefiles”. This fixed the Windows Command Prompt issue for me.

      3. Simon on December 28, 2022 at 1:58 am Reply

        This happened to me too. I got it working by using “cmake –build .” instead of “make”.

  4. HuyLE on April 27, 2022 at 10:44 am Reply

    Hi Shawn Hymel,
    I have this issue when launching gdb server :
    C:/VSARM/armcc/11.2 2022.02/bin/arm-none-eabi-gdb.exe: error while loading shared libraries: ?: cannot open
    shared object file: No such file or directory

    Do you know why ?
    Thanks

    1. JMC on June 18, 2022 at 4:30 pm Reply

      Hi HuyLE. I’m having the same problem. Have you found a solution?

    2. Buli on August 18, 2022 at 4:29 pm Reply

      I encountered the same problem. It turns out you need Python 2.7 to make arm-none-eabi-gdb.exe work.
      It’s a long journey to setup a free tooltrain and make it work for you. Finally!

      [ref]
      https://community.arm.com/support-forums/f/compilers-and-libraries-forum/52752/gdb-11-2-2022-02-does-not-start-on-windows

  5. Gautom BOse on May 27, 2022 at 6:40 pm Reply

    hi
    I have a 32 bit windows desktop PC.
    Cant run git64w64 on a 32 windows 10 PC
    can you compile a picotool and open OCD for 32 bit windows pc.
    Thanks

  6. Buli on August 18, 2022 at 3:26 am Reply

    Fail to launch gdb server in VSCode while following your video part2.

    Terminal output:
    Reading symbols from arm-none-eabi-objdump –syms -C -h -w C:\VSARM\sdk\pico\blinky\build\blinky.elf
    Reading symbols from arm-none-eabi-nm –defined-only -S -l -C -p C:\VSARM\sdk\pico\blinky\build\blinky.elf
    Launching GDB: arm-none-eabi-gdb -q –interpreter=mi2 “C:\\VSARM\\sdk\\pico\\blinky\\build\\blinky.elf”
    Set “showDevDebugOutput”: true in your “launch.json” to see verbose GDB transactions here. Helpful to debug issues or report problems
    Launching gdb-server: “C:/VSARM/sdk/pico/openocd/src/openocd.exe” -c “gdb_port 50000” -c “tcl_port 50001” -c “telnet_port 50002” -s “C:/VSARM/sdk/pico/openocd/tcl” -f “c:/Users/gbxxet1/.vscode/extensions/marus25.cortex-debug-1.4.4/support/openocd-helpers.tcl” -f interface/picoprobe.cfg -f target/rp2040.cfg
    Please check TERMINAL tab (gdb-server) for output from C:/VSARM/sdk/pico/openocd/src/openocd.exe
    Finished reading symbols from objdump: Time: 80 ms
    Finished reading symbols from nm: Time: 85 ms
    OpenOCD GDB Server Quit Unexpectedly. See gdb-server output for more details.

    1. Buli on August 18, 2022 at 4:30 pm Reply

      Need to install Python 2.7

  7. univok on November 8, 2022 at 6:55 pm Reply

    I went through the steps, kudos to you! When loading libusb-1.0.23 instead of libusb-1.0.24 from http://repo.msys2.org, I noticed that the isn’t available anymore. I found out that the segmentation fault should be fixed meanwhile and the current version of libusb is 1.0.26 (or rather the file to load is “mingw-w64-x86_64-libusb-1.0.26-1-any.pkg.tar.zst”).

    I also had a look into the OpenOCD User’s Guide “openocd.pdf” available at https://openocd.org and searched for “RP2040″, getting a hit on chapter 12 / page 110. It is noted that ” that “Flash Commands” “Supports RP2040 “Raspberry Pi Pico” microcontroller”. From now I dont’ really understand what this means.

    Do I have to build openocd.exe as described above anyway – or can I simply download a pre-built version for Windows here: https://gnutoolchains.com/arm-eabi/openocd/ ?

  8. Roman on March 8, 2023 at 6:43 am Reply

    Hello, I have gone through the installation now for 2 times in a row. Did everything exactly as told in the guide except I used the 1.0.26 version of libusb as the 1.0.23 is not available anymore. When I go through the Raspberry Pi Pico and RP2040 – C/C++ Part 2: Debugging with VS Code video I have these error after this command:
    ./openocd.exe -s ../tcl -f interface/picoprobe.cfg -f target/rp2040.cfg

    I get an error:
    Open On-Chip Debugger 0.11.0-g4f2ae61 (2023-03-08-00:29)
    Licensed under GNU GPL v2
    For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
    Info : only one transport option; autoselect ‘swd’
    adapter speed: 5000 kHz

    Info : Hardware thread awareness created
    Info : Hardware thread awareness created
    Info : RP2040 Flash Bank Command
    Info : Listening on port 6666 for tcl connections
    Info : Listening on port 4444 for telnet connections
    Error: Failed to open or find the device
    Error: Can’t find a picoprobe device! Please check device connections and permissions.

    Maybe someone know how to fix it? Would be grateful!

    1. goodhead on February 8, 2024 at 8:55 am Reply

      make sure the driver for your picoprobe is correctly installed using zadig.

  9. goodhead on February 8, 2024 at 8:53 am Reply

    if you see “error: libusb-1.x is required for the Raspberry Pi Pico Probe”
    after you run “./configure –enable-picoprobe –disable-werror” when you build openocd
    use this command:
    pacman -S mingw-w64-x86_64-libusb

Leave a Comment

Your email address will not be published. Marked fields are required.