Skip to main content
abartky
Associate II
August 25, 2026
Solved

Does MotionFX support multiple simultaneous 9X/6X instances?

  • August 25, 2026
  • 1 reply
  • 39 views

Our application is an intelligent antenna pointing system that uses two identical sets of IIS2MDC magnetometer + ISM330DHCX accelerometer/gyroscope — one pair on our base board, and one pair attached to the moving gimbal. Our overall hardware design was based on the IOT02A board: we got the DataLogFusion running flawlessly on the ST IOT02A first, then subsequently ported that code-base to our own STM32U5-based system.

Our code currently runs MotionFX sensor fusion with two instance memory pointers, with each pair of MEMS sensors feeding into the MotionFX library at a 100 Hz interval — as recommended, and as we saw done in the DataLogFusion example for a single set of magnetometer, accelerometer and gyroscope sensors.  Our firmware design used the DataLogFusion example application and setup as a starting point and then adapted it with multiple instances as we have two sets of sensors in our hardware controlled by a single STM32U575ZIT MCU.

Most of the MotionFX API takes an explicit instance/context data pointer per call — the fusion state itself, the knobs structure, the output structure, etc. all appear to be designed around multiple independent instances coexisting. Based on that pattern, we assumed running two 9-axis contexts side by side was a supported configuration.

However, now that we have added and have been attempting to use magnetometer calibration, we've noticed that the magnetometer calibration API (MotionFX_MagCal_init() / _start() / _stop() / _getParams(), per UM2220) does not take any instance/context parameter — it appears to operate on internal state that isn't per-instance the way the rest of the library is. In practice, this means we assume at minimum, we can only run a calibration session against one of our two sensor pairs at a time; starting a session on the second pair while the first is active doesn't behave as two independent calibrations

Questions:

1. Is MotionFX's 9-axis (accel+gyro+mag) fusion mode officially validated/supported for two simultaneous, independent instances on one MCU — or is that an unsupported configuration that happens to run because most of the state is instance-scoped, but MagCal specifically is a global singleton?
2. If MagCal is intentionally a single global instance regardless of how many fusion contexts are running, is that documented anywhere we've missed? We haven't found this called out explicitly in UM2220.
3. Is there a recommended pattern for our situation — e.g., time-multiplexing magnetometer calibration between sensor pairs one at a time, while running 6-axis (accel+gyro only) fusion concurrently on whichever pair isn't actively calibrating?

Any clarification — or a pointer to where this is documented — would be much appreciated. Happy to share more detail about our exact call sequence if that's useful for diagnosing this.

Thanks and best regards,

Alan Bartky

Best answer by Federica Bossi

Hi ​@abartky ,

Thank you for the detailed description of your use case.

The core MotionFX fusion APIs are instance-based: each MotionFX instance requires its own allocated state memory, and the main fusion functions operate on that instance context. The library can run 6-axis and 9-axis fusion simultaneously to provide both rotation vector and game rotation vector.

MotionFX_MagCal_init(), MotionFX_MagCal_run(), and MotionFX_MagCal_getParams() do not take a MotionFX state/context pointer, and the calibration flow is a single calibration routine. 

For this reason, the safest approach for your application would be to time-multiplex the magnetometer calibration: calibrate one sensor pair at a time, store the resulting hard-iron parameters for each pair in the application or NVM, and then use the corresponding calibration data with the appropriate MotionFX fusion instance. The magnetometer calibration can be run at a lower rate than the fusion loop, and the final calibrated magnetic field is obtained by subtracting the hard-iron offset from the raw magnetometer reading.

So, in short:

  • the fusion part is designed around per-instance state;
  • the magnetometer calibration part is a single shared calibration context in the public API;
  • for two sensor pairs, calibrating one pair at a time is the recommended and lowest-risk pattern.

1 reply

Federica Bossi
Federica BossiBest answer
ST Technical Moderator
September 8, 2026

Hi ​@abartky ,

Thank you for the detailed description of your use case.

The core MotionFX fusion APIs are instance-based: each MotionFX instance requires its own allocated state memory, and the main fusion functions operate on that instance context. The library can run 6-axis and 9-axis fusion simultaneously to provide both rotation vector and game rotation vector.

MotionFX_MagCal_init(), MotionFX_MagCal_run(), and MotionFX_MagCal_getParams() do not take a MotionFX state/context pointer, and the calibration flow is a single calibration routine. 

For this reason, the safest approach for your application would be to time-multiplex the magnetometer calibration: calibrate one sensor pair at a time, store the resulting hard-iron parameters for each pair in the application or NVM, and then use the corresponding calibration data with the appropriate MotionFX fusion instance. The magnetometer calibration can be run at a lower rate than the fusion loop, and the final calibrated magnetic field is obtained by subtracting the hard-iron offset from the raw magnetometer reading.

So, in short:

  • the fusion part is designed around per-instance state;
  • the magnetometer calibration part is a single shared calibration context in the public API;
  • for two sensor pairs, calibrating one pair at a time is the recommended and lowest-risk pattern.
In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.