STM32WB Bluetooth® LE – Wireless Stack Information

1. STM32WB - Bluetooth® LE Coprocessor Binaries

This is a description about the Bluetooth® LE Wireless stack available for the secure CM0+ coprocessor of the STM32WB Most of the information can be found within the Release Note for STM32WBxx Copro Wireless Binaries. https://github.com/STMicroelectronics/STM32CubeWB/tree/master/Projects/STM32WB_Copro_Wireless_Binaries

1.1. CubeWB v1.14.0 - Bluetooth® LE Wireless stack Summary

For Bluetooth® LE applications, 6 binaries are available and certified BLE 5.3. According to the type of application, the size of the flash, it is up to the developer to load the right binary:

  • stm32wb5x_BLE_Stack_full_extended_fw.bin - 177KB - Link Layer, HCI, L2CAP, ATT, SM, GAP and GATT database
    • To be used for Adverting/Scanning Extension - Full HCI/ACI/DTM commands/Event support
  • stm32wb5x_BLE_Stack_full_fw.bin - 143KB - Link Layer, HCI(limited), L2CAP, ATT, SM, GAP and GATT database
    • To be used for GAP Central/Peripheral & GATT Server/Client applications
    • support up to 8 connections with maximum 2 links as Slave
  • stm32wb5x_BLE_Stack_light_fw.bin - 112KB - Link Layer, HCI(limited), L2CAP, ATT, SM, GAP(limited) and GATT(limited) database
    • To be used for GAP Peripheral & GATT Server applications
    • support up to 2 links as Slave
BLE Stack 5.3 Certified GAP Peripheral GAP Central GATT Server GATT Client PHY 2M Data Length Extension Legacy Pairing, LE secure connection Privacy White List HCI Interface DTM L2CAP Connection Oriented channels support Channel Selection #2 Extended Advertising Scanning BT SIG Declaration ID
Full Extended id123456
Full reduced id123456
Light ' ?? reduced id123456


  • stm32wb5x_BLE_HCILayer_fw.bin - 93KB - Link Layer, HCI, DTM
    • To be used for BLE Host Stack running on CM4 application processor (Arduino, Zephyr,..)
  • stm32wb5x_BLE_HCILayer_extended_fw.bin - 93KB - Link Layer, HCI, DTM, Extended Advertising/Scanning
    • To be used for BLE Host Stack running on CM4 application processor (Arduino, Zephyr,..)
  • stm32wb5x_BLE_HCI_AdvScan_fw.bin - 34KB - Link Layer, HCI reduced
    • To be used for advertising and scanning through HCI interface
Info white.png Information
To use extended binaries, it is necessary to adapt the scatter file in the BLE applications as:
  • The RAM_A shared range shall be reduced to memory range [0x20030000:0x200307FF]
  • The Mail-box buffers(MB_MEM1, MB_MEM2) shall be located in RAM_B shared defined in memory range [0x20038000:0x2003A7FF]
  • The RAM_B shared shall be added to Total_RAM_region


test blalla



  • Add the support of STM32 MCU in Arduino IDE[1]:
    • Arduino_Core_STM32[2]
    • STM32 boards support to Arduino[3]
  • Include STM32duinoBLE library:
    • STM32duinoBLE[4]
      • From the "Tools > Manage Librairies..." menu, select the STM32duinoBLE library:
STM32duinoBLE library
Connectivity STM32duinoBLE lib.png



  • Configuring IDE:
    • Connect the Nucleo-64 WB55 board to the computer USB port.
    • Launch the Arduino software
    • Select the Nucleo-64 WB55 board in two steps:
      • From the "Tools > Board" menu, select the STM32 boards groups: Nucleo-64
      • Then from the "Tools > Board part number" menu, select the P-Nucleo WB55RG
Arduino Nucleo-64 WB55 Configuration
Connectivity Arduino WB55 Configuration.png

1.2. BLE Stack Configuration for P-NUCLEO-WB55

BLE Stack configuration for P-NUCLEO-WB55:

  • For release v1.12.0 and previous use full stack (stm32wb5x_BLE_Stack_full_fw.bin)
  • For release v1.13.0 and next use HCI Layer stack (stm32wb5x_BLE_HCILayer_fw.bin) and do the following modification in stm32BLEDuino library:
    • In HCISharedMemTransport.cpp file comment the following lines:
HCISharedMemTransport.cpp modification
Connectivity STM32duinoBLE lib init.png


1.3. Sketch STM32WB_P2P_Server.ino

The following Arduino's Sketch demonstrates the P2P Server application including debug traces on the UART hyperterminal.

  • compile and upload STM32WB_P2P_Server.ino
