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.