Skip to content

How to Build the Firmware Samples

rbaron edited this page May 10, 2024 · 9 revisions

Each firmware sample in the code/nrf-connect/ directory is a nRF Connect SDK project.

With nRF Connect for Desktop + Visual Studio Code

This is the usual way of building the nRF Connect SDK samples. The only caveat is that, for each sample here, you also need to add the code/nrf-connect/prstlib/ directory to your workspace in addition to the sample directory itself. The prstlib/ contains common source code for reading sensors and also common board definitions. There is a .code-workspace file inside each sample that does this automatically.

We support different nRF52 SoCs in different hardware versions, and you can select them as normally done in the nRF Connect VSCode extension:

image

With Docker

For example, let's build the ble sample for the nRF52840, revision 2.0.0.

Step 1.

From the repo's root directory:

docker run --rm -v ${PWD}:/repo nordicplayground/nrfconnect-sdk:v2.5-branch west build --pristine --board [email protected] --build-dir /repo/code/nrf-connect/samples/ble/build /repo/code/nrf-connect/samples/ble

The output will be in code/nrf-connect/samples/ble/build/zephyr/zephyr.hex. To build other samples, replace ble with the other sample's name.

[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