Introduction
This article will share manual manipulation to combine nRF5 SDK examples in one single project as well as fixes for faced issues. The use case discussed combines two SDK samples from “SDK_folder/examples/” :
- examples/dfu/secure_bootloader/pca10056_s140_ble
Secure bootloader for DFU (Device Firmware Update) - examples/peripheral/libuarte/pca10056
UART example
The objective of combining those projects is to implement UART communication in the bootloader.
Prerequisites
Hardware
- nRF52840 Development Kit
Software
Building projects separately
Before importing a project to another, it’s recommended to ensure each of the needed SDK examples can be built successfully.
Vfprintf error
If the error “__vfprintf.h: No such file or directory” is faced remove the file “SEGGER_RTT_Syscalls_SES.c” from SEGGER_RTT_Syscalls_SES folder:

Linking errors

If the linking errors “error: .text section is larger than specified size” and “error: .rodata section is larger than specified size“, remove the parameter size=”0x4″ for “.text” and “.rodata” sections in the “placement_flash.xml” file located in “ses/” folder:
<ProgramSection alignment="4" load="Yes" name=".text" />
<ProgramSection alignment="4" load="Yes" name=".rodata" />
The project could now be built successfully:

Combining the two projects
Adapting the sdk_config.h
Now that the two projects to be combined are ensured they can be built successfully, chose the one that will be used as main project to import the other project’s files. This article uses the secure_boot project as main project.
The “sdk_config.h” file can then be adapted as first step by adding needed configurations. To facilitate comparison of the two sdk_config files the external tool CMSIS will be used. The differences between the “secure_boot” and the “libuarte” config is depicted in figure 4:

The configurations highlighted in yellow are those for “libuarte” example to be added to “secure_boot”. The needed configurations can then be copied from“libuarte” sdk_config.h to “secure_boot” sdk_config.h file. The final configuration is shown in figure 5:

Adapting Preprocessor configuration
Adapting Preprocessor Definitions
Preprocessor definitions can be opened by right clicking a project> Options> Common> Preprocessor> Preprocessor definitions. Figure below shows differences between the used projects:

The highlighted definitions can then be copied and pasted to the secure_boot project’s definitions. The result definitions should look like below screenshot:

Adapting User Include Directories
Similarly to Preprocessor Definitions the “User Include Directories” option needs to be adapted by applying the same principle and making sure the paths are aligned with the same number of “../”. The include directories option can be opened by right clicking a project> Options> Common> Preprocessor> User Include Directories:

Adding project files
The needed project files can then be added to the main project (secure_boot) by right clicking the target folder> Add Existing File and browsing the file. The path to file can be obtained from the source project (libuarte) by right clicking the file> Copy Full Path.
The folders to be rectified in this use case are nRF_Drivers, nRF_Libraries and nRF_Log. Figure 9 show some of the files to be imported:

Fixing faced issues when building the project
Undeclared variables errors even when including “nrf_error.h”
Some declared variables in nrf_error.h file may be not recognized and may cause the following issues even if this header file is included in the source code:
- ‘NRF_ERROR_INVALID_PARAM’ undeclared (first use in this function)
- ‘NRF_SUCCESS’ undeclared (first use in this function); did you mean ‘EXIT_SUCCESS’?
- ‘NRF_ERROR_NO_MEM’ undeclared (first use in this function); did you mean ‘NRF_ERROR_IO_PENDING’?
- ‘NRF_ERROR_INVALID_LENGTH’ undeclared (first use in this function)

Those errors occur because of the presence of different nrf_error.h files in project folders. There is one in “/components/drivers_nrf/nrf_soc_nosd” and one in “components/softdevice/s140/headers” the first one is used in projects without softdevice (libuarte example) and the the second one is used in projects with softdevice (secure_boot example).
To fix this issue the User Include Directories needs to be rectified by removing “/components/drivers_nrf/nrf_soc_nosd” and keeping “components/softdevice/s140/headers”.
Similar errors may also occur after that in files originated from “libuarte” project (nrf_nvic.c and nrf_soc.c) such as shown in figure 11:

To fix those errors replace ‘#include “nrf_error.h”‘ with ‘#include <nrf_error.h>’ in the issued files (nrf_nvic.c and nrf_soc.c).
Multiple definition errors
Some defined functions in the main.c file may cause the following“multiple definition” errors:
- multiple definition of `app_error_handler’;
- multiple definition of `app_error_handler_bare’;

Those errors occur because some functions defined in main.c file are already defined in other files (app_error.c and app_error_handler_gcc.c) that were added in nRF_Libraries folder.
The fix would be to delete those files from nRF_Libraries if they’re defining unused functions for the project, or to simply remove the definitions from concerned files and keep those defined in the “main.c” file.
Linking errors
The “secure_boot” project size increased after importing “libuarte” project files which may cause linking errors such as:
- error: section .tdata overlaps absolute placed section .mbr_params_page
- section .mbr_params_page VMA [000fe000,000fefff] overlaps section .text VMA [000f83d4,000ff253]
- section .crypto_data VMA [000ff254,000ff25b] overlaps section .bootloader_settings_page VMA [000ff000,000fffff]

This issue can be fixed by decreasing the start address of the flash to support the project size. The start address is set by default to “0xF8000” and can e.g. be rectified to “0xF0000” in “Linker configuration> Section Placement Macros” so the final project can be built successfully:


Leave a Reply