Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Create BLE Project using STM32 Microcontroller & BlueIO
BLE Projects STM32 Projects

Create BLE Project using STM32 Microcontroller & BlueIO

Mamtaz AlamBy Mamtaz AlamUpdated:August 20, 20221 Comment4 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Create BLE Project using STM32 Microcontroller & BlueIO
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview: Create BLE Project using STM32 Microcontroller & BlueIO

In this tutorial, we will learn how to Create BLE Project using STM32 Microcontroller & BlueIO. The project is a simple example showcasing a quick way to set up a STM32Cube project as a USB CDC Host capable of communicating with the BleuIO Dongle.

When a BleuIO Dongle is connected to the Nucleo boards USB port the STM32 will recognize it. It will then accept 3 different inputs from the UART and send one of 3 preprogrammed commands to the BleuIO Dongle based on the input. The commands that are used in this example are:

  • ATI(Dongle Information)
  • AT+ADVSTART(Starts Advertising)
  • AT+ADVSTOP(Stops Advertising)

We have used an STM32 Nucleo-144 development board with STM32H743ZI microcontroller which is a micro mbed-Enabled Development Nucleo-144 series ARM® Cortex®-M7 MCU 32-Bit Embedded Evaluation Board. For this example, we will use the same STM32 Microcontroller & BlueIO & create a demo BLE project.

If you want to use another setup you will have to make sure it supports USB Host and beware that the GPIO setup might be different and may need to be reconfigured in the .ioc file.




About the Code

You can get project here: https://github.com/smart-sensor-devices-ab/stm32_bleuio_example

This project-based on a new STM32 project with these changes in the .ioc file. Under ‘Connectivity’ the ‘USB_OTG_FS’-mode is changed to Host_Only and in the NVIC Settings all global interrupts are enabled.

And under ‘Middleware’ the ‘USB_HOST’- ‘Class for FS IP’ is set to ‘Communication Host Class (Virtual Port Com)’.

To make sure the host would recognize when the bootloader is done and the BleuIO firmware is running this was added in the USBH_UserProcess function in ‘usb_host.c’ (found under ‘USB_HOST’ -> ‘App’ folder).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
static void USBH_UserProcess  (USBH_HandleTypeDef *phost, uint8_t id)
{
  /* USER CODE BEGIN CALL_BACK_1 */
  switch(id)
  {
  case HOST_USER_SELECT_CONFIGURATION:
  break;
 
  case HOST_USER_DISCONNECTION:
  Appli_state = APPLICATION_DISCONNECT;
  isBleuIOReady = false;
 
  // Turn on Red LED, turn off Green and Yellow LED
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
  break;
 
  case HOST_USER_CLASS_ACTIVE:
  Appli_state = APPLICATION_READY;
  // Check if BleuIO firmware is running
  // (idProduct:0x6001 = bootloader, idProduct:0x6002 = bleuio fw)
  if(phost->device.DevDesc.idProduct == 0x6002)
  {
      isBleuIOReady = true;
      // Sends message to uart that BleuIO is connected and ready
      HAL_UART_Transmit(&huart3, (uint8_t*)BLEUIO_READY, strlen(BLEUIO_READY), HAL_MAX_DELAY);
 
      // Turn on Green LED, turn off Yellow and Red LED
      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
      HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
 
      // Start receiving from usb
      USBH_CDC_Receive(&hUsbHostFS, CDC_RX_Buffer, RX_BUFF_SIZE);
  }
  break;
 
  case HOST_USER_CONNECTION:
  Appli_state = APPLICATION_START;
  isBleuIOReady = false;
  // Turn on Yellow LED, turn off Green and Red LED
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
  break;
 
  default:
  break;
  }
  /* USER CODE END CALL_BACK_1 */
}


About the Code

The Green, Red, and Yellow LEDs on the Nucleo board are also set up to change based on the connection status as follows.

Red = Disconnnected
Yellow = Connecting
Green = Connected

An external variable bool is BleuIOReady is also set so the status of the dongle is accessible from the main.c section.

