Raspberry pi pico sdk для windows

Introduction

Raspberry Pi Pico is a tiny, fast, and versatile board built using RP2040, a brand new microcontroller chip designed by Raspberry Pi. RP2040 features a dual-core Arm Cortex-M0+ processor with 264KB internal RAM and support for up to 16MB of off-chip Flash. A wide range of flexible I/O options includes I2C, SPI, and uniquely Programmable I/O (PIO).

In this article, we will connect a Raspberry Pi Pico to a computer and learn how to build the SDK and flash an example program in it using C/C++. We will also see how to write the code in Visual Studio Code IDE.

What You Will Learn

  • How to load the C/C++ firmware onto a Raspberry Pi Pico?
  • How to program a Raspberry Pi Pico using C/C++?
  • How to compile and build C/C++ SDK for Raspberry Pi Pico?
  • How to compile and build C/C++ programs for Raspberry Pi Pico in Windows PC?

Prerequisite Hardware

  • Raspberry Pi Pico
  • Micro USB Cable
  • Windows 10 Computer

Software Downloads

Download the Windows Executable Installer for each of the mentioned software in the list. The attached links will take you to the respective download pages.

  • ARM GCC Compiler
    Download the Windows 32-bit Installer (Signed for Windows 10 and later) 
  • CMake
    Download the Windows x64 Installer
  • Build Tools for Visual Studio 2019
    Download the Online Installer
  • Python 3.9
    Download Windows installer (64-bit) Stable Version
  • Git
    Download 64-bit Git for Windows Setup
  • Visual Studio Code
    Download Windows Installer (64-bit)
  • Doxygen (Optional)
    Download the binary distribution for Windows

Software Installation

Follow the detailed installation guide in the following sequence and make sure not to miss any steps, especially match the checkboxes as shown in the below screenshots.

Installing ARM GCC Compiler

  • Open the installer
  • Use the default installation folder
  • Add path to environment variable and add registry information

Installing CMAKE

  • Open the installer
  • Use the default installation folder
  • Add CMake to the system PATH for all the users

Installing Build Tools for Visual Studio 2019

  • Open the installer
  • Use the default installation folder
  • Select the C++ Build Tools only
  • Don’t change any other selection
  • Step 1 : Installing Build Tools for Visual Studio 2019

    Step 1 : Installing Build Tools for Visual Studio 2019
  • Step 2 : Installing Build Tools for Visual Studio 2019

    Step 2 : Installing Build Tools for Visual Studio 2019
  • Step 3 : Installing Build Tools for Visual Studio 2019

    Step 3 : Installing Build Tools for Visual Studio 2019
  • Step 4 : Installing Build Tools for Visual Studio 2019

    Step 4 : Installing Build Tools for Visual Studio 2019
  • Step 5 : Installing Build Tools for Visual Studio 2019

    Step 5 : Installing Build Tools for Visual Studio 2019
  • Step 6 : Installing Build Tools for Visual Studio 2019

    Step 6 : Installing Build Tools for Visual Studio 2019

Installing Python

  • Open the installer
  • Use the default installation folder
  • Use Customize installation option
  • Add Python 3.9 to PATH/environment variable
  • Install launcher for all users
  • Precompile standard library
  • Disable path length limit

Installing Git

  • Open the installer
  • Use the default installation folder
  • Select allow Git to be used from third-party tools
  • Select checkout as-is, commit as-is
  • Select use Windows’ default console window
  • Select Enable experimental support for pseudo consoles

Installing Visual Studio Code

  • Open the installer
  • Use the default installation folder
  • Add to PATH

The Raspberry Pi Pico SDK (Software Development Kit), provides the headers, libraries, and build system necessary to write programs for the RP2040 based devices such as the Raspberry Pi Pico in C, C++, or assembly language.

The SDK provides higher-level libraries for dealing with timers, USB, synchronization, and multi-core programming, along with additional high-level functionality built using PIO. The SDK also has examples to help get started with basic functionality and hardware interfacing.

The Build System

The Raspberry Pi Pico SDK uses CMake to manage the build. CMake is widely supported by IDEs (Integrated Development Environments) and allows a simple specification of the build (via CMakeLists.txt files), from which CMake can generate a build system ( make ) customized for the platform. CMakeList files used in Raspberry Pi Pico SDK and projects define how applications are configured and built.

The SDK builds an executable that is bare metal and runs independently on RP2040.

Download the Raspberry Pi Pico SDK and Examples

Create a new folder and open Command Prompt (cmd.exe) at that location. Run the below commands in a sequence.

D:\RP2040> git clone -b master https://github.com/raspberrypi/pico-sdk.git
D:\RP2040> cd pico-sdk
D:\RP2040\pico-sdk> git submodule update --init
D:\RP2040\pico-sdk> cd ..
D:\RP2040> git clone -b master https://github.com/raspberrypi/pico-examples.git
  • Step 1 : Download the Raspberry Pi Pico SDK and Examples

    Step 1 : Download the Raspberry Pi Pico SDK and Examples
  • Step 2 : Download the Raspberry Pi Pico SDK and Examples

    Step 2 : Download the Raspberry Pi Pico SDK and Examples
  • Step 3 : Download the Raspberry Pi Pico SDK and Examples

    Step 3 : Download the Raspberry Pi Pico SDK and Examples
  • Step 4 : Download the Raspberry Pi Pico SDK and Examples

    Step 4 : Download the Raspberry Pi Pico SDK and Examples
Step 5 : Download the Raspberry Pi Pico SDK and Examples

Step 5 : Download the Raspberry Pi Pico SDK and Examples : Folder view After SDK Download

Building the Raspberry Pi Pico SDK and Examples

  • Open the Visual Studio 2019 Developer Command Prompt
  • Navigate to the SDK download location
  • Add the environment variable with the path of the pico-sdk
  • Close the Command Prompt
 ** Visual Studio 2019 Developer Command Prompt v16.9.6
 ** Copyright (c) 2021 Microsoft Corporation
 
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools>cd /D D:RP2040
 D:\RP2040>setx PICO_SDK_PATH "D:\RP2040\pico-sdk"
Add Environment Variable for Raspberry Pi Pico SDK

