You are on page 1of 37

STM32 step-by-step

1. Step1 Tools installation


Tools installation and first test
arget description
Teach how to install the main tools for programming the STM32:

 STM32CubeMX, a tool to set and graphically program all STM32 boards and products
 STM32CubeIDE, the free IDE to develop the STM32 software
 STM32CubeProg, a tool to load/spy software in the STM32 memory
 STM32CubeL4, an STM32L4 MCU software package with embedded examples

Having completed this tutorial, you should be able to open the STM32 professional ecosystem.
You should also manage to bring applications from the ecosystem onto the NUCLEO board.
Finally, you will be able to run the blinking LED example in debug mode.

Prerequisites
 Computer with Windows 7 (or higher)
 Java installed
 web access

Hardware
 NUCLEO-L476RG[1] board (64-pin)
 USB Type-A to Mini-B cable

1 Install STM32CubeMX
 Download STM32CubeMX[2]

 Register on www.st.com web site if necessary.


 Unzip the downloaded file and launch the SetupSTM32CubeMX-xxx corresponding to your
OS.
STM32CubeMX is now installed on your computer.

2 Install STM32CubeIDE
STM32CubeIDE is the Integrated Development Environment to develop STM32 software.

 Download STM32CubeIDE[3]

 Register on www.st.com web site if necessary.


 Unzip the downloaded file and launch the STM32CubeIDE-xxx corresponding to your OS.

STM32CubeIDE is now installed on your computer, enjoy!

3 Install STM32CubeProg
STM32CubProgrammer is a tool load/spy software in STM32.

 Download STM32CubeProg[4]
 Unzip the downloaded file and launch the SetupSTM32CubeProgrammer-
xxx.exe corresponding to your OS, and follow the instructions.

STM32 USB driver and STM32CubeProg are now installed on your computer.

4 Download STM32CubeL4 Firmware package


STM32Cube MCU Package for STM32L4 Series and STM32L4 Plus Series.

 Open STM32CubeMX
 Click Manage embedded software packages in Help
 Check the last STM32CubeL4 release version
 Click Install (it may take a long time)
 Now STM32L4 libraries and examples are installed at the following location C:\Users\myname\
STM32Cube\Repository\STM32Cube_FW_L4_Vx.xx.x.

5 Launch STM32CubeIDE in debug mode and run my first


program
Use the debug mode

 Launch STM32CubeIDE
 If STM32CubeIDE asks, select the default workspace
 In File STM32CubeIDE menu, click on Open Projects from File System
 In the window, click Directory and select C:\Users\myname\STM32Cube\Repository\
STM32Cube_FW_L4_Vx.xx.x\Projects\NUCLEO-L476RG\Examples_LL\GPIO\
GPIO_InfiniteLedToggling

 Information

The path may be different depending on the product

 Select the project GPIO_InfiniteLedToggling\SW4STM32\STM32L476RG_NUCLEO


 Accept the popup, asking for conversion.

 Information

Ensure that the CN2 jumper is on, so there would not be any hardware problem.
Ensure also that the ST-Link driver is well installed.

Now your project is under STM32CubeIDE

 Default STM32CubeIDE settings are adequate for this tutorial


 Click on Debug icon to launch and debug the project
 Please ensure to click on “Shared ST-Link” option on Debug
configurations and Debugger tab
 Click Resume icon to continue the program execution

 Information

To power the NUCLEO-L476RG, use its CN1 connector to connect it with a computer through an
USB Type-A to Mini-B cable.

Now you are able to:

 find STM32 libraries


 open a project (example)
 load a project in STM32CubeIDE
 execute a project in debug mode
 make a LED blink

Now you have in your computer:

 libraries for STM32L4


 examples for STM32L4
 STM32CubeProg (to communicate with the MCU)
 STM32CubeMX (to graphically generate your project)
 STM32CubeIDE (to code)

6 References
1.  NUCLEO-L476RG
2. Jump up↑ STM32CubeMX
3. Jump up↑ STM32CubeIDE
4. Jump up↑ STM32CubeProg

2. Step2 Blink LED


Blinking LED with STM32CubeMX and HAL  30min

Target description
This tutorial shows how to use the STM32CubeMX tool to initialize the peripherals, build and
generate your starting projects with the initialization C code using HAL libraries.

