2018-01-09 06:53 AM
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, &sharp10800de0c: bic.w r3, r3, &sharp10800de10: str r3, [r1, &sharp0]0800de12: mov r3, r20800de14: str r0, [r2, &sharp0]0800de16: ldr r5, [r3, &sharp0]0800de18: cmp r5, &sharp00800de1a: 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, r30800de28: 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. AsMotionFX_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:
. 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.♯
Solved! Go to Solution.
2018-01-10 03:12 AM
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;2018-01-09 07:03 AM
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.
2018-01-09 08:25 AM
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() ?
2018-01-09 08:33 AM
Do you have enough stack size?
2018-01-09 08:45 AM
According to STM32CUBEMX, this is my configuration:
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.
2018-01-09 08:55 AM
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.
2018-01-09 09:32 AM
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 theCRCEN
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?
2018-01-10 03:10 AM
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?
HAL_CRC_Init() with my custom configuration.
Use CRC to calculate whatever I need.
HAL_CRC_Init() with the 'default' configuration.
2018-01-10 03:12 AM
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;2018-01-10 04:14 AM
The CRC peripheral is used only in MotionFX_initialize(); function so you can used it after initialization with you configuration.