Feedback
Feedback

If you are having issues with the exercises, please create a ticket on DevZone: devzone.nordicsemi.com
Click or drag files to this area to upload. You can upload up to 2 files.

Configuration files

Application and board configurations

Each application in the nRF Connect SDK must have an application configuration file, usually called prj.conf, that describes the software modules and kernel services used and their settings. The application configuration file is text-based and contains configuration options (often called symbols) in the form of:

CONFIG_<symbol_name>=<value>
Kconfig

Each configuration option must start with the prefix CONFIG_ followed by the name of the software module to configure, then the value to be set, with no spaces around the equals sign.

Let’s take a look at the application configuration file prj.conf from the blinky sample, which we covered in-depth in the previous lesson.

This file has only one line, seen below, that includes the GPIO driver.

CONFIG_GPIO=y
Kconfig

In other words, setting the CONFIG_GPIO-symbol will enable the inclusion of the source code of the GPIO driver into the build process and hence our application will be able to use it.

In addition to the application configuration file, an application inherits the board configuration file, <board_name>_defconfig, of the board that the application is built for.

Let’s take an example, the nRF52833 DK has the board configuration file nrf52833dk_nrf52833_defconfig available in <nRF Connect SDK Installation Path>\zephyr\boards\arm\nrf52833dk_nrf52833.

# SPDX-License-Identifier: Apache-2.0

CONFIG_SOC_SERIES_NRF52X=y
CONFIG_SOC_NRF52833_QIAA=y
CONFIG_BOARD_NRF52833DK_NRF52833=y

# Enable MPU
CONFIG_ARM_MPU=y

# Enable hardware stack protection
CONFIG_HW_STACK_PROTECTION=y

# Enable RTT
CONFIG_USE_SEGGER_RTT=y

# enable GPIO
CONFIG_GPIO=y

# enable uart driver
CONFIG_SERIAL=y

# enable console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

# additional board options
CONFIG_GPIO_AS_PINRESET=y
Kconfig

Board configuration file for the nRF52833 DK: nrf52833dk_nrf52833_defconfig

Note

Configuration options can be set both in the application configuration file and the board configuration file. In the example, CONFIG_GPIO symbol is set in both files. In this case, the value in the application configuration file always takes precedence.

The first three lines in the board configuration file includes software support specific to the nRF52833 DK and its nRF52833 SoC. The CONFIG_ARM_MPU is for the memory protection unit. This brings us to the question: How can we know the meaning of all these configuration options?

If you are using nRF Connect for VS Code, simply hovering the mouse over the configuration symbol will show a box that contains a description about the symbol.

Additionally, you can visit the documentation webpage and find the documentation for the specific symbol, for instance, CONFIG_GPIO.

Further examining the board configuration file of the nRF52833 DK, we can see that the UART driver (CONFIG_SERIAL), the RTT drivers, the libraries (CONFIG_USE_SEGGER_RTT), and the console drivers (CONFIG_CONSOLE) are included. CONFIG_UART_CONSOLE will make UART the default console output. All of these software components are core to interacting with a console.

Note

You should never modify any board configuration files. Instead, rely on the application configuration file to set new configurations and subsequently overwrite any default board configurations if needed.  If you change the board configuration file directly, then these changes will apply for all projects using that board.

Kernel Configuration (nRF Kconfig GUI)

In the nRF Connect SDK, symbols are grouped into menus and sub-menus to easily browse all available configurations.

An alternative way to modify the contents of the prj.conf (application configuration file) is by using the nRF Kconfig GUI . Kconfig refers to the software configurations and it groups all functionalities provided by the nRF Connect SDK and Zephyr into menus and submenus, which can be viewed in a graphical tree format.

The nRF Kconfig GUI view allows us to browse and implement the different functionalities available easily. Selecting/deselecting functionalities in the nRF Kconfig GUI corresponds to adding/removing lines in the prj.conf file.

nRF Kconfig GUI can be found under Actions in the RF Connect extension, as shown below.

nRF Kconfig GUI available in the Actions View of nRF Connect for VS Code

Important

Starting from nRF Connect SDK v2.8.0, Sysbuild is the default build system. nRF Kconfig GUI can allow you to display the Kconfig configurations for Sysbuild itself and any of its images in the project. This is done by first selecting the image of interest from the APPLICATIONS view and then clicking on the nRF Kconfig GUI in the ACTIONS view, as shown below where the application image is selected.

There are other visual editors for Kconfig; you can access them through the submenu under nRF Kconfig GUI, as shown below.

You can also change the default Kconfig visual editor a by going to File -> Preferences -> Settings -> Extensions -> nRF Connect -> Kconfig Interface and choosing the options from the dropdown list.

Kconfig is organized into menus that group related configurations together, such as Modules, Device Drivers, C Library, and Boot Options. Menus can have submenus, and submenus can have submenus of their own. If we expand any of these menus, for instance, Device Drivers, all symbols related to this category will show up, some with menus of their own.

Kconfig in nRF Connect for VS Code
blinky sample

A checked box indicated that this symbol is enabled, either in application configuration file or in the board configuration file. For example, if we type “GPIO” in the search bar at the top, we can see that the GPIO drivers are enabled in this blinky sample configuration.

GPIO driver enabled in blinky Kconfig

After making changes to in the Kconfig menu, there are 3 different ways to save those changes, as shown below.

3 different ways to save changes

The “Apply” option saves the changes in a temporary configuration file (.config file located in build->Zephyr) and these changes are reverted once you build a pristine build of your application.

The “Save to file” option saves the changes to the prj.conf file, thus preserving the changes across different builds.

The “Save minimal” option saves only the changes we just made into a separate file.

More on this

There are two interactive Kconfig interfaces (nRF Kconfig GUI , menuconfig) supported by nRF Connect for VS code. They all allow you to explore related configuration options and know their values. One advantage of menuconfig is that it lists the dependencies and where the Symbol is set. However, the disadvantage of menuconfig is that configurations are only set temporarily and will be lost any time you do a clean(pristine) build. On the other hand, nRF Kconfig GUI is the only graphical interface that can allow you to save the configurations permanently in prj.conf

Register an account
Already have an account? Log in
(All fields are required unless specified optional)

  • 8 or more characters
  • Upper and lower case letters
  • At least one number or special character

Forgot your password?
Enter the email associated with your account, and we will send you a link to reset your password.