cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault once calling MotionFX_propagate()

MMa.1893
Associate III

my mcu is STM32F730R8Tx

sensor: LSM9DS1

use CubeMx gen code, with Makefile(under linux env)

I use lsm9ds1_reg.c as sensor driver fetch raw data, and it worked fine.

then, do the following as MotionFX lib documents:

  • MotionFX_initialize()
  • MotionFX_getKnobs(&knobs);
  • MotionFX_setKnobs(&knobs);
  • MotionFX_enable_6X(MFX_ENGINE_DISABLE);
  • MotionFX_enable_9X(MFX_ENGINE_ENABLE);

I can run the code, and i can get ther version code by MotionFX_GetLibVersion(): ST MotionFX v2.4.1

But, if i enable MotionFX_propagate() in the following routie, MCU will enter Hard Falut ISR...

if (is_imu_xl_gy_drdy())
    {
      MFX_input_t raw;
      MFX_output_t out;
      imu_getdata(&raw);
 
      // curr_tick = HAL_GetTick();
      // deltatime = (curr_tick - last_tick)/1000.0;
      // last_tick = curr_tick;
      deltatime = 0.01;
 
      if (0)
      {
        len = snprintf(buf, 256, "%4.2f %4.2f %4.2f | %4.2f %4.2f %4.2f | %4.1f %4.1f %4.1f\n", raw.acc[0], raw.acc[1], raw.acc[2], raw.gyro[0], raw.gyro[1], raw.gyro[2], raw.mag[0], raw.mag[1], raw.mag[2]);
        CDC_Transmit_FS(buf, len);
      }
      
      MotionFX_propagate(&out, &raw, &deltatime);
    }

I have enable CRC in cubemx.

in Makefile, i did some change:

  • FLOAT-ABI change to -mfloat-abi=softfp
  • in LDFLAGS add -u _printf_float
  • in LIBS change to LIBS = -lc -lnosys -l:MotionFX_CM7F_wc32_ot.a -l:MotionFX_CM7F_wc16_ot.a -lm

in STM32F730R8Tx_FLASH.ld

  • change _Min_Heap_Size to 0x1000
  • change _Min_Stack_Size to 0x8000, i think it should large enough..

=============

But why HardFalut once calling MotionFX_propagate ?

Thank thee very much!!

23 REPLIES 23

Hi Eleon

Thank you!

I just try other lib: MotionEC.

Almost same problem, compile ok, MotionEC_Initialize ok, get MotionEC_GetLibVersion get expected return value.

But once call MotionEC_Run, mcu enter HardFault routine....

====

Miroslav BATEK
ST Employee

The units used for magnetometer data are uT/50.

Please check the user manual for MotionFX library.

https://www.st.com/resource/en/user_manual/dm00394369-getting-started-with-motionfx-sensor-fusion-library-in-xcubemems1-expansion-for-stm32cube-stmicroelectronics.pdf

So you need to use magentometer valeus in uT/50 units for all functions.

Also timestamp for MotionFX_MagCal_run funtion is not delta time but growing timestamp.

You can also check DatalogFusion application in X-CUBE-MEMS1 package which can be your reference how to use MotionFX library,

so, error data input can cause mcu enter HardFault routine?

In our test setup is doesn't cause HardFault, but I'm trying to recommend you changes to eliminate as much issues as possible.