Once the BleuIO dongle is confirmed to be connected the USBH_CDC_Receive function is run to start receiving data from the USB CDC. The USBH_CDC_ReceiveCallback also needs to be implemented.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost)
{
    if(phost == &hUsbHostFS)
    {
        // Handles the data recived from the USB CDC host, here just printing it out to UART
        rx_size = USBH_CDC_GetLastReceivedDataSize(phost);
        HAL_UART_Transmit(&huart3, CDC_RX_Buffer, rx_size, HAL_MAX_DELAY);
 
        // Reset buffer and restart the callback function to receive more data
        memset(CDC_RX_Buffer,0,RX_BUFF_SIZE);
        USBH_CDC_Receive(phost, CDC_RX_Buffer, RX_BUFF_SIZE);
    }
 
    return;
}

In this example, the received data is just echoed to the UART.

To send data to the Dongle the USBH_CDC_Transmit function is used. In this example, UART input is used to send different commands. For this purpose, a wrapper function has been created that can be accessed from the main.c.

1
2
3
4
5
6
7
8
/**
  * @brief Simple function that takes a string and transmit it to the dongle
  * @retval None
  */
void writeToDongle(uint8_t * cmd)
{
    USBH_CDC_Transmit(&hUsbHostFS, cmd, strlen((char *)cmd));
}

In main.c HAL_UART_RxCpltCallback is implemented to receive input from Uart and a simple UART input handler.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
    if(UartHandle == &huart3)
    {
        RX_value = (int)aRxBuffer[0];
        uartStatus = UART_RX_NONE;
 
        switch(RX_value)
        {
            case UART_RX_0:
            {
                uartStatus = UART_RX_0;
                break;
            }
            case UART_RX_1:
            {
                uartStatus = UART_RX_1;
                break;
            }
            case UART_RX_2:
            {
                uartStatus = UART_RX_2;
                break;
            }
            default:
            {
                uartStatus = UART_RX_NONE;
                break;
            }
        }
        // Resets uart recieve interrupt mode
        HAL_UART_Receive_IT(&huart3, (uint8_t *)aRxBuffer, RXBUFFERSIZE);
    }
}
 
 
/**
  * @brief Simple uart input handler
  * @retval None
  */
void handleUartInput(UARTCommandTypeDef cmd)
{
    switch(cmd)
    {
        case UART_RX_0:
        {
            // 0
            uart_buf_len = sprintf(uart_tx_buf, "\r\n(0 pressed)\r\n");
            HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
            if(isBleuIOReady)
            {
                writeToDongle((uint8_t*)DONGLE_CMD_ATI);
            } else
            {
                uart_buf_len = sprintf(uart_tx_buf, BLEUIO_NOT_READY_MSG);
                HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
            }
            uartStatus = UART_RX_NONE;
            break;
        }
        case UART_RX_1:
        {
            // 1
            uart_buf_len = sprintf(uart_tx_buf, "\r\n(1 pressed)\r\n");
            HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
            if(isBleuIOReady)
            {
                writeToDongle((uint8_t*)DONGLE_CMD_AT_ADVSTART);
            } else
            {
                uart_buf_len = sprintf(uart_tx_buf, BLEUIO_NOT_READY_MSG);
                HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
            }
            uartStatus = UART_RX_NONE;
            break;
        }
        case UART_RX_2:
        {
            // 2
            uart_buf_len = sprintf(uart_tx_buf, "\r\n(2 pressed)\r\n");
            HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
            if(isBleuIOReady)
            {
                writeToDongle((uint8_t*)DONGLE_CMD_AT_ADVSTOP);
            } else
            {
                uart_buf_len = sprintf(uart_tx_buf, BLEUIO_NOT_READY_MSG);
                HAL_UART_Transmit(&huart3, (uint8_t *)uart_tx_buf, uart_buf_len, HAL_MAX_DELAY);
            }
            uartStatus = UART_RX_NONE;
            break;
        }
        case UART_RX_NONE:
        {
            break;
        }
        default:
        {
            uartStatus = UART_RX_NONE;
            break;
        }
    }
}

