- Note
- OpenThread is still in prerelease phase and its API changes frequently. Keep in mind that when the API changes, the examples might not compile with the latest OpenThread version right away without fixes.
It is recommended to use the provided, precompiled version of the OpenThread library. However, you can also compile the latest version from GitHub. You can either:
- build the OpenThread library in POSIX environment on Mac or Linux;
- use the provided GCC, IAR, or Keil 5 projects to build the library on Windows.
Before building the latest OT libraries, you can define your own MA-L (MAC Address Block Large), formerly called OUI, by configuring the device's IEEE EUI-64 address.
Building the library with GCC on Linux or Mac (recommended)
Follow the following steps to build the library:
- Make sure you have GNU Autotools installed on your system. Refer to the documentation of your distribution for information on how to download and install them.
- Download or clone the OpenThread stack repository.
- Navigate into the repository root folder.
- Depending on your SoC, run one of the following commands:
- nRF52840 - UART transport:
$ ./bootstrap
$ make -f examples/Makefile-nrf52840 BORDER_AGENT=1 BORDER_ROUTER=1 COAP=1 COMMISSIONER=1 DISABLE_BUILTIN_MBEDTLS=1 DNS_CLIENT=1 DIAGNOSTIC=1 EXTERNAL_HEAP=1 JOINER=1 LINK_RAW=1 MAC_FILTER=1 MTD_NETDIAG=1 SERVICE=1 UDP_FORWARD=1 ECDSA=1 SNTP_CLIENT=1 COAPS=1 DHCP6_SERVER=1 DHCP6_CLIENT=1
- nRF52840 - USB transport:
$ ./bootstrap
$ make -f examples/Makefile-nrf52840 BORDER_AGENT=1 BORDER_ROUTER=1 COAP=1 COMMISSIONER=1 DISABLE_BUILTIN_MBEDTLS=1 DNS_CLIENT=1 DIAGNOSTIC=1 EXTERNAL_HEAP=1 JOINER=1 LINK_RAW=1 MAC_FILTER=1 MTD_NETDIAG=1 SERVICE=1 UDP_FORWARD=1 ECDSA=1 SNTP_CLIENT=1 COAPS=1 DHCP6_SERVER=1 DHCP6_CLIENT=1 USB=1
- Note
- For PCA10059 support in a bare OpenThread environment, you need to add
BOOTLOADER=USB
flag.
- nRF52840 - SPI transport:
$ ./bootstrap
$ make -f examples/Makefile-nrf52840 BORDER_AGENT=1 BORDER_ROUTER=1 COAP=1 COMMISSIONER=1 DISABLE_BUILTIN_MBEDTLS=1 DNS_CLIENT=1 DIAGNOSTIC=1 EXTERNAL_HEAP=1 JOINER=1 LINK_RAW=1 MAC_FILTER=1 MTD_NETDIAG=1 SERVICE=1 UDP_FORWARD=1 ECDSA=1 SNTP_CLIENT=1 COAPS=1 DHCP6_SERVER=1 DHCP6_CLIENT=1 NCP_SPI=1
- nRF52811 - UART transport:
$ ./bootstrap
$ make -f examples/Makefile-nrf52811 BORDER_ROUTER=1 COAP=1 DIAGNOSTIC=1 DNS_CLIENT=1 EXTERNAL_HEAP=1 LINK_RAW=1 MAC_FILTER=1 MTD_NETDIAG=1
- nRF52811 - SPI transport:
$ ./bootstrap
$ make -f examples/Makefile-nrf52811 BORDER_ROUTER=1 COAP=1 DIAGNOSTIC=1 DNS_CLIENT=1 EXTERNAL_HEAP=1 LINK_RAW=1 MAC_FILTER=1 MTD_NETDIAG=1 NCP_SPI=1
You can experiment with the build parameters, but make sure you include the parameters presented above. Otherwise, some examples might not compile or work properly.
- Because the SDK provides libraries with USB CDC, UART, and SPI support, rename the following USB and SPI libraries:
Default name | Rename to |
libopenthread-nrf52840-sdk.a | libopenthread-nrf52840-sdk-usb.a |
libopenthread-nrf52840-softdevice-sdk.a | libopenthread-nrf52840-sdk-softdevice-usb.a |
libopenthread-ncp-ftd.a | libopenthread-ncp-ftd-spi.a |
libopenthread-ncp-mtd.a | libopenthread-ncp-mtd-spi.a |
libopenthread-rcp.a | libopenthread-rcp-spi.a |
libopenthread-nrf52840-sdk.a | libopenthread-nrf52840-sdk-spi.a |
libopenthread-nrf52840-softdevice-sdk.a | libopenthread-nrf52840-softdevice-sdk-spi.a |
libopenthread-nrf52811-sdk.a | libopenthread-nrf52811-sdk-spi.a |
-# Copy the libraries from <OpenThreadFolder>/output/<target>/lib
to the SDK folder: /external/openthread/lib/<target>gcc
.
- Copy the
<OpenThreadFolder>/include
folder to the /external/openthread
folder.
- Copy the platform specific
platform-fem.h
and platform-softdevice.h
files from /external/project/openthread/examples/platforms/nrf528xx/src
to the /external/openthread/include/platform
folder.
- Copy
openthread-system.h
file from /external/project/openthread/examples/platforms
to the /external/openthread/include/platform
folder.
Now you can recompile the examples with the latest libraries.
Building the library with GCC on Windows
- Download or clone the OpenThread stack repository to the
<InstallFolder>/external/openthread/project/openthread
folder.
- Run the following script to build all of the GCC libraries:
py -3 <InstallFolder>/external/openthread/project/build_gcc_libs.py
.
- After the libraries are built for all devices, use the following script to copy the compiled libraries to the output folder:
py -3 <InstallFolder>/external/openthread/project/import_libs.py gcc
.
Note that you can use the following script for a clean build of all GCC libraries:
py -3 <InstallFolder>/external/openthread/project/clean_gcc_libs.py
Now you can recompile the examples with the latest libraries.
Building the library with IAR
Follow these steps to build the library:
- Download or clone the OpenThread stack repository to the
<InstallFolder>/external/openthread/project/openthread
folder.
- Open the OpenThread workspaces for all devices, for example
<InstallFolder>/external/openthread/project/nrf52840/ot_nrf52840.eww
, with IAR Embedded Workbench.
- In IAR Embedded Workbench:
- Select all of the projects in the left panel.
- Right-click on any of them and select Make.
- After the libraries are built for all devices, use the following script to copy the compiled libraries to the output folder:
py -3 <InstallFolder>/external/openthread/project/import_libs.py iar
.
Now you can recompile the examples with the latest libraries.
Building the library with Keil 5
Follow these steps to build the library:
- Download or clone the OpenThread stack repository to the
<InstallFolder>/external/openthread/project/openthread
folder.
- You must build each of the libraries separately. Open the project of a specific OpenThread library (for example,
<InstallFolder>/external/openthread/project/nrf52833/openthread/ftd/arm5_no_packsc/openthread_lib_libopenthread_ftd.uvprojx
) with Keil µVision 5. - Note
- For nRF52840, the correct path is different for the Keil compiler, because of missing nrf_security support:
<InstallFolder>/external/openthread/project/keil
.
- In Keil µVision 5, select Project->Build Target.
- After the libraries are built for all devices, use the following script to copy the compiled libraries to the output folder:
py -3 <InstallFolder>/external/openthread/project/import_libs.py keil
.
Now you can recompile the examples with the latest libraries.
- Note
- OpenThread projects for GCC, IAR, and Keil 5 in this SDK were based on a specific OpenThread commit. Refer to the release notes for the commit ID. Using a more recent commit might require some manual changes in the project to compile libraries without errors. Also, the library configuration must be done manually in case a user wants to build the libraries in other configuration than provided.