STM32WB0 BLE Peripheral Lite

1. BLE Peripheral Lite profile & application

1.1. Objective

This application shows a Bluetooth LE peripheral scenario with bidirectional communication and a simplified architecture framework (i.e. no Tasks Sequencer, simplified low-power manager).

The application is designed with a simple bare metal application framework (no tasks and while (1) with state machines). Further, a simplified low-power manager can be activated or not according to the user application scenario through the CFG_LPM_SUPPORTED option defined on app.conf.h file (default is enabled).

The BLE_Peripheral_Lite application uses the same proprietary profiled defined on the BLE_p2pServer application.

BLE_Peripheral_Lite application advertises and waits for a connection from either:

  • ST BLE Toolbox smartphone application
  • ST BLE Sensor smartphone application

Once connected, BLE_Peripheral_Lite can receive write without response messages from the client and send notifications to it.

This project can serve as a starting point for the implementation of Bluetooth LE projects based on as simple bare metal application framework and with a simplified low-power manager.

1.2. Context

To begin this project, we started by creating a new project with Peripheral Lite configuration on CubeMX.

We specifically added a new Bluetooth LE mode on this software to implement this: "Create your peripheral and GATT Lite server application," permitting us to add the minimum BLE configuration and thus start from scratch.

1.3. Architecture

The application uses similar initialization, GAP and GATT initialization with service management framework as the BLE_p2pServer application.

It doesn't define any task (no sequence is enabled) and it handles the related Bluetooth LE stack, RADIO TIMER, NVM ticks and application specific actions through a simple bare state machine model. The related ticks, state machine functions are called through the MX_APPE_Process() function, on main application while(1) loop:

  /* Infinite loop on main.c file */

  /* USER CODE BEGIN WHILE */
  while (1)

  {
    /* USER CODE END WHILE */

    MX_APPE_Process();

    /* USER CODE BEGIN 3 */
  }

  /* USER CODE END 3 */

The MX_APPE_Process() function is defined on file app_entry.c and it calls all the required process functions which handles the call to the associated ticks functions:

void MX_APPE_Process(void)
{
  /* USER CODE BEGIN MX_APPE_Process_1 */
  
  /* USER CODE END MX_APPE_Process_1 */
  VTimer_Process();

  BLEStack_Process();

  NVM_Process();

  SERVICE_APP_Process();
#if (CFG_LPM_SUPPORTED == 1)
  Enter_LowPowerMode();
#endif /* CFG_LPM_SUPPORTED */

  /* USER CODE BEGIN MX_APPE_Process_2 */
  
  /* USER CODE END MX_APPE_Process_2 */
}

Where the BLEStack_Process(), VTimer_Process(), NVM_Process() and SERVICE_APP_Process() call, respectively, the Bluetooth LE stack tick, RADIO TIMER tick, NVM module tick and the peripheral lite state machine. These functions are defined on app_ble.c file and generated automatically with the CubeMX tool:

void BLEStack_Process(void)
{
  BLE_STACK_Tick();

}

void VTimer_Process(void)
{
  HAL_RADIO_TIMER_Tick();
}

void NVM_Process(void)
{
  NVMDB_Tick();
}

void SERVICE_APP_Process(void)
{
  PERIPHERAL_LITE_SERVER_APP_Process();
}

The PERIPHERAL_LITE_SERVER_APP_Process() defines the application specific state machine according to the application target and it must be implemented by the user.


1.3.1. Simplified low-power manager

The user has still the capability to enable/disable the low-power manager through the CFG_LPM_SUPPORTED option defined on app_conf.h file. If the user wants to enable the low-power manager (set CFG_LPM_SUPPORTED to 1 on app_conf.h), the power manager modes are handled through the Enter_LowPowerMode() generated on app_entry.c file, which identifies the allowed power mode to be set each time the function is called on application main loop:

static void Enter_LowPowerMode(void)
{
  PowerSaveLevels app_powerSave_level, vtimer_powerSave_level, final_level, pka_level;

  ATOMIC_SECTION_BEGIN();

  if ((BLE_STACK_SleepCheck() != POWER_SAVE_LEVEL_RUNNING) &&
      ((app_powerSave_level = App_PowerSaveLevel_Check()) != POWER_SAVE_LEVEL_RUNNING))
  {
    vtimer_powerSave_level = HAL_RADIO_TIMER_PowerSaveLevelCheck();
    pka_level = (PowerSaveLevels) HW_PKA_PowerSaveLevelCheck();
    final_level = (PowerSaveLevels)MIN(vtimer_powerSave_level, app_powerSave_level);
    final_level = (PowerSaveLevels)MIN(pka_level, final_level);

    switch(final_level)
    {
    case POWER_SAVE_LEVEL_RUNNING:
      /* Not Power Save device is busy */

      break;
    case POWER_SAVE_LEVEL_CPU_HALT:
      sleep();
      break;
    case POWER_SAVE_LEVEL_STOP_LS_CLOCK_ON:
      deepstopTimer();
      break;
    case POWER_SAVE_LEVEL_STOP:
      deepstop();
      break;
    }
  }

  ATOMIC_SECTION_END();
}

1.4. Project description

1.4.1. Structure

Find below a software project structure with the most important parts:

Bluetooth® Low Energy Peripheral Lite structure on IAR
Connectivity Code Structure simplest project WB0.png
Connectivity yellow box.png
Main applicative part files
Connectivity dark blue box.png
Services management
Connectivity green box.png
Bluetooth® Low Energy libraries
Connectivity pink box.png
Bluetooth® LE stack modular configuration options and event dispatcher files

WARNING: Do not modify the files in Middleware folder


1.5. BLE_PeripheralLite application

1.5.1. How it works?

The BLE_PeripheraLite project defines the same service and characteristics as the BLE_p2pServer application.

Bluetooth® LE PeripheralLite Service specification
Service Characteristic Mode UUID size
P2P Service 0000FE40-cc7a-482a-984a-7f2ed5b3e58f
LED Write without Response/Read 0000FE41-8e22-4541-9d4c-21edae82ed19 2
SWITCH Notify 0000FE42-8e22-4541-9d4c-21edae82ed19 2

The BLE_Peripheral_Lite application interacts with ST BLE Toolbox or ST BLE Sensor smartphone apps as follow:

  • Once the BLE_Peripheral_Lite is downloaded into the STM32WB0 board it starts advertising with data using local name “HELLO!”.
  • The green led blinks for each advertising event slowly each ~0.5 sec.
  • The Smart phone application starts scanning.
  • Select the “HELLO!” device (containing same service as P2PServer profile) in the list of Smart phone application and connect to it. The green led toggles faster.
  • Select the P2P Server interface and click on the LED icon to switch On/Off LED1 (blue LED of the Nucleo board).
  • Notification is sent from the server (Peripheral device - Nucleo board) to the client (Smart phone) every ~1sec with associated bell display on the smartphone.
  • When the Peripheral device (Nucleo board) is disconnected, advertising is restarted and it is possible to connect to it again.


Example of flow diagram between STM32WB0 BLE Peripheral Lite & ST BLE Toolbox
STM32WB0 P2P Flow Diagram