- 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.
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 DNS_CLIENT=1 JOINER=1 LINK_RAW=1 MAC_FILTER=1 MTD_NETDIAG=1 SERVICE=1 UDP_FORWARD=1 ECDSA=1 SNTP_CLIENT=1 COAPS=1
- nRF52840 - USB transport:
$ ./bootstrap
$ make -f examples/Makefile-nrf52840 BORDER_AGENT=1 BORDER_ROUTER=1 COAP=1 COMMISSIONER=1 DNS_CLIENT=1 JOINER=1 LINK_RAW=1 MAC_FILTER=1 MTD_NETDIAG=1 SERVICE=1 UDP_FORWARD=1 ECDSA=1 SNTP_CLIENT=1 COAPS=1 USB=1
- Note
- For PCA10059 support in a bare OpenThread environment, you need to add
BOOTLOADER=1
flag.
- nRF52840 - SPI transport:
$ ./bootstrap
$ make -f examples/Makefile-nrf52840 BORDER_AGENT=1 BORDER_ROUTER=1 COAP=1 COMMISSIONER=1 DNS_CLIENT=1 JOINER=1 LINK_RAW=1 MAC_FILTER=1 MTD_NETDIAG=1 SERVICE=1 UDP_FORWARD=1 ECDSA=1 SNTP_CLIENT=1 COAPS=1 NCP_SPI=1
- nRF52811 - UART transport:
$ ./bootstrap
$ make -f examples/Makefile-nrf52811 BORDER_ROUTER=1 COAP=1 DNS_CLIENT=1 LINK_RAW=1 MAC_FILTER=1 MTD_NETDIAG=1
- nRF52811 - SPI transport:
$ ./bootstrap
$ make -f examples/Makefile-nrf52811 BORDER_ROUTER=1 COAP=1 DNS_CLIENT=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. To create libraries suitable for performing Thread certification tests, run make
commands above with the following additional parameters: DHCP6_CLIENT=1 DHCP6_SERVER=1 CERT_LOG=1
.
- 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-ncp-radio.a | libopenthread-ncp-radio-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 nRF52840-specific
platform-fem.h
and platform-softdevice.h
files from /external/project/openthread/examples/platforms/nrf52840
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
build_gcc_libs.bat
script to build all of the libraries.
- After the libraries are built, use the provided script (
py -3 <InstallFolder>/external/openthread/project/import_libs.py gcc
) to copy the compiled libraries to the output folder.
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 workspace (
<InstallFolder>/external/openthread/project/openthread_lib.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, use the provided script (
py -3 <InstallFolder>/external/openthread/project/import_libs.py iar
) to copy the compiled libraries to the output folder.
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/lib/openthread/ftd/arm5_no_packsc/openthread_lib_libopenthread_ftd.uvprojx
) with Keil µVision 5.
- In Keil µVision 5, select Project->Build Target.
- After the libraries are built, use the provided script (
py -3 <InstallFolder>/external/openthread/project/import_libs.py keil
) to copy the compiled libraries to the output folder.
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.