Dungyichao / BLE_STM32

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BLE from Ground up in STM32

1. What is the Goal and what we Need

1.1 Hardware

  • STM32F411RE Nucleo 64
  • X-Nucleo-IDB05A1

2. Basic Knowledge

A very good reading resource is in the following link: The Basics of Bluetooth Low Energy . You can also download the free ebook from the website . Here, we only provide some essential knowledge.

2.1 BLE Structure

Let's see the architecture of the BLE in the following image.

Some simple explaination of each term can be found in the following table. (reference

https://www.rfwireless-world.com/Terminology/BLE-Protocol-Stack-Architecture.html )

Layer Detail
Physical Layer • The transmitter uses GFSK modulation and operates at unlicensed 2.4 GHz frequency band.
• Using this PHY layer, BLE offers data rates of 1 Mbps (Bluetooth v4.2)/2 Mbps (Bluetooth v5.0).
• It uses frequency hopping transceiver.
• Two modulation schemes are specified to deliver 1 Msym/s and 2 Msym/s.
• Two PHY layer variants are specified viz. uncoded and coded.
• A Time Division Duplex (TDD) topology is employed in both of the PHY modes.
Link Layer It is responsible for advertising, scanning, and creating/maintaining connections. The role of BLE devices changes in peer to peer (i.e. Unicast) or broadcast modes. The common roles are Advertiser/Scanner (Initiator), Slave/Master or Broadcaster/Observer. Link layer states are defined in the figure below.

HCI It provides communication between controller and host through standard interface types. This HCI layer can be implemented either using API or by interfaces such as UART/SPI/USB. Standard HCI commands and events are defined in the bluetooth specifications.
L2CAP This layer offers data encapsulation services to upper layers. This allows logical end to end data communication.
SMP This security Manager layer provides methods for device pairing and key distributions. It offers services to other protocol stack layers in order to securely connect and exchange data between BLE devices.
GAP This layer directly interfaces with application layer and/or profiles on it. It handles device discovery and connection related services for BLE device. It also takes care of initiation of security features.
GATT This layer is service framework which specifies sub-procedures to use ATT. Data communications between two BLE devices are handled through these sub-procedures. The applications and/or profiles will use GATT directly.
ATT This layer allows BLE device to expose certain pieces of data or attributes.
Application Layer • The BLE protocol stack layers interact with applications and profiles as desired. Application interoperability in the Bluetooth system is accomplished by Bluetooth profiles.
• The profile defines the vertical interactions between the layers as well as the peer-to-peer interactions of specific layers between devices.
• A profile composed of one or more services to address particular use case. A service consists of characteristics or references to other services.
• Any profiles/applications run on top of GAP/GATT layers of BLE protocol stack. It handles device discovery and connection related services for the BLE device.

2.2 Chip Configuration

The three separate layers of the protocol and the standardized interface make it possible to implement the Host and Controller on different platforms. The following configurations are commonly used:

Configuration Detail
Single-chip A single microcontroller implements all three layers and the application itself. In this case the BLE Host and the BLE Controller communicate directly through function calls and queues in RAM. The Bluetooth specification does not specify how HCI is implemented.
This configuration is well suited for those applications and designs that require a small footprint and the lowest possible power consumption, since everything runs on a single IC.
Dual-chip

A. Typically used for cell phone or computer since they have powerful processor.
B. The chip for the application can be very samll and low power because the application doesn't need much memory or resources.
Three-chip Application, Host, and Controller layer are implemented on three different chip. The Host need two communication interface between Host-Application and Host-Controller. This is a very expensive configuration

2.3 BLE type of Device

Item Detail
Peripherals A peripheral device is a device that announces its presence by sending out advertising packets and accepts a connection from another BLE device (the BLE central).
Centrals a device that discovers and listens to other BLE devices that are advertising. It is also capable of establishing a connection to BLE peripherals (usually multiple at the same time).
Broadcaster a device that sends out advertising packets as well, but with one difference from a peripheral: the broadcaster does not allow a connection from a central device.
Observer Only discovers advertising devices, but does not have the capability to initiate a connection with the advertiser.

The following table is the files that we are going to use to program in BLE chip.

3. BLE Attribute Protocol (ATT)

About