ST X - logoUM2275
User manual

Getting started with MotionFD real-time fall detection library in X-CUBE-MEMS1 expansion for STM32Cube

Introduction

The MotionEC is a middleware library component of the X-CUBE-MEMS1 software and runs on STM3z2. It provides real-time information about the device orientation and movement status based on data from a device.
It provides the following outputs: device orientation (quaternions, Euler angles), device rotation (virtual gyroscope functionality), gravity vector and linear acceleration.
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®-M0+, ARM® Cortex®-M3, ARM® Cortex®-M33, ARM® Cortex®-M4 and ARM® Cortex®-M7 architectures.
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.

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

MotionFD middleware library in X-CUBE-MEMS1 software expansion for STM32Cube

2.1 MotionFD overview
The MotionFD library expands the functionality of the X-CUBE-MEMS1 software.
The library acquires data from the accelerometer and pressure sensor and provides information about the user fall event based on data from a 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.
Sample implementation is available for the X-NUCLEO-IKS4A1 and X-NUCLEO-IKS01A3 expansion board, mounted on a NUCLEO-F401RE, NUCLEO-U575ZI-Q or NUCLEO-L152RE development board.
2.2 MotionFD library
Technical information fully describing the functions and parameters of the MotionFD APIs can be found in the MotionFD_Package.chm compiled HTML file located in the Documentation folder.
2.2.1 MotionFD library description
The MotionFD fall detection library manages the data acquired from the accelerometer and pressure sensor; it features:

  • possibility to distinguish whether the user fall occurred or not
  • recognition based only on accelerometer and pressure sensor data
  • required accelerometer and pressure sensor data sampling frequency is 25 Hz
  • resources requirements:
    – Cortex-M3: 3.6 kB of code and 3.2 kB of data memory
    – Cortex-M33: 3.4 kB of code and 3.2 kB of data memory
    – Cortex-M4: 3.4 kB of code and 3.2 kB of data memory
    – Cortex-M7: 3.4 kB of code and 3.2 of data memory
  • available for ARM Cortex-M3, ARM Cortex-M33, ARM Cortex-M4 and ARM Cortex-M7 architectures

2.2.2 MotionFD APIs
The MotionFD library APIs are:

  • uint8_t MotionFD_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 MotionFD_Initialize(void)
    – performs MotionFD library initialization and setup of the internal mechanism

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

  • void MotionFD_Update (MFD_input_t *data_in, MFD_output_t *data_out)
    – executes fall detection algorithm
    – *data_in parameter is a pointer to a structure with input data
    – the parameters for the structure type MFD_input_t are:
    ◦ AccX is the accelerometer sensor value in X axis in mg
    ◦ AccY is the accelerometer sensor value in Y axis in mg
    ◦ AccZ is the accelerometer sensor value in Z axis in mg
    ◦ Press is the pressure sensor value in hPa
    – *data_out parameter is a pointer to an enum with the following items:
    ◦ MFD_NOFALL = 0
    ◦ MFD_FALL = 1
  • void MotionFD_SetKnobs(float fall_threshold, int32_t fall_altitude_delta, float lying_time)
    – sets library configuration parameters
    – fall_threshold acceleration threshold in mg
    – fall_altitude_delta altitude difference in cm
    – lying time time in seconds without movement after an impact
  • void MotionFD_GetKnobs(float *fall_threshold, int32_t *fall_altitude_delta, float *lying_time)
    – gets library configuration parameters
    – fall_threshold acceleration threshold in mg
    – fall_altitude_delta altitude difference in cm
    – lying time time in seconds without movement after an impact

2.2.3 API flow chart

ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library-

2.2.4 Demo code
The following demonstration code reads data from the accelerometer and pressure sensor and gets the fall event code.

ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- Demo code1ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- Demo code

2.2.5 Algorithm performance
The fall detection algorithm only uses data from the accelerometer and pressure sensor and runs at a low frequency (25 Hz) to reduce power consumption.

ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- Algorithm elapse time

2.3 Sample application
The MotionFD 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, NUCLEO-U575ZI-Q or NUCLEO-L152RE development board connected to an X-NUCLEO-IKS4A1 or X-NUCLEO-IKS01A3 expansion board.
The application recognizes the user fall event in real-time.

ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- 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 detected user fall event, accelerometer and pressure sensor 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.

ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- 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] ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- icon or [Stop] ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- icon1  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 ba

ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- Data Table

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

ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- Fall Detection

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

ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- Save To File

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.

ST X CUBE MEMS1 MotionFD Real Time Fall Detection Library- 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.

2.5 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
 22-Sep-2017 1 Initial release.
6-Feb-18 2 Added references to NUCLEO-L152RE development board and Table 2. Elapsed time (μs) algorithm.
21-Mar-18 3 Updated Introduction and Section 2.1 MotionFD overview.
19-Feb-19 4 Updated Table 2. Elapsed time (μs) algorithm and Figure 2. STM32 Nucleo: LEDs, button, jumper.
Added X-NUCLEO-IKS01A3 expansion board compatibility information.
17-Sep-24 5 Updated Section Introduction, Section 2.1: MotionFD overview, Section 2.2.1: MotionFD library description, Section 2.2.2: MotionFD APIs, Section 2.2.5: Algorithm performance, Section 2.3: Sample application, Section 2.4: MEMS-Studio application

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.

© 2024 STMicroelectronics – All rights reserved

Documents / Resources

ST X-CUBE-MEMS1 MotionFD Real Time Fall Detection Library [pdf] User Manual
X-CUBE-MEMS1 MotionFD Real Time Fall Detection Library, X-CUBE-MEMS1, MotionFD Real Time Fall Detection Library, Real Time Fall Detection Library, Fall Detection Library, Detection Library, Library

References

Leave a comment

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