Raspberry Pi Pico SDK

repository·master·Indexed 26 days ago

https://github.com/raspberrypi/pico-sdk

A development environment for RP-series microcontrollers, including Pico and Pico 2. It provides C/C++ headers, libraries, and a build system (CMake and Bazel) to access hardware features such as PIO, USB, Wi-Fi, and Bluetooth. The SDK supports RP2040 and RP2350 platforms, offering hardware-specific 'hardware_' libraries and higher-level 'pico_' libraries, as well as a host platform for testing and debugging application logic on a computer.

Tokens
4.1K
Snippets
14
Records
25
Agent score
89%

What's inside pico-sdk

  1. Overview of the Raspberry Pi Pico SDK

    master

    The Raspberry Pi Pico SDK provides the headers, libraries, and build system required to develop programs for RP-series microcontroller devices (like the Raspberry Pi Pico) using C, C++, or assembly language.

    Key features include:

    • Support for standard C and C++ libraries.
    • APIs for hardware access: DMA, IRQs, fixed-function peripherals, and PIO (Programmable IO).
    • High-level libraries for: Timers, USB, synchronization, and multi-core programming.
    • High-level PIO-based functionality (e.g., audio).
    • Ability to build everything from simple apps to full runtimes like MicroPython.
  2. Understand common code in the Pico SDK

    master
    The src/common directory contains code that is shared across all builds, regardless of the specific PICO_PLATFORM being targeted. This includes common header files and high-level functionality implemented using the underlying hardware_ or pico_ libraries provided by the target platform.
  3. Understand the RP2040 and RP2350 library structure

    master

    The SDK provides two distinct layers of libraries for targeting RP2040, RP2350, and future devices:

    1. hardware_ libraries: These provide a thin abstraction layer for individual hardware components. They offer a simple API to interact with hardware without requiring you to access hardware registers directly.
    2. pico_ libraries: These provide higher-level functionality, including runtime support for C programmers and features typically found in an OS kernel.
  4. Use the host platform for testing and debugging

    master

    The host platform provides a set of replacement library implementations that allow you to run simple applications on your computer (Raspberry Pi OS, Linux, macOS, or Windows via Cygwin/WSL) instead of the RP2040 or RP2350 hardware. This is useful for testing high-level application logic or porting code before deploying to physical hardware.

    Note that the base host library provides a minimal environment and is best suited for programs that do not access hardware directly.

  5. Install dependencies on Unix (Linux only)

    master

    To build projects using the Raspberry Pi Pico SDK on a Linux-based system, install CMake (3.13+), Python 3, build-essential, and the ARM GCC cross-compiler toolchain.

    sudo apt install cmake python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
  6. Configure CMake using SDK as a submodule

    master

    If you have added the SDK as a Git submodule named pico-sdk, use pico_sdk_init.cmake from the submodule directory.

    Note: The include call must occur before the project() command.

    cmake_minimum_required(VERSION 3.13...3.27)
    
    # initialize pico-sdk from submodule
    # note: this must happen before project()
    include(pico-sdk/pico_sdk_init.cmake)
    
    project(my_project)
    
    # initialize the Raspberry Pi Pico SDK
    pico_sdk_init()
    
    # rest of your project
  7. Configure CMake for local SDK installation

    master

    If you have cloned the SDK locally, copy pico_sdk_import.cmake from the SDK's external/ directory into your project directory. You must then set PICO_SDK_PATH in your environment or pass it to CMake via -DPICO_SDK_PATH=.

    Note: The include(pico_sdk_import.cmake) call must occur before the project() command in your CMakeLists.txt.

    cmake_minimum_required(VERSION 3.13...3.27)
    
    # initialize the SDK based on PICO_SDK_PATH
    # note: this must happen before project()
    include(pico_sdk_import.cmake)
    
    project(my_project)
    
    # initialize the Raspberry Pi Pico SDK
    pico_sdk_init()
    
    # rest of your project
  8. Setup RISC-V toolchain for RP2350

    master

    To build for the RISC-V architecture on RP2350, you must install the prebuilt toolchain and set the PICO_TOOLCHAIN_PATH and PICO_PLATFORM environment variables.

    1. Download and extract the toolchain (example for v2.0.0-5):
    wget https://github.com/raspberrypi/pico-sdk-tools/releases/download/v2.0.0-5/riscv-toolchain-14-aarch64-lin.tar.gz
    sudo mkdir -p /opt/riscv/riscv-toolchain-14
    sudo chown $USER /opt/riscv/riscv-toolchain-14
    tar xvf riscv-toolchain-14-aarch64-lin.tar.gz -C /opt/riscv/riscv-toolchain-14
    1. Set environment variables:
    export PICO_TOOLCHAIN_PATH=/opt/riscv/riscv-toolchain-14/
    export PICO_PLATFORM=rp2350-riscv