|
|
@ -1,32 +1,57 @@ |
|
|
#!/usr/bin/env bash |
|
|
#!/usr/bin/env bash |
|
|
# |
|
|
# |
|
|
# Installs the Nordic nRF Connect SDK (NCS) + Zephyr toolchain *alongside* the |
|
|
# Provisions everything the Zephyr MeshCore companion |
|
|
# existing PlatformIO setup, so MeshCore can be ported to the Zephyr-based |
|
|
# (zephyr-port/07_companion) needs, *alongside* the existing PlatformIO setup, |
|
|
# Seeed XIAO nRF54L15 without disturbing the ESP32/nRF52/RP2040/STM32 builds. |
|
|
# so the ESP32/nRF52/RP2040/STM32 builds are left untouched. |
|
|
# |
|
|
# |
|
|
# This is intentionally idempotent: re-running it skips work that's already done. |
|
|
# The companion is built on **mainline Zephyr** (NOT the Nordic nRF Connect SDK): |
|
|
# It is HEAVY (multi-GB download + Zephyr SDK). Expect the first run to take a while. |
|
|
# 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: |
|
|
# Usage: |
|
|
# bash .devcontainer/setup-zephyr.sh |
|
|
# bash .devcontainer/setup-zephyr.sh |
|
|
# |
|
|
# |
|
|
# Override defaults via env, e.g.: |
|
|
# Override defaults via env, track the moving mainline tip instead of the |
|
|
# NCS_REV=v3.0.0 NCS_WORKSPACE=$HOME/ncs bash .devcontainer/setup-zephyr.sh |
|
|
# pinned commit: |
|
|
|
|
|
# ZEPHYR_REV=main bash .devcontainer/setup-zephyr.sh |
|
|
# |
|
|
# |
|
|
set -euo pipefail |
|
|
set -euo pipefail |
|
|
|
|
|
|
|
|
# --- Tunables ---------------------------------------------------------------- |
|
|
# --- Tunables ---------------------------------------------------------------- |
|
|
# Pick the latest NCS release that ships the Seeed XIAO nRF54L15 board |
|
|
# Mainline Zephyr revision. Pinned to a known-good commit on `main` that reports |
|
|
NCS_REV="${NCS_REV:-v2.9.0}" |
|
|
# VERSION 4.4.99 and ships the Seeed XIAO nRF54L15 board |
|
|
NCS_WORKSPACE="${NCS_WORKSPACE:-$HOME/ncs}" |
|
|
# (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}" |
|
|
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 ">> Zephyr revision : ${ZEPHYR_REV}" |
|
|
echo ">> Workspace : ${NCS_WORKSPACE}" |
|
|
echo ">> Workspace : ${ZEPHYR_WORKSPACE}" |
|
|
echo ">> Python venv : ${VENV_DIR}" |
|
|
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 |
|
|
if [ ! -d "${VENV_DIR}" ]; then |
|
|
echo ">> Creating Python venv for west..." |
|
|
echo ">> Creating Python venv for west..." |
|
|
python3 -m venv "${VENV_DIR}" |
|
|
python3 -m venv "${VENV_DIR}" |
|
|
@ -34,17 +59,18 @@ fi |
|
|
# shellcheck disable=SC1091 |
|
|
# shellcheck disable=SC1091 |
|
|
source "${VENV_DIR}/bin/activate" |
|
|
source "${VENV_DIR}/bin/activate" |
|
|
pip install --upgrade pip wheel >/dev/null |
|
|
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). |
|
|
# 2) Initialise the mainline Zephyr workspace (skip if already initialised). |
|
|
if [ ! -d "${NCS_WORKSPACE}/.west" ]; then |
|
|
if [ ! -d "${ZEPHYR_WORKSPACE}/.west" ]; then |
|
|
echo ">> west init NCS workspace (${NCS_REV})..." |
|
|
echo ">> west init mainline Zephyr workspace (${ZEPHYR_REV})..." |
|
|
west init -m https://github.com/nrfconnect/sdk-nrf --mr "${NCS_REV}" "${NCS_WORKSPACE}" |
|
|
west init -m https://github.com/zephyrproject-rtos/zephyr --mr "${ZEPHYR_REV}" "${ZEPHYR_WORKSPACE}" |
|
|
else |
|
|
else |
|
|
echo ">> NCS workspace already initialised, skipping west init." |
|
|
echo ">> Zephyr workspace already initialised, skipping west init." |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
cd "${NCS_WORKSPACE}" |
|
|
cd "${ZEPHYR_WORKSPACE}" |
|
|
echo ">> west update (this is the slow part)..." |
|
|
echo ">> west update (this is the slow part)..." |
|
|
west update |
|
|
west update |
|
|
west zephyr-export |
|
|
west zephyr-export |
|
|
@ -61,38 +87,58 @@ west sdk install || { |
|
|
echo "!! Zephyr SDK manually: https://docs.zephyrproject.org/latest/develop/getting_started/index.html" |
|
|
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. |
|
|
# 5) arduino-cli + the Arduino libraries the companion CMake references by |
|
|
echo ">> Smoke-building Zephyr 'hello_world' for seeed/xiao_nrf54l15..." |
|
|
# absolute path. arduino-cli's default sketchbook is $HOME/Arduino, so the |
|
|
if west build -p always -b seeed/xiao_nrf54l15 zephyr/samples/hello_world -d /tmp/xiao_hello; then |
|
|
# 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." |
|
|
echo ">> OK: native Zephyr toolchain can build for the XIAO nRF54L15." |
|
|
else |
|
|
else |
|
|
echo "!! Zephyr build for seeed/xiao_nrf54l15 FAILED." |
|
|
echo "!! Zephyr build for ${BOARD} FAILED." |
|
|
echo "!! Likely cause: NCS_REV=${NCS_REV} predates XIAO nRF54L15 board support." |
|
|
echo "!! Likely cause: ZEPHYR_REV=${ZEPHYR_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 "!! or the board target string changed. Confirm the board at:" |
|
|
|
|
|
echo "!! https://docs.zephyrproject.org/latest/boards/seeed/xiao_nrf54l15/doc/index.html" |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
cat <<EOF |
|
|
cat <<EOF |
|
|
|
|
|
|
|
|
============================================================================ |
|
|
============================================================================ |
|
|
Zephyr / NCS toolchain ready (workspace: ${NCS_WORKSPACE}). |
|
|
Zephyr toolchain + companion deps ready. |
|
|
|
|
|
|
|
|
To use it in a shell: |
|
|
Zephyr workspace : ${ZEPHYR_WORKSPACE} (mainline, VERSION 4.4.99) |
|
|
source ${VENV_DIR}/bin/activate |
|
|
Zephyr base : ${ZEPHYR_WORKSPACE}/zephyr |
|
|
source ${NCS_WORKSPACE}/zephyr/zephyr-env.sh |
|
|
Python venv : ${VENV_DIR} |
|
|
|
|
|
Arduino libs : ${ARDUINO_DIR}/libraries/{RadioLib,Crypto,base64} |
|
|
PlatformIO is untouched and still drives the existing ESP32/nRF52/etc. variants. |
|
|
Flash/RTT tool : pyocd (target: nrf54) |
|
|
|
|
|
|
|
|
--- Arduino-Zephyr core (the recommended on-ramp; see tools/lr2021_nrf54l15_smoke) --- |
|
|
To build & flash the companion: |
|
|
The nRF54L15 Arduino core is itself Zephyr-based and reuses this NCS install. |
|
|
source ${VENV_DIR}/bin/activate |
|
|
Install arduino-cli + the core, then build the smoke test: |
|
|
export ZEPHYR_BASE=${ZEPHYR_WORKSPACE}/zephyr |
|
|
|
|
|
|
|
|
# arduino-cli (user space) |
|
|
cd zephyr-port/07_companion |
|
|
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh |
|
|
west build -b ${BOARD} -d build . --pristine |
|
|
|
|
|
pyocd flash -t nrf54 -e chip build/zephyr/zephyr.hex |
|
|
|
|
|
pyocd reset -t nrf54 |
|
|
|
|
|
|
|
|
# TODO: add the nRF54L15 Arduino core's Boards Manager URL, then: |
|
|
PlatformIO is untouched and still drives the existing ESP32/nRF52/etc. variants. |
|
|
# arduino-cli config add board_manager.additional_urls <CORE_INDEX_JSON_URL> |
|
|
|
|
|
# arduino-cli core update-index |
|
|
|
|
|
# arduino-cli core install <core:nrf54l> |
|
|
|
|
|
# Ref: https://blog.adafruit.com/2026/02/17/an-arduino-core-for-nrf54l15-zephyr-based/ |
|
|
|
|
|
============================================================================ |
|
|
============================================================================ |
|
|
EOF |
|
|
EOF |
|
|
|