After this tutorial, you should be able to:

 create and configure the STM32CubeMX project and generate the initialization code
 program and use HAL functions to blink a LED on the NUCLEO-L476RG board.

Prerequisites
 Previous Tutorial: Step1: Tools Installation and First test..

Hardware
The hardware requirements to start the application are the following:

 NUCLEO-L476RG[1] board (64-pin)
 USB Type-A to Mini-B cable

Literature
 STM32L476xx Datasheet
 UM1724 User manual STM32 Nucleo-64 boards
 UM1884 Description of STM32L4/L4+ HAL and low-layer drivers
 UM1718 User manual STM32CubeMX for STM32 configuration and initialization C code
generation

  How to build a “Blink LED” project from STM32CubeMX for ST/Atollic TrueSTUDIO® for
STM32.

In this tutorial, we explain step-by-step how to blink a LED on the NUCLEO-L476RG board,
using the STM32CubeMX tool, HAL, and STM32CubeIDE. Steps to follow:

Contents↑
 [hide] 
 1Create New Project using STM32CubeMX
 2Pinout Configuration
 3Clock Configuration
 4GPIO Configuration
 5Configure project and generate source code
 6Edit main.c to toggle the LED
 7Build the project
 8Debug the project
 9References

1 Create New Project using STM32CubeMX↑

 5min

 Run STM32CubeMX tool.
 Click New Project or Menu -> File -> New Project.
 From Board Selector section, filter to select and use NUCLEO-L476RG board:

 Check Nucleo64 type.
 Check STM32L4 on MCU Series.
 Select NUCLEO-L476RG board using Board selector:

 Click Start Project to continue.


 Answer Yes Initialize all peripherals with their default Mode ? popup.

2 Pinout Configuration↑

 5min

Verify in Pinout tab, under SYS peripheral, that Serial Wire is selected as Debug interface:

The corresponding pins PA13 and PA14 are assigned and configured automatically.
When a board is selected, STM32CubeMX allows automatically the pinout setting for the board with
the pin assignments for the communication interfaces, LEDs, and other functions.
(To configure LED pins, check in the STM32 Nucleo-64 boards User Manual and STM32L476xx
Datasheet which LED pins to use).

 Information

To see alternate pins for a signal, drag and drop the signal to a pin while keeping the Ctrl key
pressed.

This example shows the use of the green LED pin LD2 present on the NUCLEO-L476RG board as
GPIO_Output.
To verify that LD2 is set to GPIO_Output mode:

 Type “LED” in the Find field and check that LD2 (green Led) is enabled to PA5 pin as
GPIO_Output.
 When found, the pin that matches the search criteria blinks on the Chip view.
 Click on Chip view to stop the blinking. The signals can be set directly from the pinout view:

 Information

Pinout search field allows the user to search for a pin name, signal name, or signal label in the
Pinout view. When found, the pin or set of pins that matches the search criteria blinks on the Chip
view. Click on the Chip view, to stop blinking.

3 Clock Configuration↑

 4min
In the Clock Configuration tab, check that STM32CubeMX automatically configures the internal
oscillator in the clock system with PLL @80MHz and proposes the PLL configuration as follows:
1. HSI selected in PLL Source Mux (HSI – High Speed Internal clock)
2. PLLCLK selected in the System Clock Mux
3. HCLK set to 80
4 GPIO Configuration↑

 4min
To configure the GPIOs, click the GPIO button in the Configuration Tab to open the GPIO
Configuration window.

In the GPIO Tab, select Pin Name column PA5 to display the corresponding GPIO parameters and
configuration to drive the NUCLEO-L476RG LED:

 GPIO Output level: it is set to Low by default and can be changed to High.
 GPIO mode automatically configures the pins with the relevant alternate function and GPIOs
into Output Push Pull mode.
 GPIO Pull-up/Pull-dow set to No pull-up and no pull-down by default can be configured
when other choices are allowed.
 GPIO Maximum output speed set to Low by default for the power consumption optimization
can be changed to a higher frequency to fit the application requirements.
 User Label is a name assigned to a GPIO. The GPIO can be found under this name via
the Find menu.
Click Apply then OK to close the window.

5 Configure project and generate source code↑

 4min
Switch to the Project Manager tab to configure the project. In the Project tab:

 Fill the Project Name and Project Location fields


 Set Toolchain/IDE to STM32CubeIDE.

