STMicroelectronics UM3330 MotionSM Aleep Monitoring Library User Manual
- June 1, 2024
- STMicroelectronics
Table of Contents
STMicroelectronics UM3330 MotionSM Aleep Monitoring Library
Introduction
The Motion SM is a middleware library part of X-CUBE-MEMS1 software and runs on STM32. It provides real-time sleep monitoring of the user based on data from a device.
It provides real-time information if the user sleeps or not. The library is intended for wrist worn devices. 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®-M4, Arm Cortex®-M33 or Arm Cortex®-M7 architecture.
It is built on top of STM32Cube software technology that eases portability across different STM32 microcontrollers.
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 |
**MotionSM middleware library in X-CUBE-MEMS1 software expansion for
STM32Cube**
MotionSM overview
The Motion SM library expands the functionality of the X-CUBE-MEMS1 software.
The library acquires data from the accelerometer and provides real-time
information if the user sleeps or not. The library is intended for wrist-worn
devices.
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.
MotionSM library
Technical information fully describing the functions and parameters of the Motion SM APIs can be found in the MotionMC_Package.chm compiled HTML file located in the documentation folder.
Motion SM library description
- The Motion SM sleep monitoring library manages the data acquired from the accelerometer; it features:
- Possibility to distinguish if the user sleeps or not
- Intended for wrist-based devices
- Recognition based only on accelerometer data
- Required accelerometer data sampling frequency of 16 Hz
- Resources requirements:
- Cortex®-M3: 1.7 KB of code and 2.2 KB of data memory
- Cortex®-M33: 1.6 KB of code and 2.2 KB of data memory
- Cortex®-M4: 1.6 KB of code and 2.2 KB of data memory
- Cortex®-M7: 1.6 KB of code and 2.2 KB of data memory
- Available for Arm Cortex®-M3, Arm Cortex®-M33, Arm Cortex®-M4 and Arm Cortex® M7 architectures
- Known limitations: sleep state might be also detected if the device is in a stable position, for example: stored on a shelf. It is recommended to combine the sleep monitoring algorithm with the activity recognition for wrist algorithm (Motion AW library) and run it only if the lying position is detected
Motion SM APIs
The Motion SM library APIs are:
-
uint8t Motion SM GetLib Version(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 Motion SM_ Initialize(void)
- Performs Motion SM library initialization and setup of the internal mechanism
- The CRC module in the STM32 microcontroller (in RCC peripheral clock enable register) has to be enabled before using the library
Note: This function must be called before using the sleep monitoring library
-
void Motion SM_ Reset(void)
- Resets the sleep monitoring algorithm
-
void Motion SM Update(MSM inputt *data in, MSM_ outputt *data out)
- Runs the sleep monitoring algorithm
- *data_ in parameter is a pointer to a structure with input data
- The parameters for the structure type MSD_ input_t are:
- AccX is the accelerometer value in the X axis in g
- AccY is the accelerometer sensor value in the Y axis in g
- AccZ is the accelerometer sensor value in the Z axis in g
- *data_ out parameter is a pointer to a structure with output data
- The parameters for the structure type MSD_ output_t are:
- Sleep Flag is the sleep flag
- Total Sleep Time is the total sleep time
-
void Motion SM Set Orientation Acc(const char *acc_ orientation)
- Sets the accelerometer orientation
- *acc_ orientation is a pointer to a string containing reference system of the accelerometer raw data (for instance: south-west-up became “swu”, north-east-up became “ned”)
API flow chart
Figure 1. Motion SM API logic sequence
Demo code
The following demonstration code reads data from the accelerometer sensor and gets the motion intensity code.
[…]
#define VERSION_STR_LENG 35
[…]
/*** Initialization ***/
char lib_version[VERSION_STR_LENG];
/* Sleep Monitoring API initialization function */
MotionSM_Initialize();
/* Set accelerometer sensor real orientation */
MotionSM_SetOrientation_Acc(“ned”);
/* Optional: Get version */
MotionSM_GetLibVersion(lib_version);
[…]
/*** Using Sleep Monitoring algorithm ***/
Timer_OR_DataRate_Interrupt_Handler()
{
MSM_input_t data_in;
MSM_output_t data_out;
/* Get acceleration X/Y/Z in g */
MEMS_Read_AccValue(&data_in.AccX, &data_in.AccY, &data_in.AccZ);
/* Intensity Detection algorithm update */
MotionSM_ Update(&data_ in, &data_ out);
}
References
The following resources are freely available on www.st.com:
- UM1859: Getting started with the X-CUBE-MEMS1 motion MEMS and environmental sensor software expansion for STM32Cube
- UM1724: STM32 Nucleo-64 board
- UM2128: Getting started with Unicleo-GUI for motion MEMS and environmental sensor software expansion for STM32Cube
Revision history
Table 2. Document revision history
Date | Revision | Changes |
---|---|---|
02-Apr-2024 | 1 | Initial release. |
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
Read User Manual Online (PDF format)
Read User Manual Online (PDF format) >>