diff --git a/Dockerfile b/Dockerfile index 13955e8..04d8b74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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" + diff --git a/README.md b/README.md index 4e07c1d..b8a5714 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. @@ -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. @@ -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) diff --git a/install_gcc.sh b/install_gcc.sh new file mode 100644 index 0000000..0b1580c --- /dev/null +++ b/install_gcc.sh @@ -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 diff --git a/test_poject/CMakeLists.txt b/test_poject/CMakeLists.txt index 7d4c4c9..79834aa 100644 --- a/test_poject/CMakeLists.txt +++ b/test_poject/CMakeLists.txt @@ -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) diff --git a/test_sdk.sh b/test_sdk.sh old mode 100644 new mode 100755 index 0364702..d9f421f --- a/test_sdk.sh +++ b/test_sdk.sh @@ -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 +