Add Environment Variable for Raspberry Pi Pico SDK
  • Open a new Visual Studio 2019 Developer Command Prompt
  • Navigate to the SDK download location
  • Navigate to pico-examples
  • Create a build folder
  • Navigate to build
 ** Visual Studio 2019 Developer Command Prompt v16.9.6
 ** Copyright (c) 2021 Microsoft Corporation
 
 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools>cd /D D:RP2040
 D:\RP2040>cd pico-examples
 D:\RP2040\pico-examples>mkdir build
 D:\RP2040\pico-examples>cd build
 D:\RP2040\pico-examples\build>
Creating Build Folder for Raspbery Pi Pico SDK and Examples

Creating Build Folder for Raspbery Pi Pico SDK and Examples
  • Run cmake -G "NMake Makefiles" ..
  • Run nmake
  • This will produce ELF, bin, and uf2 file for each example project
D:\RP2040\pico-examples\build>cmake -G "NMake Makefiles" ..
D:\RP2040\pico-examples\build>nmake
  • Running cmake for Raspberry Pi Pico SDK and Examples

    Running cmake for Raspberry Pi Pico SDK and Examples
  • Running nmake for Raspberry Pi Pico SDK and Examples

    Running nmake for Raspberry Pi Pico SDK and Examples
  • Successful Build Raspberry Pi Pico SDK and Examples

    Successful Build Raspberry Pi Pico SDK and Examples

Setting Up Visual Studio Code IDE

  • Open a new Visual Studio 2019 Developer Command Prompt
  • Run the below command to open Visual Studio Code
D:\RP2040\pico-examples\build>code
Opening Visual Studio Code from Developer Command Prompt

Opening Visual Studio Code from Developer Command Prompt
Visual Studio Code for RP Pico

Visual Studio Code
  • Open Extensions Ctrl+Shift+X
  • Install CMake Tools Extension by Microsoft
  • Install C/C++ Extension by Microsoft
  • Open CMake Tools Extension Settings
  • Scroll Down
  • Add Cmake: Configure Environment Item as PICO_SDK_PATH
  • Add Cmake: Configure Environment Value as D:\RP2040\pico-sdk
  • Scroll Down
  • Add Cmake: Generator as NMake Makefiles
  • Add Folder pico-examples to Visual Studio Code
  • Visual Studio Code will scan for Kits
  • Select ‘Yes’ when asked: Would you like to configure project pico-examples?
  • Select ‘Yes’ if you like to configure the project upon opening
  • Click CMake in the bottom bar to select the Kit for pico-examples
  • Select Debug / Release based on your preference
  • Visual Studio Code will save all file and configure the project
  • Click on Build to build all examples
  • If no error Build will finish with exit code 0
Successful Build Output of Blink Example Project of Raspberry Pi Pico SDK and Examples

Successful Build Output of Blink Example Project of Raspberry Pi Pico SDK and Examples
  • Navigate to the folder pico-examples\build\blink
  • Successful Build will generate the above artifacts

Flashing the Raspberry Pi Pico

  • Push and hold the BOOTSEL button (white colour near USB port)
  • Plug the Pico into the USB port of the Windows 10 Computer
  • Raspberry Pi Pico will mount as a Mass Storage Device called RPI-RP2
  • Drag and Drop or Copy and Paste the blink.uf2 UF2 Binary into the RPI-RP2 Drive
  • Pico will Reboot automatically, and the on-board Green LED should start Blinking

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Everyone got excited about Raspberry Pi Pico – the latest product from the Raspberry Pi Foundation. I promptly bought 3 of them (max per person at the time of purchase) just in case I will make some grave mistakes resulting in boards giving up their lives. Unfortunately, SDK for Raspberry Pi Pico is a bit of a mess right now. I’m here to give you a quick guide on how to get started with Raspberry Pi Pico, so you don’t have to read 270 & 70 pages PDFs.

A “raspberry”, but different

Raspberry Pi Pico is a completely new animal to Raspberry Pi lineup. It’s a microcontroller, so there is no Raspbian OS to play with. Instead, the boards come with 2 most popular programming languages in the maker’s space: C/C++ and MicroPython. As I found out in my 1.5h livestream, getting started can be messy if this is your 1st time holding the board in your hands.

Encouraged by others and my mistakes, I’m here to make it work for you in a couple of minutes so all the frustration is removed from the process. This guide is for Windows devices, as this is how I do most of my tinkering with microcontrollers.

If you want a fast start – pick MicroPhyton, C/C++ is a mess right now to set up.

Getting started with MicroPhyton and Raspberry Pi Pico

To play with Raspberry Pi Pico on Windows, you will need 1 download. The Foundation recommends Thonny (Windows) as your IDE as it comes with everything you need (including Python 3.7), but you can also install the latest version of Python 3.x as the system-wide language installer in case you need some extras for your projects.

Open Thonny and go to Tools>Options>Interpreter and select MicroPython (Raspberry Pi Pico). You can leave the port configuration to automatic. Then hit “Install or update firmware” before clicking OK.

As per instructions, you have to plug the USB cable while holding the button on the Raspberry Pi Pico. When done, OK all windows and click Run (green play button) to verify that you can connect to your microcontroller. If everything went well, you should see something like this:

You are ready to program with MicroPython. Any application written in this window will be processed by Raspberry Pi Pico and results returned in the shell window below. Don’t forget to save your files as name.py. You can store it locally on your PC as well, but to run them, you should save it on Raspberry Pi Pico.

While you can have as many files saved as you want, to run them without a computer, Raspberry Pi Pico has to know where to start. The file that will run on boot should be saved as main.py. If you don’t do this, your script won’t run when connected to a power supply.

If your project includes external libraries, you have to open the files and save it to Raspberry Pi Pico as well. Here is a sample off LED library from benevpi/pico_python_ws2812b:

And you are ready to take on the world with MicroPhyton and Raspberry Pi Pico!

Getting started with C/C++ and Raspberry Pi Pico

I spent a couple of hours trying to figure out what is the correct process of setting up SDK for C/C++ on my Windows machine. I carefully followed official instructions but I run into errors. To make the process more complicated, it’s not a case of installing one thing and just rolling with it. In the world filled with alternative microcontrollers that simply work with PlatformIO or Arduino IDE, Raspberry Pi Pico SDK falls really short.

