cancel
Showing results for 
Search instead for 
Did you mean: 

Can X-CUBE-MEMS1 libraries be used in B-L475E-IOT01A board?

Hector Fernandez
Associate III
Posted on January 09, 2018 at 15:53

I have a 

http://www.st.com/en/evaluation-tools/b-l475e-iot01a.html

, which I am using now to learn about how ST MEMS sensors work and if I can use them in my future PCB designs.

I have found recently that ST provides a library to mix 9-axis sensor data to calculate the orientation of any device. This libraries are in the 

http://www.st.com/en/embedded-software/x-cube-mems1.html

.

In my case, I want to use the 'MotionFX' library, mixing the data from Magnetometer+Gyroscope+Accelerometer which there are in this board.

My problem is that the function 'MotionFX_initialize()' gets stuck and never leave. Due to the fact that ST doesn't give us the source code of the library, I can't understand why this function doesn't work, because according to the documentation, there is no requirements or preconditions to use this function.

I have checked the assembly code (using TRUESTUDIO IDE) and this is the result:

MotionFX_initialize:

0800de00: ldr r1, [pc, &sharp880] ; (0x800e174 <MotionFX_initialize+884>)

0800de02: ldr r2, [pc, &sharp884] ; (0x800e178 <MotionFX_initialize+888>)

0800de04: stmdb sp!, {r3, r4, r5, r6, r7, r8, r9, r10, r11, lr}

0800de08: ldr r3, [r1, &sharp0]

0800de0a: movs r0, &sharp1

0800de0c: bic.w r3, r3, &sharp1

0800de10: str r3, [r1, &sharp0]

0800de12: mov r3, r2

0800de14: str r0, [r2, &sharp0]

0800de16: ldr r5, [r3, &sharp0]

0800de18: cmp r5, &sharp0

0800de1a: bne.n 0x800de16 <MotionFX_initialize+22>

0800de1c: ldr r3, [pc, &sharp860] ; (0x800e17c <MotionFX_initialize+892>)

0800de1e: ldr r2, [pc, &sharp864] ; (0x800e180 <MotionFX_initialize+896>)

0800de20: str r2, [r3, &sharp0]

0800de22: ldr r2, [r3, &sharp0]

0800de24: ldr r3, [pc, &sharp860] ; (0x800e184 <MotionFX_initialize+900>)

0800de26: cmp r2, r3

0800de28: beq.n 0x800de2c <MotionFX_initialize+44>

0800de2a: b.n 0x800de2a <MotionFX_initialize+42>

The last assembly code line (

0800de2a

) is where the code gets stuck. As 

MotionFX_initialize function doesn't have any parameter, I guess all this assembly code is equal in every microcontroller or evaluation board.

In my TRUESTUDIO project, I use 'libMotionFX200_CM4F_GCC_ot.a' because 

http://www.st.com/en/evaluation-tools/b-l475e-iot01a.html

 board have a ARM-M4 microcontroller. I have configured correctly the project in order to link the library with the compiler. Even the whole project can compile without any error.

So, I wonder if there are limitations to use this library or if I have found out a bug. Can somebody who have used this library give me some help o tell me if you could use it without problems?

List of ideas I have tried so far:

  • In another post, I read this: 

    https://community.st.com/0D50X00009XkdlxSAB

    . But my CRC module has always been active and the library doesn't work.
  • Disabling optimizations.

  • Enabling optimizations to -O3 (because 'DataLogFusion' example do it).

  • Comparing the IDE configuration with the example, to check if the library linking is correct.♯

#motionfx #b-l475e-iot01a #initialize #x-cube-mems1
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on January 10, 2018 at 11:12

OK, now I see the problem.

Please use following settings or move the MX_CRC_Init() function after the 

MotionFX_initialize();

hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;

hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;

View solution in original post

9 REPLIES 9
Miroslav BATEK
ST Employee
Posted on January 09, 2018 at 16:03

If the code stuck in Initialize() function it is most probably because clock for CRC peripheral is not enabled.

The CRC module in STM32 microcontroller (in RCC peripheral clock enable register) has to be enabled before using the library.

This information will be soon added to the User Manual.

Posted on January 09, 2018 at 16:25

I am sorry. But CRC is not the solution in this situation.

I have debugged my code and I set a breakpoint on '

HAL_CRC_MspInit' (generated by STM32CUBEMX). So, I can confirm you that '__HAL_RCC_CRC_CLK_ENABLE' macro is being called. Moreover, I have checked that the macro is called before 'MotionFX_initialize' call.

But the library is still stuck there.

Are there more modules or peripherals I should active before calling MotionFX_initialize() ?

Posted on January 09, 2018 at 16:33

Do you have enough stack size?

Posted on January 09, 2018 at 16:45

According to STM32CUBEMX, this is my configuration:

  • Minimum heap size: 0x300
  • Minimum stack size: 0x600

After your reply, I have changed these parameters to 0x1000 (heap) and 0x2000 (stack), and I have changed this values in my code, using the STM32CUBEMX software.

But nothing has changed and the problem still exists.

Posted on January 09, 2018 at 16:55

Can you please try stack size 0x8000 and heap size 0x200, I don't know what is exactly the minimum stack size, but this configuration is used in our examples and it works.

Posted on January 09, 2018 at 17:32

I have used the same values of heap/stack than the example (stack = 0x800 and heap = 0x200). No changes.

I have debugged the

RCC_AHB1ENR

 register and the 

CRCEN

 is set, so CRC clock is active.

So far, none of your proposals has been effective.

This is my CRC configuration. Can it be posible that any of this parameters could be generating this error?

void MX_CRC_Init(void)

{

hcrc.Instance = CRC;

hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE;

hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_DISABLE;

hcrc.Init.GeneratingPolynomial = 32801;

hcrc.Init.CRCLength = CRC_POLYLENGTH_16B;

hcrc.Init.InitValue = 0xFFFF;

hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;

hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;

hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;

if (HAL_CRC_Init(&hcrc) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

}

MotionFX_initialize() function gets stuck in the same assembly code line. If your workmates or you could look up the source code to find the C code which generates that assembly line, we could more clues about what is going on.

Any idea?

Hector Fernandez
Associate III
Posted on January 10, 2018 at 12:10

Thank you!

Finally, it worked! 

By the way, I need to use the CRC peripheral with a different configuration (neither default polinomial nor initivalue). So, in order to use MotionFX, can't I use CRC anymore?

Or maybe every time I want to use the CRC with custom configuration, do I have to do the next steps?

  1. HAL_CRC_Init() with my custom configuration.

  2. Use CRC to calculate whatever I need.

  3. HAL_CRC_Init() with the 'default' configuration.

Posted on January 10, 2018 at 11:12

OK, now I see the problem.

Please use following settings or move the MX_CRC_Init() function after the 

MotionFX_initialize();

hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;

hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
Miroslav BATEK
ST Employee
Posted on January 10, 2018 at 13:14

The CRC peripheral is used only in MotionFX_initialize(); function so you can used it after initialization with you configuration.