Getting RPI Pico SDK
Start by downloading the actual SDK from github repository using this command. Make sure you have git installed and get inside that directory.
git clone https://github.com/raspberrypi/pico-sdk
cd pico-sdk
Then you need to download submodules that are required by some parts of SDK otherwise they won't work. You can download by running this command inside SDK directory:
git submodule update --init
Setting up a project
Replace project_name with actual name of the project
cd ../
mkdir project_name
cd project_name
cp $HOME/pico_sdk/pico_sdk_init.cmake .
Make sure you have pico sdk in your root home directory or change path if differs. Now create files program.c and CMakeLists.txt. Set enviromental variable PICO_SDK_PATH to path to pico_sdk folder or you can edit rc of your shell to make work faster
export PICO_SDK_PATH=$HOME/pico_sdk/
Program.c
Example of code that turn on onboard LED
#include "pico/stdlib.h"
int main() {
gpio_init(25); //Onboard LED is on GPIO with number 25
gpio_set_dir(25, 1); //Set GPIO to output mode
gpio_put(25, 1); //Turn on the led
while(1); //infinite loop so program never ends
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(blink_led)
add_executable(program
program.c
)
target_link_libraries(program pico_stdlib)
pico_add_extra_outputs(program)
Compilation
cmake CMakeLists.txt
make
After compilation you will see program.uf2 and that file copy to pico's flash.