Ports
On Linux, working with Bluetooth devices typically involves the BlueZ. The operating system detects and initializes the controller, while BlueZ acts as the central service that exposes Bluetooth functionality to applications. Although the kernel provides a uniform HCI interface for controllers connected via USB, UART, or SDIO, applications communicate with BlueZ over D-Bus and other high-level APIs to perform tasks such as device discovery, pairing, and accessing GATT services.

BTstack, our proprietary user-space Bluetooth Host Stack, follows a different approach: it interacts directly with Bluetooth controllers at the HCI level. For embedded Linux systems, it provides custom HCI transport implementations for UART and USB to communicate with the controller. The direct access enables BTstack to handle controller initialization, including firmware download and vendor-specific setup steps for a wide range of devices, which are often required on embedded platforms. This gives developers full control over the complete Bluetooth stack within their application.
The Web has evolved into a powerful platform for hardware interaction, yet Classic Bluetooth and LE Audio support have long remained one of the last frontiers trapped in native code. Breaking that barrier would open the door to a new class of connected Web experiences – connecting your Bluetooth headphones, sensors, and controllers directly through the browser, with no drivers, or system dependencies could enable innovation that isn’t gated by operating systems but fueled by open standards and creativity.
Once testing on Linux, macOS, or Windows is complete — and if there are no plans to run BTstack directly on an SoC — the next challenge is usually connecting an MCU development kit to a Bluetooth Controller breakout board via the Bluetooth UART HCI interface, and getting the stack up and running on the MCU. While BTstack can be ported to almost any MCU/development kit, the process involves figuring out the correct UART pinout and carefully adding jumper wires between the boards. No matter how carefully this is done, the result will be a fragile setup that’s inconvenient to transport or use for demonstrations.
In this blog post, we provide an overview on how to use Bluetooth Controllers via USB as well report on our journey of porting BTstack to the STM32 F4 Discovery board which has an USB On-The-Go (OTG) interface.
Using a USB Bluetooth Controller has a higher complexity than one connected via the UART, mainly due to the need for an USB Host Stack. However, such controller may become quite handy when we need to a) add Bluetooth functionality to existing devices with an USB port, and/or b) avoid radio emission testing for low volume products as the device is shipped without RF functionality.
When using Bluetooth Controllers via the H4/UART transport, there’s no error-correction mechanism. Therefore, a single lost byte causes the HCI transport to loose synchronization and requires a full Controller reboot.
An effective way to prevent loosing bytes on the UART peripheral is to enable hardware CTS/RTS flow control. For example, most STM32 MCUs have a rather simple, yet effective implementation: – when a byte is received, the RTS line raises causing the Bluetooth Controller to pause output; – when the UART’s receive register is read, the RTS line is lowered again.

For two Bluetooth devices to communicate securely, pairing is required to authenticate and encrypt the communication between them by entering a PIN or comparing a number shown on both devices. If the created secret data is stored, the process is called bonding.
For Bluetooth Classic, a shared link key is created. For LE, a long term key (similar to link key) is created, but also additional device information is exchanged like Identify Resolving Key (IRK) and the public BD_ADDR. This information allows to recognize and reconnect to previously bonded device, even if it is using a resolvable private private Bluetooth address.
After a small detour handling Cross-Platform Console Input, we’re back and got audio streaming via A2DP to work in both directions on the STM32 F4 Discovery board.
Given the hardware options on the board, we’d like to play stereo music via the built-in Cirrus 43L22 Audio Codec and stream some music to a headset / loudspeaker, ignoring the microphone on the Discovery board.
Audio Playback with the Cirrus 43L22 Audio Codec
As the audio codec was already on the dev kit, we expected playing a simple sound like a sine wave to be a straightforward task, using Makefiles and the GNU ARM Embedded Toolchain.

After we got BTstack running on the STM32 F4 Discovery board, next on our plan was to play music received by A2DP via the built-in Cypress Audio Codec.
However, it turned out that it’s not possible to output audio via the I2S interface at exactly 44100 Hz. It can be configured for 44108 Hz though, which is close enough for our human perception, but if we receive audio at the nominal rate of 44100 Hz, our buffer will underflow after a while – even if there are only 8 samples missing per second. So, while we need to work on an algorithm that keeps the audio in sync by adding or dropping a single sample occasionally, we’ll look at another practical problem.

In our first post we’ll describe, in a (mostly) linear fashion, how we ported BTstack to the STM32 platform. The steps we took to port BTstack could be easily generalized, so this example should serve as well as a tutorial for porting BTstack to other platforms.
Hardware Overview
For this port, we will get BTstack up and running on some ready-to-use hardware without soldering or too much jumper wires.