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:
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.
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.
Board configuration file for the nRF52833 DK: nrf52833dk_nrf52833_defconfig
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. Another way is by using an interface called guiconfig, which will be covered in the next section.
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.
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 (Kconfig)
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 Kconfig view. Kconfig refers to the Zephyr kernel configuration and it groups all functionalities provided by the Zephyr kernel into menus and submenus which can be viewed in a graphical tree format.
The Kconfig view allows us to easily browse and implement the different functionalities available. Selecting/deselecting functionalities in the Kconfig corresponds to adding/removing lines in the prj.conf file.
Kconfig can be found under Actions in the RF Connect extension, as shown below.
If instead of Kconfig, you find GUIconfig, you can still view Kconfig by viewing the submenu under Guiconfig, as shown below.
You can also make Kconfig appear by default instead of GUIconfig by going to File -> Preferences -> Settings -> Extensions -> nRF Connect -> Kconfig Interface and choose Kconfig 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.
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.
After making changes to in the Kconfig menu, there are 3 different ways to save those changes, as shown below.
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.
There are three interactive Kconfig interfaces (Kconfig, guiconfig, menuconfig) supported by nRF Connect for VS code. They all allow you to explore related configuration options and know their values. One advantage of guiconfig is that it lists the dependencies and where the Symbol is set. However, the disadvantage of guiconfig and menuconfig is that configurations are only set temporarily and will be lost any time you do a clean build. On the other hand, Kconfig is the only GUI that can allow you to save the configurations permanently in prj.conf