Quick-start your own project
| The following instructions are terse, and Linux-based only. For detailed steps, instructions for other platforms, and just in general, we recommend you see the Getting started with Raspberry Pi Pico and Raspberry Pi Pico C/C++ SDK books. |
Install CMake (at least version 3.13), and GCC cross compiler
$ sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
Set up your project to point to use the Raspberry Pi Pico SDK by cloning the SDK locally:
$ git clone https://github.com/raspberrypi/pico-sdk.git
Copy external/pico_sdk_import.cmake from the SDK into your project directory
Set PICO_SDK_PATH to the SDK location in your environment, or pass it (-DPICO_SDK_PATH=) to cmake later.
Setup a CMakeLists.txt like:
cmake_minimum_required(VERSION 3.13) # initialise the SDK based on PICO_SDK_PATH # note: this must happen before project() include(pico_sdk_import.cmake) project(my_project) # initialise the Raspberry Pi Pico SDK pico_sdk_init() # rest of your project
Go ahead and write your code, see pico-examples or the Raspberry Pi Pico C/C++ SDK book for more information on how to go about that.
About the simplest you can do is a single source file (for example, hello_world.c)
#include <stdio.h>
#include "pico/stdlib.h"
int main() {
setup_default_uart();
printf("Hello, world!\n");
return 0;
}
and add the following to your CMakeLists.txt:
add_executable(hello_world
hello_world.c
)
# Add pico_stdlib library which aggregates commonly used features
target_link_libraries(hello_world pico_stdlib)
# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(hello_world)
| This example uses the default UART for stdout; if you want to use the default USB see the hello-usb example. |
Setup a CMake build directory. For example, if not using an IDE:
$ mkdir build
$ cd build
$ cmake ..
When building for a board other than the Raspberry Pi Pico, pass -DPICO_BOARD=board_name to the cmake command above, for example, cmake -DPICO_BOARD=pico_w .. to configure the SDK and build options accordingly for that particular board.
Doing so sets up various compiler defines (for example, default pin numbers for UART and other hardware) and in certain cases also enables the use of additional libraries (for example, wireless support when building for PICO_BOARD=pico_w) which cannot be built without a board which provides the requisite functionality.
For a list of boards defined in the SDK itself, look in this directory which has a header for each named board.
Make your target from the build directory you created.
$ make hello_world
You now have hello_world.elf to load by using a debugger, or hello_world.uf2 that can be installed and run on your Raspberry Pi Pico through drag and drop.