MotionFX Library compile failed under the PIO but success under Arduino IDE

Hi,

I have installed the stm32duino MotionFX Library to my PlatformIO and just load the example code to run but compiled failed.

In the same time I tested the example under Arduino IDE but success build.

I am not sure is there anything I could add into my platformio.ini?

Reference: GitHub - stm32duino/MotionFX: Sensor Fusion Library for ST sensors and microcontrollers

Please note: I just compile the example code, that’s all

Well, what is your platformio.ini with which you’re trying to include that library?

1 Like

[env:nucleo_f401re]
platform = ststm32
framework = arduino
board = nucleo_f401re
board_build.core = ststm32
lib_ldf_mode = deep+

lib_deps = 
           stm32duino/STM32duino MotionFX @ ^1.1.0
           Wire
           SPI

lib_archive = false

upload_protocol = stlink

above is my platformio.ini

1 Like

The MotionFX library is not an open source, ST provided the pre-compiled by libMotionFX.a

…\STM32duino MotionFX\src\cortex-m4\libMotionFX.a

I am not sure, maybe compiler between PlatformIO and Arduino IDE are different version

Hm. PlatformIO does not link in the .pio\libdeps\nucleo_f401re\STM32duino MotionFX\src\cortex-m4\fpv4-sp-d16-hard\libMotionFX.a file although the library.properties says precompiled = true. This has been a bug before in the PlatformIO core but thought to be resolved. Let me double check.

1 Like

Thank you, I love PIO rather than using the Arduino IDE so waiting for your good news!

This is really cursed. The only way I can get it to compile is if I copy the MotionFX arduino library into lib/, delete the STM32duino MotionFX/src/cortex-m4/libMotionFX.a file and add

build_flags =
  -L"lib/STM32duino MotionFX/src/cortex-m4/fpv4-sp-d16-hard"
  -lMotionFX

into the platformio.ini.

It insisted on adding STM32duino MotionFX/src/cortex-m4/ to the library search path, where it would find the wrong MotionFX library (compiled without floating point).

Linking .pio\build\nucleo_f401re\firmware.elf
c:/users/max/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: warning: .pio/build/nucleo_f401re/firmware.elf has a LOAD segment with RWX permissions
Checking size .pio\build\nucleo_f401re\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   6.4% (used 6336 bytes from 98304 bytes)
Flash: [=         ]  13.1% (used 68520 bytes from 524288 bytes)
Building .pio\build\nucleo_f401re\firmware.bin

I’ve pushed the proof-of-concept to

Last issues about that were in https://github.com/platformio/platformio-core/issues/4056, time to open a new one.

1 Like

Actually I think this should be tracked in

1 Like

[env:nucleo_f401re]
platform = ststm32
framework = arduino
board = nucleo_f401re

build_flags =
-L"lib/STM32duino MotionFX/src/cortex-m4/fpv4-sp-d16-hard"
-lMotionFX

lib_ldf_mode = deep+

lib_deps =
stm32duino/STM32duino MotionFX @ ^1.1.0
Wire
SPI

lib_archive = false
upload_protocol = stlink


I still compile failed

I copied library to \lib\STM32duino MotionFX\src\cortex-m4
and deleted the file libMotionFX.a as you mentioned.

Is there anything I did wrong?

I still have .pio\libdeps\nucleo_f401re\STM32duino MotionFX.…
and Full clean, clean before I compile

This must be deleted from lib_deps then otherwise you have the libary twice. Better delete the whole .pio folder after this too. You might then need to re-add the library for your specific sensor, like STM32duino LSM6DSL to your lib_deps.

The Github CI builds the https://github.com/maxgerhardt/pio_motionfx_workaround base example just fine.

1 Like

I created a new project


[env:nucleo_f401re]
platform = ststm32
board = nucleo_f401re
framework = arduino

build_flags =
  -L"lib/STM32duino MotionFX/src/cortex-m4/fpv4-sp-d16-hard"
  -lMotionFX

lib_ldf_mode = deep+

lib_deps = 
           Wire
           SPI

lib_archive = false

upload_protocol = stlink

  • I have libMotionFX.a file only this path \lib\STM32duino MotionFX\src\cortex-m4\fpv4-sp-d16-hard\libMotionFX.a

  • The rest I deleted out, and I used the example file name Fusion9X_IKS01A3.ino

  • the .pio\libdeps is empty, no file

I still cannot compile, same error

src\main.cpp:108:24: error: 'MFXState_t' was not declared in this scope
  108 |   MotionFX_initialize((MFXState_t *)mfxstate);
      |                        ^~~~~~~~~~Compiling .pio\build\nucleo_f401re\FrameworkArduino\pins_arduino.c.o

src\main.cpp:108:36: error: expected primary-expression before ')' token
  108 |   MotionFX_initialize((MFXState_t *)mfxstate);
      |                                    ^
src\main.cpp:108:3: error: 'MotionFX_initialize' was not declared in this scope; did you mean 'MotionFX_CM0P_initialize'?
  108 |   MotionFX_initialize((MFXState_t *)mfxstate);
      |   ^~~~~~~~~~~~~~~~~~~

I have 3 libraries in the \lib folder :
\lib\STM32duino MotionFX
\lib\STM32duino LSM6DSO
\lib\STM32duino LIS2MDL

This is working fine

the GitHub - maxgerhardt/pio_motionfx_workaround

Let me learn from this

Thank you!

Are you sure you have

#include <Arduino.h>
#if (__CORTEX_M == 0U)
#include "motion_fx_cm0p.h"
#else
#include "motion_fx.h"
#endif
#include "LSM6DSLSensor.h"

at the top, this type is in motion_fx.h.

1 Like

Yes, I got it working.
Thank you!
You are real expert!