The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

Introduction

In the past, when developing with STM32, communication with mobile phones generally required an additional Wi-Fi module or Bluetooth module, typically connected via serial port to the Bluetooth module.

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

When designing wireless communication solutions, the ESP32 is often chosen, as this Bluetooth + MCU integrated solution is very appealing. However, the ESP32 has its drawbacks, as its peripheral functionality is inferior to that of the STM32 series, leading to frequent choices needing to be made.

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

In my graduation project, to achieve Bluetooth communication with a mobile phone, I specifically added a BLE Bluetooth chip: WS8100, to enable the main control STM32U0 to have wireless communication capabilities.

Therefore, a solution that combines STM32 and wireless communication is highly necessary.

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules NeededThe Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules NeededThe Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

The STM32W series has unlimited communication capabilities. I have a STM32WL55-Nucleo board, which has a large antenna for communication, but unfortunately, the WL55 cannot be used for BLE and Wi-Fi communication, it supports LORA, etc.

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

During my visit to the STM32 National Seminar by STMicroelectronics, I received a free STM32WBA:

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

STM32WBA supports BLE 5.4, allowing this STM32 to communicate directly with mobile phones. In this issue, we will test the connection with STM32WBA.

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

1

Preparation Work

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

The basic peripherals of WBA need to be enabled: serial port, Debug download port (to prevent secondary programming failures), external high-speed clock, external low-speed clock, and an LED for debugging.

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules NeededThe Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

In the expansion package: STM32_WPAN, enable the BLE functionality. There are many options for functionality here, which will be explained in detail in a future issue.

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

Modify the BLE device name, and then we need to set some basic advertising configurations, which will be the key information for us to search for the BLE device.

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

The advertising information includes power information and advertising name, which we will call YIYANG_STM32 (modify as needed)

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

We can randomly add a service, and then configure this service.

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules NeededThe Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules NeededThe Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

After enabling WPAN, I CACHE, RAMCFG, RTC, and the TIM16 timer will also be enabled as the BLE heart and RF radio frequency functionality.

2

Code Modification

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

In Main.c, add app_ble.h, which contains the application layer functions we need to call:

  MX_APPE_Init(NULL);  APP_BLE_Init();

After peripheral initialization, enable BLE scheduling, so that BLE Bluetooth can work properly. After BLE Bluetooth is enabled, we also need to modify the BLE Bluetooth permissions to make it discoverable.

APP_BLE_Procedure_Gap_Peripheral(PROC_GAP_PERIPH_ADVERTISE_START_FAST);

3

View Results

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

After running the code, we can see our surrounding BLE devices in the BLE debugging assistant, where we can see the STM32WBA’s advertising name: YIYANG_STM32.

After connecting to this device, we can check its service characteristics:

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

Here we read the content of Device Name to see if the data we read matches the device name we set:

The Perfect Integration of STM32 and Bluetooth: No More External Bluetooth Modules Needed

Leave a Comment