In the Code Generator tab, ensure that the following options are checked:

 In STM32Cube Firmware Library Package section: Copy all used libraries into the project


folder.
 In Generated files section: Keep user code when regenerating the C code option, which
only applies to the user sections within the STM32CubeMX generated files.

To generate the project in STM32CubeIDE:

 Click on Generate Code.

 Click on Open Project to open the project with STM32CubeIDE.

6 Edit main.c to toggle the LED↑

 4min
In STM32CubeIDE, from the Project Explorer tab, open the main.c file, in Src folder and add the
adequate functions for the LED blinking, using HAL functions with the STM32CubeL4 firmware
package.
To get an idea about the usage of HAL functions, refer to the UM1884 “Description of STM32L4/L4+
HAL and low-layer drivers” user manual, which provides the common and generic functions to use.

The user code can be added in the main.c file, inside the while (1) loop between /* USER CODE
BEGIN 3 */ and /* USER CODE END 3 */ section (this will preserve your code after regeneration).

For the LED toggling , use these functions:

HAL_GPIO_TogglePin (GPIOA, GPIO_PIN_5);

HAL_Delay (100); /* Insert delay 100 ms */


7 Build the project↑

 2min
To power the NUCLEO-L476RG, use its CN1 connector to connect in with a computer through a
USB Type-A to Mini-B cable.
Click on the project from the project explorer, then right click and select Build Project, to compile
the project (or click on Build button on the toolbar).

8 Debug the project↑

 2min

Click on the Build toolbar icon  , then on the Debug button   to build the project and start the
debug session (or in the menu, select Project > Build Project then Run > Debug).
Click on Resume icon   to continue the execution.
Now watch the green LED (LD2) toggling on the Nucleo-L476RG board.

Now you are able to:

 create a new project using STM32CubeMX.


 configure a project in STM32CubeMx and generate the initialization code.
 update the project code in STM32CubeIDE using HAL functions.
 execute a project in debug mode.
 make a LED blink.

9 References↑
1. Jump up↑ NUCLEO-L476RG board (64-pin)

3. Step3 Introduction to the UART


UART and new board introduction  34min

Target description
Following this tutorial, you will:

 get familiar with the L475 IoT Node Discovery board,


 learn how to program and use a RS232 serial link on:
 the previously used NUCLEO-L476RG board
 the L475 IoT Node Discovery board (B-L475E-IOT01A ).

Prerequisites
 Previous Tutorials:

 Step1: Tools Installation and First test


 Step2: Blinking LED with STM32CubeMX and HAL

Hardware
The hardware requirements to start the application are the following:

 NUCLEO-L476RG[1] board (64-pin)
 STM32L4 Discovery kit IoT node[2] (B-L475E-IOT01A )
 USB cables Type-A to Mini-B and Type-A to Micro-B

Contents↑
 [hide] 

 1Introduction to the UART I/F on NUCLEO-L476RG


 2Introduction to the UART I/F on B-L475E-IOT01A (IoT Node)
 3References

1 Introduction to the UART I/F on NUCLEO-L476RG↑

 12min
Create NUCLEO-L476RG UART project using STM32CubeMX
 Create a new project using STM32CubeMX.
 Select NUCLEO-L476RG board using Board Selector.
 Answer Yes to Initialize all peripherals with their default mode ? popup.
 In Pinout view tab, check that USART2 mode is configured to Asynchronous, PA2 is
connected to USART2_TX and PA3 is connected to USART2_RX.

 Click on USART2 button in Configuration tab and set Word Length to 8 Bits.


 Make sure that the settings are as in the screenshot below:

 Disable all other USARTs.


 Switch to the Project Manager tab and select STM32CubeIDE as Toolchain / IDE and give a
name to your project.
 Click on Generate Code and accept to open your project in STM32CubeIDE.

Edit and compile the NUCLEO-L476RG UART project using STM32CubeIDE

 Open main.c in Project Explorer / myproject / Src / main.c.


 Insert the following lines between /* USER CODE BEGIN 3 */ and /* USER CODE END 3 */:

uint8_t Test[] = "Hello World !!!\r\n"; //Data to send

HAL_UART_Transmit(&huart2,Test,sizeof(Test),10);// Sending in normal mode

HAL_Delay(1000);

 Click on Build button   to compile the project.


 Click in Debug button   to run the software.
 Open a console emulator such as TeraTerm[3]. Configure the console baud rate and data bits
