A SDK environment for Raspberry Pi Pico 1 and 2 in a Docker container.
The latest image is available on Docker Hub and can be used to run a container. The following commands show how to run the container using the Docker Hub image:
docker run -d -it --name pico-sdk --mount type=bind,source=${PWD},target=/home/dev lukstep/raspberry-pi-pico-sdk:latest
docker exec -it pico-sdk /bin/sh
The directory from which the docker run
command was executed will be mounted in the container at /home/dev
.
After attaching to the SDK container, you can build your project by executing the following steps:
cd /home/dev
mkdir build
cd build
cmake .. && make -j4
To build your own SDK image, clone this repository and run the following commands:
cd raspberry-pi-pico-docker-sdk
docker build . --tag pico-sdk
docker run -d -it --name pico-sdk --mount type=bind,source=${PWD},target=/home/dev pico-sdk
docker exec -it pico-sdk /bin/sh
You can use the SDK container with Visual Studio Code to create an IDE for Raspberry Pi Pico projects. There are two solutions prepared: a new one using the Visual Studio Dev Containers extension and an old one with manual configuration.
To use the dev container, you need to have VSCode, Docker, and the VSCode extensions installed. Follow this guide for setup.
- Clone pico-template-project repository.
- Open
pico-template-project
folder in Visual Studio Code. - In VSCode, click the button in the bottom left corner of VSCode and select: Reopen in Container...
- Build the project.
- Enjoy coding you Pico project with Intellisense.
Warning
OpenOCD not support RP2350 (Pico 2). Currently this part is only valid for RP2040 boards (Pico 1).
To work efficiently on the project, we need the ability to upload firmware to the microcontroller, debug, and communicate through the serial port. The Raspberry Pi Pico board itself allows for software uploads, but this process is not very convenient or efficient for larger projects. The Pico Probe extends the capabilities of the Raspberry Pi Pico board to include fast firmware uploads to the microcontroller's memory, debugging via Serial Wire Debug (SWD), and it also serves as a USB UART converter.
The Debug Probe is compatible with the CMSIS-DAP interface, allowing OpenOCD to be used as the debugger server. By using OpenOCD, it becomes possible to communicate between development containers and the Debug Probe via TCP. On Linux, the Docker container can communicate directly through COM ports. However, on Mac and Windows, this is not possible because Docker runs in a dedicated virtual machine that does not have access to COM ports. Therefore, a solution with the OpenOCD server on the host machine was chosen.
The diagram below shows the environment topology:
-
Pico Probe is connected to the Raspberry Pi Pico board:
- SWD (Serial Wire Debug) interface for debugging.
- UART (Universal Asynchronous Receiver/Transmitter) interface for serial communication.
-
The Pico Probe is connected to the PC via USB.
-
OpenOCD (Open On-Chip Debugger) runs on the PC and communicates with the Pico Probe.
-
The development container (devContainer) connects to OpenOCD via TCP.
To install OpenOCD on Linux, run the following command in a terminal:
sudo apt install openocd
To install OpenOCD on macOS, run the following command:
brew install openocd
To install OpenOCD on Windows, follow these steps:
-
Go to the page https://github.com/xpack-dev-tools/openocd-xpack/releases.
-
Download the Windows build of OpenOCD. For example, you might download a file named xpack-openocd-0.12.0-2-win32-x64.zip.
-
Unzip the downloaded file to extract its contents.
- Connect the Pico Probe to the Pico Board via SWD (1) and connect the Pico board UART to the UART-USB converter on the Pico Probe (2).
-
Connect the Pico Probe and Pico Board to your PC
-
Start the OpenOCD
On Linux and Mac, open a new terminal and run the following command:
sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c 'bindto 0.0.0.0' -c 'adapter speed 5000' -c 'init'
On Windows, open PowerShell, navigate to the folder containing OpenOCD, and run
openocd.exe
:cd .\Desktop\xpack-openocd-0.12.0-2\ .\bin\openocd.exe -f interface\cmsis-dap.cfg -f target\rp2040.cfg -c 'bindto 0.0.0.0' -c 'adapter speed 5000' -c 'init'
-
Open the project in the Dev Container.
-
Make a debug build. Go to the CMake extension tab (1), click "Select Variant" (2), and choose "Debug" build (3). Start the build (4). If the build completes successfully, you can proceed to flashing the memory and debugging.
- To start a debug session, first add a breakpoint in the main function. Next, go to the debugger extension tab (1), and click "Play" (2). The debug session starts by flashing the Pico's memory and restarting the microcontroller. After the reset, the flashed firmware starts and the program should stop at the breakpoint.
It is possible to flash the Pico's memory without starting a debugger session. To do that, run the preprogrammed tasks.
- Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac) to open the Command Palette.
- Type Run Task into the Command Palette and press Enter.
- Select task
Flash
.
Refer here for step-by-step instruction