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,

i have committed again. please check

Now, the mcu will enter hard fault loop asap power on, but if comment L158( main.c ) which call MotionFX_propagate(), you can see imu raw data via usb cdc port.

here is some samples

[15:09:19:770] 15.74 -860.10 499.47 | -0.00 0.00 0.00 | 236.6 1271.4 -1005.7�?�

[15:09:19:778] 16.10 -860.22 499.47 | 0.00 0.00 -0.00 | 236.6 1271.4 -1005.7�?�

[15:09:19:787] 16.23 -860.10 499.71 | 0.00 -0.00 -0.00 | 237.8 1272.5 -996.4�?�

[15:09:19:795] 16.10 -860.10 499.47 | 0.00 0.00 0.00 | 235.5 1269.0 -1004.6�?�

[15:09:19:804] 16.10 -860.34 499.59 | -0.00 0.00 0.00 | 235.5 1269.0 -1004.6�?�

[15:09:19:813] 15.98 -860.59 499.35 | -0.01 0.00 0.00 | 238.4 1269.6 -1002.2�?�

[15:09:19:821] 15.98 -860.59 499.47 | -0.01 -0.00 0.00 | 240.1 1273.1 -1001.7�?�

[15:09:19:830] 16.10 -860.34 499.35 | 0.00 -0.00 -0.00 | 240.1 1273.1 -1001.7�?�

[15:09:19:838] 16.23 -859.98 499.47 | 0.01 -0.00 -0.01 | 237.8 1273.7 -1003.4�?�

[15:09:19:846] 16.59 -859.73 499.59 | 0.01 -0.00 -0.00 | 237.8 1273.7 -994.1�?�

[15:09:19:855] 16.71 -859.61 499.96 | -0.00 0.00 0.00 | 235.5 1271.4 -994.1�?�

[15:09:19:863] 16.59 -859.73 499.96 | -0.01 0.01 0.01 | 233.2 1273.7 -1009.8�?�

Hi @MMa.1893​ ,

unfortunately it is still not clear...

If the hard fault happens immediately after reset even before it reach the MotionFX_propagate() function it could be like linker issue.

As a general comment, however, since this code has not been produced by ST, our suggestion is to directly ask to the Github project author…

-Eleon

no, no

I mean, hard fault happen as soon as calling MotionFX_propagate().

 MotionFX_propagate(&out, &raw, &deltatime);   // <<---- mcu enter hard fault, once calling this function!!

Please HELP, all things stuck on the firmware... 

Hi, Eleon

I found a new situation.

i'm tring to add MotionFX_MagCal_init/ MotionFX_MagCal_run before enter main loop.

but it failed to compile

last message is

arm-none-eabi-gcc build/main.o build/gpio.o build/dac.o build/i2c.o build/spi.o build/stm32f7xx_it.o build/stm32f7xx_hal_msp.o build/usb_device.o build/usbd_desc.o build/usbd_cdc_if.o build/usbd_conf.o build/stm32f7xx_hal_pcd.o build/stm32f7xx_hal_pcd_ex.o build/stm32f7xx_ll_usb.o build/stm32f7xx_hal_rcc.o build/stm32f7xx_hal_rcc_ex.o build/stm32f7xx_hal_flash.o build/stm32f7xx_hal_flash_ex.o build/stm32f7xx_hal_gpio.o build/stm32f7xx_hal_dma.o build/stm32f7xx_hal_dma_ex.o build/stm32f7xx_hal_pwr.o build/stm32f7xx_hal_pwr_ex.o build/stm32f7xx_hal_cortex.o build/stm32f7xx_hal.o build/stm32f7xx_hal_i2c.o build/stm32f7xx_hal_i2c_ex.o build/stm32f7xx_hal_exti.o build/stm32f7xx_ll_rcc.o build/stm32f7xx_ll_utils.o build/stm32f7xx_ll_exti.o build/stm32f7xx_ll_dac.o build/stm32f7xx_ll_gpio.o build/stm32f7xx_ll_dma.o build/stm32f7xx_hal_spi.o build/stm32f7xx_hal_spi_ex.o build/stm32f7xx_hal_tim.o build/stm32f7xx_hal_tim_ex.o build/system_stm32f7xx.o build/usbd_core.o build/usbd_ctlreq.o build/usbd_ioreq.o build/usbd_cdc.o build/cmd_proc.o build/adns3080.o build/dwt_delay.o build/imu.o build/lsm9ds1_reg.o build/rtc.o build/stm32f7xx_hal_rtc.o build/stm32f7xx_hal_rtc_ex.o build/crc.o build/stm32f7xx_hal_crc.o build/stm32f7xx_hal_crc_ex.o build/startup_stm32f730xx.o -mcpu=cortex-m7 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=softfp -specs=nano.specs -lc -TSTM32F730R8Tx_FLASH.ld -LMiddlewares/ST/STM32_MotionFX_Library/Lib -lc -lnosys -l:MotionFX_CM7F_wc32_ot.a -lm -Wl,-Map=build/odom_board.map,--cref -Wl,--gc-sections -o build/odom_board.elf
 
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: Middlewares/ST/STM32_MotionFX_Library/Lib/MotionFX_CM7F_wc32_ot.a(motion_fx.o): in function `MEMSloadFromNVM.isra.10':
motion_fx.c:(.text.MEMSloadFromNVM.isra.10+0x0): undefined reference to `MotionFX_LoadMagCalFromNVM'
/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/../lib/gcc/arm-none-eabi/8.2.1/../../../../arm-none-eabi/bin/ld: Middlewares/ST/STM32_MotionFX_Library/Lib/MotionFX_CM7F_wc32_ot.a(motion_fx.o): in function `MEMSsaveInNVM.isra.11':
motion_fx.c:(.text.MEMSsaveInNVM.isra.11+0x0): undefined reference to `MotionFX_SaveMagCalInNVM'
collect2: error: ld returned 1 exit status
make: *** [Makefile:215: build/odom_board.elf] Error 1

Is this related to my previous problem?

any other lib should i link to proj besides "MotionFX_CM7F_wc32_ot.o" ??

Miroslav BATEK
ST Employee

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;
}

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?

any more update?

MMa.1893
Associate III

any update ....

MMa.1893
Associate III

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

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

Hi @MMa.1893​ ,

Miroslav is currently away.

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

-Eleon