Since the official instructions for this module for setting up the developer environment are poor and specialised to VSCode on Windows, I would like to present an alternative approach using devenv.
The following devenv.nix
is all you need install the required packages and drivers for this module:
{pkgs, ...}: let
# Download the free rtos source
freeRtosRp2040 = pkgs.fetchgit {
url = "https://github.com/raspberrypi/FreeRTOS-Kernel.git";
rev = "4f7299d6ea746b27a9dd19e87af568e34bd65b15";
sha256 = "sha256-1ClybKUaRHfoWozzhTTrpsWa954Q0zT6vvYu6OFWqUY=";
fetchSubmodules = true;
deepClone = true;
};
# Build the full pico sdk with all submodules
pico-sdk-full = pkgs.pico-sdk.overrideAttrs (o: {
pname = "pico-sdk-full";
version = "2.1.1";
src = pkgs.fetchgit {
url = "https://github.com/raspberrypi/pico-sdk.git";
rev = "ee68c78d0afae2b69c03ae1a72bf5cc267a2d94c";
sha256 = "sha256-kOwiPDTggVkbz8j6jBiANeKl9RLp+ZLD+fxphz8C3SA=";
fetchSubmodules = true;
deepClone = true;
};
});
# Download and build the debug probe from source
pico-debug-probe = pkgs.stdenv.mkDerivation {
pname = "pico-debug-probe";
version = "2.2.1";
src = pkgs.fetchgit {
url = "https://github.com/raspberrypi/debugprobe.git";
rev = "83e28db1d36e454914adb452ad8fc24bf1a66e73";
sha256 = "sha256-hW/pdIitQs18QY33FaDBqxoopwXOYFXDWpfiw59glSA=";
fetchSubmodules = true;
deepClone = true;
};
env = {
PICO_SDK_PATH = "${pico-sdk-full}/lib/pico-sdk";
};
nativeBuildInputs = with pkgs; [
cmake
gnumake
python314
gcc-arm-embedded
git
picotool
];
# Patch free rtos importer to work correctly
patches = [
./fix-freertos-import.patch
];
cmakeFlags = [
"-DFREERTOS_KERNEL_PATH=${freeRtosRp2040}"
"-DCMAKE_C_COMPILER=${pkgs.gcc-arm-embedded}/bin/arm-none-eabi-gcc"
"-DCMAKE_CXX_COMPILER=${pkgs.gcc-arm-embedded}/bin/arm-none-eabi-g++"
];
installPhase = ''
mkdir -p $out/bin
cp *.uf2 $out/bin
cat <<EOF > $out/bin/pico-debug-probe-load
#!/usr/bin/env bash
sudo ${pkgs.picotool}/bin/picotool load $out/bin/debugprobe.uf2
EOF
chmod +x $out/bin/pico-debug-probe-load
'';
};
in {
packages = with pkgs; [
# Pico sdk deps
python314
pico-sdk-full
gcc-arm-embedded
cmake
gnumake
git
# Debug adapter protocol
openocd-rp2040
pico-debug-probe
# Write to the pico
picotool
picocom
# Use clangd for cmakelists
clang-tools
asm-lsp
];
# Build so that clangd files are created on entry
# Regular files can be compiled with `make`
enterShell = "cmake -S $DEVENV_ROOT/pico-apps -B $DEVENV_ROOT/pico-apps/build";
env = {
# Make pico sdk available
PICO_SDK_PATH = "${pico-sdk-full}/lib/pico-sdk";
# Have cmake generate files for clangd
CMAKE_EXPORT_COMPILE_COMMANDS = true;
};
}
To make this work, I needed to patch the debug probe’s rtos import script, here is the patch I applied:
--- a/FreeRTOS_Kernel_import.cmake
+++ b/FreeRTOS_Kernel_import.cmake
@@ -13,14 +13,8 @@ endif ()
# first pass we look in old tree; second pass we look in new tree
foreach(SEARCH_PASS RANGE 0 1)
- if (SEARCH_PASS)
- # ports may be moving to submodule in the future
- set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "portable/ThirdParty/Community-Supported-Ports/GCC")
- set(FREERTOS_KERNEL_RP2040_BACK_PATH "../../../../..")
- else()
- set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "portable/ThirdParty/GCC")
- set(FREERTOS_KERNEL_RP2040_BACK_PATH "../../../..")
- endif()
+ set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "portable/ThirdParty/GCC")
+ set(FREERTOS_KERNEL_RP2040_BACK_PATH "../../../..")
if(PICO_PLATFORM STREQUAL "rp2040")
set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/RP2040")
Save this to ./fix-freertos-import.patch
next to devenv.nix
.
If you get issues make sure devenv.yaml
is using the latest version of nixpkgs
:
inputs:
nixpkgs:
url: github:nixos/nixpkgs/nixos-unstable
To start type devenv shell
or setup direnv.