ST X-CUBE-MEMS1 Sensor and Motion Algorithm Software Expansion

USER MANUAL

MODEL: UM2350

The MotionPW library expands the functionality of the X-CUBE-MEMS1 software by acquiring data from the accelerometer to provide information about the number of steps and cadence performed with the wearable device.

Introduction

The MotionPW middleware library is part of the X-CUBE-MEMS1 software and runs on STM32 Nucleo. It provides real-time information about the number of steps and cadence which the user just performed with the wearable device (e.g. a smart watch).

This library is intended to work with ST MEMS only.
The algorithm is provided in static library format and is designed to be used on STM32 microcontrollers based on the ARM® Cortex®-M3, ARM Cortex®-M33, ARM® Cortex®-M4, ARM® Cortex®-M7 architecture.

It is built on top of STM32Cube software technology to ease portability across different STM32 microcontrollers.

The software comes with sample implementation running on X-NUCLEO-IKS4A1 or X-NUCLEO-IKS01A3 expansion board on a NUCLEO-F401RE, NUCLEO-U575ZI-Q or NUCLEO-L152RE development board.

1. Acronyms and abbreviations

Table 1. List of acronyms

Acronym Description
API Application programming interface
BSP Board support package
GUI Graphical user interface
HAL Hardware abstraction layer
IDE Integrated development environment

 

2. MotionPW middleware library in X-CUBE-MEMS1 software expansion for STM32Cube

2.1 MotionPW overview

The MotionPW library expands the functionality of the X-CUBE-MEMS1 software.

The library acquires data from the accelerometer and provides information about the number of steps and cadence the user just performed with the wearable device.
The library is designed for ST MEMS only. Functionality and performance when using other MEMS sensors are not analyzed and can be significantly different from what described in the document.
A sample implementation is available for X-NUCLEO-IKS4A1 and X-NUCLEO-IKS01A3 expansion boards, mounted on aNUCLEO-F401RE, NUCLEO-U575ZI-Q or NUCLEO-L152RE development board.

2.2 MotionPW library

Technical information fully describing the functions and parameters of the MotionPW APIs can be found in the
MotionPW_Package.chm compiled HTML file located in the Documentation folder.

2.2.1 MotionPW library description

The MotionPW pedometer library manages the data acquired from the accelerometer; it features:

  • possibility of detecting the number of steps, cadence and confidence
  • recognition based on accelerometer data only
  • required accelerometer data sampling frequency of 50 Hz
  • resources requirements:
    – Cortex-M3: 3.7 kB of code and 1.8 kB of data memory
    – Cortex-M33: 3.5 kB of code and 1.8 kB of data memory
    – Cortex-M4: 3.5 kB of code and 1.8 kB of data memory
    – Cortex-M7: 3.6 kB of code and 1.8 kB of data memory
  • available for ARM® Cortex®-M3, ARM® Cortex®-M33, ARM® Cortex®-M4 and ARM® Cortex®-M7 architectures

2.2.2 MotionPW APIs

The MotionPW library APIs are:

  • uint8_t MotionPW_GetLibVersion(char *version)
    – retrieves the library version
    – *version is a pointer to an array of 35 characters
    – returns the number of characters in the version string
  • void MotionPW_Initialize(void)
    – performs MotionPW library initialization and setup of the internal mechanism including the dynamic memory allocation

Note: This function must be called before using the fitness activity library and the CRC module in the STM32 microcontroller (in RCC peripheral clock enable register) has to be enabled.

  •  void MotionPW_Update(MPW_input_t *data_in, MPW_output_t *data_out)
    – executes pedometer for wrist algorithm
    – *data_in parameter is a pointer to a structure with input data
    – the parameters for the structure type MPW_input_t are:
    ◦ AccX is the accelerometer sensor value in X axis in g
    ◦ AccY is the accelerometer sensor value in Y axis in g
    ◦ AccZ is the accelerometer sensor value in Z axis in g
    – CurrentActivity is the enumerated input type MPW_activity_t with the following values:
    ◦ MPW_UNKNOWN_ACTIVITY = 0x00
    ◦ MPW_WALKING = 0x01
    ◦ MPW_FASTWALKING = 0x02
    ◦ MPW_JOGGING = 0x03
    – *data_out parameter is a pointer to a structure with output data
    – the parameters for the structure type MPW_output_t are:
    ◦ Nsteps is number of steps performed by user
    ◦ Cadence is the cadence of user steps
    ◦ Confidence is the confidence of calculated output parameter
  •  void MotionPW_ResetPedometerLibrary(void)
    – resets the library internal variables and mechanism into default values (including current step count)
  •  void MotionPW_ResetStepCount(void)
    – resets the current step count
  •  void MotionPW_UpdateEnergyThreshold(float *energy_threshold)
    – updated energy threshold to fine tune step detection algorithm
    – *energy_threshold parameter is a pointer to energy threshold value

2.2.3 API flow chart

ST X-CUBE-MEMS1 Sensor and Motion Algorithm Software Expansion

2.2.4 Demo code
The following demonstration code example reads data from the accelerometer sensor, obtains the current activity from MotionAW library and gets the number of steps, cadence and confidence from MotionPW library.

Expansion

 

Expansion

2.2.5 Algorithm performance
The pedometer for wrist algorithm uses data from the accelerometer only and runs at a low frequency (50 Hz) to reduce power consumption.
When replicating fitness activity with the STM32 Nucleo board, ensure the board is oriented perpendicularly to the forearm, to simulate the wristband position.

Expansion

Expansion

2.3 Sample application

The MotionPW middleware can be easily manipulated to build user applications.
A sample application is provided in the Application folder. It is designed to run on a NUCLEO-F401RE, NUCLEOU575ZI- Q or NUCLEO-L152RE development board connected to an X-NUCLEO-IKS4A1 or X-NUCLEO-IKS01A3 expansion board.