The only light in the tunnel is the cooperation with Arduino. As they will also get RP2040-based microcontroller, I’m pretty sure that programming in C/C++ will be as easy as selecting the correct board from the board manager in Arduino IDE.

If you want to give it a shot here is what you have to do. Download all programs listed below (yes, this is why I’m not too impressed with the toolchain):

  • Python 3.x
  • ARM GCC compiler
  • CMake
  • Build Tools for Visual Studio 2019 (C++ build tools only)
  • Visual Studio Code
  • pico-sdk tools

During the installation, please pay attention to the installer options and make sure the following items are selected:
Python: Add Path, Install for all users
AGM GCC compiler: Add Path (all options selected, the installer may hang at the end so give it time)
CMAKE: Add Path
Build Tools for Visual Studio: Install C++ only with default options
pico-sdk: download the zip and unpack the folder to the directory of your choice

Once the installation is complete, let’s make sure the Environmental Variables on Windows are set correctly. (Win key + type “edit the system environmental variables”). In User Variables add:

Variable Value
PICO_SDK_PATH C:\path to downloaded folder\pico-sdk
Path C:\Users\mzoln\AppData\Local\Programs\Microsoft VS Code\bin

In System, Variables make sure you have the following

Variable Value
Path C:\Program Files\Python39\
Path C:\Program Files\Python39\Scripts\
Path C:\Program Files\CMake\bin
Path C:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2020-q4-major\bin
Path C:\Users\mzoln\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Visual Studio Code

Next, search installed programs for Visual Studio 2019 – and use Developer Command Prompt (open as an administrator via right-click) to open VSC (if you open VSC normally, it won’t work and after 2h of playing with variables I gave up). Type code to open the VSC with correct build tools.

VSC configuration

In Extension panel to the left, search for C/C++ & CMake Tools from Microsoft. Once installed go to Extension settings for CMake Tools and change the following:

Create a new folder on your computer for the test project. Use VSC to open this folder, it’s going to be your workspace for the project. At the bottom of the VSC window select the compiler (you may need to use a scan option) to GCC for arm-none-eabi.

Congratulations, you are set!

Test program (blink)

Instead of confusing you with the list of everything available for Raspberry Pi Pico, I slimmed down the files needed for compilations. I will shortly explain the files and functions for you. Each project will need a 3 file (at least) to compile. Your program file (program.c) the SDK import instructions for CMake (pico_sdk_import.cmake) and CMake build instructions (CMakeLists.txt).

blink.c

This is your program file. Pay attention to the name, as you will need to use this name in other files to compile it correctly. All your programming should go into the name.c file, any referred files should be also placed in the same project folder.

blink.c


#include "pico/stdlib.h"

int main() {
const uint LED_PIN = 25;
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
while (true) {
gpio_put(LED_PIN, 1);
sleep_ms(250);
gpio_put(LED_PIN, 0);
sleep_ms(250);
}
}

pico_sdk_import.cmake

This is an instruction set for CMake that contains information about where the sdk is and how to compile the code for you. You won’t need to modify this, but the file has to be present for each workspace. You can have multiple examples of your program in the workspace, but you will only need one pico_sdk_import.cmake file

pico_sdk_import.cmake


# This is a copy of /external/pico_sdk_import.cmake

# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()

# todo document

if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()

set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the PICO SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of PICO SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")

