Skip to content

Raspberry Pi Pico 2 support #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
FROM alpine:3.17.0

# Install toolchain
RUN apk update && \
apk upgrade && \
apk add git \
python3 \
py3-pip \
cmake \
build-base \
libusb-dev \
bsd-compat-headers \
newlib-arm-none-eabi \
gcc-arm-none-eabi
FROM ubuntu:24.10 AS gcc_build

# Build GCC RISC-V
COPY ./install_gcc.sh /home/install_gcc.sh
RUN bash /home/install_gcc.sh

FROM ubuntu:24.10 as sdk_setup

RUN apt-get update -y && \
apt-get upgrade -y && \
apt-get install --no-install-recommends -y \
git \
ca-certificates \
python3 \
tar \
build-essential \
gcc-arm-none-eabi \
libnewlib-arm-none-eabi \
libstdc++-arm-none-eabi-newlib \
cmake && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Raspberry Pi Pico SDK
ARG SDK_PATH=/usr/local/picosdk
RUN git clone --depth 1 --branch 1.5.1 https://github.com/raspberrypi/pico-sdk $SDK_PATH && \
RUN git clone --depth 1 --branch 2.0.0 https://github.com/raspberrypi/pico-sdk $SDK_PATH && \
cd $SDK_PATH && \
git submodule update --init

Expand All @@ -30,11 +38,16 @@ RUN git clone --depth 1 --branch V11.0.1 https://github.com/FreeRTOS/FreeRTOS-Ke
ENV FREERTOS_KERNEL_PATH=$FREERTOS_PATH

# Picotool installation
RUN git clone --depth 1 --branch 1.1.2 https://github.com/raspberrypi/picotool.git /home/picotool && \
RUN git clone --depth 1 --branch 2.0.0 https://github.com/raspberrypi/picotool.git /home/picotool && \
cd /home/picotool && \
mkdir build && \
cd build && \
cmake .. && \
make && \
cp /home/picotool/build/picotool /bin/picotool && \
make -j$(nproc) && \
cmake --install . && \
rm -rf /home/picotool

# Install GCC RISC-V
COPY --from=gcc_build /opt/riscv/gcc14-rp2350-no-zcmp /opt/riscv/gcc14-rp2350-no-zcmp
ENV PATH="$PATH:/opt/riscv/gcc14-rp2350-no-zcmp/bin"

11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Raspberry Pi Pico Docker SDK

A lightweight SDK environment for Raspberry Pi Pico in a Docker container.
A SDK environment for Raspberry Pi Pico 1 and 2 in a Docker container.

## Pulling the Image from Docker Hub and Running

