RP2040 Windows Dev Setup

C/C++ dev environment for the Raspberry Pi Pico and RP2040, on Windows

RP2040 Dev Setup on Windows

Here is how to install and configure a C/C++ development environment for the Raspberry Pi Pico and other RP2040 dev boards, using the Raspberry Pi Pico SDK and Visual Studio Code on Windows. All of the software except Windows is available at no cost.

This is a fairly involved process. For a simpler solution, you may wish to use the Arduino IDE which can be configured to support RP2040 boards (see here for example).

Note: These instructions are up to date as of 2022-04-24.

Acknowledgements

These instructions mostly follow these video tutorials by Learn Embedded Systems:

Toolchain Installation

ARM GCC Compiler

Go to the download page for the Arm GNU Toolchain: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads

Download and run the installer for Windows host and AArch32 bare-metal target (arm-none-eabi).

Note: In the installer, select “Add path to environment variable”.

CMake

Go to the CMake download page: https://cmake.org/download/. Download and run the 64-bit Windows installer.

Note: In the installer, select “Add Cmake to the system PATH for all users”.

Visual Studio Build Tools

There are two ways to install the Visual Studio Build Tools. Either:

Or:

Python 3

Go to the Python download page: https://www.python.org/downloads/. Download and run the 64-bit Windows installer for the current stable version.

Note: In the installer, select “Add Python to PATH”, and if prompted to remove the max path length, do so.

Git

Go to the Git download page: https://git-scm.com/download/win.

Download and run the 64-bit Windows installer.

Select these options in the installer:

Raspberry Pi Pico SDK

Make a new directory named Pico (or anything else) where you wish to store the Pico SDK and your development projects.

Open a Windows command window (or Git Bash shell) and cd to that directory.

Clone the Pico SDK and example code into a local git repo:

git clone -b master https://github.com/raspberrypi/pico-sdk.git Or, if an SSL private key has been configured: git clone -b master git@github.com:raspberrypi/pico-sdk.git cd pico-sdk git submodule update --init cd .. git clone -b master https://github.com/raspberrypi/pico-examples.git Or, if an SSL private key has been configured: git clone -b master git@github.com:raspberrypi/pico-examples.git

Test Build

Open a Developer Command Prompt by searching for that in the Start menu.

Navigate (cd) to the Pico directory created above.

Set the path to the Pico SDK (only needs to be done once, not every time a build is done):

setx PICO_SDK_PATH "..\..\pico-sdk"

Note: The absolute pathname of the pico-sdk directory may be used here instead of a relative pathname (e.g. C:\Dev\Pico\pico-sdk).

Close and re-open the Developer Command Prompt window to load that change. Navigate to the Pico directory again.

Build the Pico example projects:

cd pico-examples mkdir build cd build cmake -G "NMake Makefiles" .. Or, with an RP2040 board other than the Pi Pico (see src/boards/include/boards): cmake -D"PICO_BOARD=adafruit_feather_rp2040" -G "NMake Makefiles" .. nmake

Note: This will take some time.

Find the file blink.uf2 in the pico-examples\build\blink directory.

Connect the Pi Pico (or other RP2040 dev board) to the PC while pressing the Pico’s BOOTSEL button.

Open the Pi Pico device in Windows Explorer.

Drag blink.uf2 to the Pico’s storage.

The Pico’s LED should start blinking.

Visual Studio Code

Go to the VS Code download page: https://code.visualstudio.com/Download.

Download and run the 64-bit Windows installer.

Open a Developer Command Prompt and type code to run VS Code.

Note: VS Code must always be run from a Developer Command Prompt window, otherwise it will not be able to find the build tools.

CMake Tools Extensions

In VS Code, click on the Extensions button on the left.

Search for these extensions and install both of them:

Navigate to the CMake Tools settings: Click on the Manage button in the bottom-left, then select Settings, then Extensions, then CMake Tools.

Under Cmake: Configure Environment, click Add Item and add an item named PICO_SDK_PATH with the value ..\..\pico-sdk. (Again, the absolute pathname may be used instead, e.g. C:\Dev\Pico\pico-sdk.)

If compiling for a supported RP2040 board other than the Pi Pico, add another item named PICO_BOARD with the name of the board. The valid values are the names of the files in pico_sdk\src\boards\include\boards (omitting the .h file extension).

Under Cmake: Preferred Generators, click Edit in settings.json and add this section to the file:

"cmake.preferredGenerators": [ "NMake Makefiles" ],

Save and close the settings file.

Test Build from VS Code

In VS Code, open the folder pico_examples.

Select the correct compiler to use for builds:

Click the Build button at the bottom of the window to build the example programs again.

Upload blink.uf2 to the Pico again and its LED will blink.

Create a New Project

Here is how to create a new RP2040 C/C++ project. In this example the new project will be named NewProject.

Create a sub-directory named NewProject in the Pico directory that was created above.

Copy the file pico_sdk_import.cmake from the pico_examples directory to the NewProject directory.

Open a Developer Command Prompt window.

Type the command code to run Visual Studio Code. Note: VS Code must be run from a Developer Command Prompt window so that it gets the correct tool settings.

In VS Code, open the NewProject folder.

Create a new file named CMakeLists.txt and add these lines to the file. Use the name of your project in place of NewProject.

cmake_minimum_required(VERSION 3.12) include(pico_sdk_import.cmake) project(NewProject) pico_sdk_init() add_executable(NewProject NewProject.c) target_link_libraries(NewProject pico_stdlib) pico_add_extra_outputs(NewProject)

Initialize the build configuration: Select Configure Tasks from the Terminal menu and wait for it to complete. (This may happen automatically when CMakeLists.txt is saved.)

Note: If the Configure Tasks command fails or does nothing, it may be necessary to:

Create a C or C++ file named NewProject.c or NewProject.cpp. Note: The filename should match the one specified in CMakeLists.txt.

Click the Build button at the bottom of the VS Code window and watch it compile.

Upload NewProject.uf2 to the Pico board.