length. the COM Port name may differ on your PC.
 STM32CubeIDE opens Debug perspective. Click on Resume button   to execute your code.
 TeraTerm[3] displays Hello World !!! string confirming you were able to program and use
RS232.
 Information

TeraTerm is a free software terminal emulator (communication program).

2 Introduction to the UART I/F on B-L475E-IOT01A (IoT Node)↑

 22min
Quick view
The B-L475E-IOT01A Discovery kit[2] for IoT node allows the users to develop applications with direct
connection to cloud servers.
Key features
The Discovery kit enables a wide diversity of applications by exploiting low-power communication,
multiway sensing and Arm® Cortex®-M4 core-based STM32L4 Series features.

Create B-L475E-IOT01A UART project using STM32CubeMX

 Create a new project using STM32CubeMX.


 Select B-L475E-IOT01A board using Board selector.
 Answer Yes to Initialize all peripherals with their default Mode ? popup.
 Verify in Pinout tab that USART1 mode is configured to Asynchronous.
 USART1 conflicts can be solved by (1) disabling all unnecessary features (I2C, LCD, SAI, SPI,
UART, USART2) and (2) setting the pins PA9 and PB7 to reset state.
 Click on USART1 button in Configuration tab and set Word Length to 8 Bits, baud rate
to 115200 Bits/s, Parity to None and Stop Bits to 1 as shown below.

 Switch to the Project Manager tab and select STM32CubeIDE as Toolchain / IDE and give a


name to your project.
 Click on Generate Code and accept to open the project in STM32CubeIDE.

Edit and compile B-L475E-IOT01A UART project using STM32CubeIDE

 Open main.c in Project Explorer / myproject / Src / main.com.


 Insert the following lines between /* USER CODE BEGIN 3 */ and /* USER CODE END 3 */:

uint8_t Test[] = "Hello World !!!\r\n"; //Data to send

HAL_UART_Transmit(&huart1,Test,sizeof(Test),10);// Sending in normal mode

HAL_Delay(1000);

 Click on Build button   to compile the project.


 Click on Debug button  to run the software.
 Open a console emulator such as TeraTerm[3]. Configure the console baud rate and data bits
length. The COM Port name may differ on your PC.
 STM32CubeIDE opens Debug perspective. Click on Resume   button to execute your code.
 TeraTerm[3] displays Hello World !!! string confirming you were able to program and use
RS232.
Now you are able to:

 use the UART I/F on NUCLEO-L476RG


 use the L475 IoT Node Discovery board
 use the UART I/F on L475 IoT Node Discovery board

3 References↑
1. Jump up↑ NUCLEO-L476RG board (64-pin)
2. ↑ Jump up to:2.0 2.1 STM32L4 Discovery kit IoT node
3. ↑ Jump up to:3.0 3.1 3.2 3.3 TeraTerm

4. Step4 Sensors usage


Sensors usage with B-L475E-IOT01A 60min

Target description
The purpose of this tutorial is to explain how to perform measurements with sensors available in the
STM32L4 Discovery kit. Configuration of the temperature sensor is described step by step.
After this tutorial, you will be able to collect values using the sensors available on B-L475E-IOT01A
board.
The appendix of this tutorial provides guidelines on how to port an AC6 example to STM32CubeIDE.

Prerequisites
You have gone through:

 Step1: Tools installation and first test


 Step3: UART and new board introduction

Hardware
 STM32L4 Discovery kit IoT node[1] (B-L475E-IOT01A )
 USB cable Type-A to Micro-B

Literature
 UM2153 Discovery kit for IoT node, multi-channel communication with STM32L4
 UM1884 Description of STM32L4/L4+ HAL and low-layer drivers
 UM1859 Getting started with the X-CUBE-MEMS1 motion MEMS and environmental sensor
software expansion for STM32Cube
 UM2579 Migration guide from System Workbench to STM32CubeIDE
  Getting starting with STM32L4 Discovery kit IoT node
Contents↑
 [hide] 

 1Sensors usage with B-L475E-IOT01A

 1.1Hardware description
 1.2Example: Get temperature values using the HTS221 sensor and display them on a terminal

1.2.1Create a working project with STM32CubeMX



1.2.2Copy BSP drivers to your project

