Applications demonstrating the Bluetooth peripheral functionality may be extended by adding Thread protocol support to them. In this way, dynamic multiprotocol functionality can be achieved.
For reference, see <InstallFolder>\examples\multiprotocol\experimental\ble_thread_dyn_mtd_coap_cli
, which is a modified version of the ble_app_uart
example.
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:
Note that you may need to use another set of libraries, depending on the Thread use case that you aim for. See OpenThread libraries.
Add the below snippet to the Makefile of a BLE application:
In order to use the Thread API, you need to add headers include paths. To do that, 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\experimental\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 needed libraries according to the above section. Note that IAR additionally requires the libopenthread-platform-utils.a
library.
To use the Thread API, you need to add headers include paths. To do that, 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\experimental\utils
folders.
After the folder paths are added, depending on your project location, the following records should be visible.
You must also add the Thread utils source file. Select Project -> Add Files and add the \components\thread\experimental\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\experimental\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 needed libraries according to above section. Click on the freshly created 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 need to add headers include paths. To do that, 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\experimental\utils
folders.
After folder paths are added, depending on your project location, the following records should 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\experimental\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\experimental\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\experimental\utils
folders:
The include paths may vary depending on your project location.
You must also add the Thread utils source files. Click Project -> Add Existing File..., navigate to \components\thread\experimental\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\experimental\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 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 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.
E.g.
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:
with the following:
1) At the top of the main.c file, add all necessary includes, depending on the Thread use case.
2) Ensure that the application registers the SoftDevice's SoC event handler (using the 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
).
3) Inside of the soc_evt_handler function, add OpenThread's SoftDevice platform handler called PlatformSoftdeviceSocEvtHandler
.
4) Add the function for initializing the Thread protocol. Note that it depends on your Thread use case.
If you wish to handle Thread device state changes, you must add an appropriate handler.
Initialization:
For reference on how to add the CoAP functionality (for example) see: <InstallFolder>\examples\multiprotocol\experimental\ble_thread_dyn_mtd_coap_cli\main.c
5) Call the thread_instance_init
function inside of the application main function.
Important! This function must be called after the SoftDevice has been initialized.
6) Add the following snippet inside the main loop of your application:
In case the application enters the 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 (e.g. 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 may 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. Refer to the Hardware requirements page.