- OpenThread on EFR32
This directory contains example platform drivers for the Silicon Labs EFR32MG based on EFR32™ Mighty Gecko Wireless Starter Kit or Thunderboard™ Sense 2 Sensor-to-Cloud Advanced IoT Development Kit.
The example platform drivers are intended to present the minimal code necessary to support OpenThread. EFR32MG has rich memory and peripheral resources which can support all OpenThread capabilities.
See EFR32 Sleepy Demo Example for instructions for an example that uses the low-energy modes of the EFR32MG when running as a Sleepy End Device.
When using this repo to generate a solution that requires two different projects, such as an RCP & OTBR, make sure they are relying on the same OpenThread version to ensure maximum compatibility. You can check which commit this repo relies upon in the "openthread" submodule (in the root of this repo).
If your OTBR project was generated using the Silabs SiSDK / Simplicity Studio, we recommend to also use it to generate the RCP project and not this repo. This will mitigate potential incompatibility issues due to mismatched OpenThread versions.
Download and install the GNU toolchain for ARM Cortex-M.
In a bash
terminal, follow these instructions to install the GNU toolchain and other dependencies.
$ cd <path-to-ot-efr32>
$ ./script/bootstrap
Install Simplicity Studio to flash, debug, and make use of logging features with SEGGER J-Link.
Alternatively, the J-Link software pack can be used to flash and debug.
Before building example apps, make sure to initialize all submodules. Afterward, the build can be launched using ./script/build
.
Example
The example below demonstrates how to build for efr32mg24
on brd4186c
, but the same command maybe used for other platforms and boards.
$ cd <path-to-ot-efr32>
$ git submodule update --init --recursive .
$ board="brd4186c"
$ ./script/build $board
...
-- Configuring done
-- Generating done
-- Build files have been written to: <path-to-ot-efr32>/build/<board>
+ [[ -n ot-rcp ot-cli-ftd ot-cli-mtd ot-ncp-ftd ot-ncp-mtd sleepy-demo-ftd sleepy-demo-mtd ]]
+ ninja ot-rcp ot-cli-ftd ot-cli-mtd ot-ncp-ftd ot-ncp-mtd sleepy-demo-ftd sleepy-demo-mtd
[572/572] Linking CXX executable bin/ot-ncp-ftd
+ cd <path-to-ot-efr32>
After a successful build, the elf
files are found in <path-to-ot-efr32>/build/<board>/bin
.
$ ls build/$board/bin
ot-cli-ftd ot-cli-mtd ot-ncp-ftd ot-ncp-mtd ot-rcp sleepy-demo-ftd sleepy-demo-mtd
ot-cli-ftd.s37 ot-cli-mtd.s37 ot-ncp-ftd.s37 ot-ncp-mtd.s37 ot-rcp.s37 sleepy-demo-ftd.s37 sleepy-demo-mtd.s37
Compiled binaries may be flashed onto the EFR32 using various tools from the [J-Link][j-link] software pack. EFR32 Starter kit mainboard integrates an on-board SEGGER J-Link debugger.
Simplicity Commander provides command line and graphical interfaces for J-Link Commander. It's included as part of Simplicity Studio and is also available as a standalone application
For Windows and Linux, the Simplicity Commander executable can be found in the location that the package is extracted. On MacOS, the executable can be found at the following directory:
$ /Applications/Commander.app/Contents/MacOS
Launch the Simplicity Commander executable commander
at the path stated above to open the Commander GUI, and perform the following steps to flash build artifacts to a target device:
- In the J-Link Device drop-down list select the serial number of the device to flash.
- Click the Adapter Connect button.
- Ensure the Debug Interface drop-down list is set to SWD and click the Target Connect button.
- Click on the Flash icon on the left side of the window to switch to the flash page.
- In the Flash MCU pane, enter the path of the
ot-cli-ftd.s37
file or choose the file with the Browse... button. - Click the Flash button located under the Browse... button.
The Simplicity Commander CLI provides another method of flashing binaries to a device without opening a GUI.
When using Simplicity Commander in CLI mode, it is highly recommended to add the directory of the executable to your environment's PATH
variable. This can be done with the following command:
$ export PATH=$PATH:<path-to-executable-directory>
Once the executable is visible from PATH
, build artifacts can be flashed to the target device with the flash
command.
Example: Flashing ot-cli-ftd
to a device using its jlink serial number:
$ commander flash --serialno=<jlink-serial-number> <path-to-build-directory>/ot-cli-ftd.s37
Example: Flashing ot-cli-ftd
to a device using its IP address:
$ commander flash --ip=<target-device-ip-address> <path-to-build-directory>/ot-cli-ftd.s37
For more information see UG162: Simplicity Commander Reference
Compiled binaries also may be flashed onto the specified EFR32 dev board using J-Link Commander.
Example: Flashing ot-cli-ftd
to a brd4186c
device
$ cd <path-to-ot-efr32>
$ source ./script/efr32-definitions
$ board="brd4186c"
$ cd <path-to-ot-efr32>/build/$board/bin
$ arm-none-eabi-objcopy -O ihex ot-cli-ftd ot-cli-ftd.hex
$ <path-to-JLinkGDBServer>/JLinkExe -device $(efr32_get_jlink_device $board) -speed 4000 -if SWD -autoconnect 1 -SelectEmuBySN <SerialNo>
$ J-Link>loadfile ot-cli-ftd.hex
$ J-Link>r
$ J-Link>q
Note: SerialNo
is J-Link serial number. Use the following command to get the serial number of the connected J-Link.
$ JLinkExe
-
Flash two EFR32 boards with the
CLI example
firmware (as shown above). -
Open terminal to first device
/dev/ttyACM0
(serial port settings: 115200 8-N-1). Typehelp
for a list of commands.> help help channel childtimeout contextreusedelay extaddr extpanid ipaddr keysequence leaderweight mode netdata register networkidtimeout networkkey networkname panid ping prefix releaserouterid rloc16 route routerupgradethreshold scan start state stop
-
Start a Thread network as Leader.
> dataset init new Done > dataset Active Timestamp: 1 Channel: 13 Channel Mask: 0x07fff800 Ext PAN ID: d63e8e3e495ebbc3 Mesh Local Prefix: fd3d:b50b:f96d:722d::/64 Network Key: dfd34f0f05cad978ec4e32b0413038ff Network Name: OpenThread-8f28 PAN ID: 0x8f28 PSKc: c23a76e98f1a6483639b1ac1271e2e27 Security Policy: 0, onrcb Done > dataset commit active Done > ifconfig up Done > thread start Done wait a couple of seconds... > state leader Done
-
Open terminal to second device
/dev/ttyACM1
(serial port settings: 115200 8-N-1) and attach it to the Thread network as a Router.> dataset networkkey dfd34f0f05cad978ec4e32b0413038ff Done > dataset commit active Done > routerselectionjitter 1 Done > ifconfig up Done > thread start Done wait a couple of seconds... > state router Done
-
List all IPv6 addresses of Leader.
> ipaddr fd3d:b50b:f96d:722d:0:ff:fe00:fc00 fd3d:b50b:f96d:722d:0:ff:fe00:c00 fd3d:b50b:f96d:722d:7a73:bff6:9093:9117 fe80:0:0:0:6c41:9001:f3d6:4148 Done
-
Send an ICMPv6 ping to Leader's Mesh-EID IPv6 address.
> ping fd3d:b50b:f96d:722d:7a73:bff6:9093:9117 16 bytes from fd3d:b50b:f96d:722d:558:f56b:d688:799: icmp_seq=1 hlim=64 time=24ms
For a list of all available commands, visit OpenThread CLI Reference.
A debug session may be started with J-LinkGDBServer.
Example: Debugging ot-cli-ftd
on a brd4186c
device
$ source <path-to-ot-efr32>/script/efr32-definitions
$ board="brd4186c"
$ cd <path-to-JLinkGDBServer>
$ sudo ./JLinkGDBServer -if swd -singlerun -device $(efr32_get_jlink_device $board)
$ cd <path-to-ot-efr32>/build/$board/bin
$ arm-none-eabi-gdb ot-cli-ftd
$ (gdb) target remote 127.0.0.1:2331
$ (gdb) load
$ (gdb) monitor reset
$ (gdb) c
The above example demonstrates basic OpenThread capabilities. Enable more features/roles (e.g. commissioner, joiner, DHCPv6 Server/Client, etc.) by assigning compile-options before compiling.
Example Building efr32mg24 for board brd4186c
with some more features/roles enabled
$ cd <path-to-ot-efr32>
$ ./script/build brd4186c -DOT_COMMISSIONER=ON -DOT_JOINER=ON -DOT_DHCP6_CLIENT=ON -DOT_DHCP6_SERVER=ON
The following toolchain has been used for testing and verification:
- gcc version 7.3.1
The EFR32 example has been verified with following Silicon Labs Simplicity SDK Library version:
- Silicon Labs Simplicity SDK v4.1.x