1.2.3Support BSP in STM32CubeIDE workspace

1.2.4Update include paths

1.2.5Update source files

1.2.6Compile and run the example

 2Appendix: Porting an AC6 example to STM32CubeIDE
 2.1Hardware description
 2.2Example: Get temperature values using the HTS221 sensor and display them on terminal
(Porting from AC6 to STM32CubeIDE)
 2.2.1Hardware setup
 2.2.2Example details
 2.2.3Porting the example to STM32CubeIDE
 2.2.4Compiling and running the example
 3References

1 Sensors usage with B-L475E-IOT01A↑


1.1 Hardware description↑

The main sensors available in the STM32L4 Discovery kit IoT node (B-L475E-IOT01A) are:

 Capacitive digital sensor for relative humidity and temperature (HTS221)


 260-1260 hPa absolute digital output barometer (LPS22HB)
 3D accelerometer and 3D gyroscope (LSM6DSL)
 High-performance 3-axis magnetometer (LIS3MDL).
1.2 Example: Get temperature values using the HTS221 sensor and display them on a terminal↑

The purpose of this section is to explain step by step how to interface with the HTS221
sensor to get temperature values and display them on a terminal.

1.2.1 Create a working project with STM32CubeMX↑

The starting point is the project generated with STM32CubeMX described in the Step3 tutorial
titled Introduction to the UART I/F on B-L475E-IOT01A.
Follow the steps described there and call the generated project L4_IOT_Sensors.

1.2.2 Copy BSP drivers to your project↑

The BSP (board support package) drivers are available in the STM32CubeL4 package. This


provides APIs corresponding to the hardware components of a board. The last version of the
STM32CubeL4 package is downloaded by default in the STM32CubeMX repository (C:\Users\
user_name\STM32Cube\Repository\STM32Cube_FW_L4_Vx.xx.x).
BSP location and content in the tree:

 Information

STM32CubeL4 used version is 1.11.0, but it can increase over time.

Here are the steps to follow in order to copy the BSP drivers into your project:

 Copy the STM32CubeL4/Drivers/BSP/B-L475E-IOT01 folder
 In the generated project, create a folder L4_IOT_Sensors/Drivers/BSP. Paste the copied
folder there.
 Copy the STM32CubeL4/Drivers/BSP/Components folder. Paste it
under L4_IOT_Sensors/Drivers/BSP/Components.
 Optional cleanup of working directory: as only the HTS221 temperature sensor is used, some
other files and folders already copied to the working directory may be removed

 Under L4_IOT_Sensors\Drivers\BSP\B-L475E-IOT01, keep only the following files:

 Under L4_IOT_Sensors\Drivers\BSP\Components, keep only the following folders:

1.2.3 Support BSP in STM32CubeIDE workspace↑

After being copied, the added folders appear automatically in the STM32CubeIDE workspace:

1.2.4 Update include paths↑

Update the paths to support new header files:

 Select the relevant project from the Project Explorer perspective:

 From Project menu or File menu, go to Properties > C/C++ Build > Settings > Tool
Settings > MCU GCC Compiler > Include paths

 Click on   to include the new paths


 Add ../Drivers/BSP/B-L475E-IOT01 and ../Drivers/BSP/Components/hts221 paths
The following screenshot summarizes the steps to follow:

1.2.5 Update source files↑

The only file to modify is main.c, as follows:

 Include the header files: stm32l475e_iot01.h, stm32l475e_iot01_tsensor.h and math.h

/* USER CODE BEGIN Includes */<br>

#include "stm32l475e_iot01.h"

#include "stm32l475e_iot01_tsensor.h"

#include <math.h>

/* USER CODE END Includes */

 Add private values to use for temperature values and displayed messages on the terminal:
/* USER CODE BEGIN PV */

/* Private variables -------------------------------------------------------*/

float temp_value = 0; // Measured temperature value

char str_tmp[100] = ""; // Formatted message to display the temperature value

uint8_t msg1[] = "****** Temperature values measurement ******\n\n\r";

uint8_t msg2[] = "=====> Initialize Temperature sensor HTS221 \r\n";

uint8_t msg3[] = "=====> Temperature sensor HTS221 initialized \r\n ";

/* USER CODE END PV */

 Display messages on the terminal and initialize the HTS221 temperature sensor:

/* USER CODE BEGIN 2 */