if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
if (NOT pico_sdk)
message("Downloading PICO SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"PICO SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()

get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()

set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the PICO SDK")
endif ()

set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the PICO SDK" FORCE)

include(${PICO_SDK_INIT_CMAKE_FILE})

CMakeLists.txt

You will have to modify this file according to your project. CMake needs to know what files to compile and this lists tell it so. For each project you should append to file the following:

project(blink)
add_executable(blink blink.c)

# Pull in our pico_stdlib which pulls in commonly used features
target_link_libraries(blink pico_stdlib)

# create map/bin/hex file etc.
pico_add_extra_outputs(blink)

Highlighted sections have to be changed to the name of your program.c file. If your project has multiple files and directories, your CMake file will has to reflect his as well. Assuming that your project structure looks like this:

main.c
-FolderA
    --fileA.h
    --fileB.c

Your CMake section to append would have to look like this:

project(test)
include_directories(FolderA)
file(GLOB SOURCES "FolderA/*.c")
add_executable(test main.c ${SOURCES})


# Pull in our pico_stdlib which pulls in commonly used features
target_link_libraries(test pico_stdlib)

# create map/bin/hex file etc.
pico_add_extra_outputs(test)

Compiler would generate the file build/test.uf2 to transfer to Raspberry Pi Pico.

CMakeLists.txt


cmake_minimum_required(VERSION 3.12)

include(pico_sdk_import.cmake)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

pico_sdk_init()
project(blink)
add_executable(blink blink.c)

# Pull in our pico_stdlib which pulls in commonly used features
target_link_libraries(blink pico_stdlib)

# create map/bin/hex file etc.
pico_add_extra_outputs(blink)

Build

Thankfully, flashing programs to Raspberry Pi Pico is easy. Build and compile the program using VSB button at the bottom of the screen (blue section) and the compiled file .uf2 will be available in the build folder.

Hold the button of Raspberry Pi Pico when powering up and it will open as portable drive. Drag the .uf2 file over and you are set!

Final thoughts

C/C++ is a bit of a mess. I’m surprised there is no PlatformIO integration or anything more streamlined. After all Windows machines are the most popular machines, so it makes perfect sense to spend some time streamlining this process. I spent way too much time trying to figure out the perfect combinations of settings with a friend of mine (Hi Dmytro!) and I can only imagine the frustrations an average Pi enthusiast have to go through to do a bit o C/C++ on Windows. I hope the experience improves and I cannot wait for Arduino IDE integration. Issues or comments? Let me know in this Reddit thread.

This tutorial is a Getting-Started Guide For The Raspberry Pi Pico C/C++ SDK Programming (And Pico W). The RP2040-based Raspberry Pi Pico boards can also be programmed using (Arduino C++, MicroPython, CircuitPython, and Rust). You can find navigation buttons on the left sidebar to go to the Raspberry Pi Pico tutorials series using the programming language you prefer.

In this tutorial, we’ll set up the Raspberry Pi Pico C/C++ SDK Toolchain to use VS Code as an IDE for the development of embedded projects with RP2040-based Pi Pico boards. Without further ado, let’s get right into it!

Table of Contents

  1. Raspberry Pi Pico C/C++ SDK Programming
  2. Installing Pi Pico C/C++ SDK Toolchain
  3. Flashing Firmware To Raspberry Pi Pico (C SDK)
  4. Standalone Raspberry Pi Pico C/C++ Project
  5. Raspberry Pi Pico C/C++ SDK LED Blinking Example
  6. Raspberry Pi Pico W C/C++ SDK LED Blinking Example
  7. Raspberry Pi Pico C/C++ SDK Project Simulation (Wokwi)
  8. Concluding Remarks

As stated in the previous Getting Started With Raspberry Pi Pico (MicroPython) tutorial, the Pi Pico C/C++ SDK programming is the most conservative way of programming the RP2040-based microcontrollers. Embedded-C programming gives you the highest level of control over your embedded software behavior and performance.

We can deterministically build reliable embedded systems using the C programming language as we’ve always been doing over the past decades. It’s still the standard way of developing such systems across multiple industries. Therefore, in this tutorial, we’ll prepare the required setup to develop and build C projects for the Raspberry Pi Pico RP2040 microcontroller.

RP2040 Hardware Architecture

The RP2040 microcontroller, like most microcontrollers, has: internal RAM, ROM, GPIOs, Peripherals, and DMA. Additionally, it’s got dual-core ARM Cortex-M0+ processors and a PIO which is a very interesting feature that we’ll address in future tutorials. The diagram below shows you the internal architecture and interconnection of the RP2040 hardware.

What is an SDK? Why To Use Pico C/C++ SDK?

All the peripherals and hardware features that you’ve seen in the RP2040’s architecture diagram above are configured and controlled with special function registers (SFRs) in the microcontroller’s memory. You can refer to the RP2040’s datasheet for details of how each peripheral operates and which registers are responsible for which configuration or operation.

To build embedded applications using the RP2040, or any other microcontroller, we need to build a memory map for the hardware registers that define the address of each SFR register in the memory and give it a name that we can refer to in the code. This is, of course, a tedious process that we have to do unless the manufacturer provides their own SDK (Software Development Kit) that has, at least, memory-mapped low-level register definitions.

The Raspberry Pi Pico C/C++ SDK not only will give us low-level memory-mapped register definitions, but also all the necessary low-level drivers for most of the hardware peripherals in the microcontroller. It’s got also some other features as we’ll see in the next section.

Raspberry Pi Pico C/C++ SDK Overview

The Raspberry Pi Pico C/C++ SDK consists of multiple low-level device drivers and hardware abstraction drivers that are built on top of the low-level drivers. There are also a handful of high-level APIs that provide some services to support your target application (things like time, sleep, utilities, etc).

The Raspberry Pi Pico C/C++ SDK software architecture can be viewed as shown in the figure below. The Pico SDK will abstract the interfacing between the applications we’ll be developing in this series of tutorials and the target RP2040 microcontroller’s low-level hardware.

CMake & Pico C/C++ SDK Build Process

As of writing this tutorial, there is no “proper” IDE for developing embedded-C projects based on the RP2040 microcontroller. This means that we’ll have to install individual tools to create a convenient development environment and we’ll have to deal with compilers at a lower level and use things like CMake, compiler flags, build tools, etc.

The maker space has always been dominated by Arduino, AVR, PIC, STM32, and other mainstream microcontrollers. Each of which has an excellent development environment where IDEs handle all low-level stuff and no one has to deal with compiler flags, CMake, and such. Just don’t get frustrated by this matter and look at it as a chance to learn new things and get closer to the compiler and the C build process.

The Raspberry Pi Pico SDK uses CMake to manage project builds. Each project should have a file called CMakeLists.txt, which specifies the header files to which the project should link, any source files that it should include, and other configurations for the build process.

For each project we’ll create, we’ll use a CMakeLists.txt file template that will be modified to suit each project’s needs. We’ll demonstrate this more later on in this tutorial as we’ll create and build a project from scratch after installing the required toolchain.

What is CMake?

CMake is an open-source cross-platform build system that provides a unified, platform-independent way to manage the build process for software projects. It allows developers to describe the build process using a simple scripting language (CMake language) and it generates native build files for various platforms and build environments.


Installing Pi Pico C/C++ SDK Toolchain

Now, we need to install the Raspberry Pi Pico C/C++ SDK toolchain to start developing our first embedded project for the RP2040 microcontroller. Here is a list of the software tools that we need to install:

  • Arm GNU Toolchain
  • CMake
  • Ninja
  • Python 3.9
  • Git for Windows
  • Visual Studio Code
  • OpenOCD

These software tools include the ARM C compiler, CMake, build manager, VS code editor (we’ll use it as an IDE), and on-chip debugger (OpenOCD). Luckily, instead of downloading and setting up each tool independently, there is a community-contributed Windows installer that packs up all of the toolchain software tools into one file that you can download and it’ll automatically set up and configure everything for us.

❕ Note

A lot of users have so many complaints about the setup and configuration process for the Raspberry Pi Pico C/C++ SDK toolchain which can actually go wrong in many ways. So, please stick to the following setup step-by-step guide and let me know if you’re experiencing any issues.

Here is a step-by-step guide for downloading and installing everything you need to establish a Raspberry Pi Pico C/C++ SDK development environment on your PC (windows):

Step #1

First of all, we need to download the “Raspberry Pi Pico Windows Setup” file that includes all the Pico C SDK toolchain software tools. It’ll take a bit of time, so let it finish downloading and start installation once it’s complete.

❕ Note

You may need to completely disable your Windows Defender settings to be able to run the Pico Windows Setup installer exe file. It may also require you to disable the smart screen option on the security settings page.

The installation process is standard and it won’t require any input from your side it’ll also take some time, so let it finish. At the end, a CMD window will pop up prompting you to accept building all pi pico SDK example projects, say yes, and let it also complete building the examples.

Now, you’ve successfully installed the Raspberry Pi Pico C/C++ SDK toolchain. Open the start menu and look for the recently added software tools, you should find the following 3 shortcuts:

Make a shortcut/copy of the “Pico – Visual Studio Code” launcher as we’ll be using it for all projects thereafter. This launcher shortcut starts the VS code IDE with default settings for the Raspberry Pi Pico C/C++ SDK and configures the paths for CMake, GCC Compiler, etc. It’s important to have a copy of it on your desktop or wherever it seems convenient to you.

Step #2

Open the “Pico – Visual Studio Code” shortcut launcher. Select File > Open Folder, and navigate to where you’ve installed the pico SDK examples.

Make sure you’ve selected the “Pico ARM GCC” compiler. You may need to click on the build button or it may automatically attempt building all the pico SDK example projects on its own. For me, selecting the compiler or just opening the “pico-examples” folder initiates the build process and it shows you the results in the OUTPUT window at the bottom of the VS Code IDE.

In the output window, it shows you where the build output files are stored. So you can navigate to that path and check the output files.

Step #3

Finally, we should verify that everything is working as expected by flashing the blink example UF2 file to the Raspberry Pi Pico board and make sure it works as expected. The next section illustrates the required steps to flash any firmware project output file to the Raspberry Pi Pico board.


Flashing Firmware To Raspberry Pi Pico (C SDK)

Here is a step-by-step guide for how to flash a new firmware project output binary file to the Raspberry Pi Pico (or Pico W) board.

Step #1

Hold the BOOTSEL button of the Raspberry Pi Pico board before connecting it to the USB port of your PC. While holding the BOOTSEL button, connect the Raspberry Pi Pico to your PC’s USB port.

It’ll boot in the bootloader mode and your PC will detect it as a USB storage device, so you’re now free to release the BOOTSEL button.

Step #2

It’s a matter of dragging and dropping the UF2 output file to the Raspberry Pi Pico USB drive. It’ll take a couple of seconds to load, then it’ll automatically reboot and start running the new firmware that we’ve flashed to the RP2040 microcontroller.

You should notice the onboard LED blinking with a 250ms of delay between every toggle event. This is the built-in Pico SDK blink example project.

Next, we’ll learn how to create a standalone Raspberry Pi Pico C/C++ SDK project from scratch, add the CMakeList file, build the project, and flash the output binary file to validate the whole process.


Standalone Raspberry Pi Pico C/C++ Project

Let’s now create our first standalone Raspberry Pi Pico C/C++ SDK project which will also be an LED blinking example with a 100ms delay between LED state toggle events. We’ll create the project from scratch in a manual way, however, there does exist a Raspberry Pi Pico SDK project generator software tool that automates this process. Which we’ll discuss and use in a future tutorial as well.

Step #1

Create the project folder LED_BLINK and a main.c source code file. This is the source code to paste into the main.c file.

#include «pico/stdlib.h»

#define BUILTIN_LED PICO_DEFAULT_LED_PIN

int main()

{

    gpio_init(BUILTIN_LED);

    gpio_set_dir(BUILTIN_LED, GPIO_OUT);

    while (1)

    {

        gpio_put(BUILTIN_LED, 1);

        sleep_ms(100);

        gpio_put(BUILTIN_LED, 0);

        sleep_ms(100);

    }

}

Step #2

Create and add the CMakeLists.txt file to the project’s folder. This is the CMake code to paste into the CMakeLists.txt file.

cmake_minimum_required(VERSION 3.13)

include(pico_sdk_import.cmake)

project(LED_BLINK C CXX ASM)

pico_sdk_init()

add_executable(main main.c)

pico_add_extra_outputs(main)

target_link_libraries(main pico_stdlib)

Step #3

Copy the file named ( pico_sdk_import.cmake ) CMake source file from the pico-sdk/external folder into your new project’s folder. The new project’s folder should now look like the one shown below.

Step #4

Open the “Pico – Visual Studio Code” shortcut launcher from the desktop of the start menu (recently added software). Select File > Open Folder. Navigate to where your new project’s folder is located and choose that folder.

VS Code will prompt you at the bottom of the IDE’s window to configure the project’s folder for you, select ‘yes’, and let it do that for you.

Step #5

Finally, check the main.c file if you’d like to change the LED blinking delay or something. Start the build process using the build button or from the top menu select Terminal > Run Build Task. Wait tell completion and you should get an output message like the one shown below, it also shows you the path for the output files. Ideally, you should find everything in the build folder inside the project folder that we’ve created.

Step #6

Let’s now flash the new project firmware to the Raspberry Pi Pico board. Hold the BOOTSEL button of the Raspberry Pi Pico board before connecting it to the USB port of your PC. While holding the BOOTSEL button, connect the Raspberry Pi Pico to your PC’s USB port.

It’ll boot in the bootloader mode and your PC will detect it as a USB storage device, so you’re now free to release the BOOTSEL button.

Drag and drop the UF2 output file to the Raspberry Pi Pico USB drive. It’ll take a couple of seconds to load, then it’ll automatically reboot and start running the new firmware that we’ve flashed to the RP2040 microcontroller.


Raspberry Pi Pico C/C++ SDK LED Blinking Example

This is the Raspberry Pi Pico C/C++ SDK LED blinking example project that we’ve created in the previous section.

main.c (Raspberry Pi Pico)

/*

* LAB Name: Raspberry Pi Pico Arduino IDE (Project Template)

* Author: Khaled Magdy

* For More Info Visit: www.DeepBlueMbedded.com

*/

void setup() {

  pinMode(LED_BUILTIN, OUTPUT);

}

void loop() {

  // Toggle onBoard LED

  digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));

  delay(100);

}

