Raspberry Pi — Pico

Raspberry Pi Pico — C/C++ SDK Setup

The C/C++ SDK gives you full control over the Pico's hardware with native performance. The easiest way to set it up in 2025 is using the VS Code Raspberry Pi Pico extension, which automatically downloads and configures the SDK, toolchain, and build tools for you.


Prerequisites


Step 1 — Install the Raspberry Pi Pico VS Code Extension

  1. Open VS Code
  2. Press Ctrl+Shift+X to open Extensions
  3. Search for "Raspberry Pi Pico"
  4. Install the extension by Raspberry Pi
  5. A Pico icon appears in the left sidebar

Step 2 — Create Your First Project

  1. Click the Raspberry Pi Pico icon in the sidebar
  2. Click "New Project from Example"
  3. Select:
    • Name: hello_blink
    • Board: Pico or Pico 2 (match your hardware)
    • Language: C
    • Example: blink
    • Location: Choose a folder on your computer
  4. Click "Create"

The extension will automatically:

  • Download the Pico SDK (first time only, ~200 MB)
  • Download the ARM toolchain (arm-none-eabi-gcc)
  • Download CMake and Ninja build tools
  • Configure the project's CMakeLists.txt

This first-time setup takes 5–15 minutes depending on your internet speed.


Step 3 — Understand the Project Structure

text
hello_blink/
├── .vscode/
│   ├── cmake-kits.json         # Toolchain configuration
│   ├── launch.json             # Debug configuration
│   └── settings.json           # Build settings
├── build/                       # Build output (generated)
├── CMakeLists.txt               # Build system configuration
├── hello_blink.c                # Your application code
└── pico_sdk_import.cmake        # SDK import

The generated hello_blink.c looks like this:

c
1#include "pico/stdlib.h"
2
3int main() {
4 const uint LED_PIN = PICO_DEFAULT_LED_PIN;
5 gpio_init(LED_PIN);
6 gpio_set_dir(LED_PIN, GPIO_OUT);
7
8 while (true) {
9 gpio_put(LED_PIN, 1);
10 sleep_ms(500);
11 gpio_put(LED_PIN, 0);
12 sleep_ms(500);
13 }
14}

Step 4 — Build the Project

In VS Code:

  • Click the Build button in the status bar (⚙️), or
  • Press Ctrl+Shift+B, or
  • Open Terminal → run:
shell
cd build
cmake ..
make -j4

After a successful build, you'll find:

  • build/hello_blink.uf2 — The flashable firmware file
  • build/hello_blink.elf — Debug-friendly binary (with symbols)

Step 5 — Flash the Firmware

Method A: Drag-and-Drop (No SWD needed)

  1. Put the Pico in BOOTSEL mode (hold BOOTSEL, plug in USB, release)
  2. The Pico appears as RPI-RP2 drive
  3. Drag build/hello_blink.uf2 onto the drive
  4. The Pico reboots and runs the code

Method B: From VS Code (with SWD debug probe)

If you have a second Pico configured as a debug probe (or a standalone Picoprobe / J-Link):

  1. Click the Flash button in the VS Code Pico extension sidebar, or
  2. Run from terminal:
shell
openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg \
  -c "adapter speed 5000" \
  -c "program build/hello_blink.elf verify reset exit"

Step 6 — Manual SDK Setup (Advanced)

If you prefer command-line setup without VS Code:

Windows (PowerShell)

powershell
# Install build tools via scoop or winget
winget install Kitware.CMake
winget install GnuWin32.Make

# Clone the SDK
git clone https://github.com/raspberrypi/pico-sdk.git
cd pico-sdk
git submodule update --init

# Set environment variable
[System.Environment]::SetEnvironmentVariable("PICO_SDK_PATH", "C:\pico-sdk", "User")

Ubuntu

shell
# Install ARM toolchain and build tools
sudo apt install -y \
  cmake \
  ninja-build \
  gcc-arm-none-eabi \
  libnewlib-arm-none-eabi \
  build-essential \
  git

# Clone the SDK
git clone https://github.com/raspberrypi/pico-sdk.git ~/pico-sdk
cd ~/pico-sdk && git submodule update --init

# Set in .bashrc
echo 'export PICO_SDK_PATH=$HOME/pico-sdk' >> ~/.bashrc
source ~/.bashrc

macOS

shell
# Install toolchain via Homebrew
brew install cmake ninja
brew install --cask gcc-arm-embedded

# Clone SDK
git clone https://github.com/raspberrypi/pico-sdk.git ~/pico-sdk
cd ~/pico-sdk && git submodule update --init

echo 'export PICO_SDK_PATH=$HOME/pico-sdk' >> ~/.zshrc
source ~/.zshrc

Step 7 — Build and Flash from Command Line

shell
mkdir hello_blink && cd hello_blink
# Create CMakeLists.txt and main.c (or copy from SDK examples)

mkdir build && cd build
cmake .. -DPICO_BOARD=pico         # Use pico2 for Pico 2
make -j4

# Flash via drag-and-drop of build/hello_blink.uf2

Key SDK Libraries

c
1#include "pico/stdlib.h" // GPIO, sleep, stdio, UART
2#include "hardware/gpio.h" // GPIO control
3#include "hardware/pwm.h" // PWM
4#include "hardware/i2c.h" // I2C
5#include "hardware/spi.h" // SPI
6#include "hardware/uart.h" // UART
7#include "hardware/adc.h" // ADC
8#include "hardware/dma.h" // DMA
9#include "hardware/pio.h" // PIO state machines
10#include "hardware/timer.h" // Hardware timers
11#include "pico/multicore.h" // Dual-core support
12#include "pico/cyw43_arch.h" // Wi-Fi (Pico W only)

Dual-Core Example

c
1#include "pico/stdlib.h"
2#include "pico/multicore.h"
3
4void core1_task() {
5 // This runs on Core 1
6 while (1) {
7 printf("Core 1 running\n");
8 sleep_ms(1000);
9 }
10}
11
12int main() {
13 stdio_init_all();
14
15 // Launch code on Core 1
16 multicore_launch_core1(core1_task);
17
18 // This runs on Core 0
19 while (1) {
20 printf("Core 0 running\n");
21 sleep_ms(500);
22 }
23}

Next Steps

Previous
MicroPython on Pico