HAL_UART_Transmit(&huart1,msg1,sizeof(msg1),1000);

HAL_UART_Transmit(&huart1,msg2,sizeof(msg2),1000);

BSP_TSENSOR_Init();

HAL_UART_Transmit(&huart1,msg3,sizeof(msg3),1000);

/* USER CODE END 2 *//

 In the while (1) loop, read the temperature value, format it, and then display the message with
the measured value on the terminal:
/* USER CODE BEGIN 3 */

temp_value = BSP_TSENSOR_ReadTemp();

int tmpInt1 = temp_value;

float tmpFrac = temp_value - tmpInt1;

int tmpInt2 = trunc(tmpFrac * 100);

snprintf(str_tmp,100," TEMPERATURE = %d.%02d\n\r", tmpInt1, tmpInt2);

HAL_UART_Transmit(&huart1,( uint8_t * )str_tmp,sizeof(str_tmp),1000);

HAL_Delay(1000);

/* USER CODE END 3 */

 Information

Pay attention to make updates in the correct USER CODE section in order to avoid over-writing
them with a new STM32CubeMX code generation.

1.2.6 Compile and run the example↑

 Click on Build button   to compile the project


 Click on Debug button   to run the software
 Open a console emulator such as TeraTerm [2]. To configure the console baud rate, select data
bits: 8 and click OK. Port name may differ on your PC
 STM32CubeIDE opens the Debug perspective. Click on the Resume button   to execute
the code
 TeraTerm [2] displays the initialization message preceding the measured temperature values:
Now you are able to:

 Build your own project to measure temperature values with the sensor embedded on the B-
L475E-IOT01A
 Add BSP components to an STM32CubeMx generated project
 Extend the use of the board to sensors other than HTS221, to make environmental
measurements.

2 Appendix: Porting an AC6 example to STM32CubeIDE↑


The example to be used in this appendix is DataLogTerminal located
under: STM32CubeExpansion_MEMS1_V7.1.0\Projects\STM32L476RG-Nucleo\Examples\
IKS01A2\DataLogTerminal

 Information

STM32CubeExpansion_MEMS1_V7.1.0 is the extract of X-CUBE-MEMS. More recent versions of


this package may be available over time from the same link.

 Warning

It is recommended to put the package under C: in order to avoid compilation errors later (because
of long paths)
2.1 Hardware description↑

The X-NUCLEO-IKS01A2[3] is a motion MEMS and environmental sensor expansion board for the
STM32 64-pin Nucleo. It interfaces with NUCLEO-L476RG via I²C-bus pins.

2.2 Example: Get temperature values using the HTS221 sensor and display them on terminal
(Porting from AC6 to STM32CubeIDE)↑

The purpose of this section is to explain step by step how to interface the X-NUCLEO
IKS01A2 HTS221 sensor and NUCLEO-L476RG to get temperature values and display them on a
terminal.

2.2.1 Hardware setup↑

 Extend your Nucleo board with the X-NUCLEO-IKS01A2 shield using the Arduino connectors
 Connect the board with its shield to your PC.

2.2.2 Example details↑

A description of the DataLogTerminal example is available


under STM32CubeExpansion_MEMS1_ V7.1.0\Projects\STM32L476RG-Nucleo\Examples\
IKS01A2\DataLogTerminal in the readme.txt file:

@par Example Description

Main function is to show how to use sensor expansion board to send sensor data from a Nucleo board using
UART to a connected PC or desktop, and display it on generic applications like TeraTerm.

After connection has been established:

- The user can view the data from various on-board environment sensors such as temperature, humidity, and
pressure
- The user can also view data from various on-board MEMS sensors such as accelerometer, gyroscope, and
magnetometer.

2.2.3 Porting the example to STM32CubeIDE↑

Import the DataLogTerminal example based on SW4STM32 and dedicated to the NUCLEO-


L476RG into STM32CubeIDE: STM32CubeExpansion_MEMS1_V7.1.0\Projects\STM32L476RG-
Nucleo\Examples\IKS01A2\DataLogTerminal.
The project must be converted and the following message is displayed:

 When clicking on OK, the following message pops up:

 Click OK
 Select the relevant project from the Project Explorer perspective:

2.2.4 Compiling and running the example↑

 Click on the Build button   to compile the project.


 Click on the Debug button arrow   and select Debug Configurations...
 In the Debug Configuration window that pops up, make sure that the selected Debug