Expand Down Expand Up @@ -50,8 +50,8 @@ Follow [this](https://code.visualstudio.com/docs/devcontainers/tutorial#_prerequ

#### Using the Dev Container for Pico IDE

- Clone [pico-dev-container](https://github.com/lukstep/pico-dev-container/tree/main) repository.
- Open `pico-dev-container` folder in Visual Studio Code.
- Clone [pico-template-project](https://github.com/lukstep/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...
![image-1](https://github.com/lukstep/raspberry-pi-pico-docker-sdk/assets/20487002/f1f06bca-cb0b-4c2d-bf4c-611ef004e70a)
- Build the project.
Expand All @@ -60,6 +60,9 @@ Follow [this](https://code.visualstudio.com/docs/devcontainers/tutorial#_prerequ

## Pico Memory Flashing and Debugging via Pico Probe and OpenOCD

> [!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.
Expand Down Expand Up @@ -148,4 +151,6 @@ Refer [here](docs/vscode_manual_setup.md) for step-by-step instruction

[Raspberry Pi Debug Probe](https://www.raspberrypi.com/documentation/microcontrollers/debug-probe.html)

[Raspberry Pi Pico C/C++ SDK](https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf)

[OpenOCD project page](https://openocd.org)
51 changes: 51 additions & 0 deletions install_gcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

RET_VALUE=$?
RED='\033[0;31m'
NC='\033[0m' # No Color

apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y autoconf automake autotools-dev curl python3 python3-pip libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev ninja-build git cmake libglib2.0-dev libslirp-dev


if [ $RET_VALUE != 0 ]; then
echo "${RED}Instalation failed!${NC}"
exit 1
fi

mkdir -p /opt/riscv/gcc14-rp2350-no-zcmp

chown -R "$(whoami)" /opt/riscv/gcc14-rp2350-no-zcmp

git clone --depth 1 https://github.com/riscv/riscv-gnu-toolchain /home/riscv-gnu-toolchain

if [ $RET_VALUE != 0 ]; then
echo "${RED}Cloning RISC-V repo failed!${NC}"
exit 1
fi

cd /home/riscv-gnu-toolchain || exit

git clone --depth 1 https://github.com/gcc-mirror/gcc gcc-14 -b releases/gcc-14

if [ $RET_VALUE != 0 ]; then
echo "${RED}Cloning GCC repo failed!${NC}"
exit 1
fi

./configure --prefix=/opt/riscv/gcc14-rp2350-no-zcmp \
--with-arch=rv32ima_zicsr_zifencei_zba_zbb_zbs_zbkb_zca_zcb --with-abi=ilp32 \
--with-multilib-generator="rv32ima_zicsr_zifencei_zba_zbb_zbs_zbkb_zca_zcb-ilp32--;rv32imac_zicsr_zifencei_zba_zbb_zbs_zbkb-ilp32--" \
--with-gcc-src=`pwd`/gcc-14

if [ $RET_VALUE != 0 ]; then
echo "${RED}Configure failed!${NC}"
exit 1
fi

make -j$(nproc)

cd /home || exit

rm -rf /home/riscv-gnu-toolchain
6 changes: 1 addition & 5 deletions test_poject/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
cmake_minimum_required(VERSION 3.13)

include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)

include($ENV{PICO_SDK_PATH}/pico_sdk_init.cmake)
project(sample C CXX ASM)

set(CMAKE_C_COMPILER /usr/bin/arm-none-eabi-gcc CACHE PATH "" FORCE)
set(CMAKE_CXX_COMPILER /usr/bin/arm-none-eabi-g++ CACHE PATH "" FORCE)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

Expand Down
54 changes: 46 additions & 8 deletions test_sdk.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
#! /usr/bin/env bash

RED="\e[31m"
GREEN="\e[32m"
NC="\e[0m"
STATUS=0

if [[ -z $1 ]]; then
echo "Please provide an SDK image you want to test"
fi

docker run -d -it --name pico-sdk --mount type=bind,source=${PWD}/test_poject,target=/home/dev $1
docker exec pico-sdk /bin/sh -c "cd /home/dev && mkdir build && cd build && cmake .. && make -j4"
docker exec pico-sdk /bin/sh -c "picotool"
docker container kill pico-sdk
docker container rm pico-sdk
declare -a boards=("pico" "pico_w" "pico2" "pico2_riscv")


docker run -d -it --name pico-sdk --mount type=bind,source="${PWD}"/test_poject,target=/home/dev "$1"

for board in "${boards[@]}"
do
echo "---- $board build test ----"
docker exec pico-sdk /bin/bash -c "rm -rf /home/dev/build"
if [[ $board = pico2_riscv ]] ; then
docker exec -i pico-sdk /bin/bash -c "cd /home/dev && mkdir build && cd build && cmake .. -DPICO_BOARD=pico2 -DPICO_PLATFORM=rp2350-riscv && make -j4"
else
docker exec -i pico-sdk /bin/bash -c "cd /home/dev && mkdir build && cd build && cmake .. -DPICO_BOARD=${board} && make -j4"
fi
if [ $? != 0 ]; then
echo -e "${RED}----- Test failed -----${NC}"
STATUS=1
break
fi
echo "${GREEN}----- Test passed -----${NC}"
done

docker run -d -it --name pico-sdk --mount type=bind,source=${PWD}/freertos_test_project,target=/home/dev $1
docker exec pico-sdk /bin/sh -c "cd /home/dev && mkdir build && cd build && cmake .. && make -j4"
docker exec pico-sdk /bin/sh -c "picotool"
docker container kill pico-sdk
docker container rm pico-sdk

exit ${STATUS}

# for board in "${boards[@]}"
# do
# echo "FreeRTOS $board build test"
# docker run -d -it --name pico-sdk --mount type=bind,source=${PWD}/freertos_test_project,target=/home/dev $1
# if [[ $board -eq "pico2_riscv" ]] ; then
# docker exec pico-sdk /bin/bash -c "cd /home/dev && mkdir build && cd build && cmake .. -DPICO_BOARD=pico2 -DPICO_PLATFORM=rp2350-riscv && make -j4"
# else
# docker exec pico-sdk /bin/bash -c "cd /home/dev && mkdir build && cd build && cmake .. -DPICO_BOARD=${board} && make -j4 && cd .. && rm -rf build"
# fi
# docker exec pico-sdk /bin/bash -c "rm -rf /home/dev/build"
# docker container kill pico-sdk
# docker container rm pico-sdk
# rm -rf ./test_poject/build/
# done

Loading