Challenge
The challenge of this highly complex project was to implement Bluetooth functionality into a game controller, which required deep expertise in low-level programming and solid RF engineering skills.
Solution
One of the project key stages was to implement the Bluetooth functionality into a game controller, which enables wireless communication between the Station and the Controller. The device is small and light, but at the same time capable of operating long enough.
Our team managed to achieve 6-8 hours of continuous operations on the battery powered device. The device we developed turned out to be portable, secure, and highly usable. We implemented and customized the product effectively within specified timeframes and budgets.
Bluetooth Stack Implementation
The first step of project implementation was the development of the antenna part of the radio tract. We implemented a hardware abstraction layer for the transceiver (a microchip that is a Bluetooth receiver-transmitter). Then, we ported the Open Source Library which provides the lower protocol layers of the Bluetooth Protocol to work on STM32F103 MCU.
The library is called BT Stack and provides two lower layers of Bluetooth protocol, HCI and L2CAP. The HCI protocol layer implements the HCI commands for the Bluetooth hardware by accessing baseband commands, link manager commands, hardware status registers, control registers and event registers. The HCI driver on the Host exchanges data and commands with the HCI firmware on the Bluetooth hardware. The Host Control Transport Layer (i.e. physical bus) driver provides both components – MCU (microcontroller) and transceiver chip – with the ability to exchange information between each other.
The next layer in Bluetooth protocol stack is the logical link control and adaptation protocol (L2CAP) that supports higher level protocol multiplexing, packet segmentation and reassembly, and conveys quality of service information. L2CAP permits higher level protocols and applications to transmit and receive upper layer data packets (L2CAP Service Data Units, SDU) up to 64 kilobytes in length. L2CAP also permits per-channel flow control and retransmission via the Flow Control and Retransmission Modes.
As Bluetooth protocol is very time-critical and the transceiver is software driven, we made sure everything worked quickly and efficiently. In fact, we managed to optimize the BT Stack efficiency using limited hardware resources. Microcontrollers that are used in applications such as multimedia players, mobile phones and other similar devices, are economic in terms of energy consumption but are not adequately fast enough. In order to achieve a high performance of the device, we optimized thoroughly the ready-made library. One of optimization examples is packet queuing, as data buffers in BT transceiver chip are prone to overflow resulting in undesired data loss. We implemented the firmware-side packet queue which greatly improved robustness and stability of the radio link. As a result, the BT transceiver is supplied with new data from the queue only when it indicates that it is free to process the new data.
Another challenge of implementation is communications between the MCU and the BT transceiver. We optimized communications between these two components to send more data within a limited time frame and resolved some stability issues of BT Stack framework.