/**
******************************************************************************
* @file    STM32WB_P2P_Server.ino
* @author  WBL BLE Application Team
* @brief   Arduino STM32WB P2P Server Application (Custom STM)
******************************************************************************
* @attention
* This example creates a P2P server Application
* P2P service                     - 0000FE40-cc7a-482a-984a-7f2ed5b3e58f
* Led control Characteristic      - 0000FE41-8e22-4541-9d4c-21edae82ed19 (Read|WritewithoutResponse)
*                                     Byte 0 - Board Selection
*                                     Byte 1 - LED Status (1 : ON; 0 : OFF)
* Button control Characteristic   - 0000FE42-8e22-4541-9d4c-21edae82ed19 (Notify)
*                                     Byte 0 - Board Selection
*                                     Byte 1 - LED Status (1 : ON; 0 : OFF)
* To be supported by Smart Phone application ST BLE Sensor, the advertsing data shall contain the AD element Manufacturer as following:
* Manufacturer_data:
*   0x01,                   // SKD version 
*   0x83,                   // CFG_DEV_ID_P2P_SERVER1 
*   0x00,                   // GROUP A Feature  
*   0x00,                   // GROUP A Feature 
*   0x00,                   // GROUP B Feature 
*   0x00,                   // GROUP B Feature 
* };
*
* The two characteristics are used :
*  -- to control (Write) the LED1 of Nucleo64-WB55 board LED 
*  -- or to Notify the Remote device by pushing SW1 f Nucleo68-WB55 board.
*  
*  The Circuit:
*  - Nucleo68-WB55
*  You can use a generic BLE central app, like ST BLE Sensor or ST BLE Toolbox, to interact with the services and characteristics
*  created in this sketch.
*
*  This example code is in the public domain.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include <STM32duinoBLE.h>

/* Private typedef -----------------------------------------------------------*/
typedef struct __attribute__((packed)) {
    byte boardSelection;
    byte ledStatus;
} P2P_STM32WB_led_t;
P2P_STM32WB_led_t ledControl;

typedef struct __attribute__((packed)) {
    byte boardSelection;
    byte ButtonStatus;
} P2P_STM32WB_button_t;
P2P_STM32WB_button_t buttonInfo;

/* Private variables ---------------------------------------------------------*/
const int buttonPin = PC4; // set buttonPin to digital pin PC4
const int ledPin = LED_BUILTIN; // set ledPin to on-board LED
const int buttonPushed = 1;
const int boardWB_1 = 1;

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 1;     // previous state of the button

/* Private variables ---------------------------------------------------------*/
/* UUID for P2P Service-------------------------------------------------------*/
BLEService P2PService("0000FE40-cc7a-482a-984a-7f2ed5b3e58f"); 

/* create switch characteristic and allow remote device to read and write -----*/
BLECharacteristic ledCharacteristic("0000FE41-8e22-4541-9d4c-21edae82ed19", BLERead | BLEWriteWithoutResponse,sizeof(ledControl),true);

/* create button characteristic and allow remote device to get notifications --*/
BLECharacteristic buttonCharacteristic("0000FE42-8e22-4541-9d4c-21edae82ed19", BLENotify,sizeof(buttonInfo),true);

/* Manufacturer Advertising Data element structure ----------------------------*/
static const uint8_t manufacturer_data[6] = {
    0x01, // BlueST Protocol - SDK Version
    0x83, // Device ID - STM32WB P2P Server 
    0x00, // GROUP A Feature
    0x00, // GROUP A Feature
    0x00, // GROUP B Feature
    0x00, // GROUP B Feature
};

HCISharedMemTransportClass HCISharedMemTransport;
BLELocalDevice BLEObj(&HCISharedMemTransport);
BLELocalDevice& BLE = BLEObj;

/**
* @brief  Connection Event Handler
* @param  BLE Central Device
* @retval None
*/
void blePeripheralConnectHandler(BLEDevice central) {
  // central connected event handler
  Serial.print("==> Connection established with central: ");
  Serial.print(central.address());
    if (BLE.connected()) {
      Serial.print(" -- RSSI = ");
      Serial.println(BLE.rssi());
    }
}

/**
* @brief  Disconnection Event Handler
* @param  BLE Central Device
* @retval None
*/
void blePeripheralDisconnectHandler(BLEDevice central) {
  // central disconnected event handler
  Serial.print("==> Disconnection event with central: ");
  Serial.println(central.address());
}

