How to setup Raspberry Pi Pico SDK in Ubuntu

Raspberry Pi Pico is one of the most affordable microcomputers available in the market. Today let us see how to setup the SDK and Toolchain in Ubuntu 20.04LTS and compile Example application.

Cloning the the SDK and Example Repos

First Create a folder where you want to store your SDK & Example source code

cd ~

mkdir rpi-pico

cd rpi-pico/

Now clone the SDK Package

git clone -b master https://github.com/raspberrypi/pico-sdk.git

cd pico-sdk

git submodule update --init

Now come back to previous folder and download example source code

cd ..

git clone -b master https://github.com/raspberrypi/pico-examples.git

Now you will have two folders namely pico-examples and pico-sdk. Now it is time to setup the Toolchain.

Installing the Toolchain

First make sure that your system is up to date and install the Toolchain packages

sudo apt update

sudo apt install gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib build-essential

Note : Here, cmake version should be at least version 3.13. So if you are using any older version of Ubuntu, download the source code from the CMake website and build the package from the source or install from snap package

Compiling the Example application

One of the easiest way to compile any application in Raspberry Pi Pico is to by cloning the Pico SDK locally which we have already done.

We can compile the Example application we have downloaded.

First set PICO_SDK_PATH environment variable to our downloaded SDK path

export PICO_SDK_PATH=$HOME/rpi-pico/pico-sdk

Now go to any example application. Here we will go to hello_world application over USB.

Note : If you use UART hello world application, you may have to connect UART pins. USB hello world application will use USB as serial console.

cd pico-examples/hello_world/usb/

Now edit the available CMakeLists.txt with the below content

cmake_minimum_required(VERSION 3.13)

# initialize pico-sdk from submodule
# note: this must happen before project()
include(pico_sdk_import.cmake)

project(hello_usb)

# initialize the Raspberry Pi Pico SDK
pico_sdk_init()

add_executable(hello_usb
        hello_usb.c
        )

# Pull in our pico_stdlib which aggregates commonly used features
target_link_libraries(hello_usb pico_stdlib)


# enable usb output, disable uart output
pico_enable_stdio_usb(hello_usb 1)
pico_enable_stdio_uart(hello_usb 0)

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

Now create a build folder and use the above CMakeLists.txt file and build the project

mkdir build

cmake ..

make hello_usb

You now have hello_usb.elf to load via a debugger, or hello_usb.uf2 that can be installed and run on your Raspberry Pi Pico via drag and drop.

8 thoughts on “How to setup Raspberry Pi Pico SDK in Ubuntu”

  1. Ended incorrectly with:
    — Configuring incomplete, errors occurred!

    ###

    $ cmake ..

    — The C compiler identification is GNU 7.5.0
    — The CXX compiler identification is GNU 7.5.0
    — Check for working C compiler: /usr/bin/cc
    — Check for working C compiler: /usr/bin/cc — works
    — Detecting C compiler ABI info
    — Detecting C compiler ABI info – done

    — Detecting C compile features
    — Detecting C compile features – done
    — Check for working CXX compiler: /usr/bin/c++
    — Check for working CXX compiler: /usr/bin/c++ — works
    — Detecting CXX compiler ABI info
    — Detecting CXX compiler ABI info – done
    — Detecting CXX compile features
    — Detecting CXX compile features – done
    CMake Error at serial/CMakeLists.txt:9 (pico_add_extra_outputs):
    Unknown CMake command “pico_add_extra_outputs”.

    CMake Warning (dev) in CMakeLists.txt:
    No cmake_minimum_required command is present. A line of code such as

    cmake_minimum_required(VERSION 3.10)

    should be added at the top of the file. The version specified may be lower
    if you wish to support older CMake versions for this project. For more
    information run “cmake –help-policy CMP0000”.
    This warning is for project developers. Use -Wno-dev to suppress it.

    — Configuring incomplete, errors occurred!

    ###

    Here is exact copy of CMakeLists.txt I created from this article:

    $ cat CMakeLists.txt

    cmake_minimum_required(VERSION 3.13)

    # initialize pico-sdk from submodule
    # note: this must happen before project()
    include(pico_sdk_import.cmake)

    project(hello_usb)

    # initialize the Raspberry Pi Pico SDK
    pico_sdk_init()

    add_executable(hello_usb
    hello_usb.c
    )

    # Pull in our pico_stdlib which aggregates commonly used features
    target_link_libraries(hello_usb pico_stdlib)

    # enable usb output, disable uart output
    pico_enable_stdio_usb(hello_usb 1)
    pico_enable_stdio_uart(hello_usb 0)

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

    Reply
  2. Same output as Dave. No cmake_required_version, even though the file as edited has the inclusion. I tried it with cmake with no dots, one dot, and 2 dots. With no dots cmake didn’t know where to look for the source. One and two dots gave the same results. The other problem it complained about was the “pico_add_extra_outputs”, which it had no idea what I was talking about.

    Guess I’ll have to find yet another tutorial to get one that actually works. I’ve written c for a quarter century without cmake. But the idiot SDK requires it.

    Reply

Leave a Comment