How to Quickly and Cost Effectively Add Bluetooth 5.3 to Edge IoT Designs

By Jens Wallmann

Contributed By DigiKey's European Editors

Relentless competition puts pressure on Internet of Things (IoT) device developers to rapidly introduce new and innovative products while reducing costs and ensuring robust, low power, and secure communication. Traditional intelligent IoT end nodes comprise a microcontroller unit (MCU) to enable edge processing and a wireless IC for connectivity. Problems arise when design teams lack the radio frequency (RF) skills required for an effective solution.

To complete, certify, and move their wireless IoT designs into volume production on time, developers need to make the development process more efficient. One way to boost the efficiency of the development process involves using a low-power MCU with an integrated Bluetooth Low Energy (BLE) wireless interface.

This article introduces the ultra-low-power STM32WBA52 MCU series from STMicroelectronics and shows how developers can use a BLE evaluation board, development tools, and application examples to get a BLE 5.3 wireless design up and running quickly. A brief look at programming and MCU wiring is included.

Power-saving wireless MCU with high security level

Certified for BLE 5.3, the STM32WBA52 MCU series is a cost-effective solution that enables novice developers to quickly add wireless communications to their devices. Based on the Arm® Cortex®-M33 core with a 100 megahertz (MHz) clock and TrustZone technology, these microcontrollers provide a high level of security, protect data and intellectual property (IP), and prevent hacks and device cloning.

While the STM32WBA52CEU6 wireless MCU has 512 kilobytes (Kbytes) of flash memory and 96 Kbytes of static RAM (SRAM), the STM32WBA52CGU6 variant offers 1 megabyte (Mbyte) of flash memory and 128 Kbytes of SRAM. Figure 1 shows the functional scope of the IC in a 48 UFQFN package. Incidentally, up to 20 capacitive touch channels enable the operation of hermetically sealed devices (no mechanical keys are needed).

Functional block diagram of STMicroelectronics STM32WBA52Figure 1: A functional block diagram of the STM32WBA52 shows the integrated BLE 5.3 radio, flash and SRAM, and security support. (Image source: STMicroelectronics)

A rich STM32Cube ecosystem supports the implementation and programming of the BLE application. It includes the STM32CubeIDE development environment, as well as tools like the STM32CubeMX peripheral configurator and code generator, the STM32CubeMonitorRF performance tester, and the STM32Cube.AI desktop and cloud versions for artificial intelligence (AI). A matching evaluation board, the NUCLEO-WBA52CG, simplifies prototyping and accelerates validation with many BLE sample applications and freely available source code.

Device and data security

The STM32WBA52 product line complies with the IoT security standards Platform Security Arm (PSA) Certified Level 3 and Security Evaluation Standard for IoT Platforms Assurance Level 3 (SESIP3). Cyber protection is enhanced by the PSA security program based on security isolation, memory protection, tamper protection, and the MCUs’ Cortex-M33 with Arm TrustZone architecture. The Trusted Firmware for Arm Cortex-M (TF-M) complies with the industry standard PSA Certified Security Framework with PSA immutable Root of Trust (RoT), including secure boot and secure firmware update (X-CUBE-SBSFU), cryptography, secure storage, and run-time attestation.

Integrated radio minimizes the BOM

The integrated ultra-low-power radio module delivers +10 decibels referenced to 1 milliwatt (mW) (dBm) RF output power. It enables reliable communication over short distances (BLE 5.3) and long distances (Long Range) with data rates of up to 2 megabits per second (Mbps). A deep standby low power mode reduces overall electrical power when radio communication is active. The STM32WBA MCUs can support up to 20 simultaneous connections.

Electrical performance characteristics of the radio module:

  • 2.4 gigahertz (GHz) RF transceiver supporting BLE 5.3
  • RX sensitivity: -96 dBm (BLE at 1 Mbps)
  • Programmable output power, up to +10 dBm in 1 dB steps
  • Integrated balun

Smaller battery due to highly efficient energy management

The STM32WBA52 MCUs have many energy-saving technologies, including STMicroelectronics' Low Power Direct Memory Access (LPDMA) and flexible power-saving states with fast wake-up times. Together, these features can reduce MCU power consumption by up to 90%, which translates to a significantly smaller battery or a longer battery life.

Electrical performance features of FlexPowerControl:

  • 1.71 to 3.6 volt power supply
  • 140 nanoampere (nA) standby mode (16 wakeup pins)
  • 200 nA standby mode with real-time clock (RTC)
  • 2.4 microampere (μA) standby mode with 64 Kbytes SRAM
  • 16.3 μA stop mode with 64 Kbytes SRAM
  • 45 μA/MHz run mode at 3.3 volts
  • Radio: Rx 7.4 milliamperes (mA) / Tx @ 0 dBm 10.6 mA

Additionally, Bluetooth 5.3 offers faster switching between low duty and high duty cycles, making it more energy efficient than previous versions.

Architecture of the Bluetooth stack and data packets

The single-core Arm Cortex-M33 MCUs in the STM32WBA52 are designed for the development of application firmware, including profiles and services on the BLE stack (controller and host). The MCUs process the data flow from the integrated RF module at the lowest physical layer (PHY) to the generic attribute profile (GATT) and generic access profile (GAP) (Figure 2). The GAP defines and manages advertising and connection, while the GATT defines and manages in/out data exchange.

Image of MCUs process the data flow from the radio PHY to the GATT and GAPFigure 2: The MCUs process the data flow from the radio PHY to the GATT and GAP. (Image source: STMicroelectronics)

BLE sends data packets that are defined as a fixed frame structure of a bit sequence. The length of the user data area can vary dynamically from 27 to 251 bytes.

BLE application examples

The online encyclopedia, STMicro-Wiki for STM32WBA MCUs, contains several application examples for different Bluetooth roles, including:

  • Advert: BLE_Beacon
  • Sensor: BLE_HealthThermometer,BLE_HeartRate
  • Bridge: BLE_SerialCom
  • Router: BLE_p2pRouter
  • Data: BLE_DataThroughput, BLE_p2pServer & Multi Slave BLE_p2pClient
  • RF-Monitor: BLE_TransparentMode,
  • Firmware Update Over The Air: BLE_Fuota

Matching their own BLE project, device designers and programmers can flash the compiled binary from the corresponding GitHub project directory to the NUCLEO board and start the Bluetooth connection to a smartphone or desktop PC. The required programmer software, STM32CubeProg, provides reading, writing, and verification of device memory through both the debug interface and the bootloader interface.

Running the BLE example “Health Thermometer Sensor”

The Health Thermometer Profile (HTP) is a GAP based low-energy profile defined by the Bluetooth Special Interest Group (SIG). It combines a Health Thermometer Collector and a Health Thermometer Sensor to connect and exchange data in different applications (Figure 3).

Image of BLE communication between the NUCLEO board and a smartphone (click to enlarge)Figure 3: BLE communication between the NUCLEO board as sensor/server and a smartphone as collector/client. (Image source: STMicroelectronics)

The Health Thermometer Sensor:

  • Measures the temperature and exposes it via the Health Thermometer Service
  • Contains the Device Information Service to be identified by the remote device
  • Is the GATT server

The Health Thermometer Collector:

  • Accesses the information exposed by the Health Thermometer Sensor and can display it to the end-user or store it on nonvolatile memory for later analysis
  • Is the GATT client

After the Health Thermometer binary file is flashed into the NUCLEO’s MCU, the developer needs to follow the next steps to run the BLE application example:

Using the Smartphone-App

  1. Install ST BLE Toolbox on a smartphone. The app is used to interact with and debug ST BLE devices.
  2. Power on the STM32WBA NUCLEO board with the Health Thermometer application flashed in.
  3. Turn the smartphone Bluetooth (BT) on and scan BT devices available in the app. Select Health Thermometer and connect.

Using the Web browser interface

  1. Ensure browser compatibility:
    • on a desktop computer: Chrome, Edge, or Opera
    • on a smartphone device: Chrome Android
  2. Power on the STM32WBA NUCLEO board with the Health Thermometer application flashed in.
  3. Activate Bluetooth on the computer.
  4. Open the web page https://applible.github.io/Web_Bluetooth_App_WBA/ in the browser.
  5. Click on the connect button at the top of the web page, then select HT_xx in the device list and click pair. The device is now connected.
  6. Click on Health Thermometer to show the interface.

Table 1 describes the structure of the services of the Health Thermometer Sensor. The 128-bit long Universally Unique Identifier (UUID) distinguishes the individual characteristics and services.

Service Characteristic Property UUID Size
Health Termometer Service 0x1809
Temperature measurement Indicate 0x2A1C 13
Temperature type Read 0x2A1D 1
Intermediate temperature Notify 0x2A1E 13
Measurement interval Read, write, indicate 0x2A21 2
Device Information Service 0x180A
Manufacturer name string Read 0x2A29 32
Model number string Read 0x2A24 32
System ID Read 0x2A23 8

Table 1: GATT services and their UUID for the "Health Thermometer Sensor" GAP. (Image source: STMicroelectronics)

The following JavaScript sequence from GitHub shows how the web browser interface filters the different GATT datathroughput characteristics (Listing 1).

Copy
[...]

// Filtering the different datathroughput characteristics
  props.allCharacteristics.map(element => {
    switch (element.characteristic.uuid) {
      case "00002a1c-0000-1000-8000-00805f9b34fb":
        IndicateCharacteristic = element; // Temperature Measurement (TEMM)
        IndicateCharacteristic.characteristic.startNotifications();
        IndicateCharacteristic.characteristic.oncharacteristicvaluechanged = 
        temperatureMeasurement;
        break;
      case "00002a1d-0000-1000-8000-00805f9b34fb":
        ReadCharacteristic = element; // Temperature Type
        readTemperatureType();
        break;
      case "00002a1e-0000-1000-8000-00805f9b34fb":
        NotifyCharacteristic = element; //Immediate Temperature
        NotifyCharacteristic.characteristic.startNotifications();
        NotifyCharacteristic.characteristic.oncharacteristicvaluechanged = notifHandler;
        break; 
      case "00002a21-0000-1000-8000-00805f9b34fb":
        ReadWriteIndicateCharacteristic = element; // Measurement Interval
        readMeasurementInterval();
        break;
      default:
        console.log("# No characteristics found..");
    }
  });

[...]

Listing 1: This JavaScript sequence filters the different GATT datathroughput characteristics from Table 1. (Listing source: GitHub, STMicroelectronics)

Tracing the BLE stack processes

The NUCLEO-WBA52CG embeds the ST-LINK/V3 in-circuit debugger and programmer, supporting the STM32 virtual COM port driver for communication with a PC via a serial interface. Any software terminal can open this serial communication port to show the short text messages generated in the code by the function APP_DBG_MSG.

The traces within the project need to be enabled in the file app_conf.h

#define CFG_DEBUG_APP_TRACE   (1)

Alternatively, the smartphone app "SE BLE Toolbox" offers a trace function on tab <Application Log>.

Programming BLE 5.3 applications

For programming the STM32WBA52 MCUs, STM has put together the STM32CubeWBA-Package consisting of a hardware abstraction layer (HAL), low-layer application programming interfaces (APIs) and CMSIS, File system, RTOS, BLE/802.15.4, Thread, and Zigbee stacks, as well as examples running on STMicroelectronics boards.

Project structure setups for all three development environments (IDEs), such as IAR Embedded Workbench for Arm (EWARM), Keil MDK-ARM, and STM32CubeIDE, are included in each NUCLEO-WBA52CG BLE application example.

In the case of the Health Thermometer example, only specific files from the project directory tree (frame in Figure 4 left) generate the GATT services. The two routines, "Health Thermometer Service” (hts) and "Device Information Service” (dis) from Table 1, run in parallel (bottom right of Figure 4).

Diagram of programmers can add their own GATT content to the framed code files (click to enlarge)Figure 4: Programmers can add their own GATT content to the framed code files (left); these files generate the GATT services (right). (Image source: STMicroelectronics)

Programmers can use the source code for their own projects and extend it with their GATT content in the areas marked with USER CODE BEGIN / USER CODE END (Listing 2). The initialization sequence from file hts.c generates the GATT characteristic Temperature Measurement (TEMM) carrying the UUID 0x2A1C.

Copy
[...]
 void HTS_Init(void)
 {
 [...]

  /* TEMM, Temperature Measurement */
  
  uuid.Char_UUID_16 = 0x2a1c;
  ret = aci_gatt_add_char(HTS_Context.HtsSvcHdle,
                          UUID_TYPE_16,
                          (Char_UUID_t *) &uuid,
                          SizeTemm,
                          CHAR_PROP_INDICATE,
                          ATTR_PERMISSION_NONE,
                          GATT_DONT_NOTIFY_EVENTS,
                          0x10,
                          CHAR_VALUE_LEN_VARIABLE,
                          &(HTS_Context.TemmCharHdle));
  if (ret != BLE_STATUS_SUCCESS)
  {
    APP_DBG_MSG("  Fail   : aci_gatt_add_char command  : TEMM, error code: 0x%2X\n", ret);
  }
  else
  {
    APP_DBG_MSG("  Success: aci_gatt_add_char command  : TEMM\n");
  }

  /* USER CODE BEGIN SVCCTL_InitService2Char1 */

  /* USER CODE END SVCCTL_InitService2Char1 */

 [...]
 }
[...]

Listing 2: The initialization sequence from file hts.c generates the GATT characteristic TEMM. (Image source: GitHub, STMicroelectronics)

External component requirements

The STM32WBA52 wireless MCU requires only a few external components for basic operation with Bluetooth functionality. These include capacitors for the voltage supply, a crystal oscillator, a printed circuit board (pc board) antenna with impedance matching, and a harmonic filter (Figure 5).

Diagram of STMicroelectronics STM32WBA52 RF terminal (click to enlarge)Figure 5: For Bluetooth, the STM32WBA52’s RF terminal connects to an impedance-matching network, a harmonic filter, and an antenna. (Image source: STMicroelectronics)

Conclusion

Developers of wireless IoT devices need to shorten design cycles and lower costs to compete in a rapidly evolving market. However, RF design is challenging. The STM32WBA52 MCU, with its integrated BLE 5.3 interface, allows developers to get to market quickly and cost-effectively. The pre-programmed BLE stack and several BLE application examples form a programming template for custom projects where GATT contents are easily inserted.

DigiKey logo

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of DigiKey or official policies of DigiKey.

About this author

Jens Wallmann

Jens Wallmann

Jens Wallmann is a freelancing editor and contributes to electronics publications, both print and online. As an electrical engineer (communications engineering) and a trained industrial electronic engineer he has more than 25 years in electronics development with a focus on measuring technology, automotive electronics, process industry and Radio Frequency.

About this publisher

DigiKey's European Editors