Skip to content

Commit 373cb3a

Browse files
EllerbachnetworkfusionCopilotjosesimoes
authored
Add Raspberry PICO RP2040 and RP2040_W with ChibiOS (#3301)
Co-authored-by: Robin Jones <networkfusion@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: José Simões <jose.simoes@eclo.solutions>
1 parent 2962c03 commit 373cb3a

161 files changed

Lines changed: 15823 additions & 151 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/All/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// Bind the Unix socket the Docker daemon listens on by default
1010
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
1111
// Keep command history
12-
"source=nano-bashhistory,target=/home/vscode/commandhistory,type=volume",
12+
"source=nano-bashhistory,target=/home/vscode/commandhistory,type=volume"
1313
// OPTIONAL: Mount .azure folder for seamless az cli auth
14-
// "source=${env:HOME}${env:USERPROFILE}/.azure,target=/home/vscode/.azure,type=bind"
14+
// ,"source=${env:HOME}${env:USERPROFILE}/.azure,target=/home/vscode/.azure,type=bind"
1515
],
1616
// Set the *default* container specific settings.json values on container create.
1717
"customizations": {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Pre-built image is not yet available for ChibiOS-RP.
2+
# Use Dockerfile.ChibiOS-RP.SRC to build from source.
3+
# Once published, replace this line with the image reference, e.g.:
4+
# FROM ghcr.io/nanoframework/dev-container-chibios-rp:v1.0
5+
FROM ghcr.io/nanoframework/dev-container-chibios-rp:v1.0
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
FROM ubuntu:latest AS downloader
2+
RUN apt-get update \
3+
&& apt-get -y install --no-install-recommends apt-utils \
4+
&& apt-get install -y \
5+
curl \
6+
xz-utils \
7+
unzip \
8+
wget
9+
10+
RUN mkdir -p /tmp/dc-downloads /tmp/dc-extracted
11+
12+
ARG GCC_VERSION=13.3.rel1
13+
ARG GCC_URI=https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu/$GCC_VERSION/binrel/arm-gnu-toolchain-$GCC_VERSION-x86_64-arm-none-eabi.tar.xz
14+
RUN mkdir -p /tmp/dc-downloads /tmp/dc-extracted/gcc \
15+
&& curl -o /tmp/dc-downloads/gcc-arm.tar.xz $GCC_URI \
16+
&& xz -d /tmp/dc-downloads/gcc-arm.tar.xz \
17+
&& tar -xvf /tmp/dc-downloads/gcc-arm.tar -C /tmp/dc-extracted/gcc --strip-components 1 \
18+
&& rm -rf /tmp/dc-extracted/gcc/share/doc/ /tmp/dc-extracted/gcc/share/gcc-arm-none-eabi/samples/
19+
20+
ARG CMAKE_VERSION=3.31.6
21+
ARG CMAKE_SCRIPT=https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-linux-x86_64.sh
22+
RUN wget $CMAKE_SCRIPT \
23+
-q -O /tmp/dc-downloads/cmake-install.sh \
24+
&& chmod u+x /tmp/dc-downloads/cmake-install.sh \
25+
&& mkdir -p /tmp/dc-extracted/cmake \
26+
&& /tmp/dc-downloads/cmake-install.sh --skip-license --prefix=/tmp/dc-extracted/cmake \
27+
&& rm /tmp/dc-downloads/cmake-install.sh
28+
29+
FROM ubuntu:latest AS devcontainer
30+
31+
# Avoid warnings by switching to noninteractive
32+
ENV DEBIAN_FRONTEND=noninteractive
33+
34+
# You can set up non-root user
35+
# ARG USERNAME=vscode
36+
# ARG USER_UID=1000
37+
# ARG USER_GID=$USER_UID
38+
39+
# Configure apt and install packages
40+
RUN apt-get update \
41+
&& apt-get -y install --no-install-recommends apt-utils dialog icu-devtools 2>&1 \
42+
&& apt-get install -y \
43+
git \
44+
git-svn \
45+
subversion \
46+
clang-format \
47+
curl \
48+
ninja-build \
49+
srecord \
50+
python3 \
51+
python3-pip \
52+
libusb-1.0-0-dev \
53+
pkg-config \
54+
build-essential
55+
56+
# Create needed directories
57+
RUN mkdir -p /usr/local/bin/gcc
58+
59+
# ============================================================
60+
# KEY DIFFERENCE from ChibiOS container:
61+
# Clone ChibiOS master/trunk which has RP2040/RP2350 support
62+
# The stable_21.11.x branch does NOT include RP ports.
63+
# ============================================================
64+
# Try GitHub mirror first (faster), fall back to SVN trunk
65+
RUN git clone --branch master https://github.com/ChibiOS/ChibiOS.git --depth 1 ./sources/ChibiOs \
66+
|| git svn clone http://svn.code.sf.net/p/chibios/code/trunk -rHEAD ./sources/ChibiOs
67+
68+
# NO STM32 Cube packages — not needed for RP targets
69+
70+
# Clone dependent repos (mbedtls, fatfs, littlefs, lwIP)
71+
RUN git clone --branch R0.16 https://github.com/abbrev/fatfs.git --depth 1 ./sources/fatfs \
72+
&& git clone --branch v2.11.2 https://github.com/littlefs-project/littlefs --depth 1 ./sources/littlefs \
73+
&& git clone --branch STABLE-2_1_3_RELEASE https://github.com/lwip-tcpip/lwip.git --depth 1 ./sources/lwip \
74+
&& git clone --branch mbedtls-3.6.5 https://github.com/ARMmbed/mbedtls.git --depth 1 ./sources/mbedtls \
75+
&& cd ./sources/mbedtls \
76+
&& git submodule update --init --recursive
77+
78+
# set gcc location
79+
ARG TMP_GCC_PATH=/usr/local/bin/gcc
80+
ENV ARM_GCC_PATH=$TMP_GCC_PATH/bin
81+
82+
# Copy from our other container
83+
COPY --from=downloader /tmp/dc-extracted/gcc $TMP_GCC_PATH
84+
COPY --from=downloader /tmp/dc-extracted/cmake /usr/bin/cmake
85+
86+
ENV PATH=/usr/bin/cmake/bin:${PATH}
87+
88+
# picotool is NOT included — it requires the Pico SDK (PICO_SDK_PATH) to build.
89+
# Since we use ChibiOS (not the Pico SDK), picotool can be added later if UF2
90+
# conversion is needed, by also cloning the pico-sdk.
91+
# hex2dfu is NOT included — RP targets use UF2 format, not DFU
92+
# srecord is still useful for bin packaging
93+
94+
# Install Python dependencies for Kconfig configuration system
95+
RUN pip3 install --no-cache-dir --break-system-packages pyserial "kconfiglib>=14.1.0"
96+
97+
# Clean up downloaded files
98+
RUN apt-get autoremove -y \
99+
&& apt-get clean -y \
100+
&& rm -rf /var/lib/apt/lists/*
101+
102+
# Install .NET SDK 9.0 and .NET 8.0 runtime (needed by nanoFramework build tooling)
103+
RUN curl -sSL https://dot.net/v1/dotnet-install.sh -o /tmp/dotnet-install.sh \
104+
&& chmod +x /tmp/dotnet-install.sh \
105+
&& /tmp/dotnet-install.sh --channel 9.0 --install-dir /usr/share/dotnet \
106+
&& /tmp/dotnet-install.sh --channel 8.0 --runtime dotnet --install-dir /usr/share/dotnet \
107+
&& ln -sf /usr/share/dotnet/dotnet /usr/local/bin/dotnet \
108+
&& rm /tmp/dotnet-install.sh
109+
110+
ENV DOTNET_ROOT=/usr/share/dotnet
111+
112+
# Switch back to dialog for any ad-hoc use of apt-get
113+
ENV DEBIAN_FRONTEND=dialog
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "nanoFramework-ChibiOS-RP",
3+
// This container is for developing Raspberry Pi Pico (RP2040/RP2350) targets using ChibiOS.
4+
// It uses Dockerfile.ChibiOS-RP.SRC which builds from source because there is no pre-built image yet.
5+
// Once a pre-built image is published, change "dockerFile" to "Dockerfile.ChibiOS-RP".
6+
"dockerFile": "Dockerfile.ChibiOS-RP.SRC",
7+
"context": ".",
8+
"runArgs": ["--privileged", "--device=/dev/ttyUSB0:/dev/ttyUSB0"],
9+
"mounts": [
10+
// Bind the Unix socket the Docker daemon listens on by default
11+
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
12+
// Keep command history
13+
"source=nano-bashhistory,target=/home/vscode/commandhistory,type=volume",
14+
// Map /dev for USB device access (debug probes, serial ports)
15+
"source=/dev,target=/dev,type=bind"
16+
// OPTIONAL: Mount .azure folder for seamless az cli auth
17+
// ,"source=${env:HOME}${env:USERPROFILE}/.azure,target=/home/vscode/.azure,type=bind"
18+
],
19+
// Set the *default* container specific settings.json values on container create.
20+
"customizations": {
21+
"vscode": {
22+
"settings": {
23+
"cmake.preferredGenerators": [
24+
"Ninja"
25+
],
26+
"cmake.generator": "Ninja",
27+
"cmake.autoRestartBuild" : true,
28+
"cmake.configureSettings": {
29+
"CMAKE_MAKE_PROGRAM":"/usr/bin/ninja"
30+
},
31+
"cmake.configureOnOpen": false
32+
},
33+
// Add the IDs of extensions you want installed when the container is created.
34+
"extensions": [
35+
"ms-vsliveshare.vsliveshare-pack",
36+
"streetsidesoftware.code-spell-checker",
37+
"twxs.cmake",
38+
"ms-vscode.cmake-tools",
39+
"xaver.clang-format"
40+
]
41+
}
42+
},
43+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
44+
// "forwardPorts": [],
45+
// Use 'postCreateCommand' to run commands after the container is created.
46+
// This is needed to allow cloning repositories
47+
"postCreateCommand": "git config --global safe.directory '*'"
48+
// Uncomment to connect as a non-root user. See https: //aka.ms/vscode-remote/containers/non-root.
49+
// ,"remoteUser": "vscode"
50+
}

.devcontainer/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The available pre build images are:
1010
* ghcr.io/nanoframework/dev-container-esp32: contains all elements to build a firmware image for any of the ESP32 targets
1111
* ghcr.io/nanoframework/dev-container-azure-rtos: contains all elements to build a firmware image for any of the Eclipse ThreadX (used to be Azure RTOS) targets
1212
* ghcr.io/nanoframework/dev-container-freertos-nxp: contains all elements to build a firmware image for any of the NXP targets
13+
* ChibiOS-RP: contains all elements to build a firmware image for Raspberry Pi Pico (RP2040/RP2350) ChibiOS targets. Uses ChibiOS master branch which includes RP support.
1314

1415
You can choose the dev container needed when opening a remote container in VSCode. The options are:
1516

@@ -19,6 +20,7 @@ You can choose the dev container needed when opening a remote container in VSCod
1920
* `nanoFramework-ESP32` to use the pre build container with all the elements to build ESP32 targets
2021
* `nanoFramework-TI` to use the pre build container with all the elements to build TI SimpleLink targets
2122
* `nanoFramework-FreeRTOS-NXP` to use the pre build container with all the elements to build TI SimpleLink targets
23+
* `nanoFramework-ChibiOS-RP` to build from source a container with all the elements to build Raspberry Pi Pico RP2040/RP2350 ChibiOS targets
2224

2325
To use the source dockerfile for the respective platform adjust its `devcontainer.json` file and change the `"dockerFile": "Dockerfile.<platform>"` element for the image you would like to use:
2426

@@ -28,6 +30,7 @@ To use the source dockerfile for the respective platform adjust its `devcontaine
2830
* `Dockerfile.ESP32.SRC` to build the container image from the source with all the elements to build ESP32 based devices
2931
* `Dockerfile.TI.SRC` to build the container image from the source with all the elements to build TI SimpleLink based devices
3032
* `Dockerfile.FreeRTOS.NXP.SRC` to build the container image from the source with all the elements to build NXP based devices
33+
* `Dockerfile.ChibiOS-RP.SRC` to build the container image from the source with all the elements to build Raspberry Pi Pico (RP2040/RP2350) ChibiOS targets
3134

3235

3336
## Building and releasing Docker images in a fork
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright (c) .NET Foundation and Contributors
2+
# See LICENSE file in the project root for full license information.
3+
4+
name: Build Dev Container for ChibiOS-RP
5+
6+
env:
7+
CONTAINER_REPO: ghcr.io
8+
CONTAINER_NAME: dev-container-chibios-rp
9+
CONTAINER_SRC_FILE: .devcontainer/ChibiOS-RP/Dockerfile.ChibiOS-RP.SRC
10+
11+
on:
12+
push:
13+
branches:
14+
- main
15+
paths:
16+
- '**Dockerfile.ChibiOS-RP'
17+
18+
workflow_dispatch:
19+
20+
jobs:
21+
build:
22+
if: ${{ vars.PUBLISH_DOCKER_IMAGE == 'true' }}
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
steps:
27+
28+
- name: Checkout Repository
29+
uses: actions/checkout@v5
30+
31+
- name: Free Disk Space (Ubuntu)
32+
uses: jlumbroso/free-disk-space@main
33+
with:
34+
# this might remove tools that are actually needed,
35+
# when set to "true" but frees about 6 GB
36+
tool-cache: true
37+
large-packages: false
38+
39+
- name: Get container version
40+
run: |
41+
$dockerfileContent = Get-Content(".devcontainer/ChibiOS-RP/Dockerfile.ChibiOS-RP")
42+
$dockerfileContent -match '(?<=\:)(?:[v]\d+.\d+)'
43+
$containerVersion = $Matches[0].ToString()
44+
echo "GCR_VERSION=$containerVersion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
45+
shell: pwsh
46+
47+
- name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@v3
49+
50+
- name: Login to GitHub Container Registry
51+
uses: docker/login-action@v3
52+
with:
53+
registry: ghcr.io
54+
username: ${{ github.repository_owner }}
55+
password: ${{ secrets.CONTAINER_BUILD_TOKEN }}
56+
57+
- name: Build and Push Docker Image
58+
uses: docker/build-push-action@v6
59+
with:
60+
file: ${{ env.CONTAINER_SRC_FILE }}
61+
push: true # Will only build if this is not here
62+
tags: |
63+
${{ env.CONTAINER_REPO }}/${{ github.repository_owner }}/${{ env.CONTAINER_NAME }}:${{ env.GCR_VERSION }}
64+
${{ env.CONTAINER_REPO }}/${{ github.repository_owner }}/${{ env.CONTAINER_NAME }}:latest

.github/workflows/devcontainer-smoketest.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
# { target: ESP32_H2_THREAD, build-type: Debug, container: ESP32 },
2828
{ target: NXP_MIMXRT1060_EVK, build-type: Debug, container: FreeRTOS-NXP },
2929
{ target: NXP_MIMXRT1060_EVK, build-type: Debug, container: All },
30+
{ target: RP_PICO_W_RP2040, build-type: Debug, container: ChibiOS-RP },
3031
{ target: TI_CC1352R1_LAUNCHXL, build-type: Debug, container: TI, radio-freq: 915 },
3132
{ target: TI_CC1352R1_LAUNCHXL, build-type: Debug, container: All, radio-freq: 915 },
3233
{ target: TI_CC1352R1_LAUNCHXL, build-type: Debug, container: TI, radio-freq: 868 },
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# Copyright (c) .NET Foundation and Contributors
3+
# See LICENSE file in the project root for full license information.
4+
#
5+
6+
#################################################################
7+
# WHEN ADDING A NEW SERIES add the appropriate GCC options below
8+
#################################################################
9+
10+
# RP2040: ARM Cortex-M0+ (ARMv6-M), no FPU, soft float
11+
12+
# need to specify this for assembler
13+
set(CMAKE_ASM_FLAGS " -mthumb -mcpu=cortex-m0plus -mfloat-abi=soft -mabi=aapcs -x assembler-with-cpp -DCRT0_VTOR_INIT=TRUE" CACHE INTERNAL "asm compiler flags")
14+
15+
# need to specify linker flags here
16+
set(CMAKE_EXE_LINKER_FLAGS " -Wl,--gc-sections -Wl,--no-wchar-size-warning -Wl,--print-memory-usage -Wl,--no-warn-rwx-segments -mthumb -mcpu=cortex-m0plus -mfloat-abi=soft -mabi=aapcs -nostartfiles " CACHE INTERNAL "executable linker flags")
17+
18+
19+
# TARGET parameter to set the target that's setting them for
20+
# optional EXTRA_COMPILE_OPTIONS with compile options to be added
21+
macro(nf_set_compile_options)
22+
23+
# parse arguments
24+
cmake_parse_arguments(NFSCO "" "TARGET" "EXTRA_COMPILE_OPTIONS" ${ARGN})
25+
26+
if(NOT NFSCO_TARGET OR "${NFSCO_TARGET}" STREQUAL "")
27+
message(FATAL_ERROR "Need to set TARGET argument when calling nf_set_compile_options()")
28+
endif()
29+
30+
# include any extra options coming from any extra args?
31+
target_compile_options(${NFSCO_TARGET} PUBLIC ${NFSCO_EXTRA_COMPILE_OPTIONS} -mthumb -mcpu=cortex-m0plus -mabi=aapcs -nostdlib -Wall -Wextra -Werror -Wundef -Wshadow -Wimplicit-fallthrough $<$<COMPILE_LANGUAGE:CXX>:-Wno-cast-user-defined> -fshort-wchar -fno-builtin -fno-common -mno-long-calls -fno-exceptions -fcheck-new )
32+
33+
# RP2040 has no FPU (Cortex-M0+)
34+
# Note: RP2040 is defined by ChibiOS board.h, no need to add it here
35+
target_compile_definitions(${NFSCO_TARGET} PUBLIC -DPLATFORM_ARM -DCORTEX_USE_FPU=FALSE -DUSE_FPU=FALSE)
36+
37+
endmacro()
38+
39+
40+
# TARGET parameter to set the target that's setting them for
41+
# optional EXTRA_LINK_FLAGS with link flags to be added
42+
macro(nf_set_link_options)
43+
44+
# parse arguments
45+
cmake_parse_arguments(NFSLO "" "TARGET;EXTRA_LINK_FLAGS" "" ${ARGN})
46+
47+
if(NOT NFSLO_TARGET OR "${NFSLO_TARGET}" STREQUAL "")
48+
message(FATAL_ERROR "Need to set TARGET argument when calling nf_set_link_options()")
49+
endif()
50+
51+
# set optimization linker flags for RELEASE and MinSizeRel
52+
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
53+
set_property(TARGET ${NFSLO_TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Os -flto -fuse-linker-plugin -fstrict-aliasing -fomit-frame-pointer -fno-unroll-loops -frounding-math -fsignaling-nans -ffloat-store -fno-math-errno -ftree-vectorize -fno-default-inline -finline-functions-called-once -fno-defer-pop ")
54+
endif()
55+
56+
# request specs from newlib nano
57+
set_property(TARGET ${NFSLO_TARGET} APPEND_STRING PROPERTY LINK_FLAGS " --specs=nano.specs ")
58+
59+
# include libraries in build
60+
nf_include_libraries_in_build(${NFSLO_TARGET})
61+
62+
# set extra linker flags
63+
set_property(TARGET ${NFSLO_TARGET} APPEND_STRING PROPERTY LINK_FLAGS " ${NFSLO_EXTRA_LINK_FLAGS} ")
64+
65+
# set optimization flags
66+
nf_set_optimization_options(${NFSLO_TARGET})
67+
68+
endmacro()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# Copyright (c) .NET Foundation and Contributors
3+
# See LICENSE file in the project root for full license information.
4+
#
5+
6+
include(FetchContent)
7+
FetchContent_GetProperties(chibios)
8+
9+
# List of the ChibiOS generic RP2040 startup source files.
10+
# RP2040 uses ARM Cortex-M0+ (ARMv6-M architecture)
11+
12+
set(CHIBIOS_PORT_SRCS
13+
14+
# RT port for ARMv6-M
15+
chcore.c
16+
chcoreasm.S
17+
)
18+
19+
foreach(SRC_FILE ${CHIBIOS_PORT_SRCS})
20+
21+
set(CHIBIOS_RP_SRC_FILE SRC_FILE-NOTFOUND)
22+
23+
find_file(CHIBIOS_RP_SRC_FILE ${SRC_FILE}
24+
PATHS
25+
${chibios_SOURCE_DIR}/os/common/ports/ARMv6-M/compilers/GCC
26+
${chibios_SOURCE_DIR}/os/common/ports/ARMv6-M
27+
${chibios_SOURCE_DIR}/os/hal/ports/common/ARMCMx
28+
29+
CMAKE_FIND_ROOT_PATH_BOTH
30+
)
31+
32+
if (BUILD_VERBOSE)
33+
message("${SRC_FILE} >> ${CHIBIOS_RP_SRC_FILE}")
34+
endif()
35+
36+
list(APPEND CHIBIOS_SOURCES ${CHIBIOS_RP_SRC_FILE})
37+
38+
endforeach()
39+
40+
list(APPEND CHIBIOS_INCLUDE_DIRS ${chibios_SOURCE_DIR}/os/common/ports/ARMv6-M)

0 commit comments

Comments
 (0)