NUCLEO-F401RE Nucleo Development Board
“
Specifications
- Product Name: MotionCP real-time carry position library
- Compatibility: X-CUBE-MEMS1 expansion for STM32Cube
- Library Function: Acquires data from accelerometer to determine
user’s device carrying position - Designed for: ST MEMS only
- Sampling Frequency: 50 Hz
Product Usage Instructions
MotionCP Library Overview
The MotionCP library expands the functionality of X-CUBE-MEMS1
software by acquiring accelerometer data and determining the user’s
device carrying position.
Implementation Requirements
The library is compatible with X-NUCLEO-IKS4A1 and
X-NUCLEO-IKS01A3 expansion boards mounted on NUCLEO-F401RE,
NUCLEO-U575ZI-Q, or NUCLEO-L152RE development boards.
Accessing Library Information
Technical details about MotionCP APIs can be found in the
MotionCP_Package.chm file located in the Documentation folder of
the software package.
MotionCP APIs
MotionCP_GetLibVersion(char *version)
: Retrieves
the library versionMotionCP_Initialize(void)
: Initializes the carry
position library and enables the required CRC module in the STM32
microcontrollerMotionCP_Update(MCP_input_t *data_in, MCP_output_t
: Updates the library with accelerometer sensor
*data_out)
data and outputs the carrying positionMotionCP_SetOrientation_Acc(const char
: Sets the orientation of the accelerometer
*acc_orientation)
data output
Frequently Asked Questions (FAQ)
Q: Can I use the MotionCP library with non-ST MEMS
sensors?
A: The library is specifically designed for ST MEMS sensors.
Using other sensors may result in different performance and
functionality.
Q: What is the required accelerometer data sampling frequency
for MotionCP library?
A: The library requires a sampling frequency of 50 Hz for
accurate detection of carrying positions.
“`
UM2224
User manual
Getting started with MotionCP real-time carry position library in X-CUBE-MEMS1 expansion for STM32Cube
Introduction
The MotionCP middleware library is part of the X-CUBE-MEMS1 software and runs on STM32. It provides real-time information about how the user is carrying a device (i.e. cell phone). It is able to distinguish the following positions: on desk, in hand, near head, shirt pocket, trouser pocket, swinging arm and jacket pocket. 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 or 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.
UM2224 – Rev 6 – July 2025 For further information, contact your local STMicroelectronics sales office.
www.st.com
UM2224
Acronyms and abbreviations
1
Acronyms and abbreviations
Acronym API BSP GUI HAL IDE
Table 1. List of acronyms
Application programming interface Board support package Graphical user interface Hardware abstraction layer Integrated development environment
Description
UM2224 – Rev 6
page 2/17
2
2.1 2.2
2.2.1
2.2.2 Note:
UM2224
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
MotionCP overview
The MotionCP library expands the functionality of the X-CUBE-MEMS1 software.
The library acquires data from the accelerometer and provides information about how the user is carrying the 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 a NUCLEO-F401RE, NUCLEO-U575ZI-Q or NUCLEO-L152RE development board.
MotionCP library
Technical information fully describing the functions and parameters of the MotionCP APIs can be found in the MotionCP_Package.chm compiled HTML file located in the Documentation folder.
MotionCP library description
The MotionCP carry position recognition library manages the data acquired from the accelerometer; it features:
·
possibility to distinguish the following positions: on desk, in hand, near head, shirt pocket, trouser pocket,
arm swing, jacket pocket
·
recognition based on the accelerometer data only
·
required accelerometer data sampling frequency of 50 Hz
·
resources requirements:
Cortex-M3: 6.8 kB of code and 11.0 kB of data memory
Cortex-M33: 6.9 kB of code and 11.0 kB of data memory
Cortex-M4: 6.8 kB of code and 11.0 kB of data memory
Cortex-M7:7.0 kB of code and 11.0 kB of data memory
·
available for ARM® Cortex®-M3, ARM® Cortex®-M33, ARM® Cortex®-M4 and ARM® Cortex®-M7
architectures
MotionCP APIs
The MotionPE library APIs are:
·
uint8_t MotionCP_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 MotionCP_Initialize(void)
performs MotionCP library initialization and setup of the internal mechanism
This function must be called before using the carry position library and the CRC module in the STM32 microcontroller (in RCC peripheral clock enable register) has to be enabled.
UM2224 – Rev 6
page 3/17
UM2224
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
·
void MotionCP_Update(MCP_input_t *data_in, MCP_output_t *data_out)
executes carry position algorithm
*data_in parameter is a pointer to a structure with input data
the parameters for the structure type MCP_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
*data_out parameter is a pointer to an enum with the following items:
MPE_UNKNOWN = 0
MCP_ONDESK = 1
MCP_INHAND = 2
MCP_NEARHEAD = 3
MCP_SHIRTPOCKET = 4
MCP_TROUSERPOCKET = 5
MCP_ARMSWING = 6
MCP_JACKETPOCKET = 7
·
void MotionCP_SetOrientation_Acc(const char *acc_orientation)
this function is used to set the accelerometer data orientation
configuration is usually performed immediately after the MotionCP_Initialize function call
*acc_orientation parameter is a pointer to a string of three characters indicating the direction of
each of the positive orientations of the reference frame used for accelerometer data output, in the sequence x, y, z. Valid values are: n (north) or s (south), w (west) or e (east), u (up) or d (down). As shown in the figure below, the X-NUCLEO-IKS4A1 accelerometer sensor has an SEU orientation (x – South, y – East, z – Up), so the string is: “seu”.
Figure 1. Example of sensor orientations
UM2224 – Rev 6
page 4/17
2.2.3
API flow chart
UM2224
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
Figure 2. MotionCP API logic sequence Start
Initialize GetLibVersion SetOrientation_Acc
Wait Expiring Timer Data Read Interrupt
Read Accelerometer Data Update
Get Carry Position Code
2.2.4
Demo code The following demonstration code reads data from the accelerometer sensor and gets the carry position code.
[…] #define VERSION_STR_LENG 35 […]
/* Initialization */ char lib_version[VERSION_STR_LENG]; char acc_orientation[3];
/* Carry position API initialization function */ MotionCP_Initialize();
/* Optional: Get version */ MotionCP_GetLibVersion(lib_version);
/* Set accelerometer orientation */ acc_orientation[0] =’n’;
UM2224 – Rev 6
page 5/17
2.2.5 Note:
UM2224
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
acc_orientation[1] =’w’; acc_orientation[2] =’u’; MotionCP_SetOrientation_Acc(acc_orientation);
[…]
/* Using Carry Position algorithm */ Timer_OR_DataRate_Interrupt_Handler() {
MCP_input_t data_in; MCP_output_t data_out;
/* Get acceleration X/Y/Z in g */ MEMS_Read_AccValue(&data_in.AccX, &data_in.AccY, &data_in.AccZ);
/* Carry Position algorithm update */ MotionCP_Update(&data_in, &data_out); }
Algorithm performance The carry position recognition algorithm only uses data from the accelerometer and runs at a low frequency (50 Hz) to reduce power consumption. The detected position is a phone typical carry position as the algorithm is sensitive to orientation, in particular for in hand and near head positions. Some other carry positions (like arm swing and trouser pocket) are only detected when the person is walking. When replicating phone activity with the STM 32 Nucleo board, ensure the USB connector is oriented downwards, as it is on a phone (see the figure below).
Figure 3. STM32 Nucleo vs phone orientation
Carry position
Detection
probability (typical)(1)
On desk
95.31%
In hand
99.31%
Near head
96.31%
Table 2. Algorithm performance data
Best performance
Susceptible
Normal use cases when phone is on desk
Vulnerable to sustained vibrations like banging on the desk or continuously tapping on the phone
Correct orientation; i.e., natural phone carrying positions Horizontal orientation/
in hand while looking, reading or texting. Robust for
panorama orientation are not
stationary, walking and fast walking scenarios.
considered
Correct orientation,i.e. carrying phone while talking. Robust for stationary, walking and fast walking scenarios.
Wrong orientation
UM2224 – Rev 6
page 6/17
UM2224
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
Carry position
Detection
probability (typical)(1)
Best performance
Shirt pocket 98.29%
Robust for walking and fast walking scenarios.
Trouser pocket 98.68%
Robust for walking scenarios, for both front and back trouser pockets and multiple orientation in which the phone can be carried while it is in in the trouser pocket.
Swinging arm 97.68%
Walking
Jacket pocket 94.73%
Walking
1. Typical specifications are not guaranteed.
Susceptible
For stationary scenarios, the torso posture determines the algorithm performance
Stationary
Stationary Stationary
Typical detection latency is 5 second.
Table 3. Algorithm elapse time (µs) Cortex-M4, Cortex-M3
Cortex-M4 STM32F401RE at 84 MHz
Min
Avg
Max
141
190
2780
Cortex-M3 STM32L152RE at 32 MHz
Min
Avg
Max
502
680
9887
Table 4. Algorithm elapse time (µs) Cortex-M33 and Cortex-M7
Cortex- M33 STM32U575ZI-Q at 160 MHz
Min
Avg
Max
70
97
1484
Cortex- M7 STM32F767ZI at 96 MHz
Min
Avg
Max
267
391
6277
2.3
Sample application
The MotionCP 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.
UM2224 – Rev 6
page 7/17
UM2224
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
Figure 4. STM32 Nucleo: LEDs, button, jumper
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 real-time carry positions, accelerometer data, time stamp and eventually other sensor data, using the MEMS-Studio.
2.4
MEMS Studio application
The sample application uses the Windows MEMS-Studio utility, 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.
UM2224 – Rev 6
page 8/17
UM2224
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
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.
Figure 5. MEMS-Studio – Connect
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] vertical tool bar.
or [Stop] button on the outer
The data coming from the connected sensor can be viewed selecting the [Data Table] tab on the inner vertical tool bar.
Figure 6. MEMS-Studio – Library Evaluation – Data Table
UM2224 – Rev 6
page 9/17
UM2224
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
Step 4. Click on the [Carry Position] to open the dedicated application window. Figure 7. MEMS-Studio – Library Evaluation – Carry Position
Step 5.
Click on the [Save To File] to open the dataloging configuration window. Select the sensor and carry position data to be saved in the file. You can start or stop saving by clicking on the corresponding
button.
Figure 8. MEMS-Studio – Library Evaluation – Save To File
UM2224 – Rev 6
page 10/17
UM2224
MotionCP middleware library in X-CUBE-MEMS1 software expansion for STM32Cube
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.
Figure 9. MEMS-Studio – Library Evaluation – Data Injection
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.
UM2224 – Rev 6
page 11/17
UM2224
References
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
UM2224 – Rev 6
page 12/17
UM2224
Revision history
Table 5. Document revision history
Date
Version Changes
15-May-2017 1 Initial release.
25-Jan-2018 2 Added references to NUCLEO-L152RE development board and Table 3. Elapsed time (µs) algorithm.
20-Mar-2018 3 Updated Introduction, Section 2.1 MotionCP overview and Section 2.2.5 Algorithm performance.
Updated Figure 1. Example of sensor orientations, Figure 3. STM32 Nucleo vs phone orientation, 18-Feb-2019 4 Table 3. Elapsed time (µs) algorithm and Figure 4. STM32 Nucleo: LEDs, button, jumper.
Added X-NUCLEO-IKS01A3 expansion board compatiblity information.
Updated Introduction, Section 2.2.1: MotionCP library description and Section 2.2.5: Algorithm 25-Mar-2020 5 performance.
Added ARM Cortex-M7 architecture compatibility information.
01-Jul-2025
Updated Section Introduction, Section 2.1: MotionCP overview, Section 2.2.1: MotionCP library 6 description, Section 2.2.2: MotionCP APIs, Section 2.2.5: Algorithm performance,
Section 2.3: Sample application, Section 2.4: MEMS Studio application
UM2224 – Rev 6
page 13/17
UM2224
Contents
Contents
1 Acronyms and abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 MotionCP middleware library in X-CUBE-MEMS1 software expansion for
STM32Cube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 2.1 MotionCP overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.2 MotionCP library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.1 MotionCP library description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.2.2 MotionCP APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2.2.3 API flow chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2.4 Demo code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2.5 Algorithm performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.3 Sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.4 MEMS Studio application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
UM2224 – Rev 6
page 14/17
UM2224
List of tables
List of tables
Table 1. Table 2. Table 3. Table 4. Table 5.
List of acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Algorithm performance data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Algorithm elapse time (µs) Cortex-M4, Cortex-M3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Algorithm elapse time (µs) Cortex-M33 and Cortex-M7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
UM2224 – Rev 6
page 15/17
UM2224
List of figures
List of figures
Figure 1. Figure 2. Figure 3. Figure 4. Figure 5. Figure 6. Figure 7. Figure 8. Figure 9.
Example of sensor orientations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 MotionCP API logic sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 STM32 Nucleo vs phone orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 STM32 Nucleo: LEDs, button, jumper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 MEMS-Studio – Connect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 MEMS-Studio – Library Evaluation – Data Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 MEMS-Studio – Library Evaluation – Carry Position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 MEMS-Studio – Library Evaluation – Save To File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 MEMS-Studio – Library Evaluation – Data Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
UM2224 – Rev 6
page 16/17
UM2224
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
UM2224 – Rev 6
page 17/17
Documents / Resources
![]() |
ST NUCLEO-F401RE Nucleo Development Board [pdf] User Manual NUCLEO-F401RE, NUCLEO-U575ZI-Q, NUCLEO-L152RE, NUCLEO-F401RE Nucleo Development Board, NUCLEO-F401RE, Nucleo Development Board, Development Board, Board |