Skip to content

How to Build the Firmware Samples

rbaron edited this page May 23, 2026 · 14 revisions

Firmware samples live in the code/samples/ directory. The parent code/ directory is a west workspace.

Pre-Built Binaries

Samples built with the default configs are readily available in the releases page. This is the easiest way to get started.

With nRF Connect for Desktop + Visual Studio Code

Clone the repo and initialize the west workspace in the code/ directory:

cd code/
west init -l prstlib
west update --narrow --fetch-opt=--depth=1

# Open VSCode on code/
code .

In the VSCode nRF Connect Extension, select Open an existing application and add one one the sample's directory (e.g.: code/samples/ble). Add a build configuration, and make sure to select the appropriate hardware target and version:

Build setup

With Docker

The code/scripts/build-with-docker.sh is a thin wrapper around the docker cli:

cd code/

./scripts/build-with-docker.sh --help
usage: build.sh <sample> [soc] [revision]
  sample    blinky | input | ble | soil-read-loop | zigbee
  soc       nrf52840 (default) | nrf52833
  revision  2.0.0 (default) | 1.2.0 | 1.1.0 | 1.0.0

env:
  CMAKE_EXTRA   extra -D… flags appended to west build

For example, building the ble sample for the nrf52840 on revision 2.0.0:

cd code/
./scripts/build-with-docker.sh ble nrf52840 2.0.0

...

225/225] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      200244 B         1 MB     19.10%
             RAM:       30588 B       256 KB     11.67%
        IDT_LIST:          0 GB        32 KB      0.00%
[8/10] Completed 'ble'
[9/10] cd /workspace/samples/ble/build_nrf52840_2.0.0/_sysbuild && /usr/bin/cmake -E true
[10/10] Generating ../merged.hex

The built binary will be in samples/ble/build_nrf52840_2.0.0/merged.hex.

[Experimental/Advanced/Fun Party Trick] With GitHub Codespaces

GitHub Codespaces let you run an instance of VS Code directly in your browser. More importantly, it also supports plugins, including nRF Connect for VS Code! This PR introduces .devcontainer/devcontainer.json, which configures a Codespace with both the nRF VS Code plugin, as well as the whole nRF Connect SDK + toolchain. This lets you edit code and build the sample straight in your browser.

  1. Go to Codespaces and click "New codespace"
  2. Select rbaron/b-parasite, branch nrf-connect
  3. Wait. The underlying Docker image is pretty big and the build might fail. It worked on the second try for me
  4. Once the codespace is ready, navigate to code/nrf-connect/samples/ble, select ble.code-workspace and click on "Open workspace". This makes sure both the ble sample and the prstlib are present in the workspace
  5. Build the sample normally, as described in the nRF Connect SDK docs
  6. Download the built sample from ble/build/zephyr/zephyr.hex

Clone this wiki locally