UG434: Silicon Labs Bluetooth ® C
Application Developer's Guide for
SDK v3.x
This document is an essential reference for everybody developing C-based applications for the Silicon Labs Wireless Gecko
products using the Silicon Labs Bluetooth stack. The guide covers the Bluetooth stack architecture, application development
flow, usage, and limitations of the MCU core and peripherals,
stack configuration options, and stack resource usage. This version applies to the Silicon Labs Bluetooth Software Development
Kit (SDK) version 3.0.x and higher.
The purpose of the document is to capture and fill in the blanks between the Bluetooth
Stack API reference, Gecko SDK API reference, and Wireless Gecko reference manuals, when developing Bluetooth applications for the Wireless Geckos. This document
exposes details that will help developers make the most out of the available hardware
resources.
KEY POINTS
• Project structure and development flow
• Bluetooth stack and Wireless Gecko
configuration
• Interrupt handling
• Event and sleep management
• Resource usage and available resources
silabs.com | Building a more connected world.Rev. 0.6
Table of Contents
1. Introduction ................................4
1.1 About this Version .............................4
1.2 Prerequisites..............................4
2. Application Development Flow.........................5
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Introduction
1. Introduction
This document is a C developer’s guide for the Silicon Labs Bluetooth stack. It covers various angles of development, and is an important reference to everyone developing in C for Wireless Gecko products that are running the Bluetooth stack.
The document covers the following topics:
• Section 2. Application Development Flow discusses the application development flow.
• Section 4. Configuring the Bluetooth Stack and a Wireless Gecko Device explains the project include libraries and the actual
Wireless Gecko configuration in the application code.
• Section 5. Bluetooth Stack Event Handling is an important piece for everyone developing with the Silicon Labs Bluetooth stack, as it
explains how the application runs in sync with the stack in an event-based architecture.
• Section 6. Interrupts and section 7. Wireless Gecko Resources touch on the topics of peripherals and the chipset resources, covering what is reserved for the stack usage, how interrupts should be handled, and the stack’s memory footprint and available memory
for the application.
1.1 About this Version
The current version of Silicon Labs' Bluetooth SDK is 3.1.x.
Currently supported compilers and IDE versions are:
• IDE: Simplicity Studio 5.1.0 or newer
• Compiler: IAR v8.30.1 and GCC 7.2.1
1.2 Prerequisites
This document assumes the current version of Silicon Labs’ Bluetooth SDK has been properly installed to the development machine
(Windows, MAC OSX, or Linux), and that the reader is familiar with the quick start guides and with the SDK’s examples. Also, the reader should have a basic understanding of Bluetooth technology. For more information, see UG103.14: Bluetooth Technology Fundamen-tals.
For instructions on getting started using example applications in Silicon Labs Simplicity Studio development environment, see QSG169:Bluetooth® SDK v3.x Quick Start Guide.
silabs.com | Building a more connected world.Rev. 0.6 | 4
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Application Development Flow
2. Application Development Flow
The following figure describes the high-level firmware structure. The developer creates an application on top of the stack, which Silicon
Labs provides as a precompiled object-file, enabling the Bluetooth connectivity for the end-device.
Figure 2.1. Bluetooth Stack Architecture Block Diagram
The Bluetooth stack contains following blocks.
• Bootloader—The Gecko Bootloader is not part of the stack but is provided with the Bluetooth SDK. See UG266: Gecko BootloaderUser Guide and AN1086: Using the Gecko Bootloader with Silicon Labs Bluetooth Applications for more information. For information
on bootloading in general, see UG103.06: Bootloading Fundamentals.
• Bluetooth stack—Bluetooth functionality consisting of link layer, generic access profile, security manager, attribute protocol, and
generic attribute profile.
• Bluetooth AppLoader—An application that starts after the bootloader. It checks if the user application is valid and, if it is, AppLoader starts the application. If the application image is not valid, AppLoader starts the OTA process to try to receive a valid application
image. This requires using the Gecko Bootloader.
silabs.com | Building a more connected world.Rev. 0.6 | 5
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Application Development Flow
2.1 Application Build Flow
Figure 2.2. Bluetooth Project Build Flow
Building a project starts by defining the Bluetooth services and characteristics (GATT definitions) and by writing the application source
code from Silicon Labs-provided examples or an empty project template, as described in QSG169: Bluetooth® SDK v3.x Quick StartGuide.
SDK v2.1.0 and later offer two ways to define Bluetooth services and characteristics. The first option is the Visual GATT Editor GUI in
Simplicity Studio. This is a graphical tool for designing the GATT and for generating gatt_db.c and gatt_db.h. Additionally, it can import .xml and .bgproj GATT definition files. The Visual GATT Editor is the default tool for GATT definition and generation in Simplicity
Studio projects.
The second option is to create an .xml or .bgproj according to the UG118: Blue Gecko Bluetooth® Profile Toolkit Developer's Guide and
then use the BGBuild executable as a pre-compilation step to convert the GATT definition file into .c and .h. This method is used in IAR
Embedded Workbench projects.
Compiling the project generates an object file, which is then linked with the pre-compiled libraries provided in the SDK. The output of
the linking is a flash image that can be programmed to the supported Wireless Gecko devices.
silabs.com | Building a more connected world.Rev. 0.6 | 6
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Project Structure
3. Project Structure
This section explains the application project structure and the mandatory and optional resources that must be included in the project.
3.1 Bluetooth Files
Library Files
The Bluetooth stack libraries are:
• binapploader.o: Binary image of the Bluetooth AppLoader, provides the optional OTA (Over-the-Air) functionality.
• binapploader_nvm3.o: Binary image of the Bluetooth AppLoader for EFR32[B|M]G1x devices with NVM3 support.
• libbluetooth.a: Bluetooth stack library.
• libpsstore.a: PS Store functionality for the Bluetooth stack. This is not available on EFR32[B|M]G2x devices. NVM3 must be used
instead.
RAIL
The Bluetooth stack uses RAIL to access the radio and RAIL libraries needs to be linked with Bluetooth stack. RAIL has separate libraries for each device family and for single- and multi-protocol environments. RAIL libraries are provided in the Gecko SDK Suite. For
more information refer to UG103.13: RAIL Fundamentals and other RAIL documentation.
Note: To ensure regulatory compliance of the radio module, the Bluetooth stack for the radio module needs to be linked together with
the RAIL library and the configuration library for the radio module. These are librail_module_<soc family><compiler>_release.a and librail_config<modulename>.a.
EMLIBand EMDRV
The Bluetooth stack uses EMLIB and EMDRV libraries to access EFR32 hardware. EMLIB and EMDRV peripheral libraries are provided in source code and they must be included in the project. EMLIB and EMDRV are part of the Gecko SDK Suite. For more details on
EMLIB and EMDRV, see platform EMDRV documentation and EMLIB documentation on https://docs.silabs.com/.
mbed TLS
The Bluetooth stack uses the Mbedtls library for cryptographic operations. The Mbedtls library is provided in source code and must be
included in the project. Mbedtls is part of the Gecko SDK Suite. For more details, refer to the Mbedtls documentation.
Sleep Timer
Sleep Timer is a platform component providing for software timers, timekeeping and date functionality. The Bluetooth stack uses it for
deep sleep and it must be included in the project. See platform sleeptimer documentation.
Power Manager
Power Manager is a platform component that manages the system's energy modes. Its main purpose is to transition the system to a low
energy mode when the processor has nothing to execute. See the reference for your MCU on https://docs.silabs.com/ under Modules>
Platform Services>Power Manager.
Header Files
sl_bt_version.h
This file contains the Bluetooth stack version.
silabs.com | Building a more connected world.Rev. 0.6 | 7
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Project Structure
API Header Files
These files define the Bluetooth stack API.
These files serve two purposes: first they contain the actual Bluetooth stack API and the commands and events for the stack, and second they provide a configuration and event management API to the Bluetooth stack.
The configuration, event, and sleep management API is described below.
This function takes a single argument - a pointer to a sl_bt_configuration_t struct. Its purpose is to configure and initialize the Bluetooth stack with the parameters provided in the struct. Once the function sl_bt_init_stack() is called, each required stack
component must be initialized separately. This separation allows memory optimization, by not including those stack components that
are not needed. Project Configurator in Simplicity Studio 5 (SSv5) will take care of the stack initialization. In non-SSv5 applications the
application must call sl_bt_init_stack() and then initialize BGAPI classes.
The following APIs can be used to initialize stack components separately:
• sl_bt_class_dfu_init();
• sl_bt_class_system_init();
• sl_bt_class_gap_init();
• sl_bt_class_avertiser_init();
• sl_bt_class_scanner_init();
• sl_bt_class_sync_init();
• sl_bt_class_connection_init();
• sl_bt_class_gatt_init();
• sl_bt_class_gatt_server_init();
• sl_bt_class_ota_init();
• sl_bt_class_nvm_init();
• sl_bt_class_test_init();
• sl_bt_class_sm_init();
• sl_bt_class_coex_init();
• sl_bt_class_cte_transmitter_init();
• sl_bt_class_cte_receiver_init();
sl_status_t sl_bt_pop_event(sl_bt_msg_t* evt)
This is a non-blocking function to request Bluetooth events from the Bluetooth stack. When an event is requested and the event queue
is not empty, an event object is copied into the memory provided by application. If there are no events in the event queue, SL_STATUS_NOT_FOUND is returned.
The stack’s event handling is discussed in detail in section 5. Bluetooth Stack Event Handling.
int sl_bt_event_pending(void)
This function checks to see if any Bluetooth stack events are pending in the event queue. If a pending Bluetooth event is found, the
function returns a non-zero value to indicate that the event should be processed by sl_bt_pop_event(). If no event is found, zero is
returned.
silabs.com | Building a more connected world.Rev. 0.6 | 8
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Project Structure
sl_bt_types.h
sl_bt_stack_init.h
sl_bt_api.h
sl_bgapi.h
These files contain the Bluetooth stack API and the commands and events for the stack, and a configuration API for the Bluetooth
stack.
sl_bt_ncp_host_api.c, sl_bt_ncp_host.c, sl_bt_ncp_host.h and sl_bt_internal.h
These files are used when developing applications for an external host. They provide the API definitions and adaptation layer between
the host application and the BGTAPI serial protocol.
3.2 GATT Database
The GATT (Generic Attribute Profile) database is a standardized way of describing the Bluetooth profiles, services, and characteristics
of a Bluetooth device. With the Silicon Labs Bluetooth stack, the GATT definitions are either directly edited in the Visual GATT Editor
GUI in Simplicity Studio or are written in XML and passed to the BGBuild executable as a pre-build task. For more information on how
to create GATT databases and the syntax, refer to UG118: Blue Gecko Bluetooth® Smart Profile Toolkit Developer's Guide.
gatt_db.c and gatt_db.h
The gatt_db.c defines the GATT database structure and content, and is auto-generated by BGBuild or by the Visual GATT Editor.
gatt_db.h includes this database and the handles of local characteristics and services. Type definitions of GATT are automatically included from bg_gatt_db_def.h to gatt_db.h.
3.3 Device Firmware Upgrade
Device Firmware Upgrade (DFU) is the process of upgrading the application either over a serial link or over-the-air (OTA). In both cases
the application needs to add the following file to enable the support for DFU.
application_properties.c
This file includes the application properties struct that contains information about the application image, such as type, version, and security. The struct is defined in application_properties.h in the Gecko Bootloader API. A pre-generated file is included in Simplicity
Studio projects, which can be modified to include application-specific properties. The application properties can be accessed using the
Gecko Bootloader API. The following members can be updated by changing the defines:
// Version number for this application (uint32_t)
#define APP_PROPERTIES_VERSION
// Unique ID (e.g. UUID or GUID) for the product this application is built for (uint8_t[16])
#define APP_PROPERTIES_ID
When using the OTA process with Bluetooth AppLoader, a pointer to the application properties struct needs to be set to application
vector table vector 13. This is enabled automatically when using the default startup file and the struct name is sl_app_properties.
silabs.com | Building a more connected world.Rev. 0.6 | 9
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Project Structure
3.4 RTOS Support
The Bluetooth stack can also run on Micrium RTOS and FreeRTOS. In this case the following files are added to the project:
sl_bt_rtos_adaptation.c
sl_bt_rtos_adaptation.h
sl_bt_rtos_config.h
sl_bt_rtos_adaptation.c and sl_bt_rtos_adaptation.h
sl_bt_rtos_adaptation.c and sl_bt_rtos_adaptation.h provide the RTOS tasks for the IPC (Inter-Process Communication) with
the Bluetooth stack and other RTOS tasks using CMSIS-RTOS2.
sl_bt_rtos_config.h
sl_bt_rtos_config.h is used to set the Bluetooth RTOS task priorities.
Support for RTOS needs to be configured for the Bluetooth Stack in the sl_bt_configuration_t struct. The config_flags field
needs to have SL_BT_CONFIG_FLAG_RTOS set. This causes the Bluetooth stack to rely on the RTOS for sleeping, rather than sleeping
directly. scheduler_callback and stack_schedule_callback must be configured to call proper functions. These callbacks are used
to wake up the corresponding tasks.
The Bluetooth Stack configuration to use with RTOS is as follows:
sl_bt_rtos_init() can be called to initialize the stack and create needed RTOS tasks.
void sl_bt_rtos_init();
It calls function sl_bt_init() to initialize the Bluetooth stack.
3.5 Multiprotocol Support
When the Bluetooth Stack is used in a multiprotocol environment, multiprotocol features in the Bluetooth stack must be enabled with
following function:
sl_bt__init_multiprotocol();
Using Bluetooth in a multiprotocol environment also requires using the RAIL library with multiprotocol support.
3.6 Platform Components
The v3.x Bluetooth stack relies on many platform components that are part of the underlying Gecko Platform infrastructure of the Gecko
SDK Suite. The autogen folder contains sources for initializing the hardware and processing events. The config folder includes hardware and stack configuration options.
silabs.com | Building a more connected world.Rev. 0.6 | 10
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
4. Configuring the Bluetooth Stack and a Wireless Gecko Device
To run the Bluetooth stack and an application on a Wireless Gecko, the MCU and its peripherals have to be properly configured.
4.1 Wireless Gecko MCU and Peripherals Configuration
sl_system_init()
The sl_system_init() function is used to initialize the system. It will call platform, driver, service, stack, and internal app init functions,
which are located in the autogen folder.
App_init()
The App_init() function is used to initialize application-specific features.
4.1.1 Adaptive Frequency Hopping
Bluetooth Stack implements Adaptive Frequency Hopping (AFH), conforming with the ETSI EN 300 328 standard. AFH is required
when using transmit power +10 dBm and over. AFH may also provide performance improvement by avoiding congested channels.
To enable AFH in the Bluetooth stack, the following initialization function must be called:
void sl_bt_init_afh();
This is included automatically when including the bluetooth_feature_afh component. In a master-slave connection, both ends can
use AFH independent of each other. The master may be non-adaptive, but the slave still may need to be adaptive. The standard allows
using control transfer on a blocked channel. For compliance reasons, if the slave detects that a blocked channel is in use, it will only
send a single packet on that channel to prevent connection timeouts.
Note: Legacy advertising does NOT use Adaptive Frequency Hopping. Legacy advertising uses 3 channels, and AFH needs a minimum of 15 channels to fulfill the requirements of the ETSI standard. Extended advertising must be used to enable AFH with advertising.
silabs.com | Building a more connected world.Rev. 0.6 | 11
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
4.1.2 Bluetooth Clocks
The clock settings are initialized in the sl_platform_init() function in sl_event_handler.c. Clock settings include initializations of
oscillators (HFXO, LFXO, and LFRCO) with parameters such as tuning, initialization of the clocks (HFCLK, LFCLK, LFA, LFB, LFE),
and the assignment of clocks to oscillators. Note: The peripheral clocks (like GPIO clock, TIMER clock) are not enabled in this function.
They must be enabled when initializing a peripheral.
HFCLK
HFCLK is used for a radio protocol timer (PROTIMER). HFCLK is a high frequency clock where accuracy must be at least ±50 ppm.
This clock needs an external crystal to be sufficiently accurate (HFXO).
The HFXO initialization configures the external crystals for timing-critical connection and sleep management. An HFXO has to be set as
the high frequency clock (HFCLK) and physically connected to a Wireless Gecko’s HFXO input pins.
LFCLK
LFCLK, the low frequency clock, is used for two purposes. In the Bluetooth stack, it is used for Bluetooth protocol timing. It is also needed to keep track of time during sleep mode.
When a device enters into sleep mode, the current state of PROTIMER is saved. When the device wakes up, it calculates how many
ticks of sleep clock have passed and adjusts the PROTIMER accordingly. To the radio it appears that PROTIMER has been constantly
ticking.
The accuracy of this clock depends on the operating mode of the device. When advertising or scanning, accuracy is not that important,
but when a connection is open, the accuracy must be at least ±500 ppm. This clock can be driven either by LFXO, PLFRCO (EFR32[B|
M]G13 or [B|M]GM13), or LFRCO (EFR32[B|M]G2x or [B|M]GM2x), depending on the accuracy requirements. If applications only require advertising or scanning, LFRCO can be used as the clock source. However, if Bluetooth connections are required, the clock
source must be either LFXO, PLFRCO (EFR32[B|M]G13 or [B|M]GM13) or LFRCO with High Precision Mode (EFR32[B|M]G22 or [B|
M]GM22). When using PLFRCO or LFRCO, the accuracy of the clock must be configured to ±500 ppm.
In the default configuration, LFXO is connected to the Wireless Gecko and set as the clock source for LFCLK. If the design only has
PLFRCO or LFRCO with High Precision Mode, PLFRCO or LFRCO is connected and set as the clock source.
If none of LFXO, PLFRCO, or LFRCO with High Precision Mode is connected in the design, sleeping is disabled automatically if LF
clock accuracy does not meet the 500 ppm requirement.
HFRCODPLL
HFRCODPLL is a high frequency clock that is used as a system clock with the Bluetooth stack in EFR32[B|M]G2x devices. On
EFR32[B|M]G21x, HFRCODPLL needs to be configured to 80 MHz and set as the system clock source.
silabs.com | Building a more connected world.Rev. 0.6 | 12
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
CTUNE
The examples have the crystal tune (CTUNE) settings for both HFXO and LFXO set by default to work with all of the Silicon Labs’
Bluetooth modules, reference designs, and radio boards. However, in some cases the end-product design requires specific crystal calibration, either per device or per design. The CTUNE value can be adjusted according to the design in the sl_device_init_hfxo()
function.
For more information on configuring the HFXO and LFXO, refer to the EFR32 Reference Manual.
Default HFXO CTUNE Value
The system checks multiple sources for the default HFXO CTUNE value, using the following logical order:
1. CTUNE PSKEY is set. This key has ID 50 (32 in hex) and contains 2 bytes of data for the 16 bit CTUNE value. This can be programmed with the BGAPI command sl_bt_nvm_save.
2. Calibration value exists in DEVINFO. Some modules contain a factory-programmed value in the DEVINFO-page.
3. Manufacturing token exists in the user data page. This is programmed by the developer, or it can be automatically set by Simplicity
Studio if the board EEPROM contains the value. This token consists of 2 bytes, located at offset 0x0100 from the starting address of
the User Data page. Refer to the EFR32 Reference Manual for your specific EFR variant for the full flash mapping.
4. If a radio board is selected when generating the project, then use default value from board header file.
5. If nothing else is found, use the default value from CMU header file.
Note: The Bluetooth stack only supports 38.4 MHz HFXO frequency; no other HFXO frequencies are supported.
4.1.3 DC-DC Configuration
On devices that have DC-DC, the configuration is set in the sl_device_init_dcdc() function in sl_event_handler.c. The examples in
the SDK have DC-DC configuration set to work with the Silicon Labs’ Bluetooth modules, radio boards, and reference designs, but custom designs might require specific DC-DC settings. These custom settings can be set in sl_device_init_dcdc_xx.c..
For more information on configuring the DC-DC, refer to the EFR32 Reference Manual, Chapter 11, and AN0948: Power Configurations
and DC-DC.
4.1.4 LNA
A low-noise amplifier (LNA) is an electronic amplifier that amplifies a very low-power signal without significantly degrading its signal-tonoise ratio. The LNA improves RF sensitivity.
An LNA is provided on-board in some MGM12P modules as part of front-end module (FEM). To use LNA in these modules, the FEM
needs to be correctly configured and enabled. The FEM is configured in sl_fem_util_config.h.
FEM is initialized in sl_fem_util_init() within the sl_service_init() function if the board supports FEM.
silabs.com | Building a more connected world.Rev. 0.6 | 13
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
4.1.5 Periodic Advertising
Periodic advertising enables multiple listeners to be synchronized with a single advertising device. Thus it is a form of multicast.
Each listener needs to be synchronized to the advertising device before they start receiving data. Periodic advertising uses a scanner
on the listening device to establish a synchronization to the advertising device. After synchronization the scanner can then be stopped.
This makes it much more power-efficient than using the scanner full time for listening for broadcast advertisements.
The periodic advertising consists of two components: periodic advertiser role and periodic advertising synchronization on listening
side.These two components are independent of each other and need to be initialized separately.
Periodic Advertiser
max_advertisers in the Bluetooth configuration also configures the maximum number of periodic advertisers.
To enable Periodic Advertiser in the Bluetooth stack, the following initialization function must be called after the generic
sl_bt_init_stack() function, which is added automatically by including the bluetooth_feature_periodic_adv component:
void sl_bt_init_periodic_advertising();
Periodic Advertising Synchronization
max_periodic_sync in the Bluetooth config is used to configure the maximum number of synchronizations the Bluetooth stack needs to
support.
To enable Periodic Advertising Synchronization in the Bluetooth stack, the following initialization function must be called after the generic sl_bt_init_stack() function by including the bluetooth_feature_sync component:
void sl_bt_class_sync_init();
This command also initializes the BGAPI sync class, making it available to use.
4.1.6 PTI
PTI (Packet Trace Interface) is a built-in block in the Wireless Gecko SoCs to route incoming and outgoing radio packets as raw data to
the debug interface. These packets can then be captured and displayed in Simplicity Studio’s Network Analyzer. Network Analyzer has
a decoder for Bluetooth packets and can be used to debug, analyze, and measure Bluetooth networks.
PTI is initialized in sl_rail_util_pti_init() within the sl_stack_init() function. The baudrate can be set using the
SL_RAIL_UTIL_PTI_BAUD_RATE_HZ definition, and pins can be configured using the definitions with the
SL_RAIL_UTIL_PTI_DOUT_ and SL_RAIL_UTIL_PTI_DFRAME_ prefix in sl_rail_util_pti_config.h.
4.1.7 Transmit Power
Transmit power of Bluetooth depends on the maximum power allowed by the radio, the software configuration, RF path gain compensation, and usage of Adaptive Frequency Hopping (AFH).
The ETSI EN 300 328 standard requires using AFH when transmitter power is +10 dBm and over.
The maximum allowed power is limited to less than +10 dBm if prevented by adaptivity requirements. The ETSI standard requires that
at least 15 channels are in use for AFH. This requirement prevents using +10 dBm and over in the following cases: legacy advertising,
scan responses, and in connections, when not enough channels are available.
silabs.com | Building a more connected world.Rev. 0.6 | 14
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
4.1.8 Whitelisting
Whitelisting is used to filter devices. Currently it is only supported when discovering devices. Connection requests, scan requests from
remote devices during advertising, and connection initiations are not restricted by the whitelist.
Whitelist size matches the configuration for the max number of bonded devices. If the max number of bonded devices is changed when
using whitelisting, the device needs to be reset before the new setting takes effect.
Bonded devices are added to the whitelist automatically. Alternatively, they can be added manually with the BGAPI command
sl_bt_sm_add_to_whitelist().
Random address resolving is not supported. Devices using resolvable random addresses will not be visible during scanning. Since
most Android and iOS phones use resolvable random addresses, the whitelisting feature will effectively block these devices during device discovery.
To enable whitelisting in the Bluetooth stack, the following initialization function must be called after the generic sl_bt_init_stack() function:
void sl_bt_init_whitelisting();
This is included automatically when including the bluetooth_feature_whitelisting component. When the function is enabled, it can
be enabled and disabled at runtime by the BGAPI command sl_bt_gap_enable_whitelisting().
Connections may be restricted to only bonded or whitelisted devices separately using sl_bt_sm_configure(). This does not require
enabling whitelisting.
4.1.9 Wi-Fi coexistence
Wi-Fi coexistence (COEX) is a protocol where Bluetooth and Wi-Fi arbitrate which protocol can use the radio for transmitting. When
enabled, it improves the performance of Wi-Fi and Bluetooth. COEX is configured in sl_bluetooth_coex_config.h.
To enable COEX, call the following function after sl_bt_init_stack().
sl_bit_init_coex_hal();
This is included automatically when including the bluetooth_feature_coex component. COEX implements the GPIO interface to the
Wi-Fi IC. It depends on EMLIB em_gpio.c and EMDRV gpiointerrupt.c and requires both files to be included in the project.
4.1.10 OTA Configuration
Bluetooth Over-the-Air (OTA) firmware upgrades are supported, because part of the firmware upgrade is handled by the Bluetooth AppLoader application. Enable OTA configuration with the bluetooth_feature_ota_config component
The OTA mode can be configured using the sl_bt_ota_set_configuration() function, which can, for example, set OTA to use a
static random address, instead of a public address. For other options refer to the BGAPI document.
When the Wireless Gecko is in AppLoader's OTA mode, its device name and the device name length can be configured with the
sl_bt_ota_set_device_name() function. The advertisement data used in OTA mode can be set to use custom data instead of the
default one with sl_bt_ota_set_advertising_data().
If the device is not using the default RF path, it can be configured for OTA mode with sl_bt_ota_set_rf_path().
Finally, setting the device to OTA DFU mode should be secured so that only trusted devices have that capability.
For more details about OTA firmware updates, refer to UG266: Silicon Labs Gecko Bootloader User's Guide and AN1086: Using theGecko Bootloader with Silicon Labs Bluetooth Applications.
silabs.com | Building a more connected world.Rev. 0.6 | 15
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
4.1.11 Even Connection Distribution Algorithm
The even connection distribution algorithm is designed to be used especially with applications that involve several concurrent connections. The algorithm tries to distribute the connections such a way that they are distributed over time as evenly as possible without overlapping, and all connections should get an equal share of the air interface resource.
For optimal performance, the algorithm user should:
• Initiate the first connection with the longest connection interval if all connections do not have the same interval.
• Set the connection intervals of the other connections such that they are, or allow (via min-max range), integer fractions of the first
interval.
• Make the first interval long enough such that all connections would fit within the interval with a reasonable transmission time.
The algorithm and the connections can be expected to work if the above recommendations are not followed, but performance will not
likely be optimal.
By default, the link layer uses the legacy Random Connection Distribution algorithm. The Even Connection Distribution algorithm can
be enabled by including the component bluetooth_feature_ll_even_schedulingor calling link layer function
ll_connSchAlgorithmEvenEnable() during the software initialization phase. As the even connection scheduling mechanism is meant
to be used with multiple (up to 32) concurrent connections, the buffer and heap sizes are recommended to be increased as follows.
SL_BT_CONFIG_BUFFER_SIZE 20160
SL_HEAP_SIZE 22520
silabs.com | Building a more connected world.Rev. 0.6 | 16
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
4.2 Bluetooth Configuration with sl_bt_init_stack()
The sl_bt_init_stack() function is used to configure the Bluetooth stack, including memory buffer size that is allocated for connections. None of the Bluetooth stack functions can be used before the Bluetooth stack has been configured.
Configuration options in the sl_bt_init_stack() function are: Bluetooth connection count, advertiser count, periodic advertisement
sync count, memory buffer size, number of timers, GATT database, and PA configuration.
Once the function sl_bt_init_stack() is called, each stack component used has to be initialized separately. This separation allows
memory optimization by not including unnecessary stack components.
The following APIs can be used to initialize stack components separately. The calls to the initialization functions are added automatically by including the respective component.
sl_bt_class_advertiser_init()The commands and events in this class are related to advertising
functionalities in GAP peripheral and broadcaster roles.
sl_bt_class_coex_init()Enables the Bluetooth API to support the Coexistence interface.
sl_bt_class_connection_init()The commands and events in this class are related to managing
connection establishment, parameter setting, and disconnection
procedures.
sl_bt_class_cte_receiver_init()Commands and events in this class manage Constant Tone Ex-
tension (CTE) receiving.
sl_bt_class_cte_transmitter_init()Commands and events in this class manage Constant Tone Ex-
tension (CTE) transmission.
sl_bt_class_dfu_init()These commands and events are related to controlling firmware
updates over the configured host interface and are available only
when the device is booted in DFU mode. Usually not needed in
application.
sl_bt_class_gap_init()The commands and events in this class are related to the Generic
Access Profile (GAP) in Bluetooth.
sl_bt_class_gatt_init()The commands and events in this class are used to browse and
manage attributes in a remote GATT server.
sl_bt_class_gatt_server_init()These commands and events are used by the local GATT server
to manage the local GATT database.
sl_bt_class_nvm_init()Manage user data in NVM keys in the flash memory of the Blue-
tooth device.
sl_bt_class_ota_init()Commands for configuring OTA DFU.
sl_bt_class_scanner_init()The commands and events in this class are related to scanning
functionalities in GAP central and observer roles.
silabs.com | Building a more connected world.Rev. 0.6 | 17
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
sl_bt_class_sm_init()The commands in this class manage Bluetooth security, including
commands for starting and stopping encryption and commands
for management of all bonding operations.
sl_bt_class_sync_init()Provides the periodic advertising synchronization feature.
sl_bt_class_system_init()Commands and events in this class can be used to access and
query the local device.
sl_bt_class_test_init()Enables the DTM test APIs.
4.2.1 Bluetooth On-Demand Start
With the Bluetooth on-demand start feature, the application can start and stop the Bluetooth stack from running when needed. The feature is enabled by including the bluetooth_on_demand_start component. When this feature is enabled, the Bluetooth stack does not
run until sl_bt_system_start_bluetooth() is called. The main purpose of this feature is for the DMP use case, where Bluetooth is
not needed all the time, and resources need to be freed for other application uses. The Bluetooth stack can be stopped with
sl_bt_system_stop_bluetooth(), which gracefully restores Bluetooth to an idle state by disconnecting any active connections and
stopping any ongoing advertising and scanning. Any resources that were allocated when the stack was started are freed when the
stack is stopped. When the Bluetooth stack is not running, all BGAPI classes other than System become unavailable.
If this feature is not enabled, Bluetooth stack is started automatically.
4.2.2 CONFIG_FLAGS
Currently only one config flags is supported, SL_BT_CONFIG_FLAG_RTOS, which needs to be set if the application uses RTOS.
4.2.3 Mbedtls
The Mbedtls cryptography library used by the stack is configured using a configuration file that defines which algorithms are supported,
and if the implementation uses hardware acceleration or is done on software. EFR32[B|M]G2x devices use the new PSA crypto API for
crypto operations, whereas EFR32[B|M]G1x devices continue to use the classic Mbedtls API. In addition to enabling crypto operations,
the PSA crypto API enables storing long-term encryption keys encrypted on flash in Vault-enabled devices.
The Mbedtls needs to be initialized with sl_mbedtls_init(). The Mbedtls configuration file path is given using #define
MBEDTLS_CONFIG_FILE. The default configuration files config/mbedtls_config.h, autogen/mbedtls_config_autogen.h, config/
psa_crypto_config.h, and autogen/psa_crypto_config_autogen.h should be used as a template if the configuration needs to be
changed. The two latter config files are only used with EFR32[B|M]G2x devices.
In PSA crypto API, only a certain number of keys can be open at one time. Bluetooth pairing requires that 2 keys are open at the same
time. By default, no key slots are reserved for the application to save RAM. If the application uses PSA crypto API, then the
SL_PSA_KEY_USER_SLOT_COUNT setting must be set to the value of the number of keys the application needs to stay open simultane-
ously. This can be changed with the SL_PSA_KEY_USER_SLOT_COUNT setting located in config/psa_crypto_config.h. Each key slot
will use 40 bytes of RAM.
With EFR32[B|M]G1x devices, the project must also contain sl_bt_mbedtls_context.c, which is provided as source in the SDK. It is used
by the stack to get Mbedtls context sizes, which depend on the Mbedtls configuration used.
Note that the actual Bluetooth connection encryption uses RADIOAES, which does not have DPA countermeasures. RADIOAES only
has access to temporary session keys.
silabs.com | Building a more connected world.Rev. 0.6 | 18
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
4.2.4 Multiprotocol Priority Configuration
When the Bluetooth stack is used with other protocols in a multiprotocol environment, it may become necessary to change the Bluetooth priority settings for RAIL to optimize certain use cases.
The application needs to allocate the configuration struct and provide it for the Bluetooth stack:
The sl_bt_bluetooth_ll_priorities struct must be initialized to default state by the SL_BT_BLUETOOTH_PRIORITIES_DEFAULT constant.
The sl_bt_bluetooth_ll_priorities struct contains following fields:
• scan_min, scan_max, scan step - The priority range for scan operation.
• adv_min, adv_max, adv step - The priority range for advertisement operation.
• conn_min & conn_max - The priority range for connection packets.
• init_min & init_max - The priority range for connection initiation.
• rail_mapping_offset - The RAIL priority level where Bluetooth priorities are located.
• rail_mapping_range - The RAIL priority range where Bluetooth priorities are located.
For each priority range, 0 is the maximum priority, and 0xff is the minimum priority. Bluetooth priorities are different from RAIL priorities.
That is, Bluetooth has its own space between 0 and 0xff where all Bluetooth priorities are located. To map Bluetooth priorities to RAIL
priorities, the values in fields rail_mapping_offset and rail_mapping_range are used to form single-degree equation:
Wireless Gecko’s sleep mode EM2 (energy mode two) is managed by the platform power manager component. Including the power
manager component or calling the sl_power_manager_init() function automatically enables deep sleep.
The sleep modes require that an accurate 32 kHz low-frequency clock (LFCLK) is present in the hardware. If an accurate sleep clock is
not available for the Bluetooth stack and the application must support Bluetooth connections, then low power sleep modes cannot be
entered. For applications where low power sleep modes are not needed, the LFXO or LFRCO can be left out.
Disabling Sleep at Runtime
If the application needs to disable sleep at runtime, it can be done by implementing bool app_is_ok_to_sleep() function. The function
is called when the device wants to sleep. While EM2 is disabled (/blocked), the stack will switch between EM0 and EM1. For more
information, refer to Power Manager documentation.
silabs.com | Building a more connected world.Rev. 0.6 | 19
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
4.2.6 Bluetooth Stack Configuration
Buffer Memory
The Bluetooth stack uses memory for buffering API events and the data transmitted in Bluetooth connections, advertising, and scanning. This buffer memory is allocated from the heap by the Bluetooth stack when calling sl_bt_init_stack(). The size of buffer memory in bytes is defined by C-define SL_BT_CONFIG_BUFFER_SIZE in sl_bluetooth_config.h. The default value is an estimation for achieving adequate throughput and supporting multiple simultaneous connections. Consider increasing this value if the application needs
higher data throughput over connections or uses advertising or scanning with long advertisement data.
Example of setting the buffer memory size:
The absolute maximum number of simultaneous Bluetooth connections is 32. The amount of memory that is allocated for connection
management further limits the number of connections. The memory is allocated from the heap during initialization in
sl_bt_init_stack(). C-define SL_BT_CONFIG_MAX_CONNECTIONS can be defined to set the number of connections.
SL_BT_CONFIG_MAX_CONNECTIONS is passed to Bluetooth stack in the .bluetooth.max_connections field in the configuration struct.
Example of limiting the Bluetooth connections to one (1).
#define SL_BT_CONFIG_MAX_CONNECTIONS 1
For more information about connection RAM usage, refer to 7.3.2 Bluetooth Object Pools.
Advertisers
The maximum number of advertisement sets can be defined by this configuration option. These sets can be used to start multiple advertisers. This configuration option also configures the maximum number of periodic advertisements. Each advertisement context allocates ~60 bytes of RAM. The number of advertisers is defined with SL_BT_CONFIG_USER_ADVERTISERS.
Note: Maximum connectable advertisements are limited by MAX_CONNECTIONS.
Periodic Advertisement Synchronization
The maximum number of supported periodic advertisement synchronizations needs to be configured. Each synchronization context allocates ~40 bytes of RAM.
.bluetooth.max_periodic_sync = 5; //!< Maximum number of periodic advertisement synchronizations to support.
Default is 0.
4.2.7 PA
On EFR32 SoC-based designs, the PAVDD (Power Amplifier voltage regulator VDD input) can be supplied from the output of the
DC/DC or straight from a 3.3 V power supply.
The Bluetooth stack configuration defaults to using DC/DC as the PAVDD input. If PAVDD is being supplied from a 3.3 V power supply,
then the .pa.input field needs to be defined.
The Bluetooth stack automatically selects the high-power PA if available. The pa_mode configuration can be used to select the PA mode
used by the Bluetooth stack. EFR32[B|M]G21 has 3 PAs so the pa_mode setting in the Bluetooth config struct can take 3 values. Other
devices have 2 PAs.
.pa.config_enable = 1, // PA Configuration is enabled
.pa.input = SL_BT_RADIO_PA_INPUT_VBAT, // PAVDD is supplied from an 3.3 V power supply
.pa.pa_mode=0 // selects high power PA if available
silabs.com | Building a more connected world.Rev. 0.6 | 20
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Configuring the Bluetooth Stack and a Wireless Gecko Device
4.2.8 Software Timers
Maximum available software timers can be configured. Each timer needs resources from the stack to be implemented. Increasing the
amount of soft timers may cause degraded performance in some use cases.
.max_timers = 4;
4.2.9 RF Path
Gain
The application can define RF path gain values for RX and TX separately.
The Bluetooth stack takes TX RF path gain into account when adjusting transmitter power. Power radiated from the antenna then
matches the application request. For example, if maximum power requested by the application is at +10 dBm and path loss is -1 dBm,
then actual power at the pin is +11 dBm.
RX RF path gain is used to compensate the RSSI reports from the Bluetooth Stack.
.rf.tx_gain = -20; // RF TX path gain in unit of 0.1 dBm
.rf.rx_gain = -18; // RF RX path gain in unit of 0.1 dBm
Output selection
On EFR32[B|M]G21 SoC-based designs, the RF output can be selected.
For the correct value refer to the antenna path selection in the RAIL header file rail_chip_specific.h.
4.2.10 NVM3 Error Codes
The Bluetooth stack maps NVM3 error codes to the corresponding sl_status code if one exists. Other NVM3 error codes are mapped
using base value 0x480 + NVM3 error value. The NVM3 error values can be found from platform/emdrv/nvm3/inc/nvm3.h. For example,
ECODE_NVM3_ERR_ALIGNMENT_INVALID would be mapped as 0x481.
silabs.com | Building a more connected world.Rev. 0.6 | 21
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Bluetooth Stack Event Handling
5. Bluetooth Stack Event Handling
The Bluetooth stack for the Wireless Geckos is an event-driven architecture, where events are handled in the main while loop.
5.1 Non-Blocking Event Listener
This mode of operation is the default way in which event processing is done in example applications.
• The sl_bt_pop_event() function processes the internal message queue until an event is received or all of the messages are processed.
• The function copies the received event data to an sl_bt_msg_t struct, or returns SL_STATUS_NOT_FOUND if there are no events
in the queue.
The application can override a dummy weak implementation of sl_bt_on_event() to implement the event handler. It is automatically
called from the applications main loop. Below is an example from the soc-empty application.
// Handle stack events
switch (SL_BT_MSG_ID(evt->header)) {
case sl_bt_evt_system_boot_id:
// Create an advertising set.
sc = sl_bt_advertiser_create_set(&advertising_set_handle);
app_assert(sc == SL_STATUS_OK,
"[E: 0x%04x] Failed to create advertising set\n",
(int)sc);
// Start general advertising and enable connections.
sc = sl_bt_advertiser_start(
advertising_set_handle, // advertising set handle
advertiser_general_discoverable, // discoverable mode
advertiser_connectable_scannable); // connectable mode
app_assert(sc == SL_STATUS_OK,
"[E: 0x%04x] Failed to start advertising\n",
(int)sc);
break;
default:
break;
}
}
To do blocking event handling, call sl_bt_pop_event() in a loop until a valid event is returned.
5.1.1 Notification for Updating Event Listener
In some cases, there may be a need for running the Bluetooth event loop inside another event loop in the application. The Bluetooth
stack has a callback mechanism for notifying the application about the demand for updating the Bluetooth stack event listener. This is
enabled by defining a callback function in the Bluetooth configuration struct.
Note: This stack_schedule_callback is called from the interrupt context. It is important NOT to call sl_bt_pop_event from this con-
text. The application must set a flag or use another mechanism for enabling the application main loop to update the Bluetooth stack.
void bluetooth_update()
{
//set notification for application
}
silabs.com | Building a more connected world.Rev. 0.6 | 22
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Bluetooth Stack Event Handling
5.2 Event Listener with RTOS
By default, the event handling with RTOS calls sl_bt_on_event() when events are received the same way as without RTOS.
If the application needs to define its own Bluetooth event handler it needs to define SL_BT_DISABLE_EVENT_TASK. The application
can then use sl_bt_rtos_has_event_waiting() to check if any events are waiting. To process events, call
sl_bt_rtos_get_event() and sl_bt_rtos_set_event_handled() is used mark the event has been handled.
5.2.1 Commands from Multiple Tasks
It is possible to send Bluetooth commands from multiple Micrium OS tasks. It requires that each task acquires exclusivity before sending the commands and releases it afterward.
The Bluetooth stack provides two functions for convenience. BluetoothPend acquires the Micrium OS mutex and BluetoothPost releases the mutex.
The following code block acquires the mutex for Bluetooth before the Bluetooth command and releases it afterward.
BluetoothPend(&err); //acquire mutex for Bluetooth stack
gecko_cmd_gatt_server_send_characteristic_notification(0xff, gattdb_temp_measurement, 5, temp_buffer);
BluetoothPost(&err);//release mutex
silabs.com | Building a more connected world.Rev. 0.6 | 23
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Interrupts
6. Interrupts
Interrupts create events in their respective interrupt handlers, be it radio interrupts or interrupts from IO pins. The events are later processed in the main event loop from the message queue. The application should always minimize the processing time within an interrupt
handler, and leave the processing for event callbacks or to the main loop.
In general, the interrupt scheme is according to any event-based programming architecture, but a few unique and important exceptions
apply to the Bluetooth stack:
• BGAPI commands cannot be called from interrupt context.
• Only the sl_bt_external_signal() function can be called from interrupt context.
6.1 External Event
An external event is used to capture all peripheral interrupts as an external signal to be passed to the main event loop and to be processed within that loop. The external event interrupt can come from any of the peripheral interrupt sources, for example IOs, comparators, or ADCs, to name a few. The signal bit array is used for notifying the event handler of what external interrupts have been issued.
• The main purpose of the external signal is to trigger an event from the interrupt context to the main event loop.
• The BGAPI event sl_bt_evt_system_external_signal can be generated by calling the void sl_bt_external_signal(uint32
signals) function.
• The function sl_bt_external_signal can be called from the interrupt context.
• The signals parameter of the sl_bt_external_signal function is passed to the sl_bt_evt_system_external_signal event.
/**
* Main
*/
void main()
{
...
//Event loop
while(1)
{
...
//External signal indication (comes from the interrupt handler)
case sl_bt_evt_system_external_signal_id:
// Handle GPIO IRQ and do something
// External signal command’s parameter can be accessed using
//Send gecko_evt_system_external_signal_id event to the main loop
sl_bt_external_signal(...);
}
}
silabs.com | Building a more connected world.Rev. 0.6 | 24
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Interrupts
6.2 Priorities
It is highly recommended that the radio should have the highest priority interrupts. This is the default configuration, and other interrupts
are handled with lower priority. Interrupt priorities for radio is 4, for Link Layer the priority is 5, USART interrupts are 6, and other interrupts have default priority of 7. Smaller value is higher priority interrupt.
If the application needs to disable interrupts, it is recommended that the BASEPRI register is used instead of the PRIMASK register. The
BASEPRI register disables with interrupt priority, whereas PRIMASK disables all interrupts. EMLIB Core can be configured to use the
BASEPRI register, and it can then be used with the CORE_ENTER_ATOMIC() and CORE_EXIT_ATOMIC() macros, which will disable inter-
rupt priorities 3 and lower. See Core Interrupt documentation for more information.
Without RTOS, Link Layer uses PendSV for achieving priority over the application software. With RTOS the Link Layer will not use
PendSV, but Link Layer task will have higher priority over application task. RTOS scheduler will then give priority to Link Layer task
over application task.
The following table describes the three different components within the Bluetooth stack that run in different operating contexts, and their
maximum time to disable interrupts in order for each component to assure connections.
ComponentDescription
Radio
Time-critical low level
TX/RX radio control
Time-critical connection
Link layer
management procedures
and encryption
Host Stack
Bluetooth Host Stack, Security Manager, GATT
(1) PendSV interrupt is only used without RTOS
Timing
Accuracy
Operating
Context
Maximum IRQ
Disable
Microseconds Radio IRQ< ~10 µs
Milliseconds
PendSV IRQ
(1)
< ~20 ms
SecondsApplication< 30 s
If Timing Requirements
are Ignored
Packets are not transmitted or received, which will eventually cause
supervision timeout and Bluetooth
link loss.
If the link control procedure is not
handled in time, Bluetooth link loss
may happen. Slave-side channel map
update and connection update timings are controlled by master.
SMP and GATT have a 30 s timeout
and if operations are not handled
within that timeout Bluetooth link loss
will occur.
silabs.com | Building a more connected world.Rev. 0.6 | 25
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Wireless Gecko Resources
7. Wireless Gecko Resources
The Bluetooth stack uses some of the Wireless Gecko’s resources, which are not available to the application. The following table lists
the resources and describes their use by the stack. The first four resources (in red) are always used by the Bluetooth stack.
CategoryResourceUsed in softwareNotes
PRSPRS7PROTIMER RTC synchroni-
zation
TimersRTCCEM2 timingsThe sleep timer uses RTCC in the default configuration.
PROTIMERBluetoothThe application does not have access to PROTIMER.
RadioRADIOBluetoothAlways used and all radio registers are reserved for the Bluetooth stack.
GPIONCPHost communication.2 to 6 x I/O pins can be allocated for the NCP usage depending on used
PTIPacket trace2 to N x I/O pins.
TX enableTX activity indication1 x I/O pin.
RX enableRX activity indication1 x I/O pin.
COEXWi-Fi coexistence4 x I/O pin.
PRS7 always used by the Bluetooth stack.
In EFR32[B|M]G13 and EFR32[B|M]G22, RTCC can be used by applications if the sleep timer is configured to use another resource. See platform
sleeptimer documentation
features (UART, RTS/CTS, wake-up and host wake-up).
Optional to use, and valid only for NCP use case.
Optional to use.
Optional to use.
Optional to use.
Optional to use.
CRCGPCRCPS StoreCan be used in application, but application should always reconfigure
GPCRC before use, and GPCRC clock must not be disabled in CMU.
FlashMSCPS StoreCan be used by the application.
CRYPTOCRYPTOBluetooth link encryptionThe CRYPTO peripheral can only be accessed through the mbedTLS
crypto library, not through any other means. The library should be able to
do the scheduling between the stack and application access.
RADIOAESBluetooth link encryptionThe application does not have access to RADIOAES
silabs.com | Building a more connected world.Rev. 0.6 | 26
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Wireless Gecko Resources
7.1 Flash
The application and Bluetooth stack are executed from the flash memory. The flash can be split into blocks for the bootloader, the Bluetooth AppLoader, application + Bluetooth stack, and non-volatile memory, as shown in the following figure.
• The bootloader is essential to enable Bluetooth stack and application upgradeability. The bootloader has been designed to be future-proof for bootloader improvements and feature additions. On devices with separate bootloader flash the bootloader is located
there.
• The Bluetooth AppLoader provides OTA upgradability for the application. This is an optional feature, but using it requires that the
bootloader is also used.
• PS Store and NVM3 are a non-volatile data stores (NVM), where both the Bluetooth stack and the application can store permanent
data, such as Bluetooth bonding keys, application configuration data, hardware configurations, and so on. These cannot be used
simultaneously. PS Store is only supported on Series 1 devices.
• The application is located between the Bluetooth AppLoader and NVM. The Bluetooth stack is a library that is linked with the application. The Bluetooth stack includes the actual Bluetooth firmware, including link layer, GAP, SM, ATT, and GATT layers.
• Manufacturing tokens storage is used for storing manufacturing tokens. On EFR32[B|M]G2x devices it is located at end of main
flash.
Figure 7.1. Flash Usage With and Without Separate Bootloader Flash
The following table shows the flash usage for each block. The estimates can vary between use cases, configurations, application resources, or SDK version.
CompilerEFR32[B|
M]G1
EFR32[B|
M]G12
EFR32[B|
M]G13
EFR32[B|
M]G21
EFR32[B|
M]G21 with
EFR32[B|
M]G22
Vault
Bootloader-161616161624
Bluetooth AppLoader
-465050565664
soc-empty (1)GCC153163166170174180
"IAR152162165169173179
PS Store-444---
NVM3 (2)-101010404040
Manufacturing to-
----888
kens
(1) soc-empty is an example applications provided in the Bluetooth SDK. It is compiled with high size optimizations. GCC uses the -Os
flag, and IAR the -Ohz flag.
(2) NVM3 is an alternative to PS Store. They cannot be used simultaneously. NVM3 requires a minimum of 3 flash pages; the default
configuration in the Bluetooth sample applications is 5 pages in the SDK. Please refer to AN1135: Using Third Generation Non-VolatileMemory (NVM3) Data Storage for further information about NVM3.
silabs.com | Building a more connected world.Rev. 0.6 | 27
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Wireless Gecko Resources
7.1.1 Optimizing Flash Usage
Dead code elimination
Bluetooth stack libraries are designed to benefit from the linker's dead code elimination optimization. With this optimization all unused
code will be removed from application.
To fully utilize this optimization feature, it is important not to call any function that is not needed for application. These include all initialization functions for the Bluetooth stack.
Selective Initialization of Bluetooth Stack Components
Each required stack component must be individually initialized. For more information, see section 4.2 Bluetooth Configuration with
sl_bt_init_stack().
7.1.2 Bluetooth Bonding Database
Bluetooth bonding database is stored in NVM. NVM3 size must be set so that the required number of bondings can fit to it. The following table shows how much NVM3 space each bonding will require at maximum in bytes including NVM3 overheads. EFR32[B|M]G1x
devices still use use the old bonding database, whereas EFR32[B|M]G2x devices use new PSA ITS (internal trusted store) for storing
the keys.
EFR32[B|M]G1xEFR32[B|M]G2xEFR32[B|M]G2x with Vault
Secure Connections Pairing90210298
Legacy Pairing138318450
Note that in EFR32[B|M]G2x devices, during the first boot, the device tries to import keys from the old bonding database used in the
SDK v3.1.1 and older into PSA ITS. If IRK (privacy key) import fails, all existing bondings are deleted, because IRK is shared with bonded devices. If importing certain bonding fails, that bonding is erased and importing will continue with the next one.
When deployed to Secure Vault High devices, sensitive keys such as the Long Term Key (LTK) are protected using the Secure Vault
Key Management functionality. The table below shows the protected keys and their storage protection characteristics.
Wrapped KeyExportable/Non-ExportableNotes
Remote Long Term Key (LTK)Non-Exportable-
Local Long Term Key (legacy only)Non-Exportable-
Remote Identity Resolving Key (IRK)ExportableMust be Exportable for future compat-
ibility reasons
Local Identity Resolving Key (IRK)ExportableMust be Exportable because the key
is shared with other devices
Wrapped keys that are “Non-Exportable” can be used, but cannot be viewed or shared at runtime. Wrapped keys that are “Exportable”
can be used or shared at runtime, but remain encrypted while stored in flash.
silabs.com | Building a more connected world.Rev. 0.6 | 28
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Wireless Gecko Resources
7.2 Linking
The Bluetooth stack is delivered as a set of library files. The application links the Bluetooth stack libraries with the rest of application.
The linker will then create an ELF-file, which contains the application code and data ready to be loaded into flash.
For generating OTA DFU files, the application's code and data must be linked into their own section in the ELF-file. This is automatically
done with the linker files provided with the Gecko Platform.
Figure 7.2. Sections Defined in the Linker File and Their Placement
Depending on the device used, the bootloader is placed on separate flash memory or, if no separate bootloader flash exists, the linker
file reserves some memory from main flash for the bootloader. Bluetooth AppLoader is placed at the beginning of main flash and the
application with all libraries start from the next free flash page.
For more information on the OTA updates and how to enable them, please refer to UG266: Silicon Labs Gecko Bootloader User'sGuide and AN1086: Using the Gecko Bootloader with Silicon Labs Bluetooth Applications.
silabs.com | Building a more connected world.Rev. 0.6 | 29
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Wireless Gecko Resources
7.3 RAM
The Bluetooth stack reserves part of the RAM from the Wireless Gecko and leaves the unused RAM for the application.
RAM consumption of the Bluetooth functionality is divided into:
• Bluetooth stack
• Bluetooth object pools
• Bluetooth buffer memory
• Bluetooth GATT database
• C STACK
• C HEAP
The following table shows the RAM allocations that are done statically at link time.
ComponentStatic allocation at link timeConfigurable by
Bluetooth stack6 kB
Bluetooth GATT databaseApplication-dependent (20 to 200 bytes)
Call stack2752 bytesSL_STACK_SIZE
Heap memory9200 bytesSL_HEAP_SIZE
The following table shows the RAM allocations that are done dynamically from the heap at run time.
ComponentDynamic heap allocation at run timeConfigurable by
Bluetooth stack2 kB
Bluetooth connection objects1600 bytes = 400 bytes * 4SL_BT_CONFIG MAX_CONNECTIONS
Bluetooth advertiser objects160 bytes = 160 bytes * 1SL_BT_CONFIG_USER_ADVERTISERS
Bluetooth periodic advertising synchronization objects
Bluetooth software timers160 bytes = 40 bytes * 4SL_BT_CONFIG_MAX_SOFT-
WARE_TIMERS
Bluetooth buffer memory3150 bytesSL_BT_CONFIG_BUFFER_SIZE
7.3.1 Bluetooth Stack
The Bluetooth stack allocates around 6 kB of static RAM and 2 kB of heap for its internal use. It includes Bluetooth stack software with
low-level radio drivers and the application programming interface.
7.3.2 Bluetooth Object Pools
The Bluetooth stack uses memory to store the necessary context for objects such as connections, advertisers, and periodic advertisement synchronizations. The number of these objects depends on the configuration. The table in section 7.3 RAM summarizes the memory usage in the default configuration and shows which configuration items affect the number of objects allocated.
7.3.3 Bluetooth Buffer Memory
The Bluetooth stack uses memory for buffering API events and the data transmitted in Bluetooth connections, advertising, and scanning. This buffer memory is allocated from the heap by the Bluetooth stack when calling sl_bt_init_stack(). The size of buffer
memory in bytes is defined by the C-define SL_BT_CONFIG_BUFFER_SIZE in sl_bluetooth_config.h. The default value is an estimation for
achieving adequate throughput and supporting multiple simultaneous connections. Consider increasing this value if the application
needs higher data throughput over connections or uses advertising or scanning with long advertisement data.
silabs.com | Building a more connected world.Rev. 0.6 | 30
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Wireless Gecko Resources
7.3.4 Bluetooth GATT Database
The Bluetooth GATT database uses statistically-allocated RAM. The amount of RAM used depends on the user-defined GATT database and cannot be generalized. All characteristics with write enabled use as much RAM as their length defined. Plus, every attribute in
GATT needs a few bytes of RAM for maintaining the Attribute permissions. Typical RAM usage is approximately 20 to 200 bytes.
7.3.5 Call Stack
The Bluetooth stack requires at minimum a call stack to be reserved from RAM as summarized in the table in section 7.3 RAM. Application developers must allocate RAM for the application call stack on top of the memory required by the stack. The size of the call stack is
configured by SL_STACK_SIZE in sl_memory_config.h.
7.3.6 Heap memory
The Bluetooth stack uses the heap to allocate storage for object contexts and the stack internal state as summarized in the table in
section 7.3 RAM. In addition to these allocations, the Bluetooth stack requires heap memory for asymmetric encryption operations using the elliptic curve algorithms during Bluetooth pairing.
The C-define SL_HEAP_SIZE in sl_memory_config.h defines the minimum heap size that is allocated from the physical RAM at link time.
The actual heap size at runtime can end up being larger than the minimum to make use of any available physical memory that would
otherwise have remained unallocated.
The default minimum heap size is sufficient for running the Bluetooth examples with the default Bluetooth configuration. The application
should configure the minimum heap size to account for the Bluetooth configuration used and any extra heap that the application may
require.
silabs.com | Building a more connected world.Rev. 0.6 | 31
UG434: Silicon Labs
Bluetooth ® C Application Developer's Guide for SDK v3.x
Application ELF-file
8. Application ELF-file
ELF (Executable and Linkable Format) is a standard file format for executable files. This chapter describes the sections in the ELF file
related to the application and the Bluetooth stack.
Some linkers provide output describing the consumed flash, but what it contains is not obvious. A Bluetooth project might contain a
bootloader and the Bluetooth AppLoader, and the device might have separate flash for the bootloader. The ELF-file provides exact information about RAM and flash usage.
Simplicity Studio provides the GCC toolchain, which contain command line tool objdump. This tool can be used to get section information from the ELF-file.
objdump requires input ELF-file. If the parameter -h is used, objdump dumps the section header information.
IAR
Calling objdump from the command line for an example application:
.text_signature is the space reserved for the AppLoader signature.
.text contains the application code and read-only data. The size of the application in this example is 0x289dc in hexa-decimal and
166364 bytes in decimal.
.ARM.exidx is used for debugging.
.stack is a RAM section for the call stack
.data is the RAM section for initialized variables.
.bss is the RAM section for uninitialized variables.
.heap is the RAM section for heap.
Refer to GCC documentation for a description of the remaining sections.
silabs.com | Building a more connected world.Rev. 0.6 | 33
9. Documentation
UG434: Silicon Labs Bluetooth ® C Application Developer's Guide for SDK v3.x
Documentation
silabs.com | Building a more connected world.Rev. 0.6 | 34
Smart. Connected.
Energy-Friendly.
IoT Portfolio
www.silabs.com/products
Disclaimer
Silicon Labs intends to provide customer s with the latest, accurate, and in-depth documentation of all peripherals and modules available for system and sof tware implementers using or intending to use the Silicon Labs products. Characterization data, available modules and peripherals, memory sizes and memor y addresses refer to each
specic device, and “ Typical” parameters provided can and do var y in dierent applications. Application examples described herein are for illustrative purposes only. Silicon
Labs reserves the right to make changes without further notice to the product information, specications, and descriptions herein, and does not give warranties as to the
accuracy or completeness of the included information. Without prior notication, Silicon Labs may update product rmware during the manufacturing process for security or
re li abi li ty re aso ns. Suc h cha nges wi ll no t alt er the sp eci ca t io ns or the pe r for ma nce of the pro duc t. Si li con Labs sha ll ha ve no lia bil ity fo r th e con seq ue nce s of us e of the in for-
matio n supplied in th is document . This document does n ot imply or expressly grant any license to de sign or fabri cate any integrated circui ts. The pro ducts are not desig ned or
authorized to be used within any FDA Class III devices, applications for which FDA premarket approval is required or Life Suppor t Systems without the specic written consent
of Silicon Labs. A “Life Support System” is any product or system intended to support or sustain life and/or health, which, if it fails, can be reasonably expected to result in
signicant personal injury or death. Silicon Labs produc ts are not designed or authorized for militar y applications. Silicon Labs products shall under no circums tances be used
in weapons of mass destruction including (but not limited to) nuclear, biological or chemical weapons, or missiles capable of delivering such weapons. Silicon Labs disclaims
all express and implied warranties and shall not be responsible or liable for any injuries or damages related to use of a Silicon Labs produc t in such unauthorized applications.
No te: Th is co nte nt ma y con tai n o ensi ve te rmi n olo gy tha t is no w obsol ete . Sil i con La b s is re pla cin g the se te rms wi th in clu sive langu a ge wh ere ver po s sib le. Fo r more
Silicon Laboratories Inc.®, Silicon Laboratories®, Silicon Labs®, SiLabs® and the Silicon L abs logo®, Bluegiga®, Bluegiga Logo®, Clockbuilder®, CMEMS®, DSPLL®, EFM®, EFM32®,
EFR, E mber®, Energy Micro, Energy Micro logo and combinations thereof, “the world’s most energy friendly microcontrollers”, Ember®, EZLink®, EZRadio®, EZRadioPRO®, Gecko®,
Gecko OS , Gecko OS Stud io, ISOmode m®, Precision32®, ProSLIC®, Simplicity Studio®, SiPHY®, Telegesis , the Telegesis Lo go®, USBXpress® , Zentr i, the Zentr i logo and Zentr i DMS,
Z-Wave®, and others are trademarks or registered trademarks of Silicon Labs. ARM, CORTEX, Cortex-M3 and THUMB are trademarks or registered trademarks of ARM Holdings. Keil is a registered trademark of ARM Limited. Wi-Fi is a registered trademark of the Wi-Fi Alliance. All other products or brand names mentioned herein are trademarks
of their respective holders.
Silicon Laboratories Inc.
400 West Cesar Chavez
Austin, TX 7 8701
USA
Quality
www.silabs.com/quality
Support & Community
www.silabs.com/community
www.silabs.com
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.