Professional Documents
Culture Documents
STM32 step-by-step
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]
2 Install STM32CubeIDE
STM32CubeIDE is the Integrated Development Environment to develop STM32 software.
Download STM32CubeIDE[3]
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.
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.
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
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.
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.
6 References
1. NUCLEO-L476RG
2. Jump up↑ STM32CubeMX
3. Jump up↑ STM32CubeIDE
4. Jump up↑ STM32CubeProg
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.
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
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:
2 Pinout Configuration↑
5min
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.
4min
Switch to the Project Manager tab to configure the project. In the Project tab:
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).
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).
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.
9 References↑
1. Jump up↑ NUCLEO-L476RG board (64-pin)
Target description
Following this tutorial, you will:
Prerequisites
Previous Tutorials:
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]
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.
HAL_Delay(1000);
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.
HAL_Delay(1000);
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
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:
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]
1.1Hardware description
1.2Example: Get temperature values using the HTS221 sensor and display them on a terminal
The main sensors available in the STM32L4 Discovery kit IoT node (B-L475E-IOT01A) are:
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.
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.
Information
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
After being copied, the added folders appear automatically in the STM32CubeIDE workspace:
From Project menu or File menu, go to Properties > C/C++ Build > Settings > Tool
Settings > MCU GCC Compiler > Include paths
#include "stm32l475e_iot01.h"
#include "stm32l475e_iot01_tsensor.h"
#include <math.h>
Add private values to use for temperature values and displayed messages on the terminal:
/* USER CODE BEGIN PV */
Display messages on the terminal and initialize the HTS221 temperature sensor:
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);
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();
HAL_Delay(1000);
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.
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.
Information
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↑
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.
- 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.
Click OK
Select the relevant project from the Project Explorer perspective:
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
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:
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:
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