CMakeLists.txt (Raspberry Pi Pico)

cmake_minimum_required(VERSION 3.13)

include(pico_sdk_import.cmake)

project(LED_BLINK C CXX ASM)

pico_sdk_init()

add_executable(main main.c)

pico_add_extra_outputs(main)

target_link_libraries(main pico_stdlib)

As you can easily tell, it sets the onboard LED pin as an output pin. And toggle its state every 100ms and keeps repeating forever.

❕ Note

If you’re using a Raspberry Pi Pico W board, you need to proceed to the next example project which shows you how to to replicate what we’ve done to fit the Raspberry Pi Pico W board.

This article will give more in-depth information about the Raspberry Pi Pico GPIO pins and their functionalities. And how to choose the suitable pins for whatever functionality you’re trying to achieve and know the fundamental limitations of the device with some workaround tips and tricks.


Raspberry Pi Pico W C/C++ SDK LED Blinking Example

This is a Raspberry Pi Pico W C/C++ SDK LED Blinking example project. You need to follow the exact same steps of project creation as the previous project for the Raspberry Pi Pico. The only difference is: the source code ( main.c) and the ( CMakeLists.txt) files.

main.c (Raspberry Pi Pico W)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

/*

* LAB Name: Raspberry Pi Pico W C/C++ SDK (Project Template)

* Author: Khaled Magdy

* For More Info Visit: www.DeepBlueMbedded.com

*/

