Skip to main content
Visitor II
February 28, 2018
Solved

MotionFX hard fault

  • February 28, 2018
  • 7 replies
  • 4310 views
Posted on February 28, 2018 at 07:26

Hello,

I'm trying to implement MotionFX in my application. So far I have a very basic setup which executes correctly.

 MotionFX_initialize();
 MotionFX_GetLibVersion(ver);
 printu(ver, 1);
 MotionFX_getKnobs(&iKnobs);
 iKnobs.output_type = MFX_ENGINE_OUTPUT_ENU;
 iKnobs.LMode = 1;
 iKnobs.modx = 1;
 MotionFX_setKnobs(&iKnobs);
 MotionFX_enable_6X(MFX_ENGINE_DISABLE);
 MotionFX_enable_9X(MFX_ENGINE_ENABLE);�?�?�?�?�?�?�?�?�?�?

Then, in a thread, I pull data out of my sensors and push it to the motionfx:

 MFX_input_t data_in;
 MFX_output_t data_out;
 data_in.acc[0] = mptr->acc.AXIS_X * FROM_MG_TO_G;
 data_in.acc[1] = mptr->acc.AXIS_Y * FROM_MG_TO_G;
 data_in.acc[2] = mptr->acc.AXIS_Z * FROM_MG_TO_G;
 data_in.gyro[0] = mptr->gyro.AXIS_X * FROM_MDPS_TO_DPS;
 data_in.gyro[1] = mptr->gyro.AXIS_Y * FROM_MDPS_TO_DPS;
 data_in.gyro[2] = mptr->gyro.AXIS_Z * FROM_MDPS_TO_DPS;
 data_in.mag[0] = mptr->mag.AXIS_X * FROM_MGAUSS_TO_UT50;
 data_in.mag[1] = mptr->mag.AXIS_Y * FROM_MGAUSS_TO_UT50;
 data_in.mag[2] = mptr->mag.AXIS_Z * FROM_MGAUSS_TO_UT50;
 MotionFX_propagate(&data_out, &data_in, 0.01);
 MotionFX_update(&data_out, &data_in, 0.01, NULL);�?�?�?�?�?�?�?�?�?�?�?�?�?

For now, the 0.01 deltatime variable is not accurate, but will becorrected later.

The problem is that I can not call the _propagate and _update function. If I leave only _propagate, I can call that function ripediatelly and get some results. Same with _update. However, if I call them both with each iteration, I run into a hard fault every time.

I have increased stack size to 0x6000 in .ld file with the same results.

In my debugging, it seems that the two functions run fine outside of the thread context.

    This topic has been closed for replies.
    Best answer by Norman S
    Posted on February 28, 2018 at 07:40

    I resolved my problem as I was writing the question... I kept increasing the stack size of the application in the ld file, but not of the thread itself. That was the problem.

    7 replies

    Visitor II
    February 28, 2018
    Posted on February 28, 2018 at 07:34

    I use Keil IDE and try to follow the document:

    http://www.keil.com/appnotes/files/apnt209.pdf

     

    I start from the stack size checking, especially when I have a lot of local variables with big sizes like arrays inside functions.

    I check if I refer to existent memory areas when reading / writing directly from / to RAM (also SDRAM if controlled by FSMC or FMC)

    Norman SAuthorAnswer
    Visitor II
    February 28, 2018
    Posted on February 28, 2018 at 07:40

    I resolved my problem as I was writing the question... I kept increasing the stack size of the application in the ld file, but not of the thread itself. That was the problem.

    Visitor II
    February 28, 2018
    Posted on February 28, 2018 at 07:48

    I like talking to someone to explain the issue and many times during the conversation I have an answer. I heard from a professor of MIT in Computer Science area that this is very good method of approaching / attacking problems.

    It works for me and my friends in my engineering department.

    Visitor II
    September 30, 2018

    I have the same issue with ARM and STM32L031K6 and the MCU gets HardFault after the call of motionFx_CM0P_Initialize().

    My stack size is 0x1000 (already 4k) and it should be enough. I think, the problem is something else and need some help

    ST Employee
    October 1, 2018

    @drozel​ did you enable the clock for CRC unit?

    The CRC is needed for library initialization.

    Visitor II
    October 2, 2018

    @Miroslav BATEK​ yes, i've already found it after diassembly of the library code:>

    but thank you for the fast answer!

    Visitor II
    January 4, 2019

    Hello!

    I have the same problem!!!

    I used the nucleo-F103RB board and works fine. But, when I change to my board (with STM32F103RG) the MCU gets HardFault when execute 2 time MotionFX_propagate and after, MotionFX_update.

    It's the same code changing the microcontroller definition and the .ld.

    I was created the proyect with the cubeMX.

    Visitor II
    January 4, 2019

    did you initialize CRC module?

    you could also debug the library in assembler and find out the instruction causes hardFault. So i found my problem with CRC.

    Visitor II
    January 4, 2019

    Thank you Dozel!!

    Yes!! with the 103RB the program is working, but if I change to the 103RG (same family, same package but with more memory) it crash!

    I'm using Atollic and I can't see the disasembly... It is protected

    Visitor II
    January 8, 2019

    I was tried to increase the stack but it does the same.

    Visitor II
    November 6, 2020

    i meet the similar problem..

    I have enable CRC and enlarge _Min_Stack_Size = 0x8000, but no help...