A simple hello-world example project targeting the Raspberry Pi Pico W and using VSCode IDE
The licensing for this project only pertains to all files within this repository. It is up to the developer following these instructions to adhere to licenses of all 3rd party software and libraries being installed.
Install Visual Studio Code from the Microsoft Store.
If running under Windows, install WSL and your desired flavor of Linux. I recommend using Ubuntu 22.04 as that is what I have used for development. Then the steps under Linux may be run within your WSL instance.
If running Linux natively or in a VM (not under Windows WSL), install Visual Studio Code from the a linux repository. Then execute the steps below.
- Install git, cmake, and gcc-arm-none-eabi compiler by running the following commands
sudo apt update
sudo apt -y install git cmake gcc-arm-none-eabi
- Clone the pico-sdk.
git clone https://github.com/raspberrypi/pico-sdk.git
- Set PICO_SDK_PATH environment variable in bashrc file and apply it to current environment.
echo "export PICO_SDK_PATH=$(pwd)/pico-sdk" >> ~/.bashrc
export PICO_SDK_PATH=$(pwd)/pico-sdk
- Initialize the pico-sdk submodules.
cd pico-sdk
git submodule update --recursive --init
cd ..
- Clone this repo.
git clone https://github.com/Tails86/pico-w-hello-world.git
- Open this project in Visual Studio Code.
cd pico-w-hello-world
code .
- Within a few seconds after opening this project, a popup should show on the bottom right recommending to install "C/C++ Extension Pack". Click install to install this recommended package.
If you don't see this popup, click on the extensions icon on the left and manually search for "@recommended". Then install the package that shows up.
-
Restart Visual Studio Code after installing the extensions (refer back to step 6 on how to open the project).
-
After the extension is installed and Visual Studio Code is restarted, pressing
ctrl+shift+b
will activate the default cmake task to configure, build, and install the package. If everything works right, you will find the package underdist/main.uf2
.
Hold the BOOTSEL button on the Pico while plugging the USB connection into your PC. A drive with a FAT partition labeled RPI-RP2 should pop up on your system. Open this drive, and then copy the main.uf2 file here. The Pico should then automatically load the binary into flash and run it. For more information, refer to the official Raspberry Pi Pico documentation.
Use a serial communication terminal such as the Serial Debug Assistant on the Microsoft Store.
Find a device under the Port Name which matches "USB Serial Device". Then make sure DTR is selected before opening the port. You should start to see "Hello" and "World" printed here.
This project is setup for full integration into Visual Studio Code. Once the project is configured, Visual Studio's intellisense will properly work on all pico-sdk dependencies. This is achieved due to the following.
- CMakePresets.json contains all of the definitions needed to configure and build this project.
- Visual Studio's cmake tool is able to find CMakePresets.json because
cmake.useCMakePresets
is set toalways
in .vscode/settings.json.
- Visual Studio's cmake tool is able to find CMakePresets.json because
- The value of
CMAKE_EXPORT_COMPILE_COMMANDS
is set totrue
within CMakePresets.json in order to generatecompile_commands.json
under the directory specified forbinaryDir
(build).- This file will contain information about dependent source files.
- The value of
compileCommands
of .vscode/c_cpp_properties.json tells Visual Studio Code where to look for thecompile_commands.json
file. - When you press
ctrl+shift+b
in Visual Studio Code, it activates the default task defined in .vscode/tasks.json which runs configure, build, and install of CMake which automatically enables Intellisense due to all of the above.