The handleUartInput() handles the inputs 0, 1, and 2 and maps each to certain Dongle commands. The handler is then put inside the main loop.

1
2
3
4
5
6
7
8
9
10
11
/* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
    MX_USB_HOST_Process();
    /* USER CODE BEGIN 3 */
    // Simple handler for uart input
    handleUartInput(uartStatus);
  }
  /* USER CODE END 3 */


Using the example project

For creating BLE Project using STM32 Microcontroller & BlueIO, we need the following list of hardware & software.

    • A BleuIO dongle (https://www.bleuio.com/)
    • A board with an STM32 Microcontroller with a USB port. (A Nucleo-144 development board: NUCLEO-H743ZI2, was used to develop this example. (https://www.st.com/en/evaluation-tools/nucleo-h743zi.html)
      To connect the dongle to the Nucleo board a “USB A to Micro USB B”-cable with a USB A female-to-female adapter can be used.)

STM32 BLE

  • STM32CubeIDE (https://www.st.com/en/development-tools/stm32cubeide.html)



How to Setup the Project

Downloading the project from GitHub

Get the project from here: https://github.com/smart-sensor-devices-ab/stm32_bleuio_example

Either clone the project or download it as a zip file and unzip it, into your STM32CubeIDE workspace.


Importing as an Existing Project

From STM32CubeIDE choose File>Import…

Then choose General>Existing Projects into Workspace then click ‘Next >’

Make sure you’ve chosen your workspace in ‘Select root directory:’

You should see the project “stm32_bleuio_example”, check it, and click ‘Finish’./p>

STM32 BlueIO BLE



Running the example

  • In STMCubeIDE click the hammer icon to build the project.
  • Open up the ‘STMicroelectronics STLink Virtual COM Port’ with a serial terminal emulation program like TeraTerm, Putty, or CoolTerm.Serial port Setup:
    Baudrate: 115200
    Data Bits: 8
    Parity: None
    Stop Bits: 1
    Flow Control: None
  • In STMCubeIDE click the green play button to flash and run it on your board. The first time you click it the ‘Run Configuration’ window will appear. You can just leave it as is and click run.
  • Connect the BleuIO Dongle.
  • Wait until the message: “[BleuIO Dongle Ready]” is shown.

 

 

 

– Press 0 to get device information:

 

 

 

 

 

1 to start advertising:

 

 

 

2 to stop advertising:

 

 

 

The Dongle response will be printed to UART.

This is how you can create BLE Project using STM32 Microcontroller & BlueIO. You can also create a similar BLE Project using Arduino & BlueIO

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleDesign your own ESP Board for Battery Powered IoT Applications
Next Article DIY AI Camera with Google Vision & ESP32 CAM Module

Related Posts

Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

PIR Motion Detection using Bluetooth & STM32 Board

PIR Motion Detection using Bluetooth & STM32 Board

Updated:December 23, 20234K
Mobile App with XIAO BLE nRF52840 Sense

Send/Receive Data to Mobile App with XIAO BLE nRF52840 Sense

Updated:August 18, 20221110K
Using IMU & Microphone on XIAO BLE nRF52840 Sense

Using IMU & Microphone on XIAO BLE nRF52840 Sense

Updated:March 23, 202527K
Seeed XIAO BLE nRF52840 Sense

Getting Started with Seeed XIAO BLE nRF52840 Sense

Updated:November 26, 202412K
Home Automation Raspberry Pi

Smart Phone Controlled Home Automation with Raspberry Pi

Updated:October 21, 20222K
View 1 Comment

1 Comment

  1. sudar on September 26, 2022 1:08 AM

    what sensor can we use to detect stress before coming

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • MAX30102 & Arduino: Heart Rate + Blood Oxygen Monitoring
    MAX30102 & Arduino: Heart Rate + Blood Oxygen Monitoring
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.