Download Print this page
ST X-CUBE-MEMS1 Getting Started
ST X-CUBE-MEMS1 Getting Started

ST X-CUBE-MEMS1 Getting Started

Motionfx sensor fusion library
Hide thumbs Also See for X-CUBE-MEMS1:

Advertisement

Quick Links

UM2220
User manual
Getting started with MotionFX sensor fusion library in X-CUBE-MEMS1
expansion for STM32Cube
Introduction
The MotionFX is a middleware library component of the
X-CUBE-MEMS1
software and runs on STM32. It provides real-time
motion-sensor data fusion. It also performs gyroscope bias and magnetometer hard iron calibration.
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 or 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 an X-NUCLEO-IKS01A3,
X-NUCLEO-IKS4A1
or
X-NUCLEO-
IKS02A1
expansion board on a NUCLEO-F401RE, NUCLEO-U575ZI-Q,
NUCLEO-L152RE
or
NUCLEO-L073RZ
development
board.
UM2220 - Rev 9 - September 2024
www.st.com
For further information contact your local STMicroelectronics sales office.

Advertisement

loading
Need help?

Need help?

Do you have a question about the X-CUBE-MEMS1 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for ST X-CUBE-MEMS1

  • Page 1 UM2220 User manual Getting started with MotionFX sensor fusion library in X-CUBE-MEMS1 expansion for STM32Cube Introduction The MotionFX is a middleware library component of the X-CUBE-MEMS1 software and runs on STM32. It provides real-time motion-sensor data fusion. It also performs gyroscope bias and magnetometer hard iron calibration.
  • Page 2: Acronyms And Abbreviations

    UM2220 Acronyms and abbreviations Acronyms and abbreviations Table 1. List of acronyms Acronym Description Application programming interface Board support package Graphical user interface Hardware abstraction layer Integrated development environment UM2220 - Rev 9 page 2/24...
  • Page 3: Motionfx Middleware Library In X-Cube-Mems1 Software Expansion For Stm32Cube

    MEMS sensors, regardless of environmental conditions, for an optimum performance. 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 is described in the document.
  • Page 4: Motionfx Library Operation

    UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube 6-axis sensor fusion is fit for fast movements (e.g., for gaming) and when absolute orientation is not necessary. 2.2.3 MotionFX library operation The MotionFX library integrates 6 and 9-axis sensor fusion algorithms in one library; they can even run simultaneously to provide both rotation vector (9X) and game rotation vector (6X).
  • Page 5: Figure 1. Example Of Sensor Orientations

    UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube Figure 1. Example of sensor orientations Cortex-M0+ Only the sensor orientation must be set using MotionFX_CM0P_setOrientation function. The parameters of this function are orientation strings which are composed in the same manner as for Cortex-M3, Cortex-M4 and Cortex-M7 (see above).
  • Page 6: Motionfx Library Output Data Rate

    UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube 2.2.5 MotionFX library output data rate It is important to set up the sensor fusion library output data rate properly; 100 Hz is recommended. The output data rate for: •...
  • Page 7: Figure 2. Stm32 Nucleo Board Rotation During Calibration

    UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube Calibration procedure The MotionFX library magnetometer calibration library compensates for hard-iron distortions. The magnetometer calibration can be performed at a slower frequency than the sensor fusion output data rate (e.g., 25 Hz).
  • Page 8: Motionfx Apis

    UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube 2.2.7 MotionFX APIs The MotionFX APIs are: Cortex-M3, Cortex-M4 and Cortex-M7 • size_t MotionFX_GetStateSize(void) – retrieves the size of the memory to be allocated prior to run – every instance of MotionFX library requires the allocation of this size •...
  • Page 9 UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube • void MotionFX_getGbias(MFXState_t mfxstate_pt, float *gbias) – gets the initial gbias – mfxstate_pt is a pointer to the allocated memory for the instance of MotionFX – *gbias parameter is a pointer to a float array containing the gyro bias value for each axis •...
  • Page 10 UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube • char MotionFX_LoadMagCalFromNVM(unsigned short int dataSize, unsigned int *data) – the function is used to retrieve the calibration parameters from storage, the function is called when magnetometer calibration library is enabled –...
  • Page 11 UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube • void MotionFX_CM0P_enable_9X(MFX_CM0P_engine_state_t enable) – enables or disables the 9 axes function (ACC + GYRO+MAG) – enable parameter is 1 to enable, 0 to disable • void MotionFX_CM0P_enable_euler(MFX_CM0P_engine_state_t enable) –...
  • Page 12: Api Flow Chart

    UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube 2.2.8 API flow chart Figure 3. MotionFX API logic sequence Start Initialize GetLibVersion getKnobs/setKnobs MagCal_Init Wait Expiring Timer Data Read Interrupt Read Acc+Gyr+Mag Data MagCal_run / MagCal_getParams Propagate Update Get MotionFX Outputs 2.2.9...
  • Page 13 UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube #define MFX_STR_LENG #define STATE_SIZE (size_t)(2450) #define ENABLE_6X [...] /* Initialization */ char lib_version[MFX_STR_LENG]; static uint8_t mfxstate[STATE_SIZE]; MFX_knobs_t iKnobs; float LastTime; /* Check if statically allocated memory size is sufficient to store MotionFX algorithm state and resize if necessary */ if (STATE_SIZE <...
  • Page 14: Algorithm Performance

    UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube /* Run Sensor Fusion algorithm */ MotionFX_propagate(mfxstate, &data_out, &data_in, &dT); MotionFX_update(mfxstate, &data_out, &data_in, &dT, NULL); if (ENABLE_6X == 1) /* Game rotation Vector */ q = data_out.quaternion; else /* Rotation Vector in 9X */ q = data_out.quaternion;...
  • Page 15: Mems-Studio Application

    UM2220 MotionFX 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.
  • Page 16: Figure 5. Mems-Studio - Connect

    UM2220 MotionFX 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, the appropriate COM port is automatically detected. Press the [Connect] button to establish connection to the evaluation board.
  • Page 17: Figure 7. Mems-Studio - Library Evaluation - Sensor Fusion

    UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube Step 4. Click on the [Sensor Fusion] to open the dedicated window with a 3D model. To switch between 9-axes and 6-axes sensor fusion mode click on the appropriate button.
  • Page 18: Figure 9. Mems-Studio - Library Evaluation - Save To File

    UM2220 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube Step 6. Click on [Save to File] to open the dataloging configuration window. Select the sensor and sensor fusion data to be saved in the file. You can start or stop saving by clicking on the corresponding button.
  • Page 19: References

    MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube 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.
  • Page 20: Revision History

    UM2220 Revision history Table 4. Document revision history Date Version Changes 12-May-2017 Initial release. Added references to NUCLEO-L152RE development board and Section 2.2.10 Algorithm 26-Jan-2018 performance. 20-Mar-2018 Updated Introduction, Section 2.1: "MotionFX overview" and Section 2.2.9: "Demo code". Updated Section 2.2.7 MotionFX APIs and Figure 3. MotionFX API logic sequence. Added Table 3.
  • Page 21: Table Of Contents

    Acronyms and abbreviations ............2 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube .
  • Page 22: List Of Tables

    UM2220 List of tables List of tables Table 1. List of acronyms ..............2 Table 2.
  • Page 23: List Of Figures

    UM2220 List of figures List of figures Figure 1. Example of sensor orientations ............5 Figure 2.
  • Page 24 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’...