/**
* @brief  Event Handler when Characteristic Written 
* @param  BLE Central Device
* @param  Characteritic
* @retval None
*/
void LedCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
  byte data[sizeof(ledControl)];
  // central wrote new value to characteristic, update LED
  if (ledCharacteristic.written()) {
    Serial.println("==>Led Characteritics written:");
    Serial.print("Data Received: ");
    ledCharacteristic.readValue(data, sizeof(ledControl));
    Serial.print(ledCharacteristic.valueLength());
    Serial.print(" ");
    Serial.print("bytes -- ");
    for (int i = 0; i < sizeof(ledControl); i++) {
      Serial.print("0x");
      Serial.print(data[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
    ledControl.boardSelection=data[0];
    ledControl.ledStatus=data[1];
    Serial.print("Board Selected:");
    Serial.println(ledControl.boardSelection);
    Serial.print("Value:");
    Serial.println(ledControl.ledStatus);

    if(ledControl.ledStatus){
      Serial.println("==>LED1 ON");
      digitalWrite(ledPin, HIGH);
    }
    if(!ledControl.ledStatus){
      Serial.println("==>LED1 OFF");
      digitalWrite(ledPin, LOW);
    }
  }
}  

/**
* @brief  Arduino main Setup 
* @param  None
* @retval None
*/
void setup() {
  Serial.begin(115200);
  while (!Serial);

  pinMode(ledPin, OUTPUT); // use the LED as an output
  pinMode(buttonPin, INPUT_PULLUP); // use button pin as an input

  //Project P2P server
  Serial.println("======================================");
  Serial.println("== STM32WB - P2P Server Application ==");
  Serial.println("======================================");
  
  // begin initialization
  if (!BLE.begin()) {
    Serial.println("==>starting BLE failed!");

    while (1);
  }
  
  //Set the device name in the built in device name characteristic.
  BLE.setDeviceName("STM32WB-Arduino");
  //set the local name peripheral advertises
  Serial.println("==> Advertising Name - P2P_Server");
  BLE.setLocalName("P2P_Server");
  //Set the manufacturer data value used when advertising.
  BLE.setManufacturerData(manufacturer_data, sizeof(manufacturer_data));
  
  //Set the advertising interval in units of 0.625 ms. 
  //Defaults to 100ms (160 * 0.625 ms) if not provided. 
  BLE.setAdvertisingInterval(160); // 160 * 0.625 ms
   
  // set the UUID for the service this peripheral advertises:
  //BLE.setAdvertisedService(P2PService);

  // add the characteristics to the service
  P2PService.addCharacteristic(ledCharacteristic);
  P2PService.addCharacteristic(buttonCharacteristic);
  // assign event handlers for characteristic
  ledCharacteristic.setEventHandler(BLEWritten, LedCharacteristicWritten);

  // add the service
  BLE.addService(P2PService);

  //configure data to Notify when SW1 pushed
  buttonInfo.boardSelection = boardWB_1;
  buttonInfo.ButtonStatus=buttonPushed;
  
  // start advertising
  BLE.advertise();

  String address = BLE.address();
  Serial.print("==>Local address is: ");
  Serial.println(address);

  Serial.println("==>Advertising Started, waiting for connections...");

  // assign event handlers for connected, disconnected to peripheral
  BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
}

/**
* @brief  Arduino Loop 
* @param  None
* @retval None
*/
void loop() {
  // poll for BLE events
  BLE.poll();

  // read the SW1 Button input pin:
  buttonState = digitalRead(buttonPin);
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      //Serial.println("on");
      Serial.print("==> Number of time button is pushes: ");
      Serial.println(buttonPushCounter);
      
      //check if connection is established by Central device
      if(BLE.central()){
        //check if Notification is enabled
        if (buttonCharacteristic.subscribed()) {
          Serial.println("buttonCharacteristic is subscribed:");
          Serial.println("==>Notification of Button Pushed is sent");
          buttonCharacteristic.writeValue((byte*) &buttonInfo, sizeof(buttonInfo));
        } else {
           Serial.println("buttonCharacteristic is NOT subscribed:");
           Serial.println("==>Notification is NOT sent");
        }
       }
    } else {
      // if the current state is LOW then the button went from on to off:
      //Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;
}
/************************************ STMicroelectronics *****END OF FILE****/

1.4. Debug Traces

At the startup, the HyperTerminal displays the following Traces

Startup Debug Trace
Connectivity Arduino WB55 Debug.png

2. Smart Phone Application - ST BLE Sensor

  • Download ST BLE Sensor or ST BLE ToolBox application on the smartphone.
  • Scan and Connect to P2P_Server
  • Toggle SmartPhone LED or Push SW1 Button of the Nucleo-64 WB55 board.
ST BLE Sensor Scan ST BLE Sensor Connect
Connectivity Arduino ST BLE Sensor Adv.jpg
Connectivity Arduino ST BLE Sensor connect.jpg
  • Debug Trace displays all the sequences at application level
Arduino Nucleo-64 WB55 Traces
Connectivity Arduino WB55 Trace.png

3. References

No categories assignedEdit