Skip to content

Commit

Permalink
Raspberry Pi Pico 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstep committed Aug 27, 2024
1 parent 0a2bba1 commit 9a3ba53
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 34 deletions.
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"

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: 43 additions & 11 deletions test_sdk.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
#! /usr/bin/env bash

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

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

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
declare -a boards=("pico" "pico_w" "pico2" "pico2_riscv")

for board in "${boards[@]}"
do
echo "---- $board build test ----"
docker run -d -it --name pico-sdk --mount type=bind,source="${PWD}"/test_poject,target=/home/dev "$1"
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}"
exit 1
fi
docker container kill pico-sdk
docker container rm pico-sdk
echo "${GREEN}----- Test passed -----${NC}"
done


# 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

0 comments on commit 9a3ba53

Please sign in to comment.