Um2142 Getting Started With The Xcubememsxt1 Sensor and DSP Algorithm Software Expansion For Stm32cube Stmicroelectronics
Um2142 Getting Started With The Xcubememsxt1 Sensor and DSP Algorithm Software Expansion For Stm32cube Stmicroelectronics
User manual
Getting started with the X-CUBE-MEMS-XT1 sensor and DSP algorithm software
expansion for STM32Cube
Introduction
As well as the on-board sensors supported by the X-CUBE-MEMS1 expansion software package for STM32Cube, the extended
X-CUBE-MEMS-XT1 version also supports devices connected via the DIL24 socket.
X-CUBE-MEMS-XT1 runs on the STM32 and includes drivers that recognize the sensors and collect temperature, humidity,
pressure and motion data from the A3G4250D, AIS328DQ, AIS3624DQ, H3LIS331DL, HTS221, IIS2DLPC, IIS2MDC,
ISM303DAC, ISM330DLC, LIS2DH12, LIS2DW12, LIS2MDL, LIS3MDL, LPS22HB, LPS22HH, LPS25HB, LPS33HW,
LSM303AGR, LSM6DS0, LSM6DS3, LSM6DSL, LSM6DSO, LSM6DSR devices.
The expansion is built on STM32Cube software technology to ease portability across different STM32 microcontrollers. The
software comes with sample implementations of the drivers running on an X-NUCLEO-IKS01A1 or X-NUCLEO-IKS01A2
expansion board connected to a NUCLEO-F401RE or NUCLEO-L476RG development board.
1 What is STM32Cube?
modular architecture allowing it to be easily ported on any hardware by just implementing the low level
routines. It is composed of two parts:
– Component: is the driver relative to the external device on the board and not related to the STM32, the
component driver provides specific APIs to the external components of the BSP driver, and can be
ported on any other board.
– BSP driver: links the component driver to a specific board and provides a set of easy to use APIs. The
API naming convention is BSP_FUNCT_Action(): e.g., BSP_LED_Init(), BSP_LED_On().
• Hardware Abstraction Layer (HAL): this layer provides the low level drivers and the hardware interfacing
methods to interact with the upper layers (application, libraries and stacks). It provides generic, multi-
instance and function-oriented APIs to help offload user application development time by providing ready to
use processes. For example, for the communication peripherals (I²C, UART, etc.) it provides APIs for
peripheral initialization and configuration, data transfer management based on polling, interrupt or DMA
processes, and communication error management. The HAL Drivers APIs are split in two categories: generic
APIs providing common, generic functions to all the STM32 series and extension APIs which provide
special, customized functions for a specific family or a specific part number.
• Basic peripheral usage examples: this layer houses the examples built around the STM32 peripherals using
the HAL and BSP resources only.
Level 1: This level is divided into two sub-layers:
• Middleware components: set of libraries covering USB Host and Device Libraries, STemWin, FreeRTOS,
FatFS, LwIP, and PolarSSL. Horizontal interaction among the components in this layer is performed directly
by calling the feature APIs, while vertical interaction with low-level drivers is managed by specific callbacks
and static macros implemented in the library system call interface. For example, FatFs implements the disk
I/O driver to access a microSD drive or USB Mass Storage Class.
• Examples based on the middleware components: each middleware component comes with one or more
examples (or applications) showing how to use it. Integration examples that use several middleware
components are provided as well.
Level 2: This level is a single layer with a global, real-time and graphical demonstration based on the middleware
service layer, the low level abstraction layer and basic peripheral usage applications for board-based functions.
2.1 Overview
The X-CUBE-MEMS-XT1 software package expands STM32Cube functionality.
The key features are:
• Complete software to build applications using temperature and humidity sensors (HTS221 for both X-
NUCLEO-IKS01A1 and X-NUCLEO-IKS01A2), pressure sensor (LPS25HB for X-NUCLEO-IKS01A1 and
LPS22HB for X-NUCLEO-IKS01A2) and motion sensors (LIS3MDL and LSM6DS0 for X-NUCLEO-IKS01A1
and LSM303AGR and LSM6DSL for X-NUCLEO-IKS01A2), as per X-CUBE-MEMS1
• In addition, the following sensors available through the DIL24 adapter are supported: pressure sensor
(LPS22HB for X-NUCLEO-IKS01A1; LPS22HH and LPS33HW for X-NUCLEO-IKS01A2) and motion
sensors (LSM6DS3, LSM6DSL and LSM303AGR for X-NUCLEO-IKS01A1; H3LIS331DL, LIS2MDL,
LIS2DH12 and LIS2DW12 for both X-NUCLEO-IKS01A1 and X-NUCLEO-IKS01A2; A3G4250D, AIS328DQ,
AIS3624DQ, IIS2MDC, ISM303DAC, ISM330DLC, IIS2DLPC, LSM6DSO and LSM6DSR for X-NUCLEO-
IKS01A2)
• Easy portability across different MCU families thanks to STM32Cube
• Free user-friendly license terms
• Three sample implementations to transmit real time sensor data to a PC including the Unicleo-GUI
application and terminal application support
• Integrated Fast Fourier Transform (FFT) algorithm for vibration analysis
• Signal processing (MotionSP) middleware for vibration analysis in time and frequency domain
• Sample implementation of extended features like FIFO usage, detection of 6D orientation, free-fall,
pedometer, single/double tap, tilt, wake-up, sensor hub and self-test
This software gathers temperature, humidity, pressure and motion sensor drivers for the A3G4250D, AIS328DQ,
AIS3624DQ, H3LIS331DL, HTS221, IIS2DLPC, IIS2MDC, ISM303DAC, ISM330DLC, LIS2DH12, LIS2DW12,
LIS2MDL, LIS3MDL, LPS22HB, LPS22HH, LPS25HB, LPS33HW, LSM303AGR, LSM6DS0, LSM6DS3,
LSM6DSL, LSM6DSO and LSM6DSR devices running on STM32 Nucleo.
The package contains DataLogCustomFreeFall6D, DataLogCustomLite and DataLogExtended sample
applications that enable sensor data logging on a PC; just visit www.st.com and download the Unicleo-GUI
application and the associated documentation.
With this utility, you can choose between various sensors available on the STM32 Nucleo expansion board and
the sensor data can be viewed in plots and logged in a user selected file.
Availability on X- Availability on X-
Sensor name Sensor type
NUCLEO-IKS01A1 NUCLEO-IKS01A2
Availability on X- Availability on X-
Sensor name Sensor type
NUCLEO-IKS01A1 NUCLEO-IKS01A2
Note: See Section 3.3.3.2 How to use LSM303AGR or LIS2MDL together with LIS3MDL on X-NUCLEO-IKS01A1,
Section 3.3.3.3 How to use the LIS2MDL, IIS2MDC or ISM303DAC magnetometers on an X-NUCLEO-IKS01A2
expansion board and Section 3.3.3.4 How to use LPS22HH, LSM6DSO or LSM6DSR on an X-NUCLEO-
IKS01A2 expansion board.
2.2 Architecture
This software is a fully compliant expansion for STM32Cube, enabling development of applications using inertial
and environmental sensors.
The software is based on the hardware abstraction layer for the STM32 microcontroller, STM32CubeHAL. The
package extends STM32Cube by providing a Board Support Package (BSP) for the sensor expansion board and
a sample application for serial communication with a PC.
The software layers used by the application software to access the sensor expansion board are:
• STM32Cube HAL layer: consists of simple, generic and multi-instance set of APIs (application
programming interfaces) which interact with the upper layer applications, libraries and stacks. These generic
and extension APIs are based on a common framework so that overlying layers like middleware can function
without requiring specific microcontroller unit (MCU) hardware information. This structure improves library
code reusability and guarantees easy portability across other devices.
• Board Support Package (BSP) layer: provides software support for the STM32 Nucleo board peripherals,
excluding the MCU. These specific APIs provide a programming interface for certain board specific
peripherals like LEDs, user buttons, etc., and can also be used to fetch individual board version information.
It also provides support for initializing, configuring and reading data.
2.4 APIs
Full function and parameter descriptions for the user APIs can be found in a the compiled
X_CUBE_MEMS_XT1.chm HTML file in the package Documentation folder.
Note: See Section 3.3.3.2 How to use LSM303AGR or LIS2MDL together with LIS3MDL on X-NUCLEO-IKS01A1,
Section 3.3.3.3 How to use the LIS2MDL, IIS2MDC or ISM303DAC magnetometers on an X-NUCLEO-IKS01A2
expansion board and Section 3.3.3.4 How to use LPS22HH, LSM6DSO or LSM6DSR on an X-NUCLEO-
IKS01A2 expansion board.
In the DataLogCustomFreeFall6D, DataLogCustomLite, DataLogExtended and DataLogTerminal firmware
examples, the real-time sensor data is transmitted via serial port to a PC with the HAL_UART_ Transmit ( )
system call. Transmitted sensor data can be viewed with the Unicleo-GUI application
(DataLogCustomFreeFall6D, DataLogCustomLite and DataLogExtended examples) and any terminal application
like Teraterm, Hyperterminal, etc. (all the above mentioned examples plus DataLogTerminal example).
The Unicleo-GUI application developed by ST (refer to the user manual on www.st.com)) can be used to read,
view and store data from the X-NUCLEO-IKS01A1 or X-NUCLEO-IKS01A2 expansion board connected to a PC
via the STM32 Nucleo board. The firmware converts the sensor data into a readable format for the Unicleo-GUI
utility.
Sending temperature sensor data via UART would, for example, require the following steps:
1. Initialization: BSP_TEMPERATURE_ Init ( ...);
2. Sensor temperature reading: BSP_TEMPERATURE_Get_ Temp ( ...);
3. Data serialization: Serialize();
4. Data transmission: HAL_UART_Transmit ();
The Serialize( ) function converts the temperature data into a readable format for the Unicleo-GUI utility.
Similarly, data from other sensors is also formatted and communicated to the utility. When connected via
Teraterm, the user can use the blue button on the STM32 Nucleo expansion board to start and stop the data log.
Most of the DIL24 sensors are automatically detected by the firmware. If a sensor inserted into DIL24 has not a
unique I²C address and a value of WHO_AM_I register, it cannot be automatically recognized: thus, the popup
window notifies the user to select which sensor is actually connected.
All other firmware examples can be used as template to accelerate development and test every function
associated with each sensor. These examples can be easily modified to suit specific scenarios and are designed
for easy transfer from currently supported sensors to other sensors in actual applications.
2.5.1.1 DataLogCustomFreeFall6D
This sample application shows how to define simple user data and send them to Unicleo-GUI for data logging and
visualization. It is designed to use the X-NUCLEO-IKS01A1 or X-NUCLEO-IKS01A2 expansion board with the on-
board sensors and/or sensors in DIL24 socket.
The user can display the custom data in the Unicleo-GUI by clicking the Custom Fields button in the left vertical
toolbar.
The figure below shows the LSM303AGR acceleration in X, Y, Z axes in the graph first section, Free Fall / 6D
Orientation data from the LSM6DSL sensor in the Logic Analyzer section and Theta/Psi/ Phi tilt angles in the
Custom Int32 and Float Values section.
It is also designed to show how to acquire data from additional sensor data.
2.5.1.2 DataLogCustomLite
Differently from the previous example, this sample application is designed to be used on any attached expansion
board. This allows the user to either use his own expansion board or no expansion board at all; thus, he can send
and display any data from the STM32 to the PC with no need to create his own PC application.
Furthermore, it is possible to send binary, integer and float values from the PC to the STM32 microcontroller.
The user can define his own actions in the firmware and control the behavior or adjust parametrs in real-time.
Figure 6. DataLogCustomLite - Unicleo-GUI Custom Fields Plot window shows three shifted sinus functions in the
graph first section, the counter in the Logic Analyzer section and Int32 and Float Values section.
The Unicleo-GUI custom fields also include the Custom Bit Values buttons.
Custom Int32 and Float Values fields allow the user to communicate from the PC to the firmware during runtime.
It is possible to set separately ODR graphs, ODR logic analyzer and ODR values in real-time using this feature.
2.5.1.3.1 DataLogCustomFreeFall6D
• Graph 1: Up to 3 axes of data visualization
• Graph 2: Up to 3 axes of data visualization
• Logic Analyzer: Up to 16 channels of binary data visualization
2.5.1.3.2 DataLogCustomLite
From the firmware to the PC:
• Graph 1: Up to 6 axes of data visualization
• Graph 2: Up to 6 axes of data visualization
• Logic Analyzer: Up to 16 channels of binary data visualization
• Integers: Up to 8 integer values
• Floats: Up to 8 float values
From the PC to the firmware:
• Custom Bits: Up to 4 bit values
• Custom Floats: Up to 4 float values
• Custom Int32s: Up to 4 Int32 values
Bytes
Msg.Data stream
Length From To
Bytes
Msg.Data stream
Length From To
Bytes
Msg.Data stream
Length From To
Bytes
Msg.Data stream
Length From To
2.5.1.5.1 custom_config
custom_config[] message contains custom configuration numbers that allow to set the data displayed by the
Unicleo-GUI. The last three configuration numbers define the parameters the firmware has to receive from the
Unicleo-GUI (modified by the user in real-time) and influence the firmware behavior during runtime.
DataLogCustomFreeF
Length From To DataLogCustomLite
all6D
2.5.1.5.2 custom_names
custom_names[] message string 1 contains custom names and parameters delimited by "|".
Important: Each name or parameter has a variable size but the maximum length of the whole string is 250 bytes.
DataLogCustomFreeFall6D DataLogCustomLite
Graph 1 name
Graph 1 axis 1 name
Graph 1 axis 2 name
Graph 1 axis 3 name
Leave empty Graph 1 axis 4 name
Leave empty Graph 1 axis 5 name
Leave empty Graph 1 axis 6 name
Graph 1 units
Graph 1 full scale
DataLogCustomFreeFall6D DataLogCustomLite
Graph 1 integer values with time axis on: 0x01-bottom, 0x03-middle, 0x05-top
Graph 1 float values with time axis on: 0x11-bottom, 0x13-middle, 0x15-top
Graph 2 name
Graph 2 axis 1 name
Graph 2 axis 2 name
Graph 2 axis 3 name
Leave empty Graph 2 axis 4 name
Leave empty Graph 2 axis 5 name
Leave empty Graph 2 axis 6 name
Graph 2 units
Graph 2 full scale
Graph 2 integer values with time axis on: 0x01-bottom, 0x03-middle, 0x05-top
Graph 2 float values with time axis on: 0x11-bottom, 0x13-middle, 0x15-top
2.5.1.5.3 custom_names2
custom_names2[] message string 2 contains custom names and parameters delimited by "|".
Important: Each name or parameter has a variable size but the maximum length of the whole string is 250 bytes.
2.5.1.5.4 custom_names3
custom_names3[] message string 3 contains custom names and parameters delimited by "|".
Important: Each name or parameter has a variable size but the maximum length of the whole string is 250 bytes.
DataLogCustomFreeFall6D DataLogCustomLite
DataLogCustomFreeFall6D DataLogCustomLite
2.5.3.1 Unicleo-GUI
The FFT_Demo firmware is automatically detected by the Unicleo-GUI; dedicated options and a Spectrum plot
are available to select a sensor and display data.
Data can be saved as .csv file and directly opened in Excel (or similar).
2.5.3.2 Terminal
The user can select a menu option by simply pressing its number on the PC keyboard.
Pressing m or M on the keyboard, the Main menu appears.
Pressing h or H on the keyboard the following two options are switched in the main menu:
• enable HP filter/disable HP filter (allows enabling or disabling the Terminal AXL internal high pass filter)
• enable DC nulling/disable DC nulling (allows enabling or disabling the nulling of 0 Hz part in the calculated
frequency spectrum – earth gravity)
The sensor in use can be switched by pressing s or S on the keyboard.
Options not allowed in the actual sensor setup are disabled and marked by * in the menu.
The signal maximum frequency that can be displayed in the FFT graph is ODR/2.
The signal minumum magnitude that can be displayed is 1% of the maximum graph magnitude.
Under the FFT graph, there are the following info bars:
• The maximum calculated frequency in the whole displayable frequency range and its value
• The maximum frequency value calculated by using the Flat top window(1)
• The maximum calculated bin frequency displayed in the FFT graph(2)
The number of FFT samples (256, 512, 1024) is transformed into 51 bins displayed in the graph.
The graph bin contains the interval of frequencies and displays only the frequency biggest magnitude in that
interval.
FFT samples 512
Grapℎ refresℎ rate ≥ e.g. = 1.28 seconds (5)
ODR 400 Hz
Vibration Monitoring sample application supports only the LSM6DSL sensor on the X-NUCLEO-IKS01A2
expansion board together with Unicleo-GUI Windows PC application.
Figure 15. Vibration Monitoring - Unicleo-GUI spectrum plots, settings and calculated results
You can attach one among H3LIS331DL, LIS2DH12, LPS22HB, LSM303AGR, LSM6DS3 or LSM6DSL DIL24
expansion components to be used in place of the on-board sensors.
See Section 3.3.3.2 How to use LSM303AGR or LIS2MDL together with LIS3MDL on X-NUCLEO-IKS01A1,
Section 3.3.3.3 How to use the LIS2MDL, IIS2MDC or ISM303DAC magnetometers on an X-NUCLEO-IKS01A2
expansion board and Section 3.3.3.4 How to use LPS22HH, LSM6DSO or LSM6DSR on an X-NUCLEO-IKS01A2
expansion board.
3.3.2.2 PC utility
The Unicleo-GUI application for PC has following minimum requirements:
• PC running Windows 7 or higher
• At least 2 GB RAM
• USB port
• 40 MB HD space
3.3.3.3 How to use the LIS2MDL, IIS2MDC or ISM303DAC magnetometers on an X-NUCLEO-IKS01A2 expansion
board
Using the LIS2MDL, IIS2MDC or ISM303DAC magnetometers in DIL24 socket on an X-NUCLEO-IKS01A2
expansion board requires SB1 and SB2 solder bridge disconnection.
The LSM303AGR on-board sensor has to be disconnected from the I²C bus, because it has the same I²C address
with the above mentioned magnetometers.
Revision history
Contents
1 What is STM32Cube? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1 What is STM32Cube?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 STM32Cube architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
List of tables
Table 1. X-CUBE-MEMS-XT1 sensor support and availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Table 2. X-CUBE-MEMS-XT1 sample application support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 3. DataLogCustomFreeFall6D - Msg.Data stream structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Table 4. DataLogCustomLite - Msg.Data stream structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Table 5. DataLogCustomFreeFall6D and DataLogCustomLite - custom_config definition . . . . . . . . . . . . . . . . . . . . . . . . 14
Table 6. DataLogCustomXXX and DataLogCustomLite - custom_names definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Table 7. DataLogCustomFreeFall6D and DataLogCustomLite - custom_names3 definition . . . . . . . . . . . . . . . . . . . . . . 16
Table 8. X-NUCLEO-IKS01A2 LSM6DSL Sensor Hub hardware configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Table 9. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
List of figures
Figure 1. Firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Figure 2. X-CUBE-MEMS-XT1 software architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 3. X-CUBE-MEMS-XT1 package folder structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 4. DataLogCustomFreeFall6D - Unicleo-GUI Custom Fields Plot window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 5. DataLogCustomLite - Unicleo-GUI main window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 6. DataLogCustomLite - Unicleo-GUI Custom Fields Plot window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 7. FFT_Demo Unicleo-GUI - Options tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Figure 8. FFT_Demo Unicleo-GUI - Spectrum plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Figure 9. FFT_Demo interpretation of the saved data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Figure 10. FFT_Demo Terminal mode - main menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Figure 11. FFT_Demo Terminal mode - spectrum plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Figure 12. FFT_Demo Terminal mode - signal information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Figure 13. FFT_Demo Terminal mode - output data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Figure 14. FFT_Demo Terminal mode - sensor selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Figure 15. Vibration Monitoring - Unicleo-GUI spectrum plots, settings and calculated results . . . . . . . . . . . . . . . . . . . . 22
Figure 16. STM32 Nucleo board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Figure 17. X-NUCLEO-IKS01A1 expansion board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Figure 18. X-NUCLEO-IKS01A2 MEMS and environmental sensor expansion board . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Figure 19. X-NUCLEO-IKS01A2 expansion board on STM32 Nucleo development board . . . . . . . . . . . . . . . . . . . . . . . 26