Create BLE Project With STM32 and BleuIO
by bleuio in Circuits > Microcontrollers
15 Views, 0 Favorites, 0 Comments
Create BLE Project With STM32 and BleuIO
Introduction
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 a STM32 Nucleo-144 development board with STM32H743ZI MCU (STM32H743ZI micro mbed-Enabled Development Nucleo-144 series ARM® Cortex®-M7 MCU 32-Bit Embedded Evaluation Board) for this example.
If you want to use another setup you will have to make sure it support USB Host and beware that the GPIO setup might be different and may need to be reconfigured in the .ioc file.
Supplies
- A BleuIO dongle
- A board with a STM32 Microcontroller with a USB port. (A Nucleo-144 development board: NUCLEO-H743ZI2, was used developing 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.)
- STM32CubeIDE (https://www.st.com/en/development-tools/stm32cubeide.html)
About the Code
You can get project HEREhttps://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):
The Green, Red and Yellow LEDs on the Nucleo board is also setup to change based on the connection status.
Red = Disconnnected
.Yellow = Connecting.
Green = Connected.
An external variable bool isBleuIOReady is also set so the status of the dongle is accessible from main.c.
Once the BleuIO dongle is confirmed to be connected the USBH_CDC_Receive function is run to start reciving data from the USB CDC.
The USBH_CDC_ReceiveCallback also needs to be implemented:
In this example the recieved 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 main.c:
In main.c HAL_UART_RxCpltCallback is implemented to recieve input from Uart and a simple UART input handler:
The handleUartInput() handles the inputs 0, 1 and 2 and maps each to a certain Dongle commands. The handler is then put inside the main loop.
How to Setup Project
Downloading the project from GitHub
Get project HEREhttps://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 choosen your workspace in ‘Select root directory:’
You should see the project “stm32_bleuio_example”, check it and click ‘Finish’.
Running the Example
In STMCubeIDE click the hammer icon to build the project.
Open up the ‘STMicroelectronics STLink Viritual COM Port’ with a serial terminal emulation program like TeraTerm, Putty or CoolTerm.Serial port Setup:
Baudrate: 115200
Data Bits: 8
Parity: NoneStop
Bits: 1Flow
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:
Dongle response will be printed to UART.