probe is ST-LINK:
 From the same window, click on Debug, or click on the Debug button   to run the software.
 Open a console emulator such as TeraTerm [2]. Configure the Console baud rate, select Data
bits: 8 and click OK. The port name may differ on your PC.
 Click on the Resume button   to execute the code. TeraTerm [2] displays the measured
values using the sensors available in the shield X-NUCLEO-IKS01A2.
 The values measured by the X-NUCLEO-IKS01A2 sensors are displayed in the TeraTerm
window as follows:

3 References↑
1. Jump up↑ STM32L4 Discovery kit IoT node
2. ↑ Jump up to:2.0 2.1 2.2 2.3 TeraTerm
3. Jump up↑ X-NUCLEO-IKS01A2

Build an IOT system 30min

Target description
This tutorial shows how to program and use the Bluetooth interface to perform data communication
between the STM32L4 Discovery kit IoT node (B-L475E-IOT01A) and an Android application
running on a mobile device.
After this tutorial, you will be able to build an IoT system, control it from your mobile monitoring
sensors and collect data.

Prerequisites
You have gone through:

 Step3: UART and new board introduction


 Step4: Sensors usage with B-L475E-IOT01A

Hardware
 STM32L4 Discovery kit IoT node[1] (B-L475E-IOT01A )
 USB cable Type-A to Mini-B

Literature
 UM2153 Discovery kit for IoT node, multi-channel communication with STM32L4
 UM1873 Getting started with the X-CUBE-BLE1 Bluetooth ® Low Energy software expansion for
STM32Cube4
  Getting starting with STM32L4 Discovery kit IoT node

The purpose of this section is to explain step-by-step how to reuse one of the applications that are
part of the STM32CubeL4 MCU package to create a communication channel between the IoT board
emulating a heart rate monitor and a mobile device on which the data is displayed via an Android
application.

Contents↑
 [hide] 

 1Import and convert the HeartRate project from the STM32Cube package
 2Build and execute the HeartRate Project
 3Install the Android application on a mobile device
 4Connect to the IoT node
 5References
1 Import and convert the HeartRate project from the
STM32Cube package↑
 In STM32CubeIDE, import the HeartRate example located in: C:\Users\user_name\
STM32Cube\Repository\STM32Cube_FW_L4_Vx.xx.x\Projects\B-L475E-IOT01A\
Applications\BLE\HeartRate
 The project must be converted and the following message is displayed:

 Click on OK and a new message confirms the success of the conversion

 Click on OK and the STM32CubeIDE workspace opens

2 Build and execute the HeartRate Project↑


 Select the STM32L4_IOT_HR project
 Click on the Build button   to rebuild the project.
 Click on the Debug button   arrow and select Debug Configurations… and make sure the
Debug probe parameter is set to ST-LINK. Otherwise the code is not properly downloaded on
the board.

 Click on the Debug button   to run the software.


 STM32CubeIDE opens the Debug perspective. Click on the Resume button   to execute the
code.

3 Install the Android application on a mobile device↑


To interact with the IoT board, an Android application has to be installed on a mobile device.
The STM32 BLE Profile application is a companion tool to show in a human readable form all
notifications coming from Bluetooth Low Energy (BLE) devices implementing some peripheral
profiles.

4 Connect to the IoT node↑


 Go to Google Play store and install the “STM32 BLE Profiles” application on your mobile
device.
 Once installed, simply launch the STM32 BLE Profiles application. The application scans the
network and displays a list of discovered BLE devices (Here the HeartRateSensor device).

 Establish a Bluetooth connection with the B-L475E-IOT1A board selecting the HR_L475_IoT
device from the discovered devices list. It can take a while to get the connection established.
 The following screenshot shows the successful pairing with a health thermometer sensor:
 Once connected, select the Heart Rate profile among the BLE profiles proposed.

The application starts to display the heart rate data sent by the IoT connected device, which acts as
a peripheral. In this example, the data is generated on the B-L475E-IOT1A board via a formula and
does not reflect the data from a real sensor.
Now you are able to:

 Build your own IoT system to get values from a peripheral device and display them on your
mobile device
 Regenerate a project from one of the various applications available in the STM32Cube
package.

5 References↑
1. Jump up↑ STM32L4 Discovery kit IoT node

You might also like