Applications demonstrating the Bluetooth peripheral functionality can be extended by adding Thread protocol support to them. In this way, dynamic multiprotocol functionality can be achieved.
For reference, see <InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_dyn_mtd_coap_cli
, which is a modified version of the ble_app_uart
example.
For more information about multiprotocol support, see Multiprotocol support with BLE/Bluetooth.
Add the following settings to sdk_config.h
in order to configure the Thread stack:
Modify these settings if they appear in sdk_config.h:
nRF5 SDK for Thread provides precompiled OpenThread libraries that must be added to the project.
The default set of libraries for an FTD Thread device that uses CLI is the following:
/external/openthread/lib/<TOOLCHAIN>/libopenthread-cli-ftd.a
/external/openthread/lib/<TOOLCHAIN>/libopenthread-ftd.a
/external/openthread/lib/<TOOLCHAIN>/libopenthread-nrf52840-softdevice-sdk.a
/external/openthread/lib/<TOOLCHAIN>/libmbedcrypto.a
/external/nrf_cc310/lib/libnrf_cc310_0.9.12.a
/external/nrf_cc310/lib/libnrf_cc310_short_wchar_0.9.12.a
/external/nrf_cc310/lib/nrf_cc310_keil_0.9.12.lib
Add the following snippet to the Makefile of a BLE application:
To use the Thread API, you must add header include paths. To do this, add the following line inside of the INC_FOLDERS section:
Add the path to the Thread utils source file in the SRC_FILES section:
For reference, see this Makefile that is already ported: <InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_dyn_mtd_coap_cli\pca10056\s140\armgcc\Makefile
To add libraries under the IAR compiler, click Project -> Add Files. Then, choose the file type of Library/Object Files and navigate to \external\openthread\lib\iar
.
Select all required libraries according to the above section. Note that IAR additionally requires the libopenthread-platform-utils.a
library.
To use the Thread API, you must add header include paths. To do this, click Project -> Options and choose the C/C++ Compiler section. In the Preprocessor tab, navigate to the Additional include directory section. Add the path to the \external\openthread\include
and \components\thread\utils
folders.
After the folder paths are added, depending on your project location, the following records will be visible:
You must also add the Thread utils source file. Select Project -> Add Files and add the \components\thread\utils\thread_utils.c
source file.
The final step is to unselect the Perform C++ Virtual Function Elimination option in Project -> Options -> Linker -> Optimizations.
For reference, see the IAR project that is already ported: <InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_dyn_mtd_coap_cli\ble_thread_dyn_mtd_coap_cli.eww
.
To add libraries under the Keil 5 compiler, add a new group to the project by clicking on the project, selecting the Add Group option, and creating a group named 'Thread'.
Add all required libraries according to above section. Click on the new group and select Add Existing Files to Group 'Thread'. Then, choose the file type of Toolchain Library file and select all required libraries from \external\openthread\lib\keil
and \external\nrf_cc310\lib
. Note that Keil 5 additionally requires the libopenthread-platform-utils.a
library.
To use the Thread API, you must add header include paths. To do this, click on the project, select Options for Target'nrf52840', and choose the C/C++ section. In the Include Paths section, add the path to the \external\openthread\include
and \components\thread\utils
folders.
After folder paths are added, depending on your project location, the following records will be visible:
You must also add the Thread utils source file. Click on the Thread group and select Add Existing Files to Group 'Thread'. Select the \components\thread\utils\thread_utils.c
source file.
Keil 5 does not use linker scripts. Therefore, it does not require any modifications.
For reference, see this Keil 5 project that is already ported: <InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_dyn_mtd_coap_cli\pca10056\s140\arm5_no_packs\ble_thread_dyn_mtd_coap_cli_pca10056_s140.uvprojx
.
To add libraries under the SES, click Project -> Add Existing File.... Then, choose the file type of All files and navigate to \external\openthread\lib\gcc
. You also need to add the GCC version of the CC310 library from \external\nrf_cc310\lib
.
Select all needed libraries as listed in the GCC section.
To use the Thread API, you need to add headers include paths. To do that, click on the project, select Edit options, and choose the Preprocessor section. In the User Include Directories section, add the path to the \external\openthread\include
and \components\thread\utils
folders:
The include paths might vary depending on your project location.
You must also add the Thread utils source files. Click Project -> Add Existing File..., navigate to \components\thread\utils
, and select the thread_utils.c
and thread_assert.c
source files.
For reference, see the SES project that is already ported: <InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_dyn_mtd_coap_cli\pca10056\s140\ses\ble_thread_dyn_mtd_coap_cli_pca10056_s140.emProject
.
Thread requires a special block in the flash memory to store protocol-specific data, such as Active and Pending Dataset or Parent/Child information. This data is necessary for synchronization after reset.
It is recommended to use the example linker script that is already ported: <InstallFolder>\external\openthread\linker_scripts\openthread_nrf52840_multiprotocol.ld
. To change the linker file, click Project -> Options and choose the Linker section. On the Config tab, select the appropriate linker file in the Linker configuration file section.
Note that it might be possible to adjust the RAM start of the application, which depends on the SoftDevice configuration. To ensure that the RAM start is set correctly, set the ORIGIN
and LENGTH
variables of the RAM section to what is set in the original example.
For example:
It is recommended to use the example linker script that is already ported: <InstallFolder>\external\openthread\linker_scripts\openthread_nrf52840_multiprotocol.icf
Note that it may be possible to adjust the RAM start of the application, which depends on the SoftDevice configuration. To ensure that the RAM start is set correctly, set the __ICFEDIT_region_RAM_start__
and __ICFEDIT_region_RAM_end__
variables to what is set in the original example.
For example:
You must add the following section at the end of the flash_placement.xml
file for the OpenThread persistent data:
You must also modify the project file manually to export new linker symbols correctly. Open ble_app_uart_pca10056_s140.emProject
with a text editor and replace the following lines:
Replace the lines with the following:
Make sure you apply the following changes:
main.c
file, add all necessary includes, depending on the Thread use case: NRF_SDH_SOC_OBSERVER
macro). If the handler is not already registered, add the following snippet in the BLE stack initialization function (after NRF_SDH_BLE_OBSERVER
): otSysSoftdeviceSocEvtHandler
. <InstallFolder>\examples\multiprotocol\ble_thread\ble_thread_dyn_mtd_coap_cli\main.c
.thread_instance_init
function inside of the application main function. power_manage
function, which calls the sd_app_evt_wait
SoftDevice API function, modify the above snippet to: sdk_config.h
to reserve 4 flash pages for the Thread stack (for example, set to 4 for default FDS virtual page size).Timeslot API has been tested with a set of default parameters on the nRF52840 Development Kit. These parameters are preset when the PlatformInit
function is invoked.
However, in case your application needs to use a different set of parameters for the Timeslot API, the library exposes the PlatformSoftdeviceRaalConfig
function to change the default Timeslot API parameters.
One of the parameters is the crystal accuracy in PPM units, which by default is set to 25 PPM. The application can use the PlatformSoftdeviceRaalConfig
function to change the PPM value of the currently used crystal.
Instructions on how to select other parameters for specific applications will be available in the subsequent releases of nRF5 SDK for Thread.
Note that OpenThread's hardware requirements must be met in transformed examples. See Hardware support and requirements.