The application recognizes the steps, cadence and confidence in real-time. The data can be displayed through a GUI.

Expansion

The above figure shows the user button B1 and the three LEDs of the NUCLEO-F401RE board. Once the board is powered, LED LD3 (PWR) turns ON.
A USB cable connection is required to monitor real-time data. The board is powered by the PC via USB connection. This working mode allows the user to display detected steps, cadence and confidence, accelerometer data, time stamp and eventually other sensor data, in real-time, using the MEMS-Studio.

2.4 MEMS Studio application

The sample application uses MEMS-Studio application, which can be downloaded from www.st.com.

Step 1. Ensure that the necessary drivers are installed and the STM32 Nucleo board with appropriate expansion board is connected to the PC.

Step 2. Launch the MEMS-Studio application to open the main application window.

If an STM32 Nucleo board with supported firmware is connected to the PC, it is automatically detected.
Press the [Connect] button to establish connection to the evaluation board

Expansion

Step 3. When connected to a STM32 Nucleo board with supported firmware [Library Evaluation] tab is opened.

To start and stop data streaming, toggle the appropriate [Start] START  or [Stop] STOP button on the outer vertical tool bar.

The data coming from the connected sensor can be viewed selecting the [Data Table] tab on the inner vertical tool bar.

Expansion

Step 4. Click on the [Pedometer] to open the dedicated application window.

Expansion

Step 5. Click on the [Save To File] to open the dataloging configuration window. Select the sensor and pedometer data to be saved in the file. You can start or stop saving by clicking on the corresponding button.

Expansion

Step 6. Data Injection mode can be used to send the previously acquired data to the library and receive the result. Select the [Data Injection] tab on the vertical tool bar to open the dedicated view for this functionality

Expansion

Step 7. Click on the [Browse] button to select the file with the previously captured data in CSV format.

The data will be loaded into the table in the current view.

Other buttons will become active. You can click on:
– [Offline Mode] button to switch the firmware offline mode on/off (mode utilizing the previously captured data).
– [Start]/[Stop]/[Step]/[Repeat] buttons to control the data feed from MEMS-Studio to the library.

3. References

All of the following resources are freely available on www.st.com.

1. UM1859: Getting started with the X-CUBE-MEMS1 motion MEMS and environmental sensor software expansion for STM32Cube
2. UM1724: STM32 Nucleo-64 boards (MB1136)
3. UM3233: Getting started with MEMS-Studio

Revision history

Table 4. Document revision history

Date  Version  Changes
24-Jan-18 1 Initial release.
21-Mar-18 2 Updated Introduction and Section 2.1 MotionPW overview.
20-Feb-19 3 Updated Section 2.2.5: Algorithm performance and Figure 3. STM32 Nucleo: LEDs, button, jumper.
Added X-NUCLEO-IKS01A3 expansion board compatibility information.
20-May-25 4 Updated Section Introduction, Section 2.1: MotionPW overview, Section 2.2.1: MotionPW library description, Section 2.2.2: MotionPW APIs, Section 2.2.4: Demo code, Section 2.2.5: Algorithm performance, Section 2.3: Sample application, Section 2.4: MEMS Studio applica

 

IMPORTANT NOTICE – READ CAREFULLY

STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgment.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of purchasers’ products.

No license, express or implied, to any intellectual property right is granted by ST herein.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. For additional information about ST trademarks, refer to www.st.com/trademarks. All other product or service names are the property of their respective owners.

Information in this document supersedes and replaces information previously supplied in any prior versions of this document.

© 2025 STMicroelectronics – All rights reserved

Implementation

A sample implementation is available for X-NUCLEO-IKS4A1 and X-NUCLEO-IKS01A3 expansion boards mounted on specified development boards.

Technical Information

For detailed functions and parameters of the MotionPW APIs, refer to the MotionPW_Package.chm compiled HTML file located in the Documentation folder.

APIs

  • MotionPW_GetLibVersion(char *version)
  • MotionPW_Initialize(void)
  • MotionPW_Update(MPW_input_t *data_in, MPW_output_t *data_out)
  • MotionPW_ResetPedometerLibrary(void)
  • MotionPW_ResetStepCount(void)
  • MotionPW_UpdateEnergyThreshold(float *energy_threshold)

Specifications

  • Product Name: MotionPW Real-time Pedometer
  • Compatibility: X-CUBE-MEMS1 expansion for STM32Cube
  • Manufacturer: STMicroelectronics
  • Library: MotionPW Middleware Library
  • Data Acquisition: Accelerometer
  • Sampling Frequency: 50 Hz

Frequently Asked Questions (FAQ)

Q: Can I use MotionPW library with non-ST MEMS sensors?

A: The library is designed for ST MEMS sensors only.
Compatibility with other MEMS sensors is not guaranteed.

Q: What is the required accelerometer data sampling frequency?

A: The required sampling frequency is 50 Hz for accurate detection of steps and cadence.

Q: How do I initialize the MotionPW library?

A: Call the MotionPW_Initialize() function before using the fitness activity library. Ensure the CRC module in the STM32 microcontroller is enabled.

Documents / Resources

ST X-CUBE-MEMS1 Sensor and Motion Algorithm Software Expansion [pdf] User Manual
STM32 Nucleo, X-NUCLEO-IKS4A1, X-NUCLEO-IKS01A3, X-CUBE-MEMS1 Sensor and Motion Algorithm Software Expansion, X-CUBE-MEMS1, Sensor and Motion Algorithm Software Expansion, Motion Algorithm Software Expansion, Algorithm Software Expansion, Software Expansion

References

Leave a comment

Your email address will not be published. Required fields are marked *