Skip to main content
BlogNewsTop News

Developing and testing Bluetooth Low Energy products on nRF52840 in Renode and Zephyr

By August 11, 2022August 16th, 2022No Comments

Written by Michael Gielda, Chair of the Zephyr Marketing Committee and VP of Development of Antmicro

The Bluetooth Low Energy (LE) connectivity standard has gained immense popularity in recent years, mainly due to the growing ubiquity of IoT solutions in both consumer electronics and industry. Thanks to its low-power nature, it is widely used in healthcare (e.g. in blood pressure monitors), wearables, and smart home appliances. To support product development with Bluetooth LE, Antmicro implemented support for the protocol in Renode, Antmicro’s open-source software development framework, with the Nordic Semiconductor nRF52840 SoC as the first platform to do so.

Renode, Zephyr, and the nRF52840

Renode has been providing Antmicro customers and the community with multi-node simulation capabilities for many years now, but until recently the attention was mainly focused on wired or IEEE 802.15.4 networks. However, as a Platinum Member of the Zephyr Project, which among other things features a completely open-source Bluetooth LE stack, Antmicro is in a unique position to cooperate with chip vendors focusing on Bluetooth LE such as Nordic Semiconductors to fully support their platforms in Renode – helping their customers get the tools and expertise they need to develop well-tested solutions using the low-power standard.

Zephyr is a natural choice for many of Antmicro’s customers because of its open Bluetooth LE stack and its wide support for a variety of popular SoCs, such as the nRF52840 which has been available in Renode for some time now.

Renode has extensive support for boards (including many of Nordic’s Bluetooth LE-enabled boards) available in Zephyr, which you can check in the Renode Zephyr dashboard, an interactive CI dashboard developed to showcase how various Zephyr-based firmware (such as TF Lite Micro, MicroPython and soon also micro-ROS) work in Renode.

Renode for multi-node Bluetooth LE development and debugging

Developing multi-node setups is a complex process, involving many unique problems. In a typical scenario, when working with real hardware, you cannot fully isolate the device you’re testing, and any attempt to debug it will make other nodes perceive the debugged node as unresponsive. 

Hence, the functional simulation offered by Renode may come as an immense help in thoroughly testing Bluetooth LE products, thanks to the ability to completely isolate the simulated device from its environment, and fully and deterministically control the simulation process. Every part of Renode’s simulation is controlled by a central virtual time controller, meaning that the communication between the nodes is under the user’s complete supervision. Besides common debugging functions like stepping or breakpoints, Renode also enables you to control the time flow of the simulation. You can even record and replay events or simulate faults and lossy transmissions, which is crucial for the real-life usability of your IoT product. This makes debugging with Renode far more convenient and transparent compared to traditional methods. Renode also enables you to simulate the whole device, using the real, production binaries. As a result, you can test both the hardware access layer and the more complex software running on top of your system, including end-to-end ML pipelines.

Antmicro’s work with the Nordic nRF52840 SoC

Antmicro has been working with the nRF52840 for a long time now, for example, cooperating with Google’s TensorFlow Lite team when developing Renode support and CI infrastructure for TensorFlow Lite Micro – a dedicated version of TensorFlow optimized for running machine learning algorithms on microcontrollers and other small-footprint devices. The platform initially targeted in that project was the Arduino Nano 33 BLE Sense, which is popular among both developers and hobbyist users.

Together with Nordic, Antmicro ran a webinar showing the development of edge AI solutions using Renode on the nRF52840 platform and the Arduino board.

Running Zephyr Bluetooth LE samples in Renode

Zephyr’s demos include an illustrative heart-rate monitor example, which perfectly mimics the real-world use case. Renode ships with a demo script allowing you to run this example as a one-liner. After installing Renode, run the following command to create two devices, one that generates heart-rate data and a second one that reads this data and reports the reading to a console over Bluetooth LE:

The script is a great starting point for your projects.

Working with your own binaries

If the pre-built demo works for you, it’s time to try your own binaries. After setting up Zephyr as described in the project’s documentation you need to build 2 samples, which are relevant for the Bluetooth LE demo: central_hr and peripheral_hr. Then, you can override those variables in the CLI of Renode, called the Monitor.

Screenshots from Renode

Looking into the Renode demo script

The script is responsible for creating two machines, opening up their UART analyzers, connecting them to a single network, and loading the provided binaries. Zephyr samples are loaded by providing links or paths to custom binaries. First, the script creates a machine named `central` that looks for active heart-rate monitors using Bluetooth LE and connects to the device with the strongest signal. Next, a machine named `peripheral` is created. It functions as a heart-rate monitor and generates dummy heart-rate values. When a connection is established, `central` will report data reception from `peripheral`. This exemplifies the asynchronous architecture of Bluetooth LE, as there is a clear division of roles and permissions among the created machines.

For a more detailed walkthrough of the demo, visit Antmicro’s blog.

Packet interception hooks with Bluetooth LE

Renode enables you to code your hooks, like packet interception hooks, using Python. You can code your simulated machine to react to a packet appearing on the radio medium (like Bluetooth LE). This hook will execute Python code either directly from the Monitor or a designated file.

Analyzing Bluetooth LE traffic with Wireshark

Just like for Ethernet and 802.15.4 networks, you can use Wireshark to inspect the Bluetooth LE traffic between your simulated machines. To set up a connection in which you observe and log only a specific interface (like Bluetooth LE), you need to run the following command in the Renode’s Monitor:

Wireshark screenshot

As you can see, all the packets transferred through the Bluetooth LE wireless medium are captured and analyzed. Wireshark gives you useful information about your Bluetooth LE traffic, like the type of protocol used or the byte length of the captured data, as well as more information about the type of data that packet sends.

Automated testing of Bluetooth LE using Renode

Renode can be used in a variety of ways to help you with the testing and CI processes. One of the supported methods is via the Robot Framework, a popular testing tool whose test syntax mimics natural language, making the process of writing tests quite intuitive. Antmicro has created a set of tests for the nRF52840 chip, including a BLE sample test which can be adapted and run in any of your Bluetooth LE projects.

For every test suite executed, Robot generates an HTML file providing detailed information about the performed test and allows you to inspect it line by line to quickly identify errors.

Bluetooth LE for real-life IoT solutions with Antmicro

The work on Bluetooth LE support in Renode, of course, offers a lot of interesting potential follow-ups, such as end-to-end testing of device-user app interactions using e.g. Android studio. Since Renode runs binary-compatible software to what you will be running on the final hardware, it allows you to build the best user experience for your IoT solution, whether it’s a smart home gateway, wearable, or remote industrial controller.

If you need commercial help in developing your Bluetooth Low Energy project, Antmicro’s engineering services can help you benefit from the streamlined development and advanced testing features provided by Renode. In a software-oriented, test-driven methodology, Antmicro can assist you in developing your next-gen hardware, Zephyr port, or application as well as the accompanying Renode simulation models. To learn more, reach out to us at contact@antmicro.com.

This article originally ran on the Nordic DevZone blog.