#include «pico/stdlib.h»

#include «pico/cyw43_arch.h»

#define BUILTIN_LED CYW43_WL_GPIO_LED_PIN

int main() {

    stdio_init_all();

    if (cyw43_arch_init()) {

        return 1;

    }

    while (1) {

        cyw43_arch_gpio_put(BUILTIN_LED, 1);

        sleep_ms(100);

        cyw43_arch_gpio_put(BUILTIN_LED, 0);

        sleep_ms(100);

    }

}

CMakeLists.txt (Raspberry Pi Pico W)

cmake_minimum_required(VERSION 3.12)

set(PICO_BOARD pico_w)

include(pico_sdk_import.cmake)

project(main C CXX ASM)

pico_sdk_init()

add_executable(main main.c)

target_link_libraries(main pico_stdlib pico_cyw43_arch_none)

pico_add_extra_outputs(main)

❕ Note

The project’s download links are found near the end of this tutorial. In case you’d like to use them as a reference.


Raspberry Pi Pico C/C++ SDK Project Simulation (Wokwi)

As of writing this tutorial, there is only one Raspberry Pi Pico simulator that looks very promising: the online Wokwi simulator tool. There is a dedicated tutorial guide for “Raspberry Pi Pico project simulation” linked below in this section hereafter.

This is the simulation result for the previous Raspberry Pi Pico LED Blinking example project (C SDK) using Wokwi. You can find the Project Simulation files linked below, so you can save a copy of it into your Wokwi projects dashboard and play around with the simulator environment.

  • (Raspberry Pi Pico) LED Blinking Project Simulation
  • (Raspberry Pi Pico W) LED Blinking Project Simulation

Simulating your Raspberry Pi Pico projects can be really helpful especially when you’re just getting started. This step is not mandatory at all, however, running your project in a simulator environment will help you catch and fix some logic errors in the code or in the circuit wiring connections.

The Wokwi simulation project linked above will be our template for all Raspberry Pi Pico Arduino IDE Tutorials, so you need to take a copy of it into your Wokwi account project dashboard.

This article will provide more in-depth information about simulating Raspberry Pi Pico projects using the online Wokwi simulator tool. You’ll learn how to simulate MicroPython, Arduino, and C SDK projects on Raspberry Pi Pico.


Download Attachments

You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting my work through the various support options listed in the link below. Every small donation helps to keep this website up and running and ultimately supports our community.

Raspberry Pi Pico Hardware Kit

If you’re looking forward to playing around with the Raspberry Pi Pico board to test its capabilities and features, you may just need to get a single board. Just like this one here. However, if you’d like to follow along with the Raspberry Pi Pico series of tutorials published here on our website, you may consider getting the following items:

2x Pi Pico Boards, 2x Pi Pico W Boards, 4x BreadBoards, Resistors, LEDs, Buttons, Potentiometers, etc. The reason behind getting multiple boards is that we’ll be using one board as a PicoProbe debugger for SWD debugging activities. And at least 2x Pico W boards for IoT wireless applications.

The full kit list of the Raspberry Pi Pico series of tutorials is found at the link below, as well as some test equipment for debugging that you may consider getting for your home electronics LAB.


To conclude this tutorial, we can only say that it’s only the first step in the RP2040-based Raspberry Pi Pico C Programming journey. The following tutorials in this series will help you get started with Raspberry Pi Pico programming and learn more topics with practical examples and step-by-step explanations.

Follow this Raspberry Pi Pico Series of Tutorials to learn more about Raspberry Pi Pico Programming in different programming languages’ environments.

If you’re just starting with Raspberry Pi Pico, you should check out the following getting-started guides with the programming language you favor the most. There are 4 variants of the Raspberry Pi Pico tutorials to match your needs and help you along the path that you’re going to choose.

Pico SDK (C/C++)

Get Started

Affiliate Disclosure: Some links on this blog are affiliate links, meaning I earn a commission at no extra cost to you. I only recommend products and services I trust and use myself.

This tutorial will show you how to install the Raspberry Pi Pico toolchain on Windows 10 for C and C++ development.

Raspberry Pi has a fantastic getting started guide for the Pico that covers installation steps for the major operating systems. On Linux (specifically, most flavors of Debian), you can run a single script that will install everything for you. On macOS, you need to use Homebrew to install the toolchain, which is only a few commands in the terminal.

Windows, however, is a different story. Installing the toolchain is an arduous process, requiring multiple programs and manually modifying the Windows Path. The Raspberry Pi Pico getting started guide shows you how to do this, but I have issues with two parts: you need to install Build Tools for Visual Studio (around 6 GB) and you must run VS Code from within a Developer Command Prompt every time.

This guide walks you through an alternative way of installing the C/C++ toolchain for the Pico, using MinGW in place of the Build Tools for Visual Studio. Note that this guide is meant for intermediate/advanced users; it assumes you have some familiarity with environment variables in Windows and CMake.

Important! There are a lot of steps in this guide, and missing one will likely cause things to fail down the road. Take your time, and slowly perform each step in order. I recommend setting aside around 2 hours to complete the setup. If something does not work, return to earlier sections to ensure you performed each step correctly. Don’t ignore errors! Something that did not install correctly likely means the tool won’t work later.

[Update Sep 27, 2024] This guide still technically works if you use Windows Command Prompt to run CMake and Make. If you use Git Bash, you’ll likely get the error: mingw32-make[2]: *** [CMakeFiles\blink.dir\build.make:1341: blink.elf] Error -1073741819. I have not yet figured out how to solve this issue. As an alternative, you might want to try the official Raspberry Pi Pico VS Code plugin: https://github.com/raspberrypi/pico-vscode.

Table of Contents

Directory Setup

With the exception of CMake and Python, we will want all of our tools and SDK files to exist in one folder on Windows. This setup will make it easy to configure the Path and find things later on.

Create a folder named VSARM in the top level of your C drive.

In C:\VSARM, create the following folders:

  • C:\VSARM\armcc
  • C:\VSARM\lib
  • C:\VSARM\mingw
  • C:\VSARM\sdk

Note that this directory structure is similar to how you might set up other Arm compiler tools and SDKs (such as this STM32 toolchain setup). You should be able to keep all of your Arm development tools in the VSARM directory and have them coexist with other tools and SDKs.

We use these short, one-word folder names to keep paths short and to avoid spaces. Some Unix/Linux tools (that have been ported to Windows) do not work well with paths that have spaces in them.

Install GNU Arm Embedded Toolchain

The GNU Arm Embedded Toolchain contains the Arm GCC compiler that we need to compile C and C++ code for the RP2040.

Head to the GNU Arm Embedded Toolchain download page and download the latest installer for Windows. For me, this was gcc-arm-none-eabi-10-2020-q4-major-win32.exe.

[Update Apr 19, 2022] I have verified that Arm GNU Embedded Toolchain 11.2-2022.02 works.
[Update Sep 27, 2024] The Arm GNU Toolchain download page has moved here. Download the AArch32 bare-metal target (arm-none-eabi) executable (.exe) for your operating system (Windows host in this case). I have verified that this guide still works with arm-gnu-toolchain-13.3.rel1-mingw-w64-i686-arm-none-eabi.exe.

Run the installer. When asked, change the installation location to C:\VSARM\armcc. It will auto-fill the destination directory to the name of the current toolchain release.

Installing GNU Embedded Toolchain on Windows

Continue with the installation process. When it is complete, select the option to Add path to environment variable.

Add Arm GCC to Windows path during installation

At this point, you should be able to call any of the Arm compiler tools in a new command prompt, such as arm-none-eabi-gcc.exe.

Install MinGW-w64 GCC Tools

MinGW (short for Minimalist GNU for Windows) is a collection of open-source utilities, such as compilers and linkers, that allow us to build applications for Windows.

When we build Pico projects, we need to compile the elf2uf2 and pioasm tools from source. These tools run on our computer (not the target RP2040 microcontroller), and we need a native compiler and linker. The original Getting Started guide has us install Build Tools for Visual Studio to get a Windows compiler (cl.exe), linker (link.exe), and make tool (nmake.exe). We’re going to use the open-source GNU suite (e.g. gcc, ld, make) for Windows instead.

[Update Apr 19, 2022] Note: at this time, the MinGW (.exe) installer appears to be broken. You will likely see the error message “The file has been downloaded incorrectly!” As a result, I have updated the portion below to download only the MinGW-W64 GCC files (tested with v8.1.0), as that’s all we need to compile Pico programs (this no longer applies, as I have updated the instructions–see Sep 27, 2024 update).

[Update Sep 27, 2024] The SourceForge files have been reorganized, and you can no longer find the pre-compiled binaries for Windows (at least for newer versions of MinGW). As a result, I have updated the instructions below to show how to work with the latest version of MinGW (14.2.0 at the time of writing).

Head to https://github.com/niXman/mingw-builds-binaries/releases, which hosts the latest, pre-compiled binaries for MinGW. Download the x86_64-X.X.X-release-win32-seh-ucrt-rt_vY-revZ.7z (where X.X.X, Y, and Z are the respective release, version, and revision numbers). This was tested with: x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev0.7z.

Unzip the file into the C:\VSARM\mingw directory. Windows 11 should be able to handle .7z files natively now. If not, you can download the 7-zip utility. Uncheck the named unzip directory so that when everything unzips, you should have C:\VSARM\mingw\mingw64.

When it’s done, open a Windows Command Prompt and enter the following into the terminal:

echo mingw32-make %* > C:\VSARM\mingw\mingw64\bin\make.bat

This creates a wrapper batch file that will call the mingw32-make tool whenever you type make into a Windows terminal. We will update the Windows Path to find all of the tools in mingw64\bin (along with this .bat file) in a later step.

Install CMake

CMake is a tool that helps you automate the build process of programs. It does not build/compile (like Make does), but rather, it can generate the directory structures and files needed for any build system (Make, Qt Creator, Ninja, etc.). The Raspberry Pi Pico SDK relies on CMake to help create these build files.

Head to the download page on CMake’s site.

Important! There is a bug in CMake version 3.20 (at the time of writing). On the second run of make or nmake (after running cmake), the process will fail. If you’re using nmake, you’ll get an error like fatal error U1033: syntax error : ':' unexpected,  or if you’re using mingw32-make, something like *** multiple target patterns. Stop. To prevent this, install CMake version 3.19. Future versions of CMake may fix this bug, but for now, know that version 3.19 worked for me.

[Update Apr 19, 2022] I have verified that CMake 3.23.1 now works. The bug has been fixed.

Download the latest installer for Windows (cmake-3.30.4-win64-x64.msi as of Sep 27, 2024).

Run the installer and accept the user license. On Install Options, select Add CMake to the PATH environment variable.

Installing CMake 3.30.4

Continue the installation process, accepting all the defaults. Note that this will install CMake to C:\Program Files\CMake, which is fine, as it will be used as a system-wide tool (not just for VSARM projects).

Install Python

The Pico SDK relies on Python to script and automate some of the build functions.

Important! At the time of writing, the Pico SDK recommends Python version 3.9. I do not know if other versions will work.

[Update Apr 19, 2022] I have verified that Python 3.10.2 works.

[Update Sep 27, 2024] I have verified that Python 3.12.6 works.

Head to the downloads page on the Python site. Download the latest Python 3.9 (or 3.10) installer.

Run the installer. On the first screen, make sure that Install launcher for all users (recommended) is checked and check Add Python to PATH.

Add Python to Windows PATH

Click Install Now and wait while it installs Python.

At the end of the installation process, select the option to disable the path length limit.

Important! If you were not asked to disable the MAX_PATH length limit, you will want to make sure that long paths are enabled. The Pico SDK (and many other SDKs) often have long, nested folders, resulting in pathnames that exceed the original Windows limit (260 characters).

To enable long paths, search for regedit in the Windows search bar and run the Registry Editor program. Navigate to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem and add an entry (if one is not already there) for LongPathsEnabled. Change Value data to 1 and Base to Hexadecimal.

Disable pathname character limit in Windows registry

Here is a full guide if you need help modifying the registry to disable the pathname limit.

Install Git

Git makes downloading the Pico SDK much easier, and the Windows version comes with Git Bash, which is a super useful shell. We can change the shell in VS Code to Git Bash so that the command line works just like in Linux. Note that you will need Git installed (with or without Git Bash), as some of the CMake commands require it when configuring a project.

Head to the Git SCM download page and download the latest installer for Windows (e.g. 32-bit Git for Windows Setup).

Run the installer. When you get to the screen asking you to choose a default editor, feel free to pick whatever you want. I kept vim because I know it (barely) well enough to edit git comments.

Select default editor for Git on Windows

Continue the installation process, accepting all the defaults.

Download Pico SDK and Examples

The Pico SDK conains a collection of tools and libraries used to make developing on the Pico (and RP2040) much easier. We can also download a set of C/C++ examples that are useful demonstrations of how to use the SDK.

To start, create a new folder named pico in C:\VSARM\sdk.

While you could download the .zip versions of the SDK and examples repositories, it’s much easier to use git. There are nested submodules that you would need to download from other repositories, but one command in Git Bash takes care of that for us.

Open Git Bash and enter the following commands.

cd /c/VSARM/sdk/pico 
git clone -b master https://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

Download Pico SDK and examples

At this point, you should have all of the necessary build tools, SDK, and examples installed to start developing programs for the Raspberry Pi Pico and RP2040.

Update Environment Variables

Some of the tools we installed automatically updated the Windows environment variables (specifically, the Path). However, a few (like MinGW and the SDK) did not. We need to update the environment variables so that the shell and various build tools know where to find things in our filesystem.

In the Windows search bar, enter env. Click on Edit the system environment variables.

In that window, click on Environment Variables…

Under User variables for <username>, select Path and click Edit.

Add C:\VSARM\mingw\mingw64\bin as a new entry. This will allow us to use things like gcc and ld to build C and C++ programs for Windows.

Make sure you see the following entries listed:

  • C:\VSARM\armcc\<release version>\bin
  • C:\VSARM\mingw\mingw64\bin

You might see an entry for Python3x (e.g. Python39 or Python312) if you chose to install Python for the current user (as I did).

Add mingw32 to user path environment variable

Click OK to exit the user Path window.

Under User variables for <username>, click New… and add the following entry:

  • Variable name: PICO_SDK_PATH
  • Variable value: C:\VSARM\sdk\pico\pico-sdk

Click OK to save the environment variable. At this point, your User Variables should have an updated Path as well as PICO_SDK_PATH variables.

Updating environment variables in Windows for Pico SDK

Under System variables, select Path and click Edit. Check to make sure you see the following entries (add them if you do not see them):

  • C:\Program Files\CMake\bin
  • C:\Program Files\Git\cmd

These entries should have been automatically added to your system-wide Path when you ran their installers. You might also see an entry for Python39 (or Python312) if you chose to install Python for all users.

Click OK on all 3 of the open windows to close them and save changes.

At this point, you should be able to open a commend prompt and enter commands like gcc, make, and echo %PICO_SDK_PATH% to make sure the environment variables were set correctly.

Trying various mingw commands in Windows terminal

Install VS Code

Visual Studio Code (VS Code) is a great, cross-platform text editor that offers highly configurable plugins. With the right plugins, you can essentially turn VS Code into a full-fledged integrated development environment (IDE) with step-through debugging! I’ll only show the basics for now so you can get your VS Code on Windows to act like VS Code on other operating systems when working with the Pico.

Head to code.visualstudio.com and download the latest release for Windows.

Run the installer and accept all of the defaults. You’re welcome to create a desktop icon and add “Open with Code” to the Windows Explorer context menu. I like to enable these options, but they’re not necessary.

Enable custom options in VS Code installation

When the installer is done, it’s time to test building a program for the Pico.

Build Blink Example

You should be able to build Pico code from any command prompt at this point. However, we’re going to do so in VS Code to show how it might be done during development.

Open VS Code. Click Terminal > New Terminal. The default terminal that opens is likely Windows PowerShell. I recommend changing this to Git Bash (or WSL) by clicking on the drop-down menu and selecting New Git Bash.

Just like we did with the make.bat file (for Windows terminals), I recommend creating an alias for mingw32-make.exe in Git Bash. Enter the following commands (you will only need to do this once):

echo "alias make=mingw32-make.exe" >> ~/.bashrc
source ~/.bashrc

Build the blink example by entering the following commands into your terminal:

cd /c/VSARM/sdk/pico/pico-examples/
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
cd blink
make

Important! Any time you call CMake from a terminal like this, you will need to specify “MinGW Makefiles” as the build system generator (-G option).

Build Raspberry Pi Pico blink example in VS Code

This should build the blink example and generate the .elf, .hex, and .uf2 binary files. We can easily upload the .uf2 file to our Pico without any special tools.

Put the Pico board into bootloader mode (press and hold the BOOTSEL button while plugging a USB cable into the Pico).

Find which drive letter the RPI-RP2 drive is mounted to (e.g. it was G: for me). Enter the following into Git Bash (change the drive letter as necessary):

cp blink.uf2 /g/

Your Pico board should be blinking away!

Raspberry Pi Pico blinking

I hope this has helped you get started using the Raspberry Pi Pico SDK on Windows! I personally found that relying on MinGW for the compiler tools was easier than using Build Tools for Visual Studio.

From here, you can set up VS Code any way you like with various plugins like CMake Tools. I did not cover setting up debugging and other tools (picotool, gdb, OpenOCD, etc.), which are topics for another time. For now, I recommend referring to the Pico C/C++ Getting Started Guide to see how to configure those tools in VS Code.

Happy hacking!

[Update May 23, 2021] Since posting this, I have made a video (for Digi-Key) that shows you how to use VS Code plugins for one-click CMake and building. You can see that video here.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Как выключить dhcp на windows 10
  • Discord canary download windows
  • Как зайти в безопасности режим windows 10 на ноутбуке
  • Ubuntu подключить сетевой диск windows
  • Настройка стерео микшера windows 10