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_dynamic_mtd_coap_client
, 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 which must be added to the project.
The default set of libraries for an FTD Thread device which 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:
For reference, see this Makefile that is already ported: <InstallFolder>\examples\multiprotocol\experimental\ble_thread_dynamic_mtd_coap_client\pca10056\s140\armgcc\Makefile
In order 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.
In order 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
folder.
After the folder path is added, depending on your project location, the following record should be visible.
For reference, see the IAR project that is already ported: <InstallFolder>\examples\multiprotocol\experimental\ble_thread_dynamic_mtd_coap_client\ble_thread_dynamic_mtd_coap_client.eww
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. In addition, to ensure that the radio buffer is accessible for EasyDMA, it is recommended to allocate it at the beginning of the RAM.
It is recommended to use the example linker script that is already ported: <InstallFolder>\external\openthread\linker_scripts\openthread_nrf52840_multiprotocol.ld
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.
1) At the top of the main.c file, add all necessary includes, depending on the Thread use case.
2) After the section which contains defines and static variables, add the following line:
3) Ensure that application registers the SoftDevice’s SoC event handler (using the softdevice_sys_evt_handler_set
function). If the handler is not already registered, add the following snippet inside of the BLE stack initialization function (after softdevice_ble_evt_handler_set
).
4) Inside of the sys_evt_dispatch function, add OpenThread’s SoftDevice platform handler called PlatformSoftdeviceSocEvtHandler
.
5) Add the function for initializing the Thread protocol. Note that it depends on your Thread use case.
For reference on how to add the CoAP functionality (for example), or use the low power mode, see: <InstallFolder>\examples\multiprotocol\experimental\ble_thread_dynamic_mtd_coap_client\main.c
6) Call the thread_init
function inside of the application main function.
Important! This function must be called after the SoftDevice has been initialized.
7) 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:
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.