Skip to main content
MMa.1893
Associate III
November 6, 2020
Question

HardFault once calling MotionFX_propagate()

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!!

This topic has been closed for replies.

23 replies

Eleon BORLINI
ST Employee
November 6, 2020

Hi @MMa.1893​ ,

It seems so far that everything is fine in your configuration code. Could you please share which version of X-CUBE-MEMS1 or MotionFX library are you using?

Although the MotionFX library is device independent, it is typically used in combination with STM32F4 motherboards.

For this reason, I reported your question internally and we have to double-check the functionality of this function on Cortex-M7.

-Eleon

MMa.1893
MMa.1893Author
Associate III
November 9, 2020

Hi, Eleon

 i can get ther version code by MotionFX_GetLibVersion(): ST MotionFX v2.4.1

in STM32CubeMX X-CUBE-MEM1, "Drivers and sample application for MEMs components" version is 8.1.1

Eleon BORLINI
ST Employee
November 9, 2020

Thanks for the feedback @MMa.1893​ .

I actually have to correct myself regarding the above sentence "it is typically used in combination with STM32F4 motherboards", since these libraries are provided compiled for Cortex-M0, M3, M4 and M7, so they should work with all the MCU families.

-Eleon

ST Employee
November 12, 2020

Please add following functions. They can be used to save and load magnetometer calibration coefficients.

/**
 * @brief Load calibration parameter from memory
 * @param dataSize length ot the data
 * @param data pointer to the data
 * @retval (1) fail, (0) success
 */
char MotionFX_LoadMagCalFromNVM(unsigned short int dataSize, unsigned int *data)
{
 return (char)1;
}
 
/**
 * @brief Save calibration parameter to memory
 * @param dataSize length ot the data
 * @param data pointer to the data
 * @retval (1) fail, (0) success
 */
char MotionFX_SaveMagCalInNVM(unsigned short int dataSize, unsigned int *data)
{
 return (char)1;
}

MMa.1893
MMa.1893Author
Associate III
November 13, 2020

Hi, Miroslav

Thank you for reply.

add those two function, compile ok.

But when i use such test routie,  cal_quality always return Zero(0)

 if (1)
 {
 MotionFX_initialize();
 
 MFX_knobs_t knobs;
 MotionFX_getKnobs(&knobs);
 // tunning parameters
 knobs.LMode = 1;
 knobs.modx = 1;
 knobs.output_type = MFX_ENGINE_OUTPUT_ENU;
 // tunning parameters
 MotionFX_setKnobs(&knobs);
 
 // MotionFX_enable_6X(MFX_ENGINE_DISABLE);
 MotionFX_enable_9X(MFX_ENGINE_ENABLE);
 }
 
 if (1)
 {
 MFX_MagCal_output_t magcal_out;
 MFX_MagCal_input_t magcal_in;
 MotionFX_MagCal_init(25, 1);
 uint8_t buf[64];
 int len;
 CDC_Transmit_FS("mag cal..\n", 10);
 for (;;)
 {
 lsm9ds1_status_t status;
 axis3bit16_t data_raw_mag;
 // lsm9ds1_dev_status_get(&dev_mag, &dev_imu, &status);
 // if (status.status_mag.zyxda)
 while (!is_imu_xl_gy_drdy())
 {
 }
 
 lsm9ds1_acceleration_raw_get(&dev_imu, data_raw_mag.u8bit);
 lsm9ds1_angular_rate_raw_get(&dev_imu, data_raw_mag.u8bit);
 lsm9ds1_magnetic_raw_get(&dev_imu, data_raw_mag.u8bit);
 
 lsm9ds1_dev_status_get(&dev_mag, &dev_imu, &status);
 if (status.status_mag.zyxda)
 {
 // lsm9ds1_magnetic_raw_get(&dev_imu, data_raw_mag.u8bit);
 len = snprintf(buf, 64, "%d, %d, %d\n", data_raw_mag.i16bit[0], data_raw_mag.i16bit[1], data_raw_mag.i16bit[2]);
 CDC_Transmit_FS(buf, len);
 }
 else
 {
 continue;
 }
 
 magcal_in.mag[0] = lsm9ds1_from_fs16gauss_to_mG(data_raw_mag.i16bit[0]);
 magcal_in.mag[1] = lsm9ds1_from_fs16gauss_to_mG(data_raw_mag.i16bit[1]);
 magcal_in.mag[2] = lsm9ds1_from_fs16gauss_to_mG(data_raw_mag.i16bit[2]);
 magcal_in.time_stamp = 25;
 
 MotionFX_MagCal_run(&magcal_in);
 
 MotionFX_MagCal_getParams(&magcal_out);
 
 len = snprintf(buf, 64, "cal_q -> %d\n", magcal_out.cal_quality);
 CDC_Transmit_FS(buf, len);
 }
 }

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

And if i comment those MagCal routie, use raw sensor data as input of MotionFX_propagate

Code will enter HardFault loop...how to debug this?

MMa.1893
MMa.1893Author
Associate III
November 17, 2020

any update ....

MMa.1893
MMa.1893Author
Associate III
November 17, 2020

i use other version lib which is "ST MotionFX v2.4.0"

the same problem.... once call MotionFX_propagate, enter hard fault loop....

Eleon BORLINI
ST Employee
November 17, 2020

Hi @MMa.1893​ ,

Miroslav is currently away.

Please be patient, we'll update you as soon as possible ;)

-Eleon

MMa.1893
MMa.1893Author
Associate III
November 18, 2020

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....

====

ST Employee
November 18, 2020

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,

MMa.1893
MMa.1893Author
Associate III
November 18, 2020

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

ST Employee
November 20, 2020

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