Extending the Pigweed SDK with Bluetooth support for the NXP MIMXRT595

Published:

Topics: Open software libraries, Open source tools

The Pigweed SDK is an open source collection of embedded-targeted libraries for modern C++ software development in a replicable and self-contained environment. Created by Google, it powers a variety of consumer and industrial applications spanning from Pixel phones to satellites and drones.

In this article, we will describe how Antmicro extended Pigweed to support Bluetooth on the Arm Cortex-M33-based NXP MIMXRT595 MCU for use in constrained wireless devices. The work involved adapting the NXP SDK to enable the open source Sapphire Bluetooth stack (originating from the Fuchsia OS) on the RT595 MCU, which we will describe in the following paragraphs.

The Bluetooth implementation will be demonstrated with a proof of concept which uses a MIMXRT595 MCU running Pigweed and three nRF52840 SoCs, utilizing Zephyr RTOS and Antmicro’s open source Renode simulation framework.

Pigweed with Bluetooth support for NXP MIMXRT595

Extending the Pigweed SDK with Bluetooth support

To support the Bluetooth capabilities of the MIMXRT595 MCU, Antmicro extended the pre-existingmimxrt595_evk_freertos Pigweed target, which involved adding SDK components required for Bluetooth support.

As Pigweed is often used together with the Bazel build system, we implemented the ability to call a Bazel target in order to generate a Bazel build file from the NXP SDK GitHub repository for the MIMXRT595. This allows us to build separate SDK components within Bazel, replacing the need to call a custom-written local script outside of Bazel to do that. To use the NXP SDK Bluetooth controller, which requires the reservation of special memory regions in the binary, we adapted the linker scripts for the target within Pigweed.

We also created the pw_bluetooth_sapphire_mcuxpresso library which provides a Bluetooth controller implementation that can be used together with the pw_bluetooth_sapphire module to implement the Sapphire Bluetooth stack. This controller initializes and communicates with Bluetooth using HCI UART. It implements custom Receive and Send UART callbacks responsible for parsing incoming Bluetooth packets, forwarding them to the Sapphire stack for further processing and sending responses. To showcase example usage of this controller, we prepared two examples: 01_bluetooth that creates a Bluetooth Low Energy Beacon Advertiser using the Sapphire stack, and 04_bluetooth_audio that creates a Bluetooth Classic Audio A2DP Sink that incorporates the Sapphire stack for parsing Bluetooth packets up to the L2CAP Bluetooth layer and then connects with external Bluetooth audio profiles (in our case ported from Zephyr).

Audio support

In order to add audio capabilities through Bluetooth to Pigweed, first we added support for ACL packets to the controller module, and ported AVDTP and A2DP from Zephyr RTOS, as Pigweed easily integrates with other stacks.

To ensure correct audio timing and seamless playback, Antmicro included an API from the NXP SDK to handle frame delivery and notifications when needed. This API is used to provide jitter protection and correct timing issues in audio frames.

Bluetooth audio sends encoded data that needs to be decoded in order to be played properly. For handling compression and decompression of audio data during Bluetooth transmission, we used the SBC codec and leveraged the NXP library for decoding the codec and ensuring smooth audio playback.

Pigweed Bluetooth advertiser demo

To test the implementation, we prepared a demo setup with two pairs of hosts and controllers. The first pair runs the Pigweed Bluetooth advertiser sample on MIMXRT595 (host), and the Zephyr HCI-UART sample on nRF52840 (controller). The second pair runs the Zephyr Bluetooth Observer demo on the first nRF52840 (host) and the Zephyr HCI-UART sample on the second nRF52840 (controller). Hosts and controllers communicate with each other over HCI-UART.

To run the demo on your computer, first download the latest Renode portable package for Linux:

mkdir renode_portable
wget https://builds.renode.io/renode-latest.linux-portable-dotnet.tar.gz
tar xf renode-latest.linux-portable-dotnet.tar.gz -C renode_portable --strip-components=1

Alternatively, you can install the latest stable and numbered Renode version via GitHub, also available for macOS and Windows.

Then launch the Renode Monitor window:

$ ./renode_portable/renode

Start the demo using the following command in the Monitor:

start @scripts/multi-node/imxrt500_nrf52840_pigweed_bt_advertiser.resc

Renode then displays the communication between the machines as shown below:

As Pigweed features a direct Renode integration, you can refer to the Pigweed documentation for more information on how to simulate Pigweed and Renode-capable targets.

Fast and reliable embedded system development with Antmicro

With vast experience in embedded software, including Zephyr (initial support for which is already available in Pigweed) and other RTOS, wireless stacks and integrating embedded SDKs, Antmicro offers comprehensive services for developing and testing embedded products. We can help you benefit from Pigweed’s modularity and versatility, and enhance your workflow with Renode’s deterministic testing features.

If you would like to benefit from Antmicro’s experience in extending SDKs and other software for embedded system development, or to learn more about our services that enable hardware and software teams to collaborate more effectively using our open source toolkit, check out our interactive offering or get in touch at contact@antmicro.com.

See Also: