cancel
Showing results for 
Search instead for 
Did you mean: 

MotionFX hard fault

Norman S
Associate II
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.

1 ACCEPTED SOLUTION

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

View solution in original post

19 REPLIES 19
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)

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.

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.

drozel
Associate II

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

Miroslav BATEK
ST Employee

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

The CRC is needed for library initialization.

drozel
Associate II

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

but thank you for the fast answer!

GHerr.18
Associate II

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.

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.

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