diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 575d848ef..2cb17d91d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,7 +6,7 @@ "ghcr.io/rocker-org/devcontainer-features/apt-packages:1": { "packages": [ "sudo", - // Zephyr / nRF Connect SDK host build dependencies + // Mainline Zephyr host build dependencies (companion is NOT built on NCS) "git", "cmake", "ninja-build", @@ -21,7 +21,10 @@ "libsdl2-dev", "libmagic1", "python3-venv", - "python3-dev" + "python3-dev", + // pyocd (CMSIS-DAP flash/RTT for the XIAO nRF54L15 on-board debugger) + "libusb-1.0-0", + "libhidapi-hidraw0" ] } }, diff --git a/.devcontainer/setup-zephyr.sh b/.devcontainer/setup-zephyr.sh index c4bd30598..fc04b676b 100755 --- a/.devcontainer/setup-zephyr.sh +++ b/.devcontainer/setup-zephyr.sh @@ -1,32 +1,57 @@ #!/usr/bin/env bash # -# Installs the Nordic nRF Connect SDK (NCS) + Zephyr toolchain *alongside* the -# existing PlatformIO setup, so MeshCore can be ported to the Zephyr-based -# Seeed XIAO nRF54L15 without disturbing the ESP32/nRF52/RP2040/STM32 builds. +# Provisions everything the Zephyr MeshCore companion +# (zephyr-port/07_companion) needs, *alongside* the existing PlatformIO setup, +# so the ESP32/nRF52/RP2040/STM32 builds are left untouched. # -# This is intentionally idempotent: re-running it skips work that's already done. -# It is HEAVY (multi-GB download + Zephyr SDK). Expect the first run to take a while. +# The companion is built on **mainline Zephyr** (NOT the Nordic nRF Connect SDK): +# see zephyr-port/07_companion/README.md. This script therefore installs: +# 1. a west/Zephyr workspace from zephyrproject-rtos/zephyr -> $ZEPHYR_WORKSPACE +# 2. the matching Zephyr SDK (compilers) via `west sdk install` +# 3. pyocd (CMSIS-DAP flash/RTT for the XIAO's on-board debugger) +# 4. arduino-cli + the three Arduino libraries the CMake references by +# absolute path ($HOME/Arduino/libraries/{RadioLib,Crypto,base64}) +# +# It is intentionally idempotent: re-running skips work that's already done. +# It is HEAVY (multi-GB clone + Zephyr SDK). Expect the first run to take a while. # # Usage: # bash .devcontainer/setup-zephyr.sh # -# Override defaults via env, e.g.: -# NCS_REV=v3.0.0 NCS_WORKSPACE=$HOME/ncs bash .devcontainer/setup-zephyr.sh +# Override defaults via env, track the moving mainline tip instead of the +# pinned commit: +# ZEPHYR_REV=main bash .devcontainer/setup-zephyr.sh # set -euo pipefail # --- Tunables ---------------------------------------------------------------- -# Pick the latest NCS release that ships the Seeed XIAO nRF54L15 board -NCS_REV="${NCS_REV:-v2.9.0}" -NCS_WORKSPACE="${NCS_WORKSPACE:-$HOME/ncs}" +# Mainline Zephyr revision. Pinned to a known-good commit on `main` that reports +# VERSION 4.4.99 and ships the Seeed XIAO nRF54L15 board +# (boards/seeed/xiao_nrf54l15). Override with ZEPHYR_REV=main to track the tip. +# https://docs.zephyrproject.org/latest/boards/seeed/xiao_nrf54l15/doc/index.html +ZEPHYR_REV="${ZEPHYR_REV:-c9a40340e8e3b94d6660beb98f4d9a858cfd937e}" +ZEPHYR_WORKSPACE="${ZEPHYR_WORKSPACE:-$HOME/zephyrproject}" VENV_DIR="${VENV_DIR:-$HOME/.zephyr-venv}" + +# The board target the companion builds for (README + CMakeLists). +BOARD="${BOARD:-xiao_nrf54l15/nrf54l15/cpuapp}" + +# Arduino libraries the companion's CMakeLists.txt pulls in by absolute path +# ($HOME/Arduino/libraries/...). Versions match a known-good build; RadioLib +# 7.7.1 already carries the LR2021 driver *and* the multi-SF side-detector API +# (setSideDetector / setLoRaSideDetCad) upstream, so no fork/patch is needed. +ARDUINO_DIR="${ARDUINO_DIR:-$HOME/Arduino}" +RADIOLIB_VER="${RADIOLIB_VER:-7.7.1}" +CRYPTO_VER="${CRYPTO_VER:-0.4.0}" +BASE64_VER="${BASE64_VER:-1.3.0}" # ----------------------------------------------------------------------------- -echo ">> NCS revision : ${NCS_REV}" -echo ">> Workspace : ${NCS_WORKSPACE}" -echo ">> Python venv : ${VENV_DIR}" +echo ">> Zephyr revision : ${ZEPHYR_REV}" +echo ">> Workspace : ${ZEPHYR_WORKSPACE}" +echo ">> Python venv : ${VENV_DIR}" +echo ">> Board : ${BOARD}" -# 1) Isolated Python venv for west (don't pollute the PlatformIO/pipx env). +# 1) Isolated Python venv for west + pyocd (don't pollute the PlatformIO/pipx env). if [ ! -d "${VENV_DIR}" ]; then echo ">> Creating Python venv for west..." python3 -m venv "${VENV_DIR}" @@ -34,17 +59,18 @@ fi # shellcheck disable=SC1091 source "${VENV_DIR}/bin/activate" pip install --upgrade pip wheel >/dev/null -pip install --upgrade west >/dev/null +# west (build system) + pyocd (CMSIS-DAP flash & RTT console for the XIAO). +pip install --upgrade west pyocd >/dev/null -# 2) Initialise the NCS workspace (skip if already initialised). -if [ ! -d "${NCS_WORKSPACE}/.west" ]; then - echo ">> west init NCS workspace (${NCS_REV})..." - west init -m https://github.com/nrfconnect/sdk-nrf --mr "${NCS_REV}" "${NCS_WORKSPACE}" +# 2) Initialise the mainline Zephyr workspace (skip if already initialised). +if [ ! -d "${ZEPHYR_WORKSPACE}/.west" ]; then + echo ">> west init mainline Zephyr workspace (${ZEPHYR_REV})..." + west init -m https://github.com/zephyrproject-rtos/zephyr --mr "${ZEPHYR_REV}" "${ZEPHYR_WORKSPACE}" else - echo ">> NCS workspace already initialised, skipping west init." + echo ">> Zephyr workspace already initialised, skipping west init." fi -cd "${NCS_WORKSPACE}" +cd "${ZEPHYR_WORKSPACE}" echo ">> west update (this is the slow part)..." west update west zephyr-export @@ -61,38 +87,58 @@ west sdk install || { echo "!! Zephyr SDK manually: https://docs.zephyrproject.org/latest/develop/getting_started/index.html" } -# 5) Sanity build: confirm the XIAO nRF54L15 target actually compiles here. -echo ">> Smoke-building Zephyr 'hello_world' for seeed/xiao_nrf54l15..." -if west build -p always -b seeed/xiao_nrf54l15 zephyr/samples/hello_world -d /tmp/xiao_hello; then +# 5) arduino-cli + the Arduino libraries the companion CMake references by +# absolute path. arduino-cli's default sketchbook is $HOME/Arduino, so the +# libraries land in $HOME/Arduino/libraries/{RadioLib,Crypto,base64} exactly +# where CMakeLists.txt looks. +if ! command -v arduino-cli >/dev/null 2>&1; then + echo ">> Installing arduino-cli (user space -> ~/.local/bin)..." + mkdir -p "$HOME/.local/bin" + curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh \ + | BINDIR="$HOME/.local/bin" sh + export PATH="$HOME/.local/bin:$PATH" +fi +# Keep libraries in $HOME/Arduino so they match the CMake absolute paths. +arduino-cli config init --overwrite >/dev/null 2>&1 || true +arduino-cli config set directories.user "${ARDUINO_DIR}" >/dev/null 2>&1 || true +echo ">> Installing Arduino libraries (RadioLib/Crypto/base64) into ${ARDUINO_DIR}/libraries..." +arduino-cli lib update-index >/dev/null +arduino-cli lib install \ + "RadioLib@${RADIOLIB_VER}" \ + "Crypto@${CRYPTO_VER}" \ + "base64@${BASE64_VER}" + +# 6) Sanity build: confirm the XIAO nRF54L15 target actually compiles here. +echo ">> Smoke-building Zephyr 'hello_world' for ${BOARD}..." +if west build -p always -b "${BOARD}" zephyr/samples/hello_world -d /tmp/xiao_hello; then echo ">> OK: native Zephyr toolchain can build for the XIAO nRF54L15." else - echo "!! Zephyr build for seeed/xiao_nrf54l15 FAILED." - echo "!! Likely cause: NCS_REV=${NCS_REV} predates XIAO nRF54L15 board support." - echo "!! Re-run with a newer release, e.g. NCS_REV=v3.0.0 bash .devcontainer/setup-zephyr.sh" + echo "!! Zephyr build for ${BOARD} FAILED." + echo "!! Likely cause: ZEPHYR_REV=${ZEPHYR_REV} predates XIAO nRF54L15 board support," + echo "!! or the board target string changed. Confirm the board at:" + echo "!! https://docs.zephyrproject.org/latest/boards/seeed/xiao_nrf54l15/doc/index.html" fi cat < - # arduino-cli core update-index - # arduino-cli core install - # Ref: https://blog.adafruit.com/2026/02/17/an-arduino-core-for-nrf54l15-zephyr-based/ +PlatformIO is untouched and still drives the existing ESP32/nRF52/etc. variants. ============================================================================ EOF