Adding your own code

To maintain an application that uses the nRF Connect SDK, you should use the same tools that Nordic Semiconductor employs to develop it. This section describes suggested user workflows to develop and maintain an application based on the nRF Connect SDK.

See nRF Connect SDK code base for detailed information on how the nRF Connect SDK repositories are organized.

User workflows

The following workflows present different ways of adding your own code to the nRF Connect SDK. They describe the actual practicalities of developing an application that is based on the nRF Connect SDK from a version control and maintenance point of view.

Which user workflow to choose depends on the type of application, the timeframe to develop it, and the need to update the nRF Connect SDK version used.

All workflows are described under the following basic assumptions:

  • One or more applications are to be developed using the nRF Connect SDK.

  • Additional board definitions might be required by the user.

  • Additional libraries might be required by the user.

  • The term application refers to the application code and any board definitions and libraries it requires.

  • The application will require updates of the nRF Connect SDK revision.

Workflow 1: Avoid Git and west

If you have your own version control tools, you might want to simply not use Git or west at all, and instead rely on your own toolset. In such case, you must obtain a copy of the nRF Connect SDK on your file system and then manage the source code of both the SDK and your application yourself.

To obtain a copy of the nRF Connect SDK, you can use one of the following methods:

  • Install the nRF Connect SDK using the nRF Connect for VS Code extension and download the desired nRF Connect SDK version. This corresponds to steps 2 and 3 on the linked page.

  • Follow the instructions in the Obtaining a copy of the nRF Connect SDK section of the documentation. This requires you to install Git and west, but you can then ignore them from that point onwards.

If you need to update the copy of the nRF Connect SDK you are working with, you can obtain the source code again, or, if you have kept the original set of repositories, update it in the Toolchain Manager or by following steps in Updating a copy of the nRF Connect SDK.

Once you have obtained a copy of the nRF Connect SDK source code, which is self-contained in a single folder, you can then proceed to manage that code in any way you see fit.

Unless you take some additional steps, west itself must still be installed in order to build applications.

Workflow 2: Freestanding application repository

Another approach to maintaining your application is to completely decouple it from the nRF Connect SDK repositories and instead host it wherever you prefer - in Git, another version control system, or simply on your hard drive. This is typically also known as a freestanding or “out-of-tree” application, meaning that the application, board definitions, and any other libraries are actually outside any of the repositories provided by the nRF Connect SDK and can be placed anywhere at all.

As long as you do not need to make changes to any of the repositories of the nRF Connect SDK, you can use either the nRF Connect for VS Code extension or command line to get the source code and update it later, as described in Installing the nRF Connect SDK. This allows you to manage your application separately, whether it is inside or outside the top folder of the nRF Connect SDK. If you choose to have your application outside of the folder hierarchy of the nRF Connect SDK, the build system will find the location of the SDK through the ZEPHYR_BASE environment variable, which is set either through a script or manually in an IDE. More information about application development and the nRF Connect SDK build and configuration system can be found in the Build and configuration system documentation section.

The drawback with this approach is that any changes you make to the set of nRF Connect SDK repositories are not directly trackable using Git, since you do not have any of the nRF Connect SDK repositories forked. If you are tracking the main branch of the nRF Connect SDK, you can instead send the changes you require to the official repositories as Pull Requests, so that they are incorporated into the codebase.

Workflow 3: Application in a fork of sdk-nrf

Forking the sdk-nrf repository and adding the application to it is another valid option to develop and maintain your application. This approach also allows you to fork additional nRF Connect SDK repositories and point to those. This can be useful if you have to make changes to those repositories beyond adding your own application to the manifest repository.

In order to use this approach, you first need to get the source code (either through the Toolchain Manager or command line), and then fork the sdk-nrf repository. Once you have your own fork, you can start adding your application to your fork’s tree and push it to your own Git server. Every time you want to update the revision of the nRF Connect SDK that you want to use as a basis for your application, you must follow the instructions to update on your own fork of sdk-nrf.

If you have changes in additional repositories beyond sdk-nrf itself, you can point to your own forks